Search in sources :

Example 1 with ApplicationXMLFormatter

use of org.apache.axis2.transport.http.ApplicationXMLFormatter in project wso2-synapse by wso2.

the class MessageUtils method getMessageFormatter.

/**
 * This selects the formatter for a given message format based on the the content type of the received message.
 * content-type to builder mapping can be specified through the Axis2.xml.
 *
 * @param msgContext axis2 MessageContext
 * @return the formatter registered against the given content-type
 */
public static MessageFormatter getMessageFormatter(MessageContext msgContext) {
    MessageFormatter messageFormatter = null;
    String messageFormatString = getMessageFormatterProperty(msgContext);
    messageFormatString = getContentTypeForFormatterSelection(messageFormatString, msgContext);
    if (messageFormatString != null) {
        messageFormatter = msgContext.getConfigurationContext().getAxisConfiguration().getMessageFormatter(messageFormatString);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Message format is: " + messageFormatString + "; message formatter returned by AxisConfiguration: " + messageFormatter);
        }
    }
    if (messageFormatter == null) {
        messageFormatter = (MessageFormatter) msgContext.getProperty(Constants.Configuration.MESSAGE_FORMATTER);
        if (messageFormatter != null) {
            return messageFormatter;
        }
    }
    if (messageFormatter == null) {
        // If we are doing rest better default to Application/xml formatter
        if (msgContext.isDoingREST()) {
            String httpMethod = (String) msgContext.getProperty(Constants.Configuration.HTTP_METHOD);
            if (Constants.Configuration.HTTP_METHOD_GET.equals(httpMethod) || Constants.Configuration.HTTP_METHOD_DELETE.equals(httpMethod)) {
                return new XFormURLEncodedFormatter();
            }
            return new ApplicationXMLFormatter();
        } else {
            // Lets default to SOAP formatter
            messageFormatter = new SOAPMessageFormatter();
        }
    }
    return messageFormatter;
}
Also used : XFormURLEncodedFormatter(org.apache.axis2.transport.http.XFormURLEncodedFormatter) SOAPMessageFormatter(org.apache.axis2.transport.http.SOAPMessageFormatter) MessageFormatter(org.apache.axis2.transport.MessageFormatter) SOAPMessageFormatter(org.apache.axis2.transport.http.SOAPMessageFormatter) ApplicationXMLFormatter(org.apache.axis2.transport.http.ApplicationXMLFormatter)

Aggregations

MessageFormatter (org.apache.axis2.transport.MessageFormatter)1 ApplicationXMLFormatter (org.apache.axis2.transport.http.ApplicationXMLFormatter)1 SOAPMessageFormatter (org.apache.axis2.transport.http.SOAPMessageFormatter)1 XFormURLEncodedFormatter (org.apache.axis2.transport.http.XFormURLEncodedFormatter)1