private void setHttpMethod(HTTPEndpoint httpEndpoint, String httpMethod) { if (httpMethod != null) { if (httpMethod.equalsIgnoreCase(Constants.Configuration.HTTP_METHOD_POST)) { httpEndpoint.setHttpMethod(Constants.Configuration.HTTP_METHOD_POST); } else if (httpMethod.equalsIgnoreCase(Constants.Configuration.HTTP_METHOD_GET)) { httpEndpoint.setHttpMethod(Constants.Configuration.HTTP_METHOD_GET); } else if (httpMethod.equalsIgnoreCase(Constants.Configuration.HTTP_METHOD_PUT)) { httpEndpoint.setHttpMethod(Constants.Configuration.HTTP_METHOD_PUT); } else if (httpMethod.equalsIgnoreCase(Constants.Configuration.HTTP_METHOD_DELETE)) { httpEndpoint.setHttpMethod(Constants.Configuration.HTTP_METHOD_DELETE); } else if (httpMethod.equalsIgnoreCase(Constants.Configuration.HTTP_METHOD_HEAD)) { httpEndpoint.setHttpMethod(Constants.Configuration.HTTP_METHOD_HEAD); } else if (httpMethod.equalsIgnoreCase(Constants.Configuration.HTTP_METHOD_PATCH)) { httpEndpoint.setHttpMethod(Constants.Configuration.HTTP_METHOD_PATCH); } else if (httpMethod.equalsIgnoreCase(RESTConstants.METHOD_OPTIONS)) { httpEndpoint.setHttpMethod(RESTConstants.METHOD_OPTIONS); } else { if (log.isDebugEnabled()) { log.debug("Invalid http method specified." + "Hence using the http method from incoming message"); } } } }
/** * 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()); }
/** * 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()); }
/** * 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()); }