Search in sources :

Example 41 with Message

use of org.apache.cxf.common.i18n.Message in project cxf by apache.

the class JAXWSBindingParser method queryXPathNode.

private Node queryXPathNode(Node target, String expression) {
    NodeList nlst;
    try {
        ContextImpl contextImpl = new ContextImpl(target);
        XPathFactory xpathFactory = XPathFactory.newInstance();
        try {
            xpathFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
        } catch (javax.xml.xpath.XPathFactoryConfigurationException ex) {
        // ignore
        }
        XPath xpath = xpathFactory.newXPath();
        xpath.setNamespaceContext(contextImpl);
        nlst = (NodeList) xpath.evaluate(expression, target, XPathConstants.NODESET);
    } catch (XPathExpressionException e) {
        Message msg = new Message("XPATH_ERROR", LOG, new Object[] { expression });
        throw new ToolException(msg, e);
    }
    if (nlst.getLength() != 1) {
        Message msg = new Message("ERROR_TARGETNODE_WITH_XPATH", LOG, new Object[] { expression });
        throw new ToolException(msg);
    }
    Node rnode = nlst.item(0);
    if (!(rnode instanceof Element)) {
        return null;
    }
    return rnode;
}
Also used : XPath(javax.xml.xpath.XPath) Message(org.apache.cxf.common.i18n.Message) XPathExpressionException(javax.xml.xpath.XPathExpressionException) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) XPathFactory(javax.xml.xpath.XPathFactory) ToolException(org.apache.cxf.tools.common.ToolException)

Example 42 with Message

use of org.apache.cxf.common.i18n.Message in project cxf by apache.

the class AntGenerator method generate.

public void generate(ToolContext penv) throws ToolException {
    this.env = penv;
    if (passthrough()) {
        return;
    }
    Map<QName, JavaModel> map = CastUtils.cast((Map<?, ?>) penv.get(WSDLToJavaProcessor.MODEL_MAP));
    for (JavaModel javaModel : map.values()) {
        if (javaModel.getServiceClasses().isEmpty()) {
            ServiceInfo serviceInfo = env.get(ServiceInfo.class);
            String wsdl = serviceInfo.getDescription().getBaseURI();
            Message msg = new Message("CAN_NOT_GEN_ANT", LOG, wsdl);
            if (penv.isVerbose()) {
                System.out.println(msg.toString());
            }
            return;
        }
        Map<String, String> clientClassNamesMap = new HashMap<>();
        Map<String, String> serverClassNamesMap = new HashMap<>();
        Map<String, JavaInterface> interfaces = javaModel.getInterfaces();
        int index = 1;
        for (JavaServiceClass js : javaModel.getServiceClasses().values()) {
            for (JavaPort jp : js.getPorts()) {
                String interfaceName = jp.getInterfaceClass();
                JavaInterface intf = interfaces.get(interfaceName);
                if (intf == null) {
                    interfaceName = jp.getPortType();
                    intf = interfaces.get(interfaceName);
                }
                String clientClassName = intf.getPackageName() + "." + interfaceName + "_" + NameUtil.mangleNameToClassName(jp.getPortName()) + "_Client";
                String serverClassName = intf.getPackageName() + "." + interfaceName + "_" + NameUtil.mangleNameToClassName(jp.getPortName()) + "_Server";
                String clientTargetName = interfaceName + "Client";
                boolean collison = false;
                if (clientClassNamesMap.keySet().contains(clientTargetName)) {
                    clientTargetName = clientTargetName + index;
                    collison = true;
                }
                String serverTargetName = interfaceName + "Server";
                if (serverClassNamesMap.keySet().contains(serverTargetName)) {
                    serverTargetName = serverTargetName + index;
                    collison = true;
                }
                if (collison) {
                    index++;
                }
                clientClassNamesMap.put(clientTargetName, clientClassName);
                serverClassNamesMap.put(serverTargetName, serverClassName);
            }
        }
        clearAttributes();
        setAttributes("clientClassNamesMap", clientClassNamesMap);
        setAttributes("serverClassNamesMap", serverClassNamesMap);
        setAttributes("wsdlLocation", javaModel.getLocation());
        setCommonAttributes();
        doWrite(ANT_TEMPLATE, parseOutputName(null, "build", ".xml"));
    }
}
Also used : JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) Message(org.apache.cxf.common.i18n.Message) HashMap(java.util.HashMap) JavaServiceClass(org.apache.cxf.tools.common.model.JavaServiceClass) QName(javax.xml.namespace.QName) JavaPort(org.apache.cxf.tools.common.model.JavaPort) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) JavaModel(org.apache.cxf.tools.common.model.JavaModel)

Example 43 with Message

use of org.apache.cxf.common.i18n.Message in project cxf by apache.

the class ServerGenerator method generate.

public void generate(ToolContext penv) throws ToolException {
    this.env = penv;
    if (passthrough()) {
        return;
    }
    Map<QName, JavaModel> map = CastUtils.cast((Map<?, ?>) penv.get(WSDLToJavaProcessor.MODEL_MAP));
    for (JavaModel javaModel : map.values()) {
        String address = "CHANGE_ME";
        Map<String, JavaInterface> interfaces = javaModel.getInterfaces();
        if (javaModel.getServiceClasses().isEmpty()) {
            ServiceInfo serviceInfo = env.get(ServiceInfo.class);
            String wsdl = serviceInfo.getDescription().getBaseURI();
            Message msg = new Message("CAN_NOT_GEN_SRV", LOG, wsdl);
            if (penv.isVerbose()) {
                System.out.println(msg.toString());
            }
            return;
        }
        for (JavaServiceClass js : javaModel.getServiceClasses().values()) {
            for (JavaPort jp : js.getPorts()) {
                String interfaceName = jp.getInterfaceClass();
                JavaInterface intf = interfaces.get(interfaceName);
                if (intf == null) {
                    interfaceName = jp.getPortType();
                    intf = interfaces.get(interfaceName);
                }
                address = StringUtils.isEmpty(jp.getBindingAdress()) ? address : jp.getBindingAdress();
                String serverClassName = interfaceName + "_" + NameUtil.mangleNameToClassName(jp.getPortName()) + "_Server";
                serverClassName = mapClassName(intf.getPackageName(), serverClassName, penv);
                clearAttributes();
                setAttributes("serverClassName", serverClassName);
                setAttributes("intf", intf);
                String name = getImplName(jp.getPortName(), js.getServiceName(), intf, penv);
                setAttributes("impl", name);
                setAttributes("address", address);
                setCommonAttributes();
                doWrite(SRV_TEMPLATE, parseOutputName(intf.getPackageName(), serverClassName));
            }
        }
    }
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) Message(org.apache.cxf.common.i18n.Message) JavaServiceClass(org.apache.cxf.tools.common.model.JavaServiceClass) QName(javax.xml.namespace.QName) JavaModel(org.apache.cxf.tools.common.model.JavaModel) JavaPort(org.apache.cxf.tools.common.model.JavaPort)

Example 44 with Message

use of org.apache.cxf.common.i18n.Message in project cxf by apache.

the class AbstractGenerator method parseOutputName.

protected Writer parseOutputName(String packageName, String filename, String ext) throws ToolException {
    if (wantToKeep() && isCollision(packageName, filename, ext)) {
        Message msg = new Message("SKIP_GEN", LOG, packageName + '.' + filename + ext);
        LOG.log(Level.INFO, msg.toString());
        return null;
    }
    FileWriterUtil fw = new FileWriterUtil(getOutputDir(), env.get(OutputStreamCreator.class));
    final Writer writer;
    try {
        if (".java".equals(ext)) {
            writer = fw.getWriter(packageName, filename + ext, (String) getEnvironment().get(ToolConstants.CFG_ENCODING));
        } else {
            writer = fw.getWriter(packageName, filename + ext);
        }
    } catch (IOException ioe) {
        Message msg = new Message("FAIL_TO_WRITE_FILE", LOG, packageName + '.' + filename + ext);
        throw new ToolException(msg, ioe);
    }
    return writer;
}
Also used : Message(org.apache.cxf.common.i18n.Message) FileWriterUtil(org.apache.cxf.tools.util.FileWriterUtil) OutputStreamCreator(org.apache.cxf.tools.util.OutputStreamCreator) IOException(java.io.IOException) ToolException(org.apache.cxf.tools.common.ToolException) Writer(java.io.Writer)

Example 45 with Message

use of org.apache.cxf.common.i18n.Message in project cxf by apache.

the class CustomizationParser method getTargetNode.

public Element getTargetNode(String uri) {
    if (uri == null) {
        return null;
    }
    if (uri.equals(wsdlURL) && wsdlNode != null) {
        return wsdlNode;
    }
    Document doc = null;
    try (URIResolver resolver = new URIResolver(uri)) {
        if (!resolver.isResolved()) {
            return null;
        }
        XMLStreamReader reader = null;
        try {
            // NOPMD
            reader = StaxUtils.createXMLStreamReader(uri, resolver.getInputStream());
            doc = StaxUtils.read(reader, true);
        } catch (Exception e) {
            Message msg = new Message("CAN_NOT_READ_AS_ELEMENT", LOG, new Object[] { uri });
            throw new ToolException(msg, e);
        } finally {
            try {
                StaxUtils.close(reader);
            } catch (XMLStreamException e) {
            // ignore
            }
        }
    } catch (IOException e1) {
        return null;
    }
    try {
        doc.setDocumentURI(uri);
    } catch (Exception ex) {
    // ignore - probably not DOM level 3
    }
    if (doc != null) {
        return doc.getDocumentElement();
    }
    return null;
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) Message(org.apache.cxf.common.i18n.Message) XMLStreamException(javax.xml.stream.XMLStreamException) URIResolver(org.apache.cxf.resource.URIResolver) ToolException(org.apache.cxf.tools.common.ToolException) IOException(java.io.IOException) Document(org.w3c.dom.Document) URISyntaxException(java.net.URISyntaxException) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) ToolException(org.apache.cxf.tools.common.ToolException)

Aggregations

Message (org.apache.cxf.common.i18n.Message)201 ToolException (org.apache.cxf.tools.common.ToolException)69 IOException (java.io.IOException)45 QName (javax.xml.namespace.QName)42 Fault (org.apache.cxf.interceptor.Fault)34 XMLStreamException (javax.xml.stream.XMLStreamException)27 JAXBException (javax.xml.bind.JAXBException)23 ArrayList (java.util.ArrayList)19 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)17 Element (org.w3c.dom.Element)17 File (java.io.File)16 WSDLException (javax.wsdl.WSDLException)15 Method (java.lang.reflect.Method)14 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)13 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)12 InputStream (java.io.InputStream)11 HashMap (java.util.HashMap)11 List (java.util.List)11 Map (java.util.Map)11 ServiceConstructionException (org.apache.cxf.service.factory.ServiceConstructionException)11