Search in sources :

Example 1 with JAXWSBinding

use of org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding 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 2 with JAXWSBinding

use of org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding 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 3 with JAXWSBinding

use of org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding 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)

Example 4 with JAXWSBinding

use of org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding 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 5 with JAXWSBinding

use of org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding in project cxf by apache.

the class MethodMapper method map.

public JavaMethod map(OperationInfo operation) {
    JavaMethod method = new JavaMethod();
    // set default Document Bare style
    method.setSoapStyle(javax.jws.soap.SOAPBinding.Style.DOCUMENT);
    String operationName = operation.getName().getLocalPart();
    method.setName(ProcessorUtil.mangleNameToVariableName(operationName));
    method.setOperationName(operationName);
    JAXWSBinding opBinding = operation.getExtensor(JAXWSBinding.class);
    if (opBinding != null && opBinding.getMethodName() != null) {
        method.setName(opBinding.getMethodName());
    }
    if (opBinding != null && opBinding.getMethodJavaDoc() != null) {
        method.setJavaDoc(opBinding.getMethodJavaDoc());
    } else {
        method.setJavaDoc(operation.getDocumentation());
    }
    if (operation.isOneWay()) {
        method.setStyle(OperationType.ONE_WAY);
    } else {
        method.setStyle(OperationType.REQUEST_RESPONSE);
    }
    method.setWrapperStyle(operation.isUnwrappedCapable());
    return method;
}
Also used : JavaMethod(org.apache.cxf.tools.common.model.JavaMethod) JAXWSBinding(org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding)

Aggregations

JAXWSBinding (org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding)14 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)5 ToolException (org.apache.cxf.tools.common.ToolException)5 QName (javax.xml.namespace.QName)4 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)3 Message (org.apache.cxf.common.i18n.Message)3 JavaInterface (org.apache.cxf.tools.common.model.JavaInterface)3 JAXWSParameter (org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSParameter)3 Definition (javax.wsdl.Definition)2 Operation (javax.wsdl.Operation)2 PortType (javax.wsdl.PortType)2 SoapBinding (org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding)2 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)2 JAnnotationElement (org.apache.cxf.tools.common.model.JAnnotationElement)2 JavaMethod (org.apache.cxf.tools.common.model.JavaMethod)2 JavaModel (org.apache.cxf.tools.common.model.JavaModel)2 JavaParameter (org.apache.cxf.tools.common.model.JavaParameter)2 JavaPort (org.apache.cxf.tools.common.model.JavaPort)2 ClassCollector (org.apache.cxf.tools.util.ClassCollector)2 Test (org.junit.Test)2