log.error(errmsg);
odeMex.replyWithFailure(MessageExchange.FailureType.OTHER, errmsg, HttpClientHelper.prepareDetailsElement(method));
}
private void _2xx_success() {
PartnerRoleMessageExchange odeMex = (PartnerRoleMessageExchange) server.getEngine().getMessageExchange(mexId);
if (log.isDebugEnabled()) log.debug("Http Status Line=" + method.getStatusLine());
if (log.isDebugEnabled()) log.debug("Received response for MEX " + odeMex);
Operation opDef = odeMex.getOperation();
BindingOperation opBinding = portBinding.getBindingOperation(opDef.getName(), opDef.getInput().getName(), opDef.getOutput().getName());
// assumption is made that a response may have at most one body. HttpBindingValidator checks this.
MIMEContent outputContent = WsdlUtils.getMimeContent(opBinding.getBindingOutput().getExtensibilityElements());
boolean isBodyMandatory = outputContent != null && outputContent.getType().endsWith("text/xml");
try {
final InputStream bodyAsStream = method.getResponseBodyAsStream();
if (isBodyMandatory && bodyAsStream == null) {
String errmsg = "Response body is mandatory but missing! Msg Id=" + odeMex.getMessageExchangeId();
log.error(errmsg);
odeMex.replyWithFailure(MessageExchange.FailureType.OTHER, errmsg, null);
} else {
javax.wsdl.Message outputMessage = odeMex.getOperation().getOutput().getMessage();
Message odeResponse = odeMex.createMessage(outputMessage.getQName());
// handle the body if any
if (bodyAsStream != null) {
// only text/xml is supported in the response body
try {
Element bodyElement = DOMUtils.parse(bodyAsStream).getDocumentElement();
// we expect a single part per output message
// see org.apache.ode.axis2.httpbinding.HttpBindingValidator call in constructor
Part part = (Part) outputMessage.getParts().values().iterator().next();
Element partElement = httpMethodConverter.createPartElement(part, bodyElement);
odeResponse.setPart(part.getName(), partElement);
} catch (Exception e) {
String errmsg = "Unable to parse the response body: " + e.getMessage();
log.error(errmsg, e);
odeMex.replyWithFailure(MessageExchange.FailureType.FORMAT_ERROR, errmsg, null);
return;
}
}
// handle headers
httpMethodConverter.extractHttpResponseHeaders(odeResponse, method, outputMessage, opBinding.getBindingOutput());
try {
if (log.isInfoEnabled())
log.info("Response:\n" + DOMUtils.domToString(odeResponse.getMessage()));
odeMex.reply(odeResponse);
} catch (Exception ex) {
String errmsg = "Unable to process response: " + ex.getMessage();
log.error(errmsg, ex);
odeMex.replyWithFailure(MessageExchange.FailureType.OTHER, errmsg, HttpClientHelper.prepareDetailsElement(method));
}
}
} catch (IOException e) {
String errmsg = "Unable to get the request body : " + e.getMessage();
log.error(errmsg, e);
odeMex.replyWithFailure(MessageExchange.FailureType.FORMAT_ERROR, errmsg, null);
return;
}
}