Search in sources :

Example 1 with HTTPEndpoint

use of org.apache.synapse.endpoints.HTTPEndpoint in project wso2-synapse by wso2.

the class HTTPEndpointSerializerTest method test.

public void test() throws Exception {
    String inputXml = "<endpoint  xmlns=\"http://ws.apache.org/ns/synapse\">" + "<http uri-template=\"URI Template\" method=\"GET\" />" + "</endpoint>";
    OMElement inputElement = AXIOMUtil.stringToOM(inputXml);
    HTTPEndpoint endpoint = (HTTPEndpoint) HTTPEndpointFactory.getEndpointFromElement(inputElement, true, null);
    OMElement serializedResponse = HTTPEndpointSerializer.getElementFromEndpoint(endpoint);
    assertTrue("Endpoint not serialized!", compare(serializedResponse, inputElement));
}
Also used : HTTPEndpoint(org.apache.synapse.endpoints.HTTPEndpoint) OMElement(org.apache.axiom.om.OMElement)

Example 2 with HTTPEndpoint

use of org.apache.synapse.endpoints.HTTPEndpoint in project carbon-apimgt by wso2.

the class WebSocketUtils method getEndpointUrl.

/**
 * Gets the uri-template of the endpoint, which has been specified in the given resource.
 * @param resource  API Resource
 * @param synCtx    MessageContext
 * @return          URI template
 */
public static String getEndpointUrl(Resource resource, MessageContext synCtx) {
    Optional<Mediator> filterMediator = resource.getInSequence().getList().stream().filter(m -> m instanceof FilterMediator).findFirst();
    if (filterMediator.isPresent()) {
        Optional<Mediator> sendMediator = ((FilterMediator) filterMediator.get()).getList().stream().filter(m -> m instanceof SendMediator).findFirst();
        if (sendMediator.isPresent()) {
            Endpoint endpoint = ((SendMediator) sendMediator.get()).getEndpoint();
            if (endpoint instanceof IndirectEndpoint) {
                String endpointKey = ((IndirectEndpoint) endpoint).getKey();
                Endpoint directEndpoint = synCtx.getConfiguration().getEndpoint(endpointKey);
                if (directEndpoint instanceof HTTPEndpoint) {
                    return ((HTTPEndpoint) synCtx.getConfiguration().getEndpoint(endpointKey)).getUriTemplate().getTemplate();
                }
            }
        }
    }
    // Ideally we won't reach here
    return null;
}
Also used : AttributeKey(io.netty.util.AttributeKey) HTTPEndpoint(org.apache.synapse.endpoints.HTTPEndpoint) SendMediator(org.apache.synapse.mediators.builtin.SendMediator) HashMap(java.util.HashMap) IndirectEndpoint(org.apache.synapse.endpoints.IndirectEndpoint) FilterMediator(org.apache.synapse.mediators.filters.FilterMediator) Endpoint(org.apache.synapse.endpoints.Endpoint) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Mediator(org.apache.synapse.Mediator) Map(java.util.Map) Resource(org.apache.synapse.api.Resource) Optional(java.util.Optional) MessageContext(org.apache.synapse.MessageContext) IndirectEndpoint(org.apache.synapse.endpoints.IndirectEndpoint) HTTPEndpoint(org.apache.synapse.endpoints.HTTPEndpoint) HTTPEndpoint(org.apache.synapse.endpoints.HTTPEndpoint) IndirectEndpoint(org.apache.synapse.endpoints.IndirectEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) FilterMediator(org.apache.synapse.mediators.filters.FilterMediator) SendMediator(org.apache.synapse.mediators.builtin.SendMediator) FilterMediator(org.apache.synapse.mediators.filters.FilterMediator) Mediator(org.apache.synapse.Mediator) SendMediator(org.apache.synapse.mediators.builtin.SendMediator)

Example 3 with HTTPEndpoint

use of org.apache.synapse.endpoints.HTTPEndpoint in project wso2-synapse by wso2.

the class HTTPEndpointFactory method createEndpoint.

@Override
protected Endpoint createEndpoint(OMElement epConfig, boolean anonymousEndpoint, Properties properties) {
    HTTPEndpoint httpEndpoint = new HTTPEndpoint();
    OMAttribute name = epConfig.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "name"));
    if (name != null) {
        httpEndpoint.setName(name.getAttributeValue());
    }
    OMElement httpElement = epConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "http"));
    if (httpElement != null) {
        EndpointDefinition definition = createEndpointDefinition(httpElement);
        OMAttribute uriTemplateAttr = httpElement.getAttribute(new QName("uri-template"));
        if (uriTemplateAttr != null) {
            if (uriTemplateAttr.getAttributeValue().startsWith(HTTPEndpoint.legacyPrefix)) {
                httpEndpoint.setUriTemplate(UriTemplate.fromTemplate(uriTemplateAttr.getAttributeValue().substring(HTTPEndpoint.legacyPrefix.length())));
                // Set the address to the initial template value.
                definition.setAddress(uriTemplateAttr.getAttributeValue().substring(HTTPEndpoint.legacyPrefix.length()));
                httpEndpoint.setLegacySupport(true);
            } else {
                httpEndpoint.setUriTemplate(UriTemplate.fromTemplate(uriTemplateAttr.getAttributeValue()));
                // Set the address to the initial template value.
                definition.setAddress(uriTemplateAttr.getAttributeValue());
                httpEndpoint.setLegacySupport(false);
            }
        }
        httpEndpoint.setDefinition(definition);
        processAuditStatus(definition, httpEndpoint.getName(), httpElement);
        OMAttribute methodAttr = httpElement.getAttribute(new QName("method"));
        if (methodAttr != null) {
            setHttpMethod(httpEndpoint, methodAttr.getAttributeValue());
        } else {
            // Method is not a mandatory parameter for HttpEndpoint. So methodAttr Can be null
            if (log.isDebugEnabled()) {
                log.debug("Method is not specified for HttpEndpoint. " + "Hence using the http method from incoming message");
            }
        }
    }
    processProperties(httpEndpoint, epConfig);
    return httpEndpoint;
}
Also used : HTTPEndpoint(org.apache.synapse.endpoints.HTTPEndpoint) QName(javax.xml.namespace.QName) EndpointDefinition(org.apache.synapse.endpoints.EndpointDefinition) OMElement(org.apache.axiom.om.OMElement) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 4 with HTTPEndpoint

use of org.apache.synapse.endpoints.HTTPEndpoint in project wso2-synapse by wso2.

the class HTTPEndpointSerializer method serializeEndpoint.

@Override
protected OMElement serializeEndpoint(Endpoint endpoint) {
    if (!(endpoint instanceof HTTPEndpoint)) {
        handleException("Invalid endpoint type.");
    }
    fac = OMAbstractFactory.getOMFactory();
    OMElement endpointElement = fac.createOMElement("endpoint", SynapseConstants.SYNAPSE_OMNAMESPACE);
    HTTPEndpoint httpEndpoint = (HTTPEndpoint) endpoint;
    EndpointDefinition epDefinitionHttp = httpEndpoint.getDefinition();
    OMElement httpEPElement = serializeEndpointDefinition(epDefinitionHttp);
    if (httpEndpoint.getHttpMethod() != null) {
        httpEPElement.addAttribute(fac.createOMAttribute("method", null, httpEndpoint.getHttpMethod()));
    }
    if (httpEndpoint.getUriTemplate() != null) {
        if (httpEndpoint.isLegacySupport()) {
            httpEPElement.addAttribute(fac.createOMAttribute("uri-template", null, HTTPEndpoint.legacyPrefix + httpEndpoint.getUriTemplate().getTemplate()));
        } else {
            httpEPElement.addAttribute(fac.createOMAttribute("uri-template", null, httpEndpoint.getUriTemplate().getTemplate()));
        }
    }
    endpointElement.addChild(httpEPElement);
    // serialize the properties
    serializeProperties(httpEndpoint, endpointElement);
    serializeCommonAttributes(endpoint, endpointElement);
    return endpointElement;
}
Also used : HTTPEndpoint(org.apache.synapse.endpoints.HTTPEndpoint) EndpointDefinition(org.apache.synapse.endpoints.EndpointDefinition) OMElement(org.apache.axiom.om.OMElement)

Aggregations

HTTPEndpoint (org.apache.synapse.endpoints.HTTPEndpoint)4 OMElement (org.apache.axiom.om.OMElement)3 EndpointDefinition (org.apache.synapse.endpoints.EndpointDefinition)2 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 AttributeKey (io.netty.util.AttributeKey)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Optional (java.util.Optional)1 QName (javax.xml.namespace.QName)1 OMAttribute (org.apache.axiom.om.OMAttribute)1 Mediator (org.apache.synapse.Mediator)1 MessageContext (org.apache.synapse.MessageContext)1 Resource (org.apache.synapse.api.Resource)1 Endpoint (org.apache.synapse.endpoints.Endpoint)1 IndirectEndpoint (org.apache.synapse.endpoints.IndirectEndpoint)1 SendMediator (org.apache.synapse.mediators.builtin.SendMediator)1 FilterMediator (org.apache.synapse.mediators.filters.FilterMediator)1