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}&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}&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&user=john@gmail", messageContext.getTo().getAddress().toString());
}
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}&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}&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&user=john%40gmail", messageContext.getTo().getAddress().toString());
}
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}&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}&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&user=john@Günter", messageContext.getTo().getAddress().toString());
}
Aggregations