* ============LICENSE_START==========================================
* ONAP Portal
* ===================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ===================================================================
*
* Unless otherwise specified, all software contained herein is licensed
*
* ============LICENSE_END============================================
*
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ *
*/
package org.onap.portalapp.portal.service;
import org.apache.commons.lang.StringUtils;
import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.jaxrs.impl.ResponseImpl;
import org.apache.cxf.transport.http.HTTPException;
import org.onap.portalapp.portal.domain.EPApp;
import org.onap.portalapp.portal.logging.aop.EPAuditLog;
logger.debug(EELFLoggerDelegate.debugLogger, "http response status=" + status);
MDC.put(EPCommonSystemProperties.EXTERNAL_API_RESPONSE_CODE, Integer.toString(status));
if (!isHttpSuccess(status)) {
- String errMsg = "Failed. Status=" + status + "; [" + response.getStatusInfo().getReasonPhrase().toString()
+ String errMsg = "Failed. Status=" + status + "; [" + ((ResponseImpl)response).getStatusInfo().getReasonPhrase().toString()
+ "]";
URL url = null;
try {
// must not be null to avoid NPE in HTTPException constructor
url = new URL("http://null");
- if (response.getLocation() != null)
- url = response.getLocation().toURL();
+ if (((ResponseImpl)response).getLocation() != null)
+ url = ((ResponseImpl)response).getLocation().toURL();
} catch (MalformedURLException e) {
// never mind. it is only for the debug message.
logger.warn(EELFLoggerDelegate.errorLogger, "Failed to build URL", e);
if (response != null) {
verifyResponse(response);
- String str = response.readEntity(String.class);
+
+ /* It is not recommendable to use the implementation class org.apache.cxf.jaxrs.impl.ResponseImpl in the code,
+ but had to force this in-order to prevent conflict with the ResponseImpl class of Jersey Client which
+ doesn't work as expected. Created Portal-253 for tracking */
+ String str = ((ResponseImpl)response).readEntity(String.class);
+
EcompPortalUtils.logAndSerializeObject(logger, restPath, "GET result =", str);
try {
t = gson.fromJson(str, clazz);
if (response != null) {
verifyResponse(response);
- String incomingJson = response.readEntity(String.class);
+
+ /* It is not recommendable to use the implementation class org.apache.cxf.jaxrs.impl.ResponseImpl in the code,
+ but had to force this in-order to prevent conflict with the ResponseImpl class of Jersey Client which
+ doesn't work as expected. Created Portal-253 for tracking */
+ String incomingJson = ((ResponseImpl)response).readEntity(String.class);
return incomingJson;
}
if (response != null) {
verifyResponse(response);
- String str = response.readEntity(String.class);
+ String str = ((ResponseImpl)response).readEntity(String.class);
EcompPortalUtils.logAndSerializeObject(logger, restPath, "GET result =", str);
try {
// String contentType = response.getHeaderString("Content-Type");
if (clazz != null) {
- String str = response.readEntity(String.class);
+ String str = ((ResponseImpl)response).readEntity(String.class);
EcompPortalUtils.logAndSerializeObject(logger, restPath, "POST result =", str);
try {
t = gson.fromJson(str, clazz);
return post( clazz, appId, payload, restPath, SystemType.APPLICATION);
}
- //@Override
- public <T> T postForClass(Class<T> clazz, long appId, Object payload, String restPath, Class<T> forClass) throws HTTPException {
- WebClient client = null;
- Response response = null;
- T t = null;
- logger.debug(EELFLoggerDelegate.debugLogger, "Entering to createClientForApp method for payload: {} and restPath: {} and appId: {}", payload.toString(), restPath, appId);
- client = createClientForApp(appId, restPath);
- EcompPortalUtils.logAndSerializeObject(logger, restPath, "POST request =", payload);
- logger.debug(EELFLoggerDelegate.debugLogger, "Finished createClientForApp method for payload: {} and restPath: {} and appId: {}", payload.toString(), restPath, appId);
- try {
- if (client != null) {
- logger.debug(EELFLoggerDelegate.debugLogger, "Entering to POST for payload: {} and restPath: {} and appId: {}", payload.toString(), restPath, appId);
- response = client.post(payload);
- logger.debug(EELFLoggerDelegate.debugLogger, "Finished to POST for payload: {} and restPath: {} and appId: {}", payload.toString(), restPath, appId);
- } else {
- logger.error(EELFLoggerDelegate.errorLogger,
- "Unable to create the Webclient to make the '" + restPath + "' API call.");
- }
- } catch (Exception e) {
- MDC.put(EPCommonSystemProperties.EXTERNAL_API_RESPONSE_CODE,
- Integer.toString(HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
- EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeRestApiGeneralError, e);
- logger.error(EELFLoggerDelegate.errorLogger, "Exception occurred while making the POST REST API call", e);
- }
-
- if (response != null) {
- verifyResponse(response);
-
- // String contentType = response.getHeaderString("Content-Type");
- if (clazz != null) {
- String str = response.readEntity(String.class);
- EcompPortalUtils.logAndSerializeObject(logger, restPath, "POST result =", str);
- try {
- t = gson.fromJson(str, clazz);
- } catch (Exception e) {
- EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeInvalidJsonInput, e);
- }
- }
- }
- return t;
- }
-
@Override
public <T> T put(Class<T> clazz, long appId, Object payload, String restPath) throws HTTPException {
if (response != null) {
verifyResponse(response);
- String str = response.readEntity(String.class);
+ String str = ((ResponseImpl)response).readEntity(String.class);
EcompPortalUtils.logAndSerializeObject(logger, restPath, "PUT result =", str);
try {
t = gson.fromJson(str, clazz);