Bus bus = ((CxfRsEndpoint)getEndpoint()).getBus();
// We need to apply the bus setting from the CxfRsEndpoint which is not use the default bus
if (bus != null) {
cfb.setBus(bus);
}
WebClient client = cfb.createWebClient();
String httpMethod = inMessage.getHeader(Exchange.HTTP_METHOD, String.class);
Class<?> responseClass = inMessage.getHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Class.class);
Type genericType = inMessage.getHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_GENERIC_TYPE, Type.class);
Object[] pathValues = inMessage.getHeader(CxfConstants.CAMEL_CXF_RS_VAR_VALUES, Object[].class);
String path = inMessage.getHeader(Exchange.HTTP_PATH, String.class);
if (LOG.isTraceEnabled()) {
LOG.trace("HTTP method = {}", httpMethod);
LOG.trace("path = {}", path);
LOG.trace("responseClass = {}", responseClass);
}
// set the path
if (path != null) {
if (ObjectHelper.isNotEmpty(pathValues) && pathValues.length > 0) {
client.path(path, pathValues);
} else {
client.path(path);
}
}
CxfRsEndpoint cxfRsEndpoint = (CxfRsEndpoint) getEndpoint();
CxfRsBinding binding = cxfRsEndpoint.getBinding();
// set the body
Object body = null;
if (!"GET".equals(httpMethod)) {
// need to check the request object if the http Method is not GET
if ("DELETE".equals(httpMethod) && cxfRsEndpoint.isIgnoreDeleteMethodMessageBody()) {
// just ignore the message body if the ignoreDeleteMethodMessageBody is true
} else {
body = binding.bindCamelMessageBodyToRequestBody(inMessage, exchange);
if (LOG.isTraceEnabled()) {
LOG.trace("Request body = " + body);
}
}
}
setupClientQueryAndHeaders(client, exchange);
// invoke the client
Object response = null;
if (responseClass == null || Response.class.equals(responseClass)) {
response = client.invoke(httpMethod, body);
} else {
if (Collection.class.isAssignableFrom(responseClass)) {
if (genericType instanceof ParameterizedType) {
// Get the collection member type first
Type[] actualTypeArguments = ((ParameterizedType) genericType).getActualTypeArguments();
response = client.invokeAndGetCollection(httpMethod, body, (Class<?>) actualTypeArguments[0]);
} else {
throw new CamelExchangeException("Header " + CxfConstants.CAMEL_CXF_RS_RESPONSE_GENERIC_TYPE + " not found in message", exchange);
}
} else {
response = client.invoke(httpMethod, body, responseClass);
}
}
int statesCode = client.getResponse().getStatus();
//Throw exception on a response > 207
//http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
if (throwException) {
if (response instanceof Response) {
Integer respCode = ((Response) response).getStatus();