Search in sources :

Example 1 with XFormURLEncodedFormatter

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

the class XFormURLEncodedFormatterTest method testGetBytes.

public void testGetBytes() throws AxisFault, XMLStreamException {
    XFormURLEncodedFormatter formatter = new XFormURLEncodedFormatter();
    MessageContext messageContext = Util.newMessageContext("<test><test>123</test></test>");
    byte[] bytes = formatter.getBytes(messageContext, new OMOutputFormat());
    assertEquals("Invalid X-form URL Encoded string", "test=123", new String(bytes));
}
Also used : MessageContext(org.apache.axis2.context.MessageContext) OMOutputFormat(org.apache.axiom.om.OMOutputFormat)

Example 2 with XFormURLEncodedFormatter

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

the class XFormURLEncodedFormatterTest method testGetContentTypeWithSoapAction.

public void testGetContentTypeWithSoapAction() throws AxisFault, XMLStreamException {
    XFormURLEncodedFormatter formatter = new XFormURLEncodedFormatter();
    MessageContext messageContext = Util.newMessageContext();
    String contentType = formatter.getContentType(messageContext, new OMOutputFormat(), "urn:mediate");
    assertEquals("Invalid content type", "application/x-www-form-urlencoded;action=\"urn:mediate\";", contentType);
}
Also used : MessageContext(org.apache.axis2.context.MessageContext) OMOutputFormat(org.apache.axiom.om.OMOutputFormat)

Example 3 with XFormURLEncodedFormatter

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

the class XFormURLEncodedFormatterTest method testGetContentType.

public void testGetContentType() throws AxisFault, XMLStreamException {
    XFormURLEncodedFormatter formatter = new XFormURLEncodedFormatter();
    MessageContext messageContext = Util.newMessageContext();
    String contentType = formatter.getContentType(messageContext, new OMOutputFormat(), "");
    assertEquals("Invalid content type", "application/x-www-form-urlencoded", contentType);
}
Also used : MessageContext(org.apache.axis2.context.MessageContext) OMOutputFormat(org.apache.axiom.om.OMOutputFormat)

Example 4 with XFormURLEncodedFormatter

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

the class XFormURLEncodedFormatterTest method testGetContentTypeWithCharsetEncoding.

public void testGetContentTypeWithCharsetEncoding() throws AxisFault {
    OMOutputFormat format = new OMOutputFormat();
    format.setCharSetEncoding("UTF-8");
    XFormURLEncodedFormatter formatter = new XFormURLEncodedFormatter();
    MessageContext messageContext = Util.newMessageContext();
    String contentType = formatter.getContentType(messageContext, format, "");
    assertEquals("Invalid content type", "application/x-www-form-urlencoded; charset=UTF-8", contentType);
}
Also used : MessageContext(org.apache.axis2.context.MessageContext) OMOutputFormat(org.apache.axiom.om.OMOutputFormat)

Example 5 with XFormURLEncodedFormatter

use of org.apache.axis2.transport.http.XFormURLEncodedFormatter 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

OMOutputFormat (org.apache.axiom.om.OMOutputFormat)4 MessageContext (org.apache.axis2.context.MessageContext)4 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