Search in sources :

Example 1 with Fault

use of com.sun.tools.ws.processor.model.Fault in project metro-jax-ws by eclipse-ee4j.

the class WSDLModeler method handleLiteralSOAPFault.

protected void handleLiteralSOAPFault(Response response, Set duplicateNames) {
    for (BindingFault bindingFault : info.bindingOperation.faults()) {
        com.sun.tools.ws.wsdl.document.Fault portTypeFault = null;
        for (com.sun.tools.ws.wsdl.document.Fault aFault : info.portTypeOperation.faults()) {
            if (aFault.getName().equals(bindingFault.getName())) {
                if (portTypeFault != null) {
                    // the WSDL document is invalid, a wsld:fault in a wsdl:operation of a portType can be bound only once
                    error(portTypeFault, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_NOT_UNIQUE(bindingFault.getName(), info.bindingOperation.getName()));
                }
                portTypeFault = aFault;
            }
        }
        // The WSDL document is invalid, the wsdl:fault in abstract operation is does not have any binding
        if (portTypeFault == null) {
            error(bindingFault, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_NOT_FOUND(bindingFault.getName(), info.bindingOperation.getName()));
        }
    }
    for (com.sun.tools.ws.wsdl.document.Fault portTypeFault : info.portTypeOperation.faults()) {
        BindingFault bindingFault = null;
        for (BindingFault bFault : info.bindingOperation.faults()) {
            if (bFault.getName().equals(portTypeFault.getName())) {
                bindingFault = bFault;
            }
        }
        if (bindingFault == null) {
            warning(portTypeFault, ModelerMessages.WSDLMODELER_INVALID_PORT_TYPE_FAULT_NOT_FOUND(portTypeFault.getName(), info.portTypeOperation.getName()));
        }
        // wsdl:fault message name is used to create the java exception name later on
        String faultName = getFaultClassName(portTypeFault);
        Fault fault = new Fault(faultName, portTypeFault);
        fault.setWsdlFaultName(portTypeFault.getName());
        setDocumentationIfPresent(fault, portTypeFault.getDocumentation());
        if (bindingFault != null) {
            // get the soapbind:fault from wsdl:fault in the binding
            SOAPFault soapFault = (SOAPFault) getExtensionOfType(bindingFault, SOAPFault.class);
            // The WSDL document is invalid, can't have wsdl:fault without soapbind:fault
            if (soapFault == null) {
                if (options.isExtensionMode()) {
                    warning(bindingFault, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_OUTPUT_MISSING_SOAP_FAULT(bindingFault.getName(), info.bindingOperation.getName()));
                    soapFault = new SOAPFault(new LocatorImpl());
                } else {
                    error(bindingFault, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_OUTPUT_MISSING_SOAP_FAULT(bindingFault.getName(), info.bindingOperation.getName()));
                }
            }
            // the soapbind:fault must have use="literal" or no use attribute, in that case its assumed "literal"
            if (!soapFault.isLiteral()) {
                if (options.isExtensionMode()) {
                    warning(soapFault, ModelerMessages.WSDLMODELER_WARNING_IGNORING_FAULT_NOT_LITERAL(bindingFault.getName(), info.bindingOperation.getName()));
                } else {
                    error(soapFault, ModelerMessages.WSDLMODELER_INVALID_OPERATION_FAULT_NOT_LITERAL(bindingFault.getName(), info.bindingOperation.getName()));
                }
                continue;
            }
            // the soapFault name must be present
            if (soapFault.getName() == null) {
                warning(bindingFault, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_NO_SOAP_FAULT_NAME(bindingFault.getName(), info.bindingOperation.getName()));
            } else if (!soapFault.getName().equals(bindingFault.getName())) {
                warning(soapFault, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_WRONG_SOAP_FAULT_NAME(soapFault.getName(), bindingFault.getName(), info.bindingOperation.getName()));
            } else if (soapFault.getNamespace() != null) {
                warning(soapFault, ModelerMessages.WSDLMODELER_WARNING_R_2716_R_2726("soapbind:fault", soapFault.getName()));
            }
        }
        com.sun.tools.ws.wsdl.document.Message faultMessage = portTypeFault.resolveMessage(info.document);
        Iterator iter2 = faultMessage.parts();
        if (!iter2.hasNext()) {
            // the WSDL document is invalid
            error(faultMessage, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_EMPTY_MESSAGE(portTypeFault.getName(), faultMessage.getName()));
        }
        MessagePart faultPart = (MessagePart) iter2.next();
        QName faultQName = faultPart.getDescriptor();
        // Don't include fault messages with non-unique soap:fault names
        if (duplicateNames.contains(faultQName)) {
            warning(faultPart, ModelerMessages.WSDLMODELER_DUPLICATE_FAULT_SOAP_NAME(portTypeFault.getName(), info.portTypeOperation.getName(), faultPart.getName()));
            continue;
        }
        if (iter2.hasNext()) {
            // the WSDL document is invalid
            error(faultMessage, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_MESSAGE_HAS_MORE_THAN_ONE_PART(portTypeFault.getName(), faultMessage.getName()));
        }
        if (faultPart.getDescriptorKind() != SchemaKinds.XSD_ELEMENT) {
            if (options.isExtensionMode()) {
                warning(faultPart, ModelerMessages.WSDLMODELER_INVALID_MESSAGE_PART_MUST_HAVE_ELEMENT_DESCRIPTOR(faultMessage.getName(), faultPart.getName()));
            } else {
                error(faultPart, ModelerMessages.WSDLMODELER_INVALID_MESSAGE_PART_MUST_HAVE_ELEMENT_DESCRIPTOR(faultMessage.getName(), faultPart.getName()));
            }
        }
        JAXBType jaxbType = getJAXBType(faultPart);
        fault.setElementName(faultPart.getDescriptor());
        fault.setJavaMemberName(Names.getExceptionClassMemberName());
        Block faultBlock = new Block(faultQName, jaxbType, faultPart);
        fault.setBlock(faultBlock);
        // createSubfaults(fault);
        if (!response.getFaultBlocksMap().containsKey(faultBlock.getName())) {
            response.addFaultBlock(faultBlock);
        }
        info.operation.addFault(fault);
    }
}
Also used : Message(com.sun.tools.ws.wsdl.document.Message) QName(javax.xml.namespace.QName) com.sun.tools.ws.wsdl.document(com.sun.tools.ws.wsdl.document) Fault(com.sun.tools.ws.processor.model.Fault) LocatorImpl(org.xml.sax.helpers.LocatorImpl)

Example 2 with Fault

use of com.sun.tools.ws.processor.model.Fault in project metro-jax-ws by eclipse-ee4j.

the class GeneratorBase method visit.

@Override
public void visit(Operation operation) throws Exception {
    operation.getRequest().accept(this);
    if (operation.getResponse() != null) {
        operation.getResponse().accept(this);
    }
    Iterator faults = operation.getFaultsSet().iterator();
    if (faults != null) {
        Fault fault;
        while (faults.hasNext()) {
            fault = (Fault) faults.next();
            fault.accept(this);
        }
    }
}
Also used : Iterator(java.util.Iterator) Fault(com.sun.tools.ws.processor.model.Fault)

Example 3 with Fault

use of com.sun.tools.ws.processor.model.Fault in project metro-jax-ws by eclipse-ee4j.

the class JwsImplGenerator method visit.

@Override
public void visit(Service service) {
    QName serviceName = service.getName();
    // process the ordered service only if it is defined
    if (options.implServiceName != null && !equalsNSOptional(options.implServiceName, serviceName))
        return;
    for (Port port : service.getPorts()) {
        if (port.isProvider()) {
            // Not generating for Provider based endpoint
            continue;
        }
        // Generate the impl class name according to
        // Xpath(/definitions/service/port[@name]);
        QName portName = port.getName();
        // process the ordered port only if it is defined
        if (options.implPortName != null && !equalsNSOptional(options.implPortName, portName))
            continue;
        String simpleClassName = serviceName.getLocalPart() + "_" + portName.getLocalPart() + "Impl";
        String className = makePackageQualified(simpleClassName);
        implFiles.add(className);
        if (donotOverride && GeneratorUtil.classExists(options, className)) {
            log("Class " + className + " exists. Not overriding.");
            return;
        }
        JDefinedClass cls = null;
        try {
            cls = getClass(className, ClassType.CLASS);
        } catch (JClassAlreadyExistsException e) {
            log("Class " + className + " generates failed. JClassAlreadyExistsException[" + className + "].");
            return;
        }
        // Each serviceImpl will implements one port interface
        JavaInterface portIntf = port.getJavaInterface();
        String portClassName = Names.customJavaTypeClassName(portIntf);
        JDefinedClass portCls = null;
        try {
            portCls = getClass(portClassName, ClassType.INTERFACE);
        } catch (JClassAlreadyExistsException e) {
            log("Class " + className + " generates failed. JClassAlreadyExistsException[" + portClassName + "].");
            return;
        }
        cls._implements(portCls);
        // create a default constructor
        cls.constructor(JMod.PUBLIC);
        // write class comment - JAXWS warning
        JDocComment comment = cls.javadoc();
        if (service.getJavaDoc() != null) {
            comment.add(service.getJavaDoc());
            comment.add("\n\n");
        }
        comment.addAll(getJAXWSClassComment());
        // @WebService
        JAnnotationUse webServiceAnn = cls.annotate(cm.ref(WebService.class));
        writeWebServiceAnnotation(service, port, webServiceAnn);
        // @BindingType
        JAnnotationUse bindingTypeAnn = cls.annotate(cm.ref(BindingType.class));
        writeBindingTypeAnnotation(port, bindingTypeAnn);
        // extra annotation
        for (GeneratorExtension f : findService(GeneratorExtension.class)) {
            f.writeWebServiceAnnotation(model, cm, cls, port);
        }
        // WebMethods
        for (Operation operation : port.getOperations()) {
            JavaMethod method = operation.getJavaMethod();
            // @WebMethod
            JMethod m;
            JDocComment methodDoc;
            String methodJavaDoc = operation.getJavaDoc();
            if (method.getReturnType().getName().equals("void")) {
                m = cls.method(JMod.PUBLIC, void.class, method.getName());
                methodDoc = m.javadoc();
            } else {
                JAXBTypeAndAnnotation retType = method.getReturnType().getType();
                m = cls.method(JMod.PUBLIC, retType.getType(), method.getName());
                retType.annotate(m);
                methodDoc = m.javadoc();
                JCommentPart ret = methodDoc.addReturn();
                ret.add("returns " + retType.getName());
            }
            if (methodJavaDoc != null)
                methodDoc.add(methodJavaDoc);
            JClass holder = cm.ref(Holder.class);
            for (JavaParameter parameter : method.getParametersList()) {
                JVar var;
                JAXBTypeAndAnnotation paramType = parameter.getType().getType();
                if (parameter.isHolder()) {
                    var = m.param(holder.narrow(paramType.getType().boxify()), parameter.getName());
                } else {
                    var = m.param(paramType.getType(), parameter.getName());
                }
                methodDoc.addParam(var);
            }
            com.sun.tools.ws.wsdl.document.Operation wsdlOp = operation.getWSDLPortTypeOperation();
            for (Fault fault : operation.getFaultsSet()) {
                m._throws(fault.getExceptionClass());
                methodDoc.addThrows(fault.getExceptionClass());
                wsdlOp.putFault(fault.getWsdlFaultName(), fault.getExceptionClass());
            }
            m.body().block().directStatement("//replace with your impl here");
            m.body().block().directStatement(getReturnString(method.getReturnType().getName()));
        }
    }
}
Also used : JavaInterface(com.sun.tools.ws.processor.model.java.JavaInterface) JDefinedClass(com.sun.codemodel.JDefinedClass) WebService(jakarta.jws.WebService) QName(javax.xml.namespace.QName) Port(com.sun.tools.ws.processor.model.Port) JClass(com.sun.codemodel.JClass) JCommentPart(com.sun.codemodel.JCommentPart) Fault(com.sun.tools.ws.processor.model.Fault) Operation(com.sun.tools.ws.processor.model.Operation) JDocComment(com.sun.codemodel.JDocComment) JClassAlreadyExistsException(com.sun.codemodel.JClassAlreadyExistsException) JAXBTypeAndAnnotation(com.sun.tools.ws.processor.model.jaxb.JAXBTypeAndAnnotation) BindingType(jakarta.xml.ws.BindingType) JAnnotationUse(com.sun.codemodel.JAnnotationUse) JavaMethod(com.sun.tools.ws.processor.model.java.JavaMethod) JavaParameter(com.sun.tools.ws.processor.model.java.JavaParameter) JMethod(com.sun.codemodel.JMethod) JVar(com.sun.codemodel.JVar)

Example 4 with Fault

use of com.sun.tools.ws.processor.model.Fault in project metro-jax-ws by eclipse-ee4j.

the class WSDLModeler method createJavaMethodForOperation.

/* (non-Javadoc)
     * @see WSDLModelerBase#createJavaMethodForOperation(WSDLPort, WSDLOperation, JavaInterface, Set, Set)
     */
protected void createJavaMethodForOperation(Port port, Operation operation, JavaInterface intf) {
    if ((operation instanceof AsyncOperation)) {
        createJavaMethodForAsyncOperation(port, operation, intf);
        return;
    }
    String candidateName = getJavaNameForOperation(operation);
    JavaMethod method = new JavaMethod(candidateName, options, errReceiver);
    Parameter returnParam = (Parameter) operation.getProperty(WSDL_RESULT_PARAMETER);
    if (returnParam != null) {
        JavaType parameterType = returnParam.getType().getJavaType();
        method.setReturnType(parameterType);
    } else {
        method.setReturnType(JavaSimpleTypeCreator.VOID_JAVATYPE);
    }
    List<Parameter> parameterOrder = (List<Parameter>) operation.getProperty(WSDL_PARAMETER_ORDER);
    for (Parameter param : parameterOrder) {
        JavaType parameterType = param.getType().getJavaType();
        String name = (param.getCustomName() != null) ? param.getCustomName() : param.getName();
        name = BindingHelper.mangleNameToVariableName(name);
        // need to ask user to customize the parameter name if its java keyword
        if (Names.isJavaReservedWord(name)) {
            name = "_" + name;
        }
        JavaParameter javaParameter = new JavaParameter(name, parameterType, param, param.isINOUT() || param.isOUT());
        if (javaParameter.isHolder()) {
            javaParameter.setHolderName(jakarta.xml.ws.Holder.class.getName());
        }
        method.addParameter(javaParameter);
        param.setJavaParameter(javaParameter);
    }
    operation.setJavaMethod(method);
    intf.addMethod(method);
    String opName = BindingHelper.mangleNameToVariableName(operation.getName().getLocalPart());
    for (Iterator iter = operation.getFaults(); iter != null && iter.hasNext(); ) {
        Fault fault = (Fault) iter.next();
        createJavaExceptionFromLiteralType(fault, port, opName);
    }
    JavaException javaException;
    Fault fault;
    for (Iterator iter = operation.getFaults(); iter.hasNext(); ) {
        fault = (Fault) iter.next();
        javaException = fault.getJavaException();
        method.addException(javaException.getName());
    }
}
Also used : Fault(com.sun.tools.ws.processor.model.Fault)

Aggregations

Fault (com.sun.tools.ws.processor.model.Fault)4 QName (javax.xml.namespace.QName)2 JAnnotationUse (com.sun.codemodel.JAnnotationUse)1 JClass (com.sun.codemodel.JClass)1 JClassAlreadyExistsException (com.sun.codemodel.JClassAlreadyExistsException)1 JCommentPart (com.sun.codemodel.JCommentPart)1 JDefinedClass (com.sun.codemodel.JDefinedClass)1 JDocComment (com.sun.codemodel.JDocComment)1 JMethod (com.sun.codemodel.JMethod)1 JVar (com.sun.codemodel.JVar)1 Operation (com.sun.tools.ws.processor.model.Operation)1 Port (com.sun.tools.ws.processor.model.Port)1 JavaInterface (com.sun.tools.ws.processor.model.java.JavaInterface)1 JavaMethod (com.sun.tools.ws.processor.model.java.JavaMethod)1 JavaParameter (com.sun.tools.ws.processor.model.java.JavaParameter)1 JAXBTypeAndAnnotation (com.sun.tools.ws.processor.model.jaxb.JAXBTypeAndAnnotation)1 com.sun.tools.ws.wsdl.document (com.sun.tools.ws.wsdl.document)1 Message (com.sun.tools.ws.wsdl.document.Message)1 WebService (jakarta.jws.WebService)1 BindingType (jakarta.xml.ws.BindingType)1