Search in sources :

Example 1 with XFormURLEncodedBuilder

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);
}
Also used : OMElement(org.apache.axiom.om.OMElement) MessageContext(org.apache.axis2.context.MessageContext) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 2 with XFormURLEncodedBuilder

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"));
}
Also used : AxisBindingOperation(org.apache.axis2.description.AxisBindingOperation) MessageContext(org.apache.axis2.context.MessageContext) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 3 with XFormURLEncodedBuilder

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());
}
Also used : OMElement(org.apache.axiom.om.OMElement) MessageContext(org.apache.axis2.context.MessageContext) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 4 with XFormURLEncodedBuilder

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"));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MessageContext(org.apache.axis2.context.MessageContext) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 5 with XFormURLEncodedBuilder

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"));
}
Also used : AxisBindingOperation(org.apache.axis2.description.AxisBindingOperation) MessageContext(org.apache.axis2.context.MessageContext) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Aggregations

EndpointReference (org.apache.axis2.addressing.EndpointReference)5 MessageContext (org.apache.axis2.context.MessageContext)5 OMElement (org.apache.axiom.om.OMElement)2 AxisBindingOperation (org.apache.axis2.description.AxisBindingOperation)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1