Search in sources :

Example 1 with SOAPBinding

use of jakarta.jws.soap.SOAPBinding in project metro-jax-ws by eclipse-ee4j.

the class RuntimeModeler method processMethod.

/**
 * creates the runtime model for a method on the <code>portClass</code>
 * @param method the method to model
 */
private void processMethod(Method method) {
    // int mods = method.getModifiers();
    WebMethod webMethod = getAnnotation(method, WebMethod.class);
    if (webMethod != null && webMethod.exclude())
        return;
    /*
        validations are already done

        if (!Modifier.isPublic(mods) || Modifier.isStatic(mods)) {
            if(webMethod != null) {
                // if the user put @WebMethod on these non-qualifying method,
                // it's an error
                if(Modifier.isStatic(mods))
                    throw new RuntimeModelerException(ModelerMessages.localizableRUNTIME_MODELER_WEBMETHOD_MUST_BE_NONSTATIC(method));
                else
                    throw new RuntimeModelerException(ModelerMessages.localizableRUNTIME_MODELER_WEBMETHOD_MUST_BE_PUBLIC(method));
            }
            return;
        }

        if (webMethod != null && webMethod.exclude())
            return;
*/
    String methodName = method.getName();
    boolean isOneway = (getAnnotation(method, Oneway.class) != null);
    // Check that oneway methods don't thorw any checked exceptions
    if (isOneway) {
        for (Class<?> exception : method.getExceptionTypes()) {
            if (isServiceException(exception)) {
                throw new RuntimeModelerException("runtime.modeler.oneway.operation.no.checked.exceptions", portClass.getCanonicalName(), methodName, exception.getName());
            }
        }
    }
    JavaMethodImpl javaMethod;
    // Class implementorClass = portClass;
    if (method.getDeclaringClass() == portClass) {
        javaMethod = new JavaMethodImpl(model, method, method, metadataReader);
    } else {
        try {
            Method tmpMethod = portClass.getMethod(method.getName(), method.getParameterTypes());
            javaMethod = new JavaMethodImpl(model, tmpMethod, method, metadataReader);
        } catch (NoSuchMethodException e) {
            throw new RuntimeModelerException("runtime.modeler.method.not.found", method.getName(), portClass.getName());
        }
    }
    // set MEP -oneway, async, req/resp
    MEP mep = getMEP(method);
    javaMethod.setMEP(mep);
    String action = null;
    String operationName = method.getName();
    if (webMethod != null) {
        action = webMethod.action();
        operationName = webMethod.operationName().length() > 0 ? webMethod.operationName() : operationName;
    }
    // override the @WebMethod.action value by the one from the WSDL
    if (binding != null) {
        WSDLBoundOperation bo = binding.getBinding().get(new QName(targetNamespace, operationName));
        if (bo != null) {
            WSDLInput wsdlInput = bo.getOperation().getInput();
            String wsaAction = wsdlInput.getAction();
            if (wsaAction != null && !wsdlInput.isDefaultAction())
                action = wsaAction;
            else
                action = bo.getSOAPAction();
        }
    }
    javaMethod.setOperationQName(new QName(targetNamespace, operationName));
    SOAPBinding methodBinding = getAnnotation(method, SOAPBinding.class);
    if (methodBinding != null && methodBinding.style() == SOAPBinding.Style.RPC) {
        logger.warning(ModelerMessages.RUNTIMEMODELER_INVALID_SOAPBINDING_ON_METHOD(methodBinding, method.getName(), method.getDeclaringClass().getName()));
    } else if (methodBinding == null && !method.getDeclaringClass().equals(portClass)) {
        methodBinding = getAnnotation(method.getDeclaringClass(), SOAPBinding.class);
        if (methodBinding != null && methodBinding.style() == SOAPBinding.Style.RPC && methodBinding.parameterStyle() == SOAPBinding.ParameterStyle.BARE) {
            throw new RuntimeModelerException("runtime.modeler.invalid.soapbinding.parameterstyle", methodBinding, method.getDeclaringClass());
        }
    }
    if (methodBinding != null && defaultBinding.getStyle() != methodBinding.style()) {
        throw new RuntimeModelerException("runtime.modeler.soapbinding.conflict", methodBinding.style(), method.getName(), defaultBinding.getStyle());
    }
    boolean methodIsWrapped = isWrapped;
    Style style = defaultBinding.getStyle();
    if (methodBinding != null) {
        SOAPBindingImpl mySOAPBinding = createBinding(methodBinding);
        style = mySOAPBinding.getStyle();
        if (action != null)
            mySOAPBinding.setSOAPAction(action);
        methodIsWrapped = methodBinding.parameterStyle().equals(SOAPBinding.ParameterStyle.WRAPPED);
        javaMethod.setBinding(mySOAPBinding);
    } else {
        SOAPBindingImpl sb = new SOAPBindingImpl(defaultBinding);
        if (action != null) {
            sb.setSOAPAction(action);
        } else {
            String defaults = SOAPVersion.SOAP_11 == sb.getSOAPVersion() ? "" : null;
            sb.setSOAPAction(defaults);
        }
        javaMethod.setBinding(sb);
    }
    if (!methodIsWrapped) {
        processDocBareMethod(javaMethod, operationName, method);
    } else if (style.equals(Style.DOCUMENT)) {
        processDocWrappedMethod(javaMethod, methodName, operationName, method);
    } else {
        processRpcMethod(javaMethod, methodName, operationName, method);
    }
    model.addJavaMethod(javaMethod);
}
Also used : QName(javax.xml.namespace.QName) SOAPBinding(jakarta.jws.soap.SOAPBinding) Method(java.lang.reflect.Method) WSDLBoundOperation(com.sun.xml.ws.api.model.wsdl.WSDLBoundOperation) WSDLInput(com.sun.xml.ws.api.model.wsdl.WSDLInput) MEP(com.sun.xml.ws.api.model.MEP) Style(jakarta.jws.soap.SOAPBinding.Style) SOAPBindingImpl(com.sun.xml.ws.model.soap.SOAPBindingImpl)

Example 2 with SOAPBinding

use of jakarta.jws.soap.SOAPBinding in project metro-jax-ws by eclipse-ee4j.

the class RuntimeModeler method processClass.

void processClass(Class clazz) {
    classUsesWebMethod = new HashSet<>();
    determineWebMethodUse(clazz);
    WebService webService = getAnnotation(clazz, WebService.class);
    QName portTypeName = getPortTypeName(clazz, targetNamespace, metadataReader);
    // String portTypeLocalName  = clazz.getSimpleName();
    // if (webService.name().length() >0)
    // portTypeLocalName = webService.name();
    // 
    // targetNamespace = webService.targetNamespace();
    packageName = "";
    if (clazz.getPackage() != null)
        packageName = clazz.getPackage().getName();
    // if (targetNamespace.length() == 0) {
    // targetNamespace = getNamespace(packageName);
    // }
    // model.setTargetNamespace(targetNamespace);
    // QName portTypeName = new QName(targetNamespace, portTypeLocalName);
    targetNamespace = portTypeName.getNamespaceURI();
    model.setPortTypeName(portTypeName);
    model.setTargetNamespace(targetNamespace);
    model.defaultSchemaNamespaceSuffix = config.getMappingInfo().getDefaultSchemaNamespaceSuffix();
    model.setWSDLLocation(webService.wsdlLocation());
    SOAPBinding soapBinding = getAnnotation(clazz, SOAPBinding.class);
    if (soapBinding != null) {
        if (soapBinding.style() == SOAPBinding.Style.RPC && soapBinding.parameterStyle() == SOAPBinding.ParameterStyle.BARE) {
            throw new RuntimeModelerException("runtime.modeler.invalid.soapbinding.parameterstyle", soapBinding, clazz);
        }
        isWrapped = soapBinding.parameterStyle() == SOAPBinding.ParameterStyle.WRAPPED;
    }
    defaultBinding = createBinding(soapBinding);
    for (Method method : clazz.getMethods()) {
        if (!clazz.isInterface()) {
            // if clazz is SEI, then all methods are web methods
            if (method.getDeclaringClass() == Object.class)
                continue;
            if (!getBooleanSystemProperty("com.sun.xml.ws.legacyWebMethod")) {
                // legacy webMethod computation behaviour to be used
                if (!isWebMethodBySpec(method, clazz))
                    continue;
            } else {
                if (!isWebMethod(method))
                    continue;
            }
        }
        // TODO: binding can be null. We need to figure out how to post-process
        // RuntimeModel to link to WSDLModel
        processMethod(method);
    }
    // Add additional jaxb classes referenced by {@link XmlSeeAlso}
    XmlSeeAlso xmlSeeAlso = getAnnotation(clazz, XmlSeeAlso.class);
    if (xmlSeeAlso != null)
        model.addAdditionalClasses(xmlSeeAlso.value());
}
Also used : QName(javax.xml.namespace.QName) SOAPBinding(jakarta.jws.soap.SOAPBinding) Method(java.lang.reflect.Method) XmlSeeAlso(jakarta.xml.bind.annotation.XmlSeeAlso)

Example 3 with SOAPBinding

use of jakarta.jws.soap.SOAPBinding in project metro-jax-ws by eclipse-ee4j.

the class RuntimeModeler method buildRuntimeModel.

// currently has many local vars which will be eliminated after debugging issues
// first draft
/**
 * builds the runtime model from the <code>portClass</code> using the binding ID <code>bindingId</code>.
 * @return the runtime model for the <code>portClass</code>.
 */
public AbstractSEIModelImpl buildRuntimeModel() {
    model = new SOAPSEIModel(features);
    model.contractClass = config.getContractClass();
    model.endpointClass = config.getEndpointClass();
    model.classLoader = this.classLoader;
    model.wsBinding = wsBinding;
    model.databindingInfo.setWsdlURL(config.getWsdlURL());
    model.databindingInfo.properties().putAll(config.properties());
    if (model.contractClass == null)
        model.contractClass = portClass;
    if (model.endpointClass == null && !portClass.isInterface())
        model.endpointClass = portClass;
    Class<?> seiClass = portClass;
    metadataReader.getProperties(model.databindingInfo.properties(), portClass);
    WebService webService = getAnnotation(portClass, WebService.class);
    if (webService == null) {
        throw new RuntimeModelerException("runtime.modeler.no.webservice.annotation", portClass.getCanonicalName());
    }
    Class<?> seiFromConfig = configEndpointInterface();
    if (webService.endpointInterface().length() > 0 || seiFromConfig != null) {
        if (seiFromConfig != null) {
            seiClass = seiFromConfig;
        } else {
            seiClass = getClass(webService.endpointInterface(), ModelerMessages.localizableRUNTIME_MODELER_CLASS_NOT_FOUND(webService.endpointInterface()));
        }
        model.contractClass = seiClass;
        model.endpointClass = portClass;
        WebService seiService = getAnnotation(seiClass, WebService.class);
        if (seiService == null) {
            throw new RuntimeModelerException("runtime.modeler.endpoint.interface.no.webservice", webService.endpointInterface());
        }
        // check if @SOAPBinding is defined on the impl class
        SOAPBinding sbPortClass = getAnnotation(portClass, SOAPBinding.class);
        SOAPBinding sbSei = getAnnotation(seiClass, SOAPBinding.class);
        if (sbPortClass != null) {
            if (sbSei == null || sbSei.style() != sbPortClass.style() || sbSei.use() != sbPortClass.use()) {
                logger.warning(ServerMessages.RUNTIMEMODELER_INVALIDANNOTATION_ON_IMPL("@SOAPBinding", portClass.getName(), seiClass.getName()));
            }
        }
    }
    if (serviceName == null)
        serviceName = getServiceName(portClass, metadataReader);
    model.setServiceQName(serviceName);
    if (portName == null)
        portName = getPortName(portClass, metadataReader, serviceName.getNamespaceURI());
    model.setPortName(portName);
    // Check if databinding is overridden in annotation.
    com.oracle.webservices.api.databinding.DatabindingMode dbm2 = getAnnotation(portClass, com.oracle.webservices.api.databinding.DatabindingMode.class);
    if (dbm2 != null)
        model.databindingInfo.setDatabindingMode(dbm2.value());
    processClass(seiClass);
    if (model.getJavaMethods().size() == 0)
        throw new RuntimeModelerException("runtime.modeler.no.operations", portClass.getName());
    model.postProcess();
    // Make the configured databinding mode available to the
    // DatabindingConfig.
    config.properties().put(BindingContext.class.getName(), model.bindingContext);
    // we still need to do this correctly
    if (binding != null)
        model.freeze(binding);
    return model;
}
Also used : SOAPBinding(jakarta.jws.soap.SOAPBinding) BindingContext(com.sun.xml.ws.spi.db.BindingContext)

Example 4 with SOAPBinding

use of jakarta.jws.soap.SOAPBinding in project metro-jax-ws by eclipse-ee4j.

the class WebServiceVisitor method isLegalMethod.

protected boolean isLegalMethod(ExecutableElement method, TypeElement typeElement) {
    WebMethod webMethod = method.getAnnotation(WebMethod.class);
    // SEI cannot have methods with @WebMethod(exclude=true)
    if (typeElement.getKind().equals(ElementKind.INTERFACE) && webMethod != null && webMethod.exclude())
        builder.processError(WebserviceapMessages.WEBSERVICEAP_INVALID_SEI_ANNOTATION_ELEMENT_EXCLUDE("exclude=true", typeElement.getQualifiedName(), method.toString()), method);
    // With https://jax-ws.dev.java.net/issues/show_bug.cgi?id=577, hasWebMethods has no effect
    if (// backwards compatibility (for legacyWebMethod computation)
    hasWebMethods && webMethod == null)
        return true;
    if ((webMethod != null) && webMethod.exclude()) {
        return true;
    }
    /*
        This check is not needed as Impl class is already checked that it is not abstract.
        if (typeElement instanceof TypeElement && method.getModifiers().contains(Modifier.ABSTRACT)) {  // use Kind.equals instead of instanceOf
            builder.processError(method.getPosition(), WebserviceapMessages.WEBSERVICEAP_WEBSERVICE_METHOD_IS_ABSTRACT(typeElement.getQualifiedName(), method.getSimpleName()));
            return false;
        }
        */
    TypeMirror returnType = method.getReturnType();
    if (!isLegalType(returnType)) {
        builder.processError(WebserviceapMessages.WEBSERVICEAP_METHOD_RETURN_TYPE_CANNOT_IMPLEMENT_REMOTE(typeElement.getQualifiedName(), method.getSimpleName(), returnType), method);
    }
    boolean isOneWay = method.getAnnotation(Oneway.class) != null;
    if (isOneWay && !isValidOneWayMethod(method, typeElement))
        return false;
    SOAPBinding soapBinding = method.getAnnotation(SOAPBinding.class);
    if (soapBinding != null) {
        if (soapBinding.style().equals(SOAPBinding.Style.RPC)) {
            builder.processError(WebserviceapMessages.WEBSERVICEAP_RPC_SOAPBINDING_NOT_ALLOWED_ON_METHOD(typeElement.getQualifiedName(), method.toString()), method);
        }
    }
    int paramIndex = 0;
    for (VariableElement parameter : method.getParameters()) {
        if (!isLegalParameter(parameter, method, typeElement, paramIndex++))
            return false;
    }
    if (!isDocLitWrapped() && soapStyle.equals(SOAPStyle.DOCUMENT)) {
        VariableElement outParam = getOutParameter(method);
        int inParams = getModeParameterCount(method, WebParam.Mode.IN);
        int outParams = getModeParameterCount(method, WebParam.Mode.OUT);
        if (inParams != 1) {
            builder.processError(WebserviceapMessages.WEBSERVICEAP_DOC_BARE_AND_NO_ONE_IN(typeElement.getQualifiedName(), method.toString()), method);
        }
        if (returnType.accept(NO_TYPE_VISITOR, null)) {
            if (outParam == null && !isOneWay) {
                builder.processError(WebserviceapMessages.WEBSERVICEAP_DOC_BARE_NO_OUT(typeElement.getQualifiedName(), method.toString()), method);
            }
            if (outParams != 1) {
                if (!isOneWay && outParams != 0)
                    builder.processError(WebserviceapMessages.WEBSERVICEAP_DOC_BARE_NO_RETURN_AND_NO_OUT(typeElement.getQualifiedName(), method.toString()), method);
            }
        } else {
            if (outParams > 0) {
                builder.processError(WebserviceapMessages.WEBSERVICEAP_DOC_BARE_RETURN_AND_OUT(typeElement.getQualifiedName(), method.toString()), outParam);
            }
        }
    }
    return true;
}
Also used : WebMethod(jakarta.jws.WebMethod) TypeMirror(javax.lang.model.type.TypeMirror) Oneway(jakarta.jws.Oneway) SOAPBinding(jakarta.jws.soap.SOAPBinding) VariableElement(javax.lang.model.element.VariableElement)

Example 5 with SOAPBinding

use of jakarta.jws.soap.SOAPBinding in project metro-jax-ws by eclipse-ee4j.

the class WebServiceVisitor method popSoapBinding.

protected SOAPBinding popSoapBinding() {
    if (pushedSoapBinding)
        soapBindingStack.pop();
    SOAPBinding soapBinding = null;
    if (!soapBindingStack.empty()) {
        soapBinding = soapBindingStack.peek();
        if (soapBinding.style().equals(SOAPBinding.Style.RPC)) {
            soapStyle = SOAPStyle.RPC;
            wrapped = true;
        } else {
            soapStyle = SOAPStyle.DOCUMENT;
            wrapped = soapBinding.parameterStyle().equals(ParameterStyle.WRAPPED);
        }
    } else {
        pushedSoapBinding = false;
    }
    return soapBinding;
}
Also used : SOAPBinding(jakarta.jws.soap.SOAPBinding)

Aggregations

SOAPBinding (jakarta.jws.soap.SOAPBinding)7 WebMethod (jakarta.jws.WebMethod)2 Method (java.lang.reflect.Method)2 QName (javax.xml.namespace.QName)2 MEP (com.sun.xml.ws.api.model.MEP)1 WSDLBoundOperation (com.sun.xml.ws.api.model.wsdl.WSDLBoundOperation)1 WSDLInput (com.sun.xml.ws.api.model.wsdl.WSDLInput)1 SOAPBindingImpl (com.sun.xml.ws.model.soap.SOAPBindingImpl)1 BindingContext (com.sun.xml.ws.spi.db.BindingContext)1 Oneway (jakarta.jws.Oneway)1 Style (jakarta.jws.soap.SOAPBinding.Style)1 XmlSeeAlso (jakarta.xml.bind.annotation.XmlSeeAlso)1 PackageElement (javax.lang.model.element.PackageElement)1 VariableElement (javax.lang.model.element.VariableElement)1 TypeMirror (javax.lang.model.type.TypeMirror)1