Search in sources :

Example 1 with WSDLLocator

use of javax.wsdl.xml.WSDLLocator in project wso2-synapse by wso2.

the class WSDL11EndpointBuilder method populateEndpointDefinitionFromWSDL.

/**
 * Creates an EndpointDefinition for WSDL endpoint from an inline WSDL supplied in the WSDL
 * endpoint configuration.
 *
 * @param endpointDefinition the endpoint definition to populate
 * @param baseUri base uri of the wsdl
 * @param wsdl    OMElement representing the inline WSDL
 * @param service Service of the endpoint
 * @param port    Port of the endpoint
 * @return EndpointDefinition containing the information retrieved from the WSDL
 */
public EndpointDefinition populateEndpointDefinitionFromWSDL(EndpointDefinition endpointDefinition, String baseUri, OMElement wsdl, String service, String port) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        wsdl.serialize(baos);
        InputStream in = new ByteArrayInputStream(baos.toByteArray());
        InputSource inputSource = new InputSource(in);
        WSDLLocator wsdlLocator = new CustomWSDLLocator(inputSource, baseUri);
        Document doc = null;
        try {
            doc = XMLUtils.newDocument(inputSource);
        } catch (ParserConfigurationException e) {
            handleException("Parser Configuration Error", e);
        } catch (SAXException e) {
            handleException("Parser SAX Error", e);
        } catch (IOException e) {
            handleException(WSDLException.INVALID_WSDL + "IO Error", e);
        }
        if (doc != null) {
            WSDLFactory fac = WSDLFactory.newInstance();
            WSDLReader reader = fac.newWSDLReader();
            Definition definition = reader.readWSDL(wsdlLocator, doc.getDocumentElement());
            return createEndpointDefinitionFromWSDL(endpointDefinition, definition, service, port);
        }
    } catch (XMLStreamException e) {
        handleException("Error retrieving the WSDL definition from the inline WSDL.", e);
    } catch (WSDLException e) {
        handleException("Error retrieving the WSDL definition from the inline WSDL.", e);
    }
    return null;
}
Also used : WSDLLocator(javax.wsdl.xml.WSDLLocator) CustomWSDLLocator(org.apache.synapse.util.resolver.CustomWSDLLocator) InputSource(org.xml.sax.InputSource) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) EndpointDefinition(org.apache.synapse.endpoints.EndpointDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) XMLStreamException(javax.xml.stream.XMLStreamException) ByteArrayInputStream(java.io.ByteArrayInputStream) WSDLFactory(javax.wsdl.factory.WSDLFactory) CustomWSDLLocator(org.apache.synapse.util.resolver.CustomWSDLLocator) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) WSDLReader(javax.wsdl.xml.WSDLReader)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 WSDLFactory (javax.wsdl.factory.WSDLFactory)1 WSDLLocator (javax.wsdl.xml.WSDLLocator)1 WSDLReader (javax.wsdl.xml.WSDLReader)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 EndpointDefinition (org.apache.synapse.endpoints.EndpointDefinition)1 CustomWSDLLocator (org.apache.synapse.util.resolver.CustomWSDLLocator)1 Document (org.w3c.dom.Document)1 InputSource (org.xml.sax.InputSource)1 SAXException (org.xml.sax.SAXException)1