use of org.apache.axis2.builder.XFormURLEncodedBuilder in project wso2-synapse by wso2.
the class XFormURLEncodedBuilderTest method testProcessDocumentPostMethod.
/**
* Test XFormURLEncodedBuilder with HTTP POST method
* @throws AxisFault
*/
public void testProcessDocumentPostMethod() throws AxisFault {
String expectedSoapEnvelope = "<?xml version='1.0' encoding='utf-8'?>" + "<soapenv:Envelope xmlns:soapenv=\"http://www.w3.org/2003/05/soap-envelope\">" + "<soapenv:Body>" + "<xformValues>" + "<price>10</price>" + "<symbol>WSO2</symbol>" + "</xformValues>" + "</soapenv:Body>" + "</soapenv:Envelope>";
String expectedSoapEnvelope2 = "<?xml version='1.0' encoding='utf-8'?>" + "<soapenv:Envelope xmlns:soapenv=\"http://www.w3.org/2003/05/soap-envelope\">" + "<soapenv:Body>" + "<xformValues>" + "<symbol>WSO2</symbol>" + "<price>10</price>" + "</xformValues>" + "</soapenv:Body>" + "</soapenv:Envelope>";
MessageContext messageContext = Util.newMessageContext();
messageContext.setTo(new EndpointReference("http://localhost:9000/stockquote/test?symbol=WSO2&price=10"));
messageContext.setProperty(HTTPConstants.HTTP_METHOD, "POST");
XFormURLEncodedBuilder urlEncodedBuilder = new XFormURLEncodedBuilder();
OMElement element = urlEncodedBuilder.processDocument(null, "", messageContext);
boolean assertion = expectedSoapEnvelope.equals(element.toString()) || expectedSoapEnvelope2.equals(element.toString());
assertTrue("Invalid SOAPEnvelope received", assertion);
}
use of org.apache.axis2.builder.XFormURLEncodedBuilder in project wso2-synapse by wso2.
the class XFormURLEncodedBuilderTest method testExtractMultipleParametersUsingHttpLocation.
/**
* Test extracting multiple parameters from 'whttp:location'
* @throws AxisFault
*/
public void testExtractMultipleParametersUsingHttpLocation() throws AxisFault {
AxisBindingOperation axisBindingOperation = new AxisBindingOperation();
axisBindingOperation.setProperty("whttp:location", "books/{category}/{name}");
MessageContext messageContext = Util.newMessageContext();
messageContext.setProperty("AxisBindingOperation", axisBindingOperation);
messageContext.setTo(new EndpointReference("http://localhost:9000/store"));
XFormURLEncodedBuilder urlEncodedBuilder = new XFormURLEncodedBuilder();
urlEncodedBuilder.processDocument(null, "", messageContext);
assertNotNull("Parameter 'category' not found in request parameter map", ((MultipleEntryHashMap) messageContext.getProperty(Constants.REQUEST_PARAMETER_MAP)).get("category"));
assertNotNull("Parameter 'name' not found in request parameter map", ((MultipleEntryHashMap) messageContext.getProperty(Constants.REQUEST_PARAMETER_MAP)).get("name"));
}
use of org.apache.axis2.builder.XFormURLEncodedBuilder in project wso2-synapse by wso2.
the class XFormURLEncodedBuilderTest method testProcessDocument.
/**
* Test XFormURLEncodedBuilder
* @throws AxisFault
*/
public void testProcessDocument() throws AxisFault {
String expectedSoapEnvelope = "<?xml version='1.0' encoding='utf-8'?>" + "<soapenv:Envelope xmlns:soapenv=\"http://www.w3.org/2003/05/soap-envelope\">" + "<soapenv:Body />" + "</soapenv:Envelope>";
MessageContext messageContext = Util.newMessageContext();
messageContext.setTo(new EndpointReference("http://localhost:9000/stockquote/test?symbol=WSO2&price=10"));
XFormURLEncodedBuilder urlEncodedBuilder = new XFormURLEncodedBuilder();
OMElement element = urlEncodedBuilder.processDocument(null, "", messageContext);
assertEquals("Invalid SOAPEnvelope received", expectedSoapEnvelope, element.toString());
}
use of org.apache.axis2.builder.XFormURLEncodedBuilder in project wso2-synapse by wso2.
the class XFormURLEncodedBuilderTest method testExtractParametersFromInputStream.
/**
* Test extracting parameters from input stream
* @throws AxisFault
*/
public void testExtractParametersFromInputStream() throws AxisFault {
MessageContext messageContext = Util.newMessageContext();
messageContext.setTo(new EndpointReference("http://localhost:9000/stockquote/"));
messageContext.setProperty("CHARACTER_SET_ENCODING", "UTF-8");
InputStream inputStream = new ByteArrayInputStream("symbol=WSO2&price=10".getBytes());
XFormURLEncodedBuilder urlEncodedBuilder = new XFormURLEncodedBuilder();
urlEncodedBuilder.processDocument(inputStream, "", messageContext);
assertNotNull("Parameter 'symbol' not found in request parameter map", ((MultipleEntryHashMap) messageContext.getProperty(Constants.REQUEST_PARAMETER_MAP)).get("symbol"));
assertNotNull("Parameter 'price' not found in request parameter map", ((MultipleEntryHashMap) messageContext.getProperty(Constants.REQUEST_PARAMETER_MAP)).get("price"));
}
use of org.apache.axis2.builder.XFormURLEncodedBuilder in project wso2-synapse by wso2.
the class XFormURLEncodedBuilderTest method testExtractMultipleParametersUsingHttpLocation2.
/**
* Test extracting parameter from 'whttp:location'
* @throws AxisFault
*/
public void testExtractMultipleParametersUsingHttpLocation2() throws AxisFault {
AxisBindingOperation axisBindingOperation = new AxisBindingOperation();
axisBindingOperation.setProperty("whttp:location", "books/{name}/");
MessageContext messageContext = Util.newMessageContext();
messageContext.setProperty("AxisBindingOperation", axisBindingOperation);
messageContext.setTo(new EndpointReference("http://localhost:9000/store"));
XFormURLEncodedBuilder urlEncodedBuilder = new XFormURLEncodedBuilder();
urlEncodedBuilder.processDocument(null, "", messageContext);
assertNotNull("Parameter 'name' not found in request parameter map", ((MultipleEntryHashMap) messageContext.getProperty(Constants.REQUEST_PARAMETER_MAP)).get("name"));
}
Aggregations