Search in sources :

Example 1 with ParameterBinding

use of com.sun.xml.ws.api.model.ParameterBinding in project metro-jax-ws by eclipse-ee4j.

the class AbstractSEIModelImpl method applyRpcLitParamBinding.

/**
 * Applies binding related information to the RpcLitPayload. The payload map is populated correctly
 * @return
 * Returns attachment parameters if/any.
 */
private List<ParameterImpl> applyRpcLitParamBinding(JavaMethodImpl method, WrapperParameter wrapperParameter, WSDLBoundPortType boundPortType, Mode mode) {
    QName opName = new QName(boundPortType.getPortTypeName().getNamespaceURI(), method.getOperationName());
    WSDLBoundOperation bo = boundPortType.get(opName);
    Map<Integer, ParameterImpl> bodyParams = new HashMap<>();
    List<ParameterImpl> unboundParams = new ArrayList<>();
    List<ParameterImpl> attachParams = new ArrayList<>();
    for (ParameterImpl param : wrapperParameter.wrapperChildren) {
        String partName = param.getPartName();
        if (partName == null)
            continue;
        ParameterBinding paramBinding = boundPortType.getBinding(opName, partName, mode);
        if (paramBinding != null) {
            if (mode == Mode.IN)
                param.setInBinding(paramBinding);
            else if (mode == Mode.OUT || mode == Mode.INOUT)
                param.setOutBinding(paramBinding);
            if (paramBinding.isUnbound()) {
                unboundParams.add(param);
            } else if (paramBinding.isAttachment()) {
                attachParams.add(param);
            } else if (paramBinding.isBody()) {
                if (bo != null) {
                    WSDLPart p = bo.getPart(param.getPartName(), mode);
                    if (p != null)
                        bodyParams.put(p.getIndex(), param);
                    else
                        bodyParams.put(bodyParams.size(), param);
                } else {
                    bodyParams.put(bodyParams.size(), param);
                }
            }
        }
    }
    wrapperParameter.clear();
    for (int i = 0; i < bodyParams.size(); i++) {
        ParameterImpl p = bodyParams.get(i);
        wrapperParameter.addWrapperChild(p);
    }
    // add unbounded parts
    for (ParameterImpl p : unboundParams) {
        wrapperParameter.addWrapperChild(p);
    }
    return attachParams;
}
Also used : WSDLBoundOperation(com.sun.xml.ws.api.model.wsdl.WSDLBoundOperation) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) ParameterBinding(com.sun.xml.ws.api.model.ParameterBinding) WSDLPart(com.sun.xml.ws.api.model.wsdl.WSDLPart)

Example 2 with ParameterBinding

use of com.sun.xml.ws.api.model.ParameterBinding in project metro-jax-ws by eclipse-ee4j.

the class RuntimeModeler method processRpcMethod.

/**
 * models a rpc/literal method
 * @param javaMethod the runtime model <code>JavaMethod</code> instance being created
 * @param methodName the name of the <code>method</code> being modeled.
 * @param operationName the WSDL operation name for this <code>method</code>
 * @param method the runtime model <code>JavaMethod</code> instance being created
 */
protected void processRpcMethod(JavaMethodImpl javaMethod, String methodName, String operationName, Method method) {
    boolean isOneway = getAnnotation(method, Oneway.class) != null;
    // use Map to build parameters in the part order when they are known.
    // if part is unbound, we just put them at the end, and for that we
    // use a large index (10000+) to avoid colliding with ordered ones.
    // this assumes that there's no operation with # of parameters > 10000,
    // but I think it's a pretty safe assumption - KK.
    Map<Integer, ParameterImpl> resRpcParams = new TreeMap<>();
    Map<Integer, ParameterImpl> reqRpcParams = new TreeMap<>();
    // Lets take the service namespace and overwrite it with the one we get it from wsdl
    String reqNamespace = targetNamespace;
    String respNamespace = targetNamespace;
    if (binding != null && Style.RPC.equals(binding.getBinding().getStyle())) {
        QName opQName = new QName(binding.getBinding().getPortTypeName().getNamespaceURI(), operationName);
        WSDLBoundOperation op = binding.getBinding().get(opQName);
        if (op != null) {
            // it cant be null, but lets not fail and try to work with service namespce
            if (op.getRequestNamespace() != null) {
                reqNamespace = op.getRequestNamespace();
            }
            // it cant be null, but lets not fail and try to work with service namespce
            if (op.getResponseNamespace() != null) {
                respNamespace = op.getResponseNamespace();
            }
        }
    }
    QName reqElementName = new QName(reqNamespace, operationName);
    javaMethod.setRequestPayloadName(reqElementName);
    QName resElementName = null;
    if (!isOneway) {
        resElementName = new QName(respNamespace, operationName + RESPONSE);
    }
    Class wrapperType = WrapperComposite.class;
    TypeInfo typeRef = new TypeInfo(reqElementName, wrapperType);
    WrapperParameter requestWrapper = new WrapperParameter(javaMethod, typeRef, Mode.IN, 0);
    requestWrapper.setInBinding(ParameterBinding.BODY);
    javaMethod.addParameter(requestWrapper);
    WrapperParameter responseWrapper = null;
    if (!isOneway) {
        typeRef = new TypeInfo(resElementName, wrapperType);
        responseWrapper = new WrapperParameter(javaMethod, typeRef, Mode.OUT, -1);
        responseWrapper.setOutBinding(ParameterBinding.BODY);
        javaMethod.addParameter(responseWrapper);
    }
    Class returnType = method.getReturnType();
    String resultName = RETURN;
    String resultTNS = targetNamespace;
    String resultPartName = resultName;
    boolean isResultHeader = false;
    WebResult webResult = getAnnotation(method, WebResult.class);
    if (webResult != null) {
        isResultHeader = webResult.header();
        if (webResult.name().length() > 0)
            resultName = webResult.name();
        if (webResult.partName().length() > 0) {
            resultPartName = webResult.partName();
            if (!isResultHeader)
                resultName = resultPartName;
        } else
            resultPartName = resultName;
        if (webResult.targetNamespace().length() > 0)
            resultTNS = webResult.targetNamespace();
        isResultHeader = webResult.header();
    }
    QName resultQName;
    if (isResultHeader)
        resultQName = new QName(resultTNS, resultName);
    else
        resultQName = new QName(resultName);
    if (javaMethod.isAsync()) {
        returnType = getAsyncReturnType(method, returnType);
    }
    if (!isOneway && returnType != null && returnType != void.class) {
        Annotation[] rann = getAnnotations(method);
        TypeInfo rTypeReference = new TypeInfo(resultQName, returnType, rann);
        metadataReader.getProperties(rTypeReference.properties(), method);
        rTypeReference.setGenericType(method.getGenericReturnType());
        ParameterImpl returnParameter = new ParameterImpl(javaMethod, rTypeReference, Mode.OUT, -1);
        returnParameter.setPartName(resultPartName);
        if (isResultHeader) {
            returnParameter.setBinding(ParameterBinding.HEADER);
            javaMethod.addParameter(returnParameter);
            rTypeReference.setGlobalElement(true);
        } else {
            ParameterBinding rb = getBinding(operationName, resultPartName, false, Mode.OUT);
            returnParameter.setBinding(rb);
            if (rb.isBody()) {
                rTypeReference.setGlobalElement(false);
                WSDLPart p = getPart(new QName(targetNamespace, operationName), resultPartName, Mode.OUT);
                if (p == null)
                    resRpcParams.put(resRpcParams.size() + 10000, returnParameter);
                else
                    resRpcParams.put(p.getIndex(), returnParameter);
            } else {
                javaMethod.addParameter(returnParameter);
            }
        }
    }
    // get WebParam
    Class<?>[] parameterTypes = method.getParameterTypes();
    Type[] genericParameterTypes = method.getGenericParameterTypes();
    Annotation[][] pannotations = getParamAnnotations(method);
    int pos = 0;
    for (Class clazzType : parameterTypes) {
        String paramName = "";
        String paramNamespace = "";
        String partName = "";
        boolean isHeader = false;
        if (javaMethod.isAsync() && AsyncHandler.class.isAssignableFrom(clazzType)) {
            continue;
        }
        boolean isHolder = HOLDER_CLASS.isAssignableFrom(clazzType);
        // set the actual type argument of Holder in the TypeReference
        if (isHolder) {
            if (clazzType == Holder.class)
                clazzType = erasure(((ParameterizedType) genericParameterTypes[pos]).getActualTypeArguments()[0]);
        }
        Mode paramMode = isHolder ? Mode.INOUT : Mode.IN;
        for (Annotation annotation : pannotations[pos]) {
            if (annotation.annotationType() == jakarta.jws.WebParam.class) {
                jakarta.jws.WebParam webParam = (jakarta.jws.WebParam) annotation;
                paramName = webParam.name();
                partName = webParam.partName();
                isHeader = webParam.header();
                WebParam.Mode mode = webParam.mode();
                paramNamespace = webParam.targetNamespace();
                if (isHolder && mode == Mode.IN)
                    mode = Mode.INOUT;
                paramMode = mode;
                break;
            }
        }
        if (paramName.length() == 0) {
            paramName = "arg" + pos;
        }
        if (partName.length() == 0) {
            partName = paramName;
        } else if (!isHeader) {
            paramName = partName;
        }
        if (partName.length() == 0) {
            partName = paramName;
        }
        QName paramQName;
        if (!isHeader) {
            // its rpclit body param, set namespace to ""
            paramQName = new QName("", paramName);
        } else {
            if (paramNamespace.length() == 0)
                paramNamespace = targetNamespace;
            paramQName = new QName(paramNamespace, paramName);
        }
        typeRef = new TypeInfo(paramQName, clazzType, pannotations[pos]);
        metadataReader.getProperties(typeRef.properties(), method, pos);
        typeRef.setGenericType(genericParameterTypes[pos]);
        ParameterImpl param = new ParameterImpl(javaMethod, typeRef, paramMode, pos++);
        param.setPartName(partName);
        if (paramMode == Mode.INOUT) {
            ParameterBinding pb = getBinding(operationName, partName, isHeader, Mode.IN);
            param.setInBinding(pb);
            pb = getBinding(operationName, partName, isHeader, Mode.OUT);
            param.setOutBinding(pb);
        } else {
            if (isHeader) {
                typeRef.setGlobalElement(true);
                param.setBinding(ParameterBinding.HEADER);
            } else {
                ParameterBinding pb = getBinding(operationName, partName, false, paramMode);
                param.setBinding(pb);
            }
        }
        if (param.getInBinding().isBody()) {
            typeRef.setGlobalElement(false);
            if (!param.isOUT()) {
                WSDLPart p = getPart(new QName(targetNamespace, operationName), partName, Mode.IN);
                if (p == null)
                    reqRpcParams.put(reqRpcParams.size() + 10000, param);
                else
                    reqRpcParams.put(param.getIndex(), param);
            }
            if (!param.isIN()) {
                if (isOneway) {
                    throw new RuntimeModelerException("runtime.modeler.oneway.operation.no.out.parameters", portClass.getCanonicalName(), methodName);
                }
                WSDLPart p = getPart(new QName(targetNamespace, operationName), partName, Mode.OUT);
                if (p == null)
                    resRpcParams.put(resRpcParams.size() + 10000, param);
                else
                    resRpcParams.put(p.getIndex(), param);
            }
        } else {
            javaMethod.addParameter(param);
        }
    }
    for (ParameterImpl p : reqRpcParams.values()) requestWrapper.addWrapperChild(p);
    for (ParameterImpl p : resRpcParams.values()) responseWrapper.addWrapperChild(p);
    processExceptions(javaMethod, method);
}
Also used : jakarta.jws(jakarta.jws) ParameterizedType(java.lang.reflect.ParameterizedType) WrapperComposite(com.sun.xml.ws.spi.db.WrapperComposite) Mode(jakarta.jws.WebParam.Mode) QName(javax.xml.namespace.QName) Mode(jakarta.jws.WebParam.Mode) TreeMap(java.util.TreeMap) TypeInfo(com.sun.xml.ws.spi.db.TypeInfo) Annotation(java.lang.annotation.Annotation) ParameterBinding(com.sun.xml.ws.api.model.ParameterBinding) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ExceptionType(com.sun.xml.ws.api.model.ExceptionType) WSDLBoundOperation(com.sun.xml.ws.api.model.wsdl.WSDLBoundOperation) WSDLPart(com.sun.xml.ws.api.model.wsdl.WSDLPart)

Example 3 with ParameterBinding

use of com.sun.xml.ws.api.model.ParameterBinding in project metro-jax-ws by eclipse-ee4j.

the class SOAPSEIModel method fillHeaders.

/**
 */
private void fillHeaders(Iterator<ParameterImpl> params, Set<QName> headers, Mode mode) {
    while (params.hasNext()) {
        ParameterImpl param = params.next();
        ParameterBinding binding = (mode == Mode.IN) ? param.getInBinding() : param.getOutBinding();
        QName name = param.getName();
        if (binding.isHeader() && !headers.contains(name)) {
            headers.add(name);
        }
    }
}
Also used : QName(javax.xml.namespace.QName) ParameterBinding(com.sun.xml.ws.api.model.ParameterBinding)

Example 4 with ParameterBinding

use of com.sun.xml.ws.api.model.ParameterBinding in project metro-jax-ws by eclipse-ee4j.

the class WSDLBoundOperationImpl method getRequestPayloadName.

@Override
@Nullable
public QName getRequestPayloadName() {
    if (emptyRequestPayload)
        return null;
    if (requestPayloadName != null)
        return requestPayloadName;
    if (style.equals(Style.RPC)) {
        String ns = getRequestNamespace() != null ? getRequestNamespace() : name.getNamespaceURI();
        requestPayloadName = new QName(ns, name.getLocalPart());
        return requestPayloadName;
    } else {
        QName inMsgName = operation.getInput().getMessage().getName();
        EditableWSDLMessage message = messages.get(inMsgName);
        for (EditableWSDLPart part : message.parts()) {
            ParameterBinding binding = getInputBinding(part.getName());
            if (binding.isBody()) {
                requestPayloadName = part.getDescriptor().name();
                return requestPayloadName;
            }
        }
        // Its empty payload
        emptyRequestPayload = true;
    }
    // empty body
    return null;
}
Also used : EditableWSDLPart(com.sun.xml.ws.api.model.wsdl.editable.EditableWSDLPart) QName(javax.xml.namespace.QName) EditableWSDLMessage(com.sun.xml.ws.api.model.wsdl.editable.EditableWSDLMessage) ParameterBinding(com.sun.xml.ws.api.model.ParameterBinding) Nullable(com.sun.istack.Nullable)

Example 5 with ParameterBinding

use of com.sun.xml.ws.api.model.ParameterBinding in project metro-jax-ws by eclipse-ee4j.

the class WSDLModelImpl method finalizeRpcLitBinding.

public void finalizeRpcLitBinding(EditableWSDLBoundPortType boundPortType) {
    assert (boundPortType != null);
    QName portTypeName = boundPortType.getPortTypeName();
    if (portTypeName == null)
        return;
    WSDLPortType pt = portTypes.get(portTypeName);
    if (pt == null)
        return;
    for (EditableWSDLBoundOperation bop : boundPortType.getBindingOperations()) {
        WSDLOperation pto = pt.get(bop.getName().getLocalPart());
        WSDLMessage inMsgName = pto.getInput().getMessage();
        if (inMsgName == null)
            continue;
        EditableWSDLMessage inMsg = messages.get(inMsgName.getName());
        int bodyindex = 0;
        if (inMsg != null) {
            for (EditableWSDLPart part : inMsg.parts()) {
                String name = part.getName();
                ParameterBinding pb = bop.getInputBinding(name);
                if (pb.isBody()) {
                    part.setIndex(bodyindex++);
                    part.setBinding(pb);
                    bop.addPart(part, Mode.IN);
                }
            }
        }
        bodyindex = 0;
        if (pto.isOneWay())
            continue;
        WSDLMessage outMsgName = pto.getOutput().getMessage();
        if (outMsgName == null)
            continue;
        EditableWSDLMessage outMsg = messages.get(outMsgName.getName());
        if (outMsg != null) {
            for (EditableWSDLPart part : outMsg.parts()) {
                String name = part.getName();
                ParameterBinding pb = bop.getOutputBinding(name);
                if (pb.isBody()) {
                    part.setIndex(bodyindex++);
                    part.setBinding(pb);
                    bop.addPart(part, Mode.OUT);
                }
            }
        }
    }
}
Also used : EditableWSDLBoundOperation(com.sun.xml.ws.api.model.wsdl.editable.EditableWSDLBoundOperation) EditableWSDLMessage(com.sun.xml.ws.api.model.wsdl.editable.EditableWSDLMessage) WSDLMessage(com.sun.xml.ws.api.model.wsdl.WSDLMessage) WSDLPortType(com.sun.xml.ws.api.model.wsdl.WSDLPortType) EditableWSDLPortType(com.sun.xml.ws.api.model.wsdl.editable.EditableWSDLPortType) EditableWSDLPart(com.sun.xml.ws.api.model.wsdl.editable.EditableWSDLPart) QName(javax.xml.namespace.QName) EditableWSDLMessage(com.sun.xml.ws.api.model.wsdl.editable.EditableWSDLMessage) WSDLOperation(com.sun.xml.ws.api.model.wsdl.WSDLOperation) ParameterBinding(com.sun.xml.ws.api.model.ParameterBinding)

Aggregations

ParameterBinding (com.sun.xml.ws.api.model.ParameterBinding)9 QName (javax.xml.namespace.QName)8 EditableWSDLMessage (com.sun.xml.ws.api.model.wsdl.editable.EditableWSDLMessage)3 EditableWSDLPart (com.sun.xml.ws.api.model.wsdl.editable.EditableWSDLPart)3 Nullable (com.sun.istack.Nullable)2 ExceptionType (com.sun.xml.ws.api.model.ExceptionType)2 WSDLBoundOperation (com.sun.xml.ws.api.model.wsdl.WSDLBoundOperation)2 WSDLPart (com.sun.xml.ws.api.model.wsdl.WSDLPart)2 TypeInfo (com.sun.xml.ws.spi.db.TypeInfo)2 jakarta.jws (jakarta.jws)2 Mode (jakarta.jws.WebParam.Mode)2 Annotation (java.lang.annotation.Annotation)2 ParameterizedType (java.lang.reflect.ParameterizedType)2 Type (java.lang.reflect.Type)2 WSDLMessage (com.sun.xml.ws.api.model.wsdl.WSDLMessage)1 WSDLOperation (com.sun.xml.ws.api.model.wsdl.WSDLOperation)1 WSDLPortType (com.sun.xml.ws.api.model.wsdl.WSDLPortType)1 EditableWSDLBoundOperation (com.sun.xml.ws.api.model.wsdl.editable.EditableWSDLBoundOperation)1 EditableWSDLPortType (com.sun.xml.ws.api.model.wsdl.editable.EditableWSDLPortType)1 WrapperComposite (com.sun.xml.ws.spi.db.WrapperComposite)1