Search in sources :

Example 16 with EndpointDefinition

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

the class WSDLEndpointFactory method createEndpoint.

protected Endpoint createEndpoint(OMElement epConfig, boolean anonymousEndpoint, Properties properties) {
    WSDLEndpoint wsdlEndpoint = new WSDLEndpoint();
    OMAttribute name = epConfig.getAttribute(new QName(org.apache.synapse.config.xml.XMLConfigConstants.NULL_NAMESPACE, "name"));
    if (name != null) {
        wsdlEndpoint.setName(name.getAttributeValue());
    }
    OMElement wsdlElement = epConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "wsdl"));
    if (wsdlElement != null) {
        DefinitionFactory fac = getEndpointDefinitionFactory();
        EndpointDefinition endpoint;
        if (fac == null) {
            fac = new EndpointDefinitionFactory();
            endpoint = fac.createDefinition(wsdlElement);
        } else {
            endpoint = fac.createDefinition(wsdlElement);
        }
        // for now, QOS information has to be provided explicitly.
        extractSpecificEndpointProperties(endpoint, wsdlElement);
        wsdlEndpoint.setDefinition(endpoint);
        processAuditStatus(endpoint, wsdlEndpoint.getName(), wsdlElement);
        // get the service name and port name. at this point we should not worry about
        // the presence of those parameters. they are handled by corresponding WSDL builders.
        String serviceName = wsdlElement.getAttributeValue(new QName("service"));
        String portName = wsdlElement.getAttributeValue(new QName("port"));
        // check if wsdl is supplied as a URI
        String wsdlURI = wsdlElement.getAttributeValue(new QName("uri"));
        // set serviceName and portName in the endpoint. it does not matter if these are
        // null at this point. we are setting them only for serialization purpose.
        wsdlEndpoint.setServiceName(serviceName);
        wsdlEndpoint.setPortName(portName);
        String noParsing = properties.getProperty(SKIP_WSDL_PARSING);
        if (wsdlURI != null) {
            wsdlEndpoint.setWsdlURI(wsdlURI.trim());
            if (noParsing == null || !JavaUtils.isTrueExplicitly(noParsing)) {
                try {
                    OMNode wsdlOM = SynapseConfigUtils.getOMElementFromURL(new URL(wsdlURI).toString(), properties.get(SynapseConstants.SYNAPSE_HOME) != null ? properties.get(SynapseConstants.SYNAPSE_HOME).toString() : "");
                    if (wsdlOM != null && wsdlOM instanceof OMElement) {
                        OMElement omElement = (OMElement) wsdlOM;
                        OMNamespace ns = omElement.getNamespace();
                        if (ns != null) {
                            String nsUri = omElement.getNamespace().getNamespaceURI();
                            if (org.apache.axis2.namespace.Constants.NS_URI_WSDL11.equals(nsUri)) {
                                new WSDL11EndpointBuilder().populateEndpointDefinitionFromWSDL(endpoint, wsdlURI.trim(), omElement, serviceName, portName);
                            } else if (WSDL2Constants.WSDL_NAMESPACE.equals(nsUri)) {
                                // endpoint = new WSDL20EndpointBuilder().
                                // createEndpointDefinitionFromWSDL(wsdlURI, serviceName, portName);
                                handleException("WSDL 2.0 Endpoints are currently not supported");
                            }
                        }
                    }
                } catch (ConnectException e) {
                    log.warn("Could not connect to the WSDL endpoint " + wsdlURI.trim(), e);
                } catch (IOException e) {
                    log.warn("Could not read the WSDL endpoint " + wsdlURI.trim(), e);
                } catch (Exception e) {
                    handleException("Couldn't create endpoint from the given WSDL URI : " + e.getMessage(), e);
                }
            }
        }
        // check if the wsdl 1.1 document is supplied inline
        OMElement definitionElement = wsdlElement.getFirstChildWithName(new QName(org.apache.axis2.namespace.Constants.NS_URI_WSDL11, "definitions"));
        if (endpoint == null && definitionElement != null) {
            wsdlEndpoint.setWsdlDoc(definitionElement);
            if (noParsing == null || !JavaUtils.isTrueExplicitly(noParsing)) {
                String resolveRoot = properties.get(SynapseConstants.RESOLVE_ROOT).toString();
                String baseUri = "file:./";
                if (resolveRoot != null) {
                    baseUri = resolveRoot.trim();
                }
                if (!baseUri.endsWith(File.separator)) {
                    baseUri = baseUri + File.separator;
                }
                new WSDL11EndpointBuilder().populateEndpointDefinitionFromWSDL(endpoint, baseUri, definitionElement, serviceName, portName);
            } else {
                endpoint = new EndpointDefinition();
            }
        }
        // check if a wsdl 2.0 document is supplied inline
        OMElement descriptionElement = wsdlElement.getFirstChildWithName(new QName(WSDL2Constants.WSDL_NAMESPACE, "description"));
        if (endpoint == null && descriptionElement != null) {
            handleException("WSDL 2.0 Endpoints are currently not supported.");
        }
    }
    // process the parameters
    processProperties(wsdlEndpoint, epConfig);
    return wsdlEndpoint;
}
Also used : WSDLEndpoint(org.apache.synapse.endpoints.WSDLEndpoint) OMNamespace(org.apache.axiom.om.OMNamespace) WSDL11EndpointBuilder(org.apache.synapse.config.xml.endpoints.utils.WSDL11EndpointBuilder) QName(javax.xml.namespace.QName) EndpointDefinition(org.apache.synapse.endpoints.EndpointDefinition) OMElement(org.apache.axiom.om.OMElement) IOException(java.io.IOException) URL(java.net.URL) IOException(java.io.IOException) ConnectException(java.net.ConnectException) OMNode(org.apache.axiom.om.OMNode) OMAttribute(org.apache.axiom.om.OMAttribute) ConnectException(java.net.ConnectException)

Example 17 with EndpointDefinition

use of org.apache.synapse.endpoints.EndpointDefinition 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 18 with EndpointDefinition

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

the class HTTPEndpointFactory method createEndpointDefinition.

@Override
public EndpointDefinition createEndpointDefinition(OMElement elem) {
    DefinitionFactory fac = getEndpointDefinitionFactory();
    EndpointDefinition endpointDefinition;
    if (fac == null) {
        fac = new EndpointDefinitionFactory();
        endpointDefinition = fac.createDefinition(elem);
    } else {
        endpointDefinition = fac.createDefinition(elem);
    }
    extractSpecificEndpointProperties(endpointDefinition, elem);
    return endpointDefinition;
}
Also used : EndpointDefinition(org.apache.synapse.endpoints.EndpointDefinition)

Example 19 with EndpointDefinition

use of org.apache.synapse.endpoints.EndpointDefinition 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)

Example 20 with EndpointDefinition

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

the class CalloutMediator method init.

public void init(SynapseEnvironment synEnv) {
    try {
        configCtx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(clientRepository != null ? clientRepository : DEFAULT_CLIENT_REPO, axis2xml != null ? axis2xml : DEFAULT_AXIS2_XML);
        if (serviceURL != null) {
            serviceURL = changeEndPointReference(serviceURL);
        }
        blockingMsgSender = new BlockingMsgSender();
        blockingMsgSender.setConfigurationContext(configCtx);
        blockingMsgSender.init();
        EndpointDefinition endpointDefinition = null;
        if (serviceURL != null) {
            // If Service URL is specified, it is given the highest priority
            endpoint = new AddressEndpoint();
            endpointDefinition = new EndpointDefinition();
            endpointDefinition.setAddress(serviceURL);
            ((AddressEndpoint) endpoint).setDefinition(endpointDefinition);
            isWrappingEndpointCreated = true;
        } else if (endpoint == null && endpointKey == null) {
            // Use a default endpoint in this case - i.e. the To header
            endpoint = new DefaultEndpoint();
            endpointDefinition = new EndpointDefinition();
            ((DefaultEndpoint) endpoint).setDefinition(endpointDefinition);
            isWrappingEndpointCreated = true;
        }
        if (endpointDefinition != null && isSecurityOn()) {
            endpointDefinition.setSecurityOn(true);
            if (wsSecPolicyKey != null) {
                endpointDefinition.setWsSecPolicyKey(wsSecPolicyKey);
            } else {
                if (inboundWsSecPolicyKey != null) {
                    endpointDefinition.setInboundWsSecPolicyKey(inboundWsSecPolicyKey);
                }
                if (outboundWsSecPolicyKey != null) {
                    endpointDefinition.setOutboundWsSecPolicyKey(outboundWsSecPolicyKey);
                }
            }
        }
    } catch (AxisFault e) {
        String msg = "Error initializing callout mediator : " + e.getMessage();
        log.error(msg, e);
        throw new SynapseException(msg, e);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) BlockingMsgSender(org.apache.synapse.message.senders.blocking.BlockingMsgSender) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) DefaultEndpoint(org.apache.synapse.endpoints.DefaultEndpoint) SynapseException(org.apache.synapse.SynapseException) EndpointDefinition(org.apache.synapse.endpoints.EndpointDefinition)

Aggregations

EndpointDefinition (org.apache.synapse.endpoints.EndpointDefinition)24 OMElement (org.apache.axiom.om.OMElement)10 AddressEndpoint (org.apache.synapse.endpoints.AddressEndpoint)10 QName (javax.xml.namespace.QName)6 OMAttribute (org.apache.axiom.om.OMAttribute)6 SynapseException (org.apache.synapse.SynapseException)6 MessageContext (org.apache.synapse.MessageContext)4 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)4 DefaultEndpoint (org.apache.synapse.endpoints.DefaultEndpoint)4 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)3 AbstractEndpoint (org.apache.synapse.endpoints.AbstractEndpoint)3 SynapseXPath (org.apache.synapse.util.xpath.SynapseXPath)3 IOException (java.io.IOException)2 URI (java.net.URI)2 AxisFault (org.apache.axis2.AxisFault)2 TestMessageContext (org.apache.synapse.TestMessageContext)2 Endpoint (org.apache.synapse.endpoints.Endpoint)2 HTTPEndpoint (org.apache.synapse.endpoints.HTTPEndpoint)2 WSDLEndpoint (org.apache.synapse.endpoints.WSDLEndpoint)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1