Search in sources :

Example 6 with WSDLEndpoint

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

Aggregations

WSDLEndpoint (org.apache.synapse.endpoints.WSDLEndpoint)6 OMElement (org.apache.axiom.om.OMElement)5 URL (java.net.URL)3 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 Properties (java.util.Properties)2 OMNamespace (org.apache.axiom.om.OMNamespace)2 OMNode (org.apache.axiom.om.OMNode)2 SynapseException (org.apache.synapse.SynapseException)2 AddressEndpoint (org.apache.synapse.endpoints.AddressEndpoint)2 Endpoint (org.apache.synapse.endpoints.Endpoint)2 EndpointDefinition (org.apache.synapse.endpoints.EndpointDefinition)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 ConnectException (java.net.ConnectException)1 QName (javax.xml.namespace.QName)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 OMAttribute (org.apache.axiom.om.OMAttribute)1 AxisFault (org.apache.axis2.AxisFault)1