Search in sources :

Example 11 with ToolException

use of org.apache.cxf.tools.common.ToolException 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);
        XPath xpath = XPathFactory.newInstance().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) ToolException(org.apache.cxf.tools.common.ToolException)

Example 12 with ToolException

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

the class HandlerConfigGenerator method generateHandlerChainFile.

private void generateHandlerChainFile(Element hChains, Writer writer) throws ToolException {
    try {
        StaxUtils.writeTo(hChains, writer, 2);
        writer.close();
    } catch (Exception ex) {
        throw new ToolException(ex);
    }
}
Also used : ToolException(org.apache.cxf.tools.common.ToolException) ToolException(org.apache.cxf.tools.common.ToolException)

Example 13 with ToolException

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

the class OperationProcessor method processMethod.

void processMethod(JavaMethod method, OperationInfo operation) throws ToolException {
    if (isAsyncMethod(method)) {
        return;
    }
    MessageInfo inputMessage = operation.getInput();
    MessageInfo outputMessage = operation.getOutput();
    if (inputMessage == null) {
        LOG.log(Level.WARNING, "NO_INPUT_MESSAGE", new Object[] { operation.getName() });
        org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message("INVALID_MEP", LOG, new Object[] { operation.getName() });
        throw new ToolException(msg);
    }
    ParameterProcessor paramProcessor = new ParameterProcessor(context);
    method.clear();
    JAXWSBinding opBinding = operation.getExtensor(JAXWSBinding.class);
    JAXWSBinding ptBinding = operation.getInterface().getExtensor(JAXWSBinding.class);
    JAXWSBinding defBinding = operation.getInterface().getService().getDescription().getExtensor(JAXWSBinding.class);
    boolean enableAsync = false;
    boolean enableMime = false;
    boolean enableWrapper = method.isWrapperStyle();
    if (defBinding != null) {
        if (defBinding.isSetEnableMime()) {
            enableMime = defBinding.isEnableMime();
        }
        if (defBinding.isSetEnableAsyncMapping()) {
            enableAsync = defBinding.isEnableAsyncMapping();
        }
        if (defBinding.isSetEnableWrapperStyle()) {
            enableWrapper = defBinding.isEnableWrapperStyle();
        }
    }
    if (ptBinding != null) {
        if (ptBinding.isSetEnableMime()) {
            enableMime = ptBinding.isEnableMime();
        }
        if (ptBinding.isSetEnableAsyncMapping()) {
            enableAsync = ptBinding.isEnableAsyncMapping();
        }
        if (ptBinding.isSetEnableWrapperStyle()) {
            enableWrapper = ptBinding.isEnableWrapperStyle();
        }
    }
    if (opBinding != null) {
        if (opBinding.isSetEnableMime()) {
            enableMime = opBinding.isEnableMime();
        }
        if (opBinding.isSetEnableAsyncMapping()) {
            enableAsync = opBinding.isEnableAsyncMapping();
        }
        if (opBinding.isSetEnableWrapperStyle()) {
            enableWrapper = opBinding.isEnableWrapperStyle();
        }
    }
    enableWrapper = checkEnableWrapper(enableWrapper, method);
    enableAsync = checkEnableAsync(enableAsync, method);
    enableMime = checkEnableMime(enableMime, method);
    method.setWrapperStyle(enableWrapper && method.isWrapperStyle());
    paramProcessor.process(method, inputMessage, outputMessage, operation.getParameterOrdering());
    if (method.isWrapperStyle()) {
        setWrapper(operation);
        method.annotate(new WrapperAnnotator(wrapperRequest, wrapperResponse));
    }
    method.annotate(new WebMethodAnnotator());
    method.annotate(new WebResultAnnotator());
    if (!method.isOneWay() && enableAsync && !isAddedAsycMethod(method)) {
        addAsyncMethod(method);
    }
    if (enableMime) {
        method.setMimeEnable(true);
    }
}
Also used : MessageInfo(org.apache.cxf.service.model.MessageInfo) JAXWSBinding(org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding) ToolException(org.apache.cxf.tools.common.ToolException) WebMethodAnnotator(org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal.annotator.WebMethodAnnotator) WebResultAnnotator(org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal.annotator.WebResultAnnotator) WrapperAnnotator(org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal.annotator.WrapperAnnotator)

Example 14 with ToolException

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

the class ParameterProcessor method processInput.

private void processInput(JavaMethod method, MessageInfo inputMessage) throws ToolException {
    if (requireOutOfBandHeader()) {
        try {
            Class.forName("org.apache.cxf.binding.soap.SoapBindingFactory");
        } catch (Exception e) {
            LOG.log(Level.WARNING, new Message("SOAP_MISSING", LOG).toString());
        }
    }
    JAXWSBinding mBinding = inputMessage.getOperation().getExtensor(JAXWSBinding.class);
    for (MessagePartInfo part : inputMessage.getMessageParts()) {
        if (isOutOfBandHeader(part) && !requireOutOfBandHeader()) {
            continue;
        }
        JavaParameter param = getParameterFromPart(method, part, JavaType.Style.IN);
        if (mBinding != null && mBinding.getJaxwsParas() != null) {
            for (JAXWSParameter jwp : mBinding.getJaxwsParas()) {
                if (part.getName().getLocalPart().equals(jwp.getPart())) {
                    param.setName(jwp.getName());
                }
            }
        }
        addParameter(part, method, param);
    }
}
Also used : Message(org.apache.cxf.common.i18n.Message) JAXWSParameter(org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSParameter) JavaParameter(org.apache.cxf.tools.common.model.JavaParameter) JAXWSBinding(org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) ToolException(org.apache.cxf.tools.common.ToolException)

Example 15 with ToolException

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

the class PortTypeProcessor method getInterface.

public static JavaInterface getInterface(ToolContext context, ServiceInfo serviceInfo, InterfaceInfo interfaceInfo) throws ToolException {
    JavaInterface intf = interfaceInfo.getProperty("JavaInterface", JavaInterface.class);
    if (intf == null) {
        intf = new InterfaceMapper(context).map(interfaceInfo);
        JAXWSBinding jaxwsBinding = null;
        if (serviceInfo.getDescription() != null) {
            jaxwsBinding = serviceInfo.getDescription().getExtensor(JAXWSBinding.class);
        }
        JAXWSBinding infBinding = interfaceInfo.getExtensor(JAXWSBinding.class);
        if (infBinding != null && infBinding.getPackage() != null) {
            intf.setPackageName(infBinding.getPackage());
        } else if (jaxwsBinding != null && jaxwsBinding.getPackage() != null) {
            intf.setPackageName(jaxwsBinding.getPackage());
        }
        if (infBinding != null && !infBinding.getPackageJavaDoc().equals("")) {
            intf.setPackageJavaDoc(infBinding.getPackageJavaDoc());
        } else if (jaxwsBinding != null && !jaxwsBinding.getPackageJavaDoc().equals("")) {
            intf.setPackageJavaDoc(jaxwsBinding.getPackageJavaDoc());
        }
        String name = intf.getName();
        if (infBinding != null && infBinding.getJaxwsClass() != null && infBinding.getJaxwsClass().getClassName() != null) {
            name = infBinding.getJaxwsClass().getClassName();
            if (name.contains(".")) {
                intf.setPackageName(name.substring(0, name.lastIndexOf('.')));
                name = name.substring(name.lastIndexOf('.') + 1);
            }
            intf.setClassJavaDoc(infBinding.getJaxwsClass().getComments());
        }
        if (StringUtils.isEmpty(intf.getClassJavaDoc())) {
            intf.setClassJavaDoc(interfaceInfo.getDocumentation());
        }
        ClassCollector collector = context.get(ClassCollector.class);
        if (context.optionSet(ToolConstants.CFG_AUTORESOLVE)) {
            int count = 0;
            String checkName = name;
            while (collector.isReserved(intf.getPackageName(), checkName)) {
                checkName = name + "_" + (++count);
            }
            name = checkName;
        } else if (collector.isReserved(intf.getPackageName(), name)) {
            throw new ToolException("RESERVED_SEI_NAME", LOG, name);
        }
        interfaceInfo.setProperty("InterfaceName", name);
        intf.setName(name);
        collector.addSeiClassName(intf.getPackageName(), intf.getName(), intf.getPackageName() + "." + intf.getName());
        interfaceInfo.setProperty("JavaInterface", intf);
        if (context.containsKey(ToolConstants.CFG_SEI_SUPER)) {
            String[] supers = context.getArray(ToolConstants.CFG_SEI_SUPER);
            for (String s : supers) {
                intf.addSuperInterface(s);
            }
        }
    }
    return intf;
}
Also used : JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) ClassCollector(org.apache.cxf.tools.util.ClassCollector) JAXWSBinding(org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding) ToolException(org.apache.cxf.tools.common.ToolException) InterfaceMapper(org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal.mapper.InterfaceMapper)

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