Search in sources :

Example 1 with HTTPEndpointFactory

use of org.apache.synapse.config.xml.endpoints.HTTPEndpointFactory in project wso2-synapse by wso2.

the class HttpEndpointTest method testQueryParamsAsUnreservedChars.

/**
 * Tests sending sample characters that may be unreserved (@,: etc) as query parameter content
 */
@Test
public void testQueryParamsAsUnreservedChars() throws AxisFault, XMLStreamException {
    HTTPEndpointFactory factory = new HTTPEndpointFactory();
    OMElement em = AXIOMUtil.stringToOM("<endpoint><http method=\"GET\" uri-template=\"http://abc.com?symbol={+query.param.symbol}&amp;user={+query.param.user}\"/></endpoint>");
    EndpointDefinition ep1 = factory.createEndpointDefinition(em);
    HTTPEndpoint httpEndpoint = new HTTPEndpoint();
    httpEndpoint.setHttpMethod("GET");
    httpEndpoint.setDefinition(ep1);
    httpEndpoint.setUriTemplate(UriTemplate.fromTemplate("http://abc.com?symbol={+query.param.symbol}&amp;user={+query.param.user}"));
    SynapseEnvironment synapseEnvironment = getMockedSynapseEnvironment();
    httpEndpoint.init(getMockedSynapseEnvironment());
    MessageContext messageContext = createMessageContext();
    messageContext.setProperty("query.param.symbol", "US:123");
    messageContext.setProperty("query.param.user", "john@gmail");
    // set mocked SynapseEnvironment to message context
    ((Axis2MessageContext) messageContext).getAxis2MessageContext().getConfigurationContext().getAxisConfiguration().addParameter(SynapseConstants.SYNAPSE_ENV, synapseEnvironment);
    messageContext.setEnvironment(synapseEnvironment);
    httpEndpoint.executeEpTypeSpecificFunctions(messageContext);
    Assert.assertEquals("Reserved characters need to be sent in default format without encoding", "http://abc.com?symbol=US:123&amp;user=john@gmail", messageContext.getTo().getAddress().toString());
}
Also used : HTTPEndpointFactory(org.apache.synapse.config.xml.endpoints.HTTPEndpointFactory) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) OMElement(org.apache.axiom.om.OMElement) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Test(org.junit.Test)

Example 2 with HTTPEndpointFactory

use of org.apache.synapse.config.xml.endpoints.HTTPEndpointFactory in project wso2-synapse by wso2.

the class HttpEndpointTest method testQueryParamsAsReservedChars.

/**
 * Tests sending sample reserved characters(@,:) as query parameter content
 * @throws AxisFault
 * @throws XMLStreamException
 */
@Test
public void testQueryParamsAsReservedChars() throws AxisFault, XMLStreamException {
    HTTPEndpointFactory factory = new HTTPEndpointFactory();
    OMElement em = AXIOMUtil.stringToOM("<endpoint><http method=\"GET\" uri-template=\"http://abc.com?symbol={query.param.symbol}&amp;user={query.param.user}\"/></endpoint>");
    EndpointDefinition ep1 = factory.createEndpointDefinition(em);
    HTTPEndpoint httpEndpoint = new HTTPEndpoint();
    httpEndpoint.setHttpMethod("GET");
    httpEndpoint.setDefinition(ep1);
    httpEndpoint.setUriTemplate(UriTemplate.fromTemplate("http://abc.com?symbol={query.param.symbol}&amp;user={query.param.user}"));
    SynapseEnvironment synapseEnvironment = getMockedSynapseEnvironment();
    httpEndpoint.init(getMockedSynapseEnvironment());
    MessageContext messageContext = createMessageContext();
    messageContext.setProperty("query.param.symbol", "US:123");
    messageContext.setProperty("query.param.user", "john@gmail");
    // set mocked SynapseEnvironment to message context
    ((Axis2MessageContext) messageContext).getAxis2MessageContext().getConfigurationContext().getAxisConfiguration().addParameter(SynapseConstants.SYNAPSE_ENV, synapseEnvironment);
    messageContext.setEnvironment(synapseEnvironment);
    httpEndpoint.executeEpTypeSpecificFunctions(messageContext);
    Assert.assertEquals("Reserved characters need to be encoded", "http://abc.com?symbol=US%3A123&amp;user=john%40gmail", messageContext.getTo().getAddress().toString());
}
Also used : HTTPEndpointFactory(org.apache.synapse.config.xml.endpoints.HTTPEndpointFactory) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) OMElement(org.apache.axiom.om.OMElement) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Test(org.junit.Test)

Example 3 with HTTPEndpointFactory

use of org.apache.synapse.config.xml.endpoints.HTTPEndpointFactory in project wso2-synapse by wso2.

the class HttpEndpointTest method testQueryParamsWithLegacyEncoding.

/**
 * Test usage of legacy-encoding property where encoded values will be decoded
 * @throws AxisFault
 * @throws XMLStreamException
 */
@Test
public void testQueryParamsWithLegacyEncoding() throws AxisFault, XMLStreamException {
    HTTPEndpointFactory factory = new HTTPEndpointFactory();
    OMElement em = AXIOMUtil.stringToOM("<endpoint><http method=\"GET\" uri-template=\"http://abc.com?symbol={query.param.symbol}&amp;user={query.param.user}\"/></endpoint>");
    EndpointDefinition ep1 = factory.createEndpointDefinition(em);
    HTTPEndpoint httpEndpoint = new HTTPEndpoint();
    httpEndpoint.setHttpMethod("GET");
    httpEndpoint.setLegacySupport(true);
    httpEndpoint.setDefinition(ep1);
    httpEndpoint.setUriTemplate(UriTemplate.fromTemplate("http://abc.com?symbol={query.param.symbol}&amp;user={query.param.user}"));
    SynapseEnvironment synapseEnvironment = getMockedSynapseEnvironment();
    httpEndpoint.init(getMockedSynapseEnvironment());
    MessageContext messageContext = createMessageContext();
    messageContext.setProperty("query.param.symbol", "US%3A123");
    messageContext.setProperty("query.param.user", "john%40G%C3%BCnter");
    // set mocked SynapseEnvironment to message context
    ((Axis2MessageContext) messageContext).getAxis2MessageContext().getConfigurationContext().getAxisConfiguration().addParameter(SynapseConstants.SYNAPSE_ENV, synapseEnvironment);
    messageContext.setEnvironment(synapseEnvironment);
    httpEndpoint.executeEpTypeSpecificFunctions(messageContext);
    Assert.assertEquals("With legacy encoding encoded characters need to be decoded", "http://abc.com?symbol=US:123&amp;user=john@Günter", messageContext.getTo().getAddress().toString());
}
Also used : HTTPEndpointFactory(org.apache.synapse.config.xml.endpoints.HTTPEndpointFactory) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) OMElement(org.apache.axiom.om.OMElement) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Test(org.junit.Test)

Aggregations

OMElement (org.apache.axiom.om.OMElement)3 MessageContext (org.apache.synapse.MessageContext)3 HTTPEndpointFactory (org.apache.synapse.config.xml.endpoints.HTTPEndpointFactory)3 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)3 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)3 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)3 Test (org.junit.Test)3