Search in sources :

Example 41 with WSDLException

use of javax.wsdl.WSDLException in project carbon-apimgt by wso2.

the class WSDL11ProcessorImpl method init.

@Override
public boolean init(URL url) throws APIMgtWSDLException {
    setMode(Mode.SINGLE);
    WSDLReader wsdlReader = getWsdlFactoryInstance().newWSDLReader();
    // switch off the verbose mode
    wsdlReader.setFeature(JAVAX_WSDL_VERBOSE_MODE, false);
    wsdlReader.setFeature(JAVAX_WSDL_IMPORT_DOCUMENTS, false);
    try {
        wsdlDefinition = wsdlReader.readWSDL(url.toString(), getSecuredParsedDocumentFromURL(url));
        if (log.isDebugEnabled()) {
            log.debug("Successfully initialized an instance of " + this.getClass().getSimpleName() + " with a single WSDL.");
        }
    } catch (WSDLException | APIManagementException e) {
        // This implementation class cannot process the WSDL.
        log.debug("Cannot process the WSDL by " + this.getClass().getName(), e);
        setError(new ErrorItem(ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getErrorMessage(), e.getMessage(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getErrorCode(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT.getHttpStatusCode()));
    }
    return !hasError;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) WSDLException(javax.wsdl.WSDLException) ErrorItem(org.wso2.carbon.apimgt.api.ErrorItem) WSDLReader(javax.wsdl.xml.WSDLReader) APIMWSDLReader(org.wso2.carbon.apimgt.impl.utils.APIMWSDLReader)

Example 42 with WSDLException

use of javax.wsdl.WSDLException in project cxf by apache.

the class SoapTransportFactory method createSoapExtensors.

private void createSoapExtensors(Bus bus, EndpointInfo ei, SoapBindingInfo bi, boolean isSoap12) {
    try {
        String address = ei.getAddress();
        if (address == null) {
            address = "http://localhost:9090";
        }
        ExtensionRegistry registry = bus.getExtension(WSDLManager.class).getExtensionRegistry();
        SoapAddress soapAddress = SOAPBindingUtil.createSoapAddress(registry, isSoap12);
        soapAddress.setLocationURI(address);
        ei.addExtensor(soapAddress);
    } catch (WSDLException e) {
        e.printStackTrace();
    }
}
Also used : WSDLException(javax.wsdl.WSDLException) SoapAddress(org.apache.cxf.binding.soap.wsdl.extensions.SoapAddress) WSDLManager(org.apache.cxf.wsdl.WSDLManager) ExtensionRegistry(javax.wsdl.extensions.ExtensionRegistry)

Example 43 with WSDLException

use of javax.wsdl.WSDLException in project cxf by apache.

the class SoapBindingFactory method createBindingInfo.

public BindingInfo createBindingInfo(ServiceInfo si, String bindingid, Object conf) {
    SoapBindingConfiguration config;
    if (conf instanceof SoapBindingConfiguration) {
        config = (SoapBindingConfiguration) conf;
    } else {
        config = new SoapBindingConfiguration();
    }
    if (WSDLConstants.NS_SOAP12.equals(bindingid) || WSDLConstants.NS_SOAP12_HTTP_BINDING.equals(bindingid)) {
        config.setVersion(Soap12.getInstance());
        config.setTransportURI(WSDLConstants.NS_SOAP_HTTP_TRANSPORT);
    }
    SoapBindingInfo info = new SoapBindingInfo(si, bindingid, config.getVersion());
    info.setName(config.getBindingName(si));
    info.setStyle(config.getStyle());
    info.setTransportURI(config.getTransportURI());
    if (config.isMtomEnabled()) {
        info.setProperty(Message.MTOM_ENABLED, Boolean.TRUE);
    }
    for (OperationInfo op : si.getInterface().getOperations()) {
        SoapOperationInfo sop = new SoapOperationInfo();
        sop.setAction(config.getSoapAction(op));
        sop.setStyle(config.getStyle(op));
        BindingOperationInfo bop = info.buildOperation(op.getName(), op.getInputName(), op.getOutputName());
        bop.addExtensor(sop);
        info.addOperation(bop);
        BindingMessageInfo bInput = bop.getInput();
        if (bInput != null) {
            final MessageInfo input;
            BindingMessageInfo unwrappedMsg = bInput;
            if (bop.isUnwrappedCapable()) {
                input = bop.getOperationInfo().getUnwrappedOperation().getInput();
                unwrappedMsg = bop.getUnwrappedOperation().getInput();
            } else {
                input = bop.getOperationInfo().getInput();
            }
            setupHeaders(bop, bInput, unwrappedMsg, input, config);
        }
        BindingMessageInfo bOutput = bop.getOutput();
        if (bOutput != null) {
            final MessageInfo output;
            BindingMessageInfo unwrappedMsg = bOutput;
            if (bop.isUnwrappedCapable()) {
                output = bop.getOperationInfo().getUnwrappedOperation().getOutput();
                unwrappedMsg = bop.getUnwrappedOperation().getOutput();
            } else {
                output = bop.getOperationInfo().getOutput();
            }
            setupHeaders(bop, bOutput, unwrappedMsg, output, config);
        }
    }
    try {
        createSoapBinding(info);
    } catch (WSDLException e) {
        e.printStackTrace();
    }
    return info;
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) WSDLException(javax.wsdl.WSDLException) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo)

Example 44 with WSDLException

use of javax.wsdl.WSDLException in project cxf by apache.

the class WSDLManagerImpl method getDefinition.

public Definition getDefinition(final Element el) throws WSDLException {
    synchronized (definitionsMap) {
        if (definitionsMap.containsKey(el)) {
            return definitionsMap.get(el);
        }
    }
    final WSDLReader reader = factory.newWSDLReader();
    reader.setFeature("javax.wsdl.verbose", false);
    reader.setExtensionRegistry(registry);
    final Definition def;
    // This is needed to avoid security exceptions when running with a security manager
    if (System.getSecurityManager() == null) {
        def = reader.readWSDL("", el);
    } else {
        try {
            def = AccessController.doPrivileged((PrivilegedExceptionAction<Definition>) () -> reader.readWSDL("", el));
        } catch (PrivilegedActionException paex) {
            throw new WSDLException(WSDLException.PARSER_ERROR, paex.getMessage(), paex);
        }
    }
    synchronized (definitionsMap) {
        definitionsMap.put(el, def);
    }
    return def;
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) WSDLException(javax.wsdl.WSDLException) Definition(javax.wsdl.Definition) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) WSDLReader(javax.wsdl.xml.WSDLReader)

Example 45 with WSDLException

use of javax.wsdl.WSDLException in project cxf by apache.

the class WSDLManagerImpl method loadDefinition.

protected Definition loadDefinition(String url) throws WSDLException {
    final WSDLReader reader = factory.newWSDLReader();
    reader.setFeature("javax.wsdl.verbose", false);
    reader.setFeature("javax.wsdl.importDocuments", true);
    reader.setExtensionRegistry(registry);
    // we'll create a new String here to make sure the passed in key is not referenced in the loading of
    // the wsdl and thus would be held onto from the cached map from both the weak reference (key) and
    // from the strong reference (Definition).  For example, the Definition sometimes keeps the original
    // string as the documentBaseLocation which would result in it being held onto strongly
    // from the definition.  With this, the String the definition holds onto would be unique
    url = new String(url);
    CatalogWSDLLocator catLocator = new CatalogWSDLLocator(url, bus);
    final ResourceManagerWSDLLocator wsdlLocator = new ResourceManagerWSDLLocator(url, catLocator, bus);
    InputSource src = wsdlLocator.getBaseInputSource();
    final Definition def;
    if (src.getByteStream() != null || src.getCharacterStream() != null) {
        final Document doc;
        XMLStreamReader xmlReader = null;
        try {
            xmlReader = StaxUtils.createXMLStreamReader(src);
            if (xmlStreamReaderWrapper != null) {
                xmlReader = xmlStreamReaderWrapper.wrap(xmlReader);
            }
            doc = StaxUtils.read(xmlReader, true);
            if (src.getSystemId() != null) {
                try {
                    doc.setDocumentURI(new String(src.getSystemId()));
                } catch (Exception e) {
                // ignore - probably not DOM level 3
                }
            }
        } catch (Exception e) {
            throw new WSDLException(WSDLException.PARSER_ERROR, e.getMessage(), e);
        } finally {
            try {
                StaxUtils.close(xmlReader);
            } catch (XMLStreamException ex) {
                throw new WSDLException(WSDLException.PARSER_ERROR, ex.getMessage(), ex);
            }
        }
        // This is needed to avoid security exceptions when running with a security manager
        if (System.getSecurityManager() == null) {
            def = reader.readWSDL(wsdlLocator, doc.getDocumentElement());
        } else {
            try {
                def = AccessController.doPrivileged((PrivilegedExceptionAction<Definition>) () -> reader.readWSDL(wsdlLocator, doc.getDocumentElement()));
            } catch (PrivilegedActionException paex) {
                throw new WSDLException(WSDLException.PARSER_ERROR, paex.getMessage(), paex);
            }
        }
    } else {
        if (System.getSecurityManager() == null) {
            def = reader.readWSDL(wsdlLocator);
        } else {
            try {
                def = AccessController.doPrivileged((PrivilegedExceptionAction<Definition>) () -> reader.readWSDL(wsdlLocator));
            } catch (PrivilegedActionException paex) {
                throw new WSDLException(WSDLException.PARSER_ERROR, paex.getMessage(), paex);
            }
        }
    }
    return def;
}
Also used : InputSource(org.xml.sax.InputSource) XMLStreamReader(javax.xml.stream.XMLStreamReader) WSDLException(javax.wsdl.WSDLException) PrivilegedActionException(java.security.PrivilegedActionException) Definition(javax.wsdl.Definition) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) Document(org.w3c.dom.Document) XMLStreamException(javax.xml.stream.XMLStreamException) PrivilegedActionException(java.security.PrivilegedActionException) BusException(org.apache.cxf.BusException) WSDLException(javax.wsdl.WSDLException) XMLStreamException(javax.xml.stream.XMLStreamException) WSDLReader(javax.wsdl.xml.WSDLReader)

Aggregations

WSDLException (javax.wsdl.WSDLException)56 ToolException (org.apache.cxf.tools.common.ToolException)18 WSDLReader (javax.wsdl.xml.WSDLReader)14 IOException (java.io.IOException)13 Definition (javax.wsdl.Definition)12 Message (org.apache.cxf.common.i18n.Message)12 QName (javax.xml.namespace.QName)11 WSDLWriter (javax.wsdl.xml.WSDLWriter)10 APIMgtWSDLException (org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException)7 File (java.io.File)6 Writer (java.io.Writer)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)6 Document (org.w3c.dom.Document)6 URL (java.net.URL)5 WSDLManager (org.apache.cxf.wsdl.WSDLManager)5 XMLStreamException (javax.xml.stream.XMLStreamException)4 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3