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));
}
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);
}
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);
}
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);
}
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;
}
Aggregations