Search in sources :

Example 16 with Message

use of com.sun.tools.ws.wsdl.document.Message in project metro-jax-ws by eclipse-ee4j.

the class WSDLModeler method getRequestParameters.

private List<Parameter> getRequestParameters(Request request, List<String> parameterList) {
    Message inputMessage = getInputMessage();
    // there is no input message, return zero parameters
    if (inputMessage != null && !inputMessage.parts().hasNext()) {
        return new ArrayList<>();
    }
    List<Parameter> inParameters = null;
    QName reqBodyName;
    Block reqBlock;
    JAXBType jaxbReqType;
    boolean unwrappable = isUnwrappable();
    boolean doneSOAPBody = false;
    // setup request parameters
    for (String inParamName : parameterList) {
        MessagePart part = inputMessage.getPart(inParamName);
        if (part == null) {
            continue;
        }
        reqBodyName = part.getDescriptor();
        jaxbReqType = getJAXBType(part);
        if (unwrappable) {
            // So build body and header blocks and set to request and response
            JAXBStructuredType jaxbRequestType = ModelerUtils.createJAXBStructureType(jaxbReqType);
            reqBlock = new Block(reqBodyName, jaxbRequestType, part);
            if (ModelerUtils.isBoundToSOAPBody(part)) {
                request.addBodyBlock(reqBlock);
            } else if (ModelerUtils.isUnbound(part)) {
                request.addUnboundBlock(reqBlock);
            }
            inParameters = ModelerUtils.createUnwrappedParameters(jaxbRequestType, reqBlock);
            for (Parameter param : inParameters) {
                setCustomizedParameterName(info.portTypeOperation, inputMessage, part, param, unwrappable);
            }
        } else {
            reqBlock = new Block(reqBodyName, jaxbReqType, part);
            if (ModelerUtils.isBoundToSOAPBody(part) && !doneSOAPBody) {
                doneSOAPBody = true;
                request.addBodyBlock(reqBlock);
            } else if (ModelerUtils.isBoundToSOAPHeader(part)) {
                request.addHeaderBlock(reqBlock);
            } else if (ModelerUtils.isBoundToMimeContent(part)) {
                List<MIMEContent> mimeContents = getMimeContents(info.bindingOperation.getInput(), getInputMessage(), part.getName());
                jaxbReqType = getAttachmentType(mimeContents, part);
                // reqBlock = new Block(new QName(part.getName()), jaxbReqType);
                reqBlock = new Block(jaxbReqType.getName(), jaxbReqType, part);
                request.addAttachmentBlock(reqBlock);
            } else if (ModelerUtils.isUnbound(part)) {
                request.addUnboundBlock(reqBlock);
            }
            if (inParameters == null) {
                inParameters = new ArrayList<>();
            }
            Parameter param = ModelerUtils.createParameter(part.getName(), jaxbReqType, reqBlock);
            setCustomizedParameterName(info.portTypeOperation, inputMessage, part, param, false);
            inParameters.add(param);
        }
    }
    return inParameters;
}
Also used : Message(com.sun.tools.ws.wsdl.document.Message) QName(javax.xml.namespace.QName) MIMEContent(com.sun.tools.ws.wsdl.document.mime.MIMEContent)

Example 17 with Message

use of com.sun.tools.ws.wsdl.document.Message in project metro-jax-ws by eclipse-ee4j.

the class WSDLModeler method createAsyncOperation.

private Operation createAsyncOperation(Operation syncOperation, StyleAndUse styleAndUse, AsyncOperationType asyncType) {
    boolean isRequestResponse = info.portTypeOperation.getStyle() == OperationStyle.REQUEST_RESPONSE;
    if (!isRequestResponse) {
        return null;
    }
    // create async operations
    AsyncOperation operation = new AsyncOperation(info.operation, info.bindingOperation);
    // operation.setName(new QName(operation.getName().getNamespaceURI(), getAsyncOperationName(info.portTypeOperation, operation)));
    if (asyncType.equals(AsyncOperationType.CALLBACK)) {
        operation.setUniqueName(info.operation.getUniqueName() + "_async_callback");
    } else if (asyncType.equals(AsyncOperationType.POLLING)) {
        operation.setUniqueName(info.operation.getUniqueName() + "_async_polling");
    }
    setDocumentationIfPresent(operation, info.portTypeOperation.getDocumentation());
    operation.setAsyncType(asyncType);
    operation.setSOAPAction(info.operation.getSOAPAction());
    boolean unwrappable = info.operation.isWrapped();
    operation.setWrapped(unwrappable);
    SOAPBody soapRequestBody = getSOAPRequestBody();
    Message inputMessage = getInputMessage();
    Request request = new Request(inputMessage, errReceiver);
    SOAPBody soapResponseBody = getSOAPResponseBody();
    Message outputMessage = getOutputMessage();
    Response response = new Response(outputMessage, errReceiver);
    // Process parameterOrder and get the parameterList
    java.util.List<String> parameterList = getAsynParameterOrder();
    List<Parameter> inParameters = null;
    if (isOperationDocumentLiteral(styleAndUse)) {
        inParameters = getRequestParameters(request, parameterList);
        // re-create parameterList with unwrapped parameters
        if (unwrappable) {
            List<String> unwrappedParameterList = new ArrayList<>();
            if (inputMessage != null) {
                Iterator<MessagePart> parts = inputMessage.parts();
                if (parts.hasNext()) {
                    MessagePart part = parts.next();
                    JAXBType jaxbType = getJAXBType(part);
                    List<JAXBProperty> memberList = jaxbType.getWrapperChildren();
                    Iterator<JAXBProperty> props = memberList.iterator();
                    while (props.hasNext()) {
                        JAXBProperty prop = props.next();
                        unwrappedParameterList.add(prop.getElementName().getLocalPart());
                    }
                }
            }
            parameterList.clear();
            parameterList.addAll(unwrappedParameterList);
        }
    } else if (isOperationRpcLiteral(styleAndUse)) {
        String operationName = info.bindingOperation.getName();
        Block reqBlock = null;
        if (inputMessage != null) {
            QName name = new QName(getRequestNamespaceURI(soapRequestBody), operationName);
            RpcLitStructure rpcStruct = new RpcLitStructure(name, getJAXBModelBuilder().getJAXBModel());
            rpcStruct.setJavaType(new JavaSimpleType("com.sun.xml.ws.encoding.jaxb.RpcLitPayload", null));
            reqBlock = new Block(name, rpcStruct, inputMessage);
            request.addBodyBlock(reqBlock);
        }
        inParameters = createRpcLitRequestParameters(request, parameterList, reqBlock);
    }
    // add response blocks, we dont need to create respnse parameters, just blocks will be fine, lets
    // copy them from sync optraions
    // copy the response blocks from the sync operation
    Iterator<Block> blocks = info.operation.getResponse().getBodyBlocks();
    while (blocks.hasNext()) {
        response.addBodyBlock(blocks.next());
    }
    blocks = info.operation.getResponse().getHeaderBlocks();
    while (blocks.hasNext()) {
        response.addHeaderBlock(blocks.next());
    }
    blocks = info.operation.getResponse().getAttachmentBlocks();
    while (blocks.hasNext()) {
        response.addAttachmentBlock(blocks.next());
    }
    List<MessagePart> outputParts = outputMessage.getParts();
    // handle headers
    int numOfOutMsgParts = outputParts.size();
    if (numOfOutMsgParts == 1) {
        MessagePart part = outputParts.get(0);
        if (isOperationDocumentLiteral(styleAndUse)) {
            JAXBType type = getJAXBType(part);
            operation.setResponseBean(type);
        } else if (isOperationRpcLiteral(styleAndUse)) {
            String operationName = info.bindingOperation.getName();
            Block resBlock = info.operation.getResponse().getBodyBlocksMap().get(new QName(getResponseNamespaceURI(soapResponseBody), operationName + "Response"));
            RpcLitStructure resBean = (RpcLitStructure) resBlock.getType();
            List<RpcLitMember> members = resBean.getRpcLitMembers();
            operation.setResponseBean(members.get(0));
        }
    } else {
        // create response bean
        String nspace = "";
        QName responseBeanName = new QName(nspace, getAsyncOperationName(info.operation) + "Response");
        JAXBType responseBeanType = getJAXBModelBuilder().getJAXBType(responseBeanName);
        if (responseBeanType == null) {
            error(info.operation.getEntity(), ModelerMessages.WSDLMODELER_RESPONSEBEAN_NOTFOUND(info.operation.getName()));
        }
        operation.setResponseBean(responseBeanType);
    }
    QName respBeanName = new QName(soapResponseBody.getNamespace(), getAsyncOperationName(info.operation) + "Response");
    Block block = new Block(respBeanName, operation.getResponseBeanType(), outputMessage);
    JavaType respJavaType = operation.getResponseBeanJavaType();
    JAXBType respType = new JAXBType(respBeanName, respJavaType);
    Parameter respParam = ModelerUtils.createParameter(info.operation.getName() + "Response", respType, block);
    respParam.setParameterIndex(-1);
    response.addParameter(respParam);
    operation.setProperty(WSDL_RESULT_PARAMETER, respParam.getName());
    int parameterOrderPosition = 0;
    for (String name : parameterList) {
        Parameter inParameter = ModelerUtils.getParameter(name, inParameters);
        if (inParameter == null) {
            if (options.isExtensionMode()) {
                warning(info.operation.getEntity(), ModelerMessages.WSDLMODELER_WARNING_IGNORING_OPERATION_PART_NOT_FOUND(info.operation.getName().getLocalPart(), name));
            } else {
                error(info.operation.getEntity(), ModelerMessages.WSDLMODELER_ERROR_PART_NOT_FOUND(info.operation.getName().getLocalPart(), name));
            }
            return null;
        }
        request.addParameter(inParameter);
        inParameter.setParameterIndex(parameterOrderPosition);
        parameterOrderPosition++;
    }
    operation.setResponse(response);
    // add callback handlerb Parameter to request
    if (operation.getAsyncType().equals(AsyncOperationType.CALLBACK)) {
        JavaType cbJavaType = operation.getCallBackType();
        JAXBType callbackType = new JAXBType(respBeanName, cbJavaType);
        Parameter cbParam = ModelerUtils.createParameter("asyncHandler", callbackType, block);
        request.addParameter(cbParam);
    }
    operation.setRequest(request);
    return operation;
}
Also used : Message(com.sun.tools.ws.wsdl.document.Message) QName(javax.xml.namespace.QName) java.util(java.util)

Aggregations

Message (com.sun.tools.ws.wsdl.document.Message)17 QName (javax.xml.namespace.QName)9 com.sun.tools.ws.wsdl.document (com.sun.tools.ws.wsdl.document)3 MIMEContent (com.sun.tools.ws.wsdl.document.mime.MIMEContent)3 java.util (java.util)3 JType (com.sun.codemodel.JType)2 Operation (com.sun.tools.ws.processor.model.Operation)2 JAXWSBinding (com.sun.tools.ws.wsdl.document.jaxws.JAXWSBinding)2 S2JJAXBModel (com.sun.tools.xjc.api.S2JJAXBModel)2 Iterator (java.util.Iterator)2 Element (org.w3c.dom.Element)2 TWSDLExtensible (com.sun.tools.ws.api.wsdl.TWSDLExtensible)1 Fault (com.sun.tools.ws.processor.model.Fault)1 Binding (com.sun.tools.ws.wsdl.document.Binding)1 Definitions (com.sun.tools.ws.wsdl.document.Definitions)1 MessagePart (com.sun.tools.ws.wsdl.document.MessagePart)1 PortType (com.sun.tools.ws.wsdl.document.PortType)1 Service (com.sun.tools.ws.wsdl.document.Service)1 TypeAndAnnotation (com.sun.tools.xjc.api.TypeAndAnnotation)1 Mode (jakarta.jws.WebParam.Mode)1