Search in sources :

Example 16 with ToolException

use of org.apache.cxf.tools.common.ToolException in project cxf by apache.

the class ServiceProcessor method processOperation.

private void processOperation(JavaModel model, BindingOperationInfo bop, BindingInfo binding) throws ToolException {
    boolean enableOpMime = false;
    JAXWSBinding bind = binding.getExtensor(JAXWSBinding.class);
    if (bind != null && bind.isEnableMime()) {
        enableOpMime = true;
    }
    JAXWSBinding bopBinding = bop.getExtensor(JAXWSBinding.class);
    if (bopBinding != null && bopBinding.isEnableMime()) {
        enableOpMime = true;
        if (bopBinding.getJaxwsParas() != null) {
            jaxwsBinding.setJaxwsParas(bopBinding.getJaxwsParas());
        }
    }
    JavaInterface jf = null;
    for (JavaInterface jf2 : model.getInterfaces().values()) {
        if (binding.getInterface().getName().getLocalPart().equals(jf2.getWebServiceName())) {
            jf = jf2;
        }
    }
    if (jf == null) {
        throw new ToolException("No Java Interface available");
    }
    if (isSoapBinding()) {
        SoapBinding soapBinding = (SoapBinding) bindingObj;
        if (SOAPBindingUtil.getSoapStyle(soapBinding.getStyle()) == null) {
            jf.setSOAPStyle(javax.jws.soap.SOAPBinding.Style.DOCUMENT);
        } else {
            jf.setSOAPStyle(SOAPBindingUtil.getSoapStyle(soapBinding.getStyle()));
        }
    } else {
        // REVISIT: fix for xml binding
        jf.setSOAPStyle(javax.jws.soap.SOAPBinding.Style.DOCUMENT);
    }
    Object[] methods = jf.getMethods().toArray();
    for (int i = 0; i < methods.length; i++) {
        JavaMethod jm = (JavaMethod) methods[i];
        if (jm.getOperationName() != null && jm.getOperationName().equals(bop.getName().getLocalPart())) {
            if (isSoapBinding()) {
                // TODO: add customize here
                // doCustomizeOperation(jf, jm, bop);
                Map<String, Object> prop = getSoapOperationProp(bop);
                String soapAction = prop.get(soapOPAction) == null ? "" : (String) prop.get(soapOPAction);
                String soapStyle = prop.get(soapOPStyle) == null ? "" : (String) prop.get(soapOPStyle);
                jm.setSoapAction(soapAction);
                if (SOAPBindingUtil.getSoapStyle(soapStyle) == null && this.bindingObj == null) {
                    org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message("BINDING_STYLE_NOT_DEFINED", LOG);
                    throw new ToolException(msg);
                }
                if (SOAPBindingUtil.getSoapStyle(soapStyle) == null) {
                    jm.setSoapStyle(jf.getSOAPStyle());
                } else {
                    jm.setSoapStyle(SOAPBindingUtil.getSoapStyle(soapStyle));
                }
            } else {
                // REVISIT: fix for xml binding
                jm.setSoapStyle(jf.getSOAPStyle());
            }
            if (jm.getSoapStyle().equals(javax.jws.soap.SOAPBinding.Style.RPC)) {
                jm.getAnnotationMap().remove("SOAPBinding");
            }
            OperationProcessor processor = new OperationProcessor(context);
            int headerType = isNonWrappable(bop);
            OperationInfo opinfo = bop.getOperationInfo();
            JAXWSBinding opBinding = opinfo.getExtensor(JAXWSBinding.class);
            JAXWSBinding infBinding = opinfo.getInterface().getExtensor(JAXWSBinding.class);
            boolean enableMime = enableOpMime;
            boolean enableWrapperStyle = true;
            if (infBinding != null && infBinding.isSetEnableWrapperStyle()) {
                enableWrapperStyle = infBinding.isEnableWrapperStyle();
            }
            if (infBinding != null && infBinding.isSetEnableMime()) {
                enableMime = infBinding.isEnableMime();
            }
            if (opBinding != null && opBinding.isSetEnableWrapperStyle()) {
                enableWrapperStyle = opBinding.isEnableWrapperStyle();
            }
            if (opBinding != null && opBinding.isSetEnableMime()) {
                enableMime = opBinding.isEnableMime();
            }
            if (jaxwsBinding.isEnableMime() || enableMime) {
                jm.setMimeEnable(true);
            }
            if ((jm.isWrapperStyle() && headerType > this.noHEADER) || !jaxwsBinding.isEnableWrapperStyle() || (jm.enableMime() && jm.isWrapperStyle()) || !enableWrapperStyle) {
                // changed wrapper style
                jm.setWrapperStyle(false);
                processor.processMethod(jm, bop.getOperationInfo());
                jm.getAnnotationMap().remove("ResponseWrapper");
                jm.getAnnotationMap().remove("RequestWrapper");
            } else {
                processor.processMethod(jm, bop.getOperationInfo());
            }
            if (headerType == this.resultHeader) {
                JAnnotation resultAnno = jm.getAnnotationMap().get("WebResult");
                if (resultAnno != null) {
                    resultAnno.addElement(new JAnnotationElement("header", true, true));
                }
            }
            processParameter(jm, bop);
        }
    }
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) Message(org.apache.cxf.common.i18n.Message) JAnnotation(org.apache.cxf.tools.common.model.JAnnotation) JAnnotationElement(org.apache.cxf.tools.common.model.JAnnotationElement) Message(org.apache.cxf.common.i18n.Message) SoapBinding(org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod) JAXWSBinding(org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding) ToolException(org.apache.cxf.tools.common.ToolException)

Example 17 with ToolException

use of org.apache.cxf.tools.common.ToolException in project cxf by apache.

the class ServiceProcessor method processBindings.

private void processBindings(JavaModel model) {
    for (BindingInfo binding : service.getBindings()) {
        bindingType = getBindingType(binding);
        if (bindingType == null) {
            org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message("BINDING_SPECIFY_ONE_PROTOCOL", LOG, binding.getName());
            throw new ToolException(msg);
        }
        Collection<BindingOperationInfo> operations = binding.getOperations();
        for (BindingOperationInfo bop : operations) {
            processOperation(model, bop, binding);
        }
    }
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Message(org.apache.cxf.common.i18n.Message) BindingInfo(org.apache.cxf.service.model.BindingInfo) ToolException(org.apache.cxf.tools.common.ToolException) Message(org.apache.cxf.common.i18n.Message)

Example 18 with ToolException

use of org.apache.cxf.tools.common.ToolException in project cxf by apache.

the class SchemaResourceResolver method validate.

public boolean validate(String wsdlsource, String[] schemas) throws ToolException {
    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    try {
        docFactory.setNamespaceAware(true);
        docFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
        docBuilder = docFactory.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        throw new ToolException(e);
    }
    String systemId = null;
    systemId = URIParserUtil.getAbsoluteURI(wsdlsource);
    InputSource is = new InputSource(systemId);
    return validate(is, schemas);
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ToolException(org.apache.cxf.tools.common.ToolException)

Example 19 with ToolException

use of org.apache.cxf.tools.common.ToolException in project cxf by apache.

the class SchemaResourceResolver method validate.

public boolean validate(InputSource wsdlsource, String[] schemas) throws ToolException {
    boolean isValid = false;
    Schema schema;
    try {
        SAXParserFactory saxFactory = SAXParserFactory.newInstance();
        saxFactory.setFeature("http://xml.org/sax/features/namespaces", true);
        saxFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
        saxParser = saxFactory.newSAXParser();
        if (defaultSchemas != null) {
            schemas = addSchemas(defaultSchemas, schemas);
            schema = createSchema(schemas);
        } else {
            schema = createSchema(schemaFromJar, schemas);
        }
        Validator validator = schema.newValidator();
        NewStackTraceErrorHandler errHandler = new NewStackTraceErrorHandler();
        validator.setErrorHandler(errHandler);
        SAXSource saxSource = new SAXSource(saxParser.getXMLReader(), wsdlsource);
        validator.validate(saxSource);
        if (!errHandler.isValid()) {
            throw new ToolException(errHandler.getErrorMessages());
        }
        isValid = true;
    } catch (IOException ioe) {
        throw new ToolException("Cannot get the wsdl " + wsdlsource.getSystemId(), ioe);
    } catch (SAXException saxEx) {
        throw new ToolException(saxEx);
    } catch (ParserConfigurationException e) {
        throw new ToolException(e);
    }
    return isValid;
}
Also used : SAXSource(javax.xml.transform.sax.SAXSource) Schema(javax.xml.validation.Schema) ToolException(org.apache.cxf.tools.common.ToolException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Validator(javax.xml.validation.Validator) SAXParserFactory(javax.xml.parsers.SAXParserFactory) SAXException(org.xml.sax.SAXException)

Example 20 with ToolException

use of org.apache.cxf.tools.common.ToolException in project cxf by apache.

the class SchemaResourceResolver method getDefaultSchemas.

private String[] getDefaultSchemas() throws ToolException {
    String loc = schemaLocation;
    if (loc == null || "".equals(loc.trim())) {
        loc = "./";
    }
    File f = new File(loc);
    if (f.exists() && f.isDirectory()) {
        FilenameFilter filter = new FilenameFilter() {

            public boolean accept(File dir, String name) {
                if (name.toLowerCase().endsWith(".xsd") && !new File(dir.getPath() + File.separator + name).isDirectory()) {
                    return true;
                }
                return false;
            }
        };
        File[] files = f.listFiles(filter);
        if (files != null) {
            List<String> xsdUrls = new ArrayList<>(files.length);
            for (File file : files) {
                try {
                    String s = file.toURI().toURL().toString();
                    xsdUrls.add(s);
                    if (s.contains("http-conf")) {
                        xsdUrls.add(0, s);
                    }
                } catch (MalformedURLException e) {
                    throw new ToolException(e);
                }
            }
            return xsdUrls.toArray(new String[xsdUrls.size()]);
        }
    }
    return null;
}
Also used : FilenameFilter(java.io.FilenameFilter) MalformedURLException(java.net.MalformedURLException) ArrayList(java.util.ArrayList) ToolException(org.apache.cxf.tools.common.ToolException) File(java.io.File)

Aggregations

ToolException (org.apache.cxf.tools.common.ToolException)129 Message (org.apache.cxf.common.i18n.Message)69 IOException (java.io.IOException)38 File (java.io.File)30 QName (javax.xml.namespace.QName)19 WSDLException (javax.wsdl.WSDLException)18 BadUsageException (org.apache.cxf.tools.common.toolspec.parser.BadUsageException)16 ToolContext (org.apache.cxf.tools.common.ToolContext)15 XMLStreamException (javax.xml.stream.XMLStreamException)14 FileNotFoundException (java.io.FileNotFoundException)12 Test (org.junit.Test)12 Element (org.w3c.dom.Element)10 InputStream (java.io.InputStream)9 Writer (java.io.Writer)9 URISyntaxException (java.net.URISyntaxException)9 URL (java.net.URL)9 HashMap (java.util.HashMap)9 ArrayList (java.util.ArrayList)8 SoapBinding (org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding)8 WSDLWriter (javax.wsdl.xml.WSDLWriter)7