private String getHostHeader(org.apache.axis2.context.MessageContext msgCtx) { Map transportHeaders = (Map) msgCtx.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS); String hostHeader = null; if (transportHeaders != null) { hostHeader = (String) transportHeaders.get(HTTP.TARGET_HOST); } if (hostHeader == null) { hostHeader = (String) msgCtx.getProperty(NhttpConstants.SERVICE_PREFIX); } return hostHeader; }
// This is copied from PropertyMediator, required to change Content-Type private void handleSpecialProperties( Object resultValue, org.apache.axis2.context.MessageContext axis2MessageCtx) { axis2MessageCtx.setProperty(org.apache.axis2.Constants.Configuration.CONTENT_TYPE, resultValue); Object o = axis2MessageCtx.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS); Map headers = (Map) o; if (headers != null) { headers.remove(HTTP.CONTENT_TYPE); headers.put(HTTP.CONTENT_TYPE, resultValue); } }
/** * Sets the content type based on the request content type and payload factory media type. This * should be called at the end before returning from the mediate() function. * * @param synCtx */ private void setContentType(MessageContext synCtx) { org.apache.axis2.context.MessageContext a2mc = ((Axis2MessageContext) synCtx).getAxis2MessageContext(); if (mediaType.equals(XML_TYPE)) { if (!XML_CONTENT_TYPE.equals(a2mc.getProperty(Constants.Configuration.MESSAGE_TYPE)) && !SOAP11_CONTENT_TYPE.equals(a2mc.getProperty(Constants.Configuration.MESSAGE_TYPE)) && !SOAP12_CONTENT_TYPE.equals(a2mc.getProperty(Constants.Configuration.MESSAGE_TYPE))) { a2mc.setProperty(Constants.Configuration.MESSAGE_TYPE, XML_CONTENT_TYPE); a2mc.setProperty(Constants.Configuration.CONTENT_TYPE, XML_CONTENT_TYPE); handleSpecialProperties(XML_CONTENT_TYPE, a2mc); } } else if (mediaType.equals(JSON_TYPE)) { a2mc.setProperty(Constants.Configuration.MESSAGE_TYPE, JSON_CONTENT_TYPE); a2mc.setProperty(Constants.Configuration.CONTENT_TYPE, JSON_CONTENT_TYPE); handleSpecialProperties(JSON_CONTENT_TYPE, a2mc); } else if (mediaType.equals(TEXT_TYPE)) { a2mc.setProperty(Constants.Configuration.MESSAGE_TYPE, TEXT_CONTENT_TYPE); a2mc.setProperty(Constants.Configuration.CONTENT_TYPE, TEXT_CONTENT_TYPE); handleSpecialProperties(TEXT_CONTENT_TYPE, a2mc); } a2mc.removeProperty("NO_ENTITY_BODY"); }