Search in sources :

Example 1 with WrapperParameter

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

the class WSDLGenerator method sortMethodParameters.

/**
 * Sorts the parameters for the method by their position
 * @param method the {@link JavaMethod} used to sort the parameters
 * @return the sorted {@link List} of parameters
 */
protected List<ParameterImpl> sortMethodParameters(JavaMethodImpl method) {
    Set<ParameterImpl> paramSet = new HashSet<>();
    List<ParameterImpl> sortedParams = new ArrayList<>();
    if (isRpcLit(method)) {
        for (ParameterImpl param : method.getRequestParameters()) {
            if (param instanceof WrapperParameter) {
                paramSet.addAll(((WrapperParameter) param).getWrapperChildren());
            } else {
                paramSet.add(param);
            }
        }
        for (ParameterImpl param : method.getResponseParameters()) {
            if (param instanceof WrapperParameter) {
                paramSet.addAll(((WrapperParameter) param).getWrapperChildren());
            } else {
                paramSet.add(param);
            }
        }
    } else {
        paramSet.addAll(method.getRequestParameters());
        paramSet.addAll(method.getResponseParameters());
    }
    Iterator<ParameterImpl> params = paramSet.iterator();
    if (paramSet.isEmpty())
        return sortedParams;
    ParameterImpl param = params.next();
    sortedParams.add(param);
    ParameterImpl sortedParam;
    int pos;
    for (int i = 1; i < paramSet.size(); i++) {
        param = params.next();
        for (pos = 0; pos < i; pos++) {
            sortedParam = sortedParams.get(pos);
            if (param.getIndex() == sortedParam.getIndex() && param instanceof WrapperParameter)
                break;
            if (param.getIndex() < sortedParam.getIndex()) {
                break;
            }
        }
        sortedParams.add(pos, param);
    }
    return sortedParams;
}
Also used : ParameterImpl(com.sun.xml.ws.model.ParameterImpl) ArrayList(java.util.ArrayList) WrapperParameter(com.sun.xml.ws.model.WrapperParameter) HashSet(java.util.HashSet)

Example 2 with WrapperParameter

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

the class WSDLGenerator method generateBindingOperation.

protected void generateBindingOperation(JavaMethodImpl method, Binding binding) {
    BindingOperationType operation = binding.operation().name(method.getOperationName());
    extension.addBindingOperationExtension(operation, method);
    String targetNamespace = model.getTargetNamespace();
    QName requestMessage = new QName(targetNamespace, method.getOperationName());
    List<ParameterImpl> bodyParams = new ArrayList<>();
    List<ParameterImpl> headerParams = new ArrayList<>();
    splitParameters(bodyParams, headerParams, method.getRequestParameters());
    SOAPBinding soapBinding = method.getBinding();
    operation.soapOperation().soapAction(soapBinding.getSOAPAction());
    // input
    TypedXmlWriter input = operation.input();
    extension.addBindingOperationInputExtension(input, method);
    BodyType body = input._element(Body.class);
    boolean isRpc = soapBinding.getStyle().equals(Style.RPC);
    if (soapBinding.getUse() == Use.LITERAL) {
        body.use(LITERAL);
        if (headerParams.size() > 0) {
            if (bodyParams.size() > 0) {
                ParameterImpl param = bodyParams.iterator().next();
                if (isRpc) {
                    StringBuilder parts = new StringBuilder();
                    int i = 0;
                    for (ParameterImpl parameter : ((WrapperParameter) param).getWrapperChildren()) {
                        if (i++ > 0)
                            parts.append(' ');
                        parts.append(parameter.getPartName());
                    }
                    body.parts(parts.toString());
                } else {
                    body.parts(param.getPartName());
                }
            } else {
                body.parts("");
            }
            generateSOAPHeaders(input, headerParams, requestMessage);
        }
        if (isRpc) {
            body.namespace(method.getRequestParameters().iterator().next().getName().getNamespaceURI());
        }
    } else {
        // TODO localize this
        throw new WebServiceException("encoded use is not supported");
    }
    if (method.getMEP() != MEP.ONE_WAY) {
        // output
        bodyParams.clear();
        headerParams.clear();
        splitParameters(bodyParams, headerParams, method.getResponseParameters());
        TypedXmlWriter output = operation.output();
        extension.addBindingOperationOutputExtension(output, method);
        body = output._element(Body.class);
        body.use(LITERAL);
        if (headerParams.size() > 0) {
            StringBuilder parts = new StringBuilder();
            if (bodyParams.size() > 0) {
                ParameterImpl param = bodyParams.iterator().hasNext() ? bodyParams.iterator().next() : null;
                if (param != null) {
                    if (isRpc) {
                        int i = 0;
                        for (ParameterImpl parameter : ((WrapperParameter) param).getWrapperChildren()) {
                            if (i++ > 0) {
                                parts.append(" ");
                            }
                            parts.append(parameter.getPartName());
                        }
                    } else {
                        parts = new StringBuilder(param.getPartName());
                    }
                }
            }
            body.parts(parts.toString());
            QName responseMessage = new QName(targetNamespace, method.getResponseMessageName());
            generateSOAPHeaders(output, headerParams, responseMessage);
        }
        if (isRpc) {
            body.namespace(method.getRequestParameters().iterator().next().getName().getNamespaceURI());
        }
    }
    for (CheckedExceptionImpl exception : method.getCheckedExceptions()) {
        Fault fault = operation.fault().name(exception.getMessageName());
        extension.addBindingOperationFaultExtension(fault, method, exception);
        SOAPFault soapFault = fault._element(SOAPFault.class).name(exception.getMessageName());
        soapFault.use(LITERAL);
    }
}
Also used : BindingOperationType(com.sun.xml.ws.wsdl.writer.document.BindingOperationType) WebServiceException(jakarta.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) CheckedExceptionImpl(com.sun.xml.ws.model.CheckedExceptionImpl) SOAPBinding(com.sun.xml.ws.api.model.soap.SOAPBinding) WrapperParameter(com.sun.xml.ws.model.WrapperParameter) Fault(com.sun.xml.ws.wsdl.writer.document.Fault) SOAPFault(com.sun.xml.ws.wsdl.writer.document.soap.SOAPFault) BodyType(com.sun.xml.ws.wsdl.writer.document.soap.BodyType) TypedXmlWriter(com.sun.xml.txw2.TypedXmlWriter) ParameterImpl(com.sun.xml.ws.model.ParameterImpl) SOAPFault(com.sun.xml.ws.wsdl.writer.document.soap.SOAPFault) Body(com.sun.xml.ws.wsdl.writer.document.soap.Body)

Example 3 with WrapperParameter

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

the class WSDLGenerator method generateSOAPMessages.

/**
 * Generates messages for a SOAPBinding
 * @param method The {@link JavaMethod} to generate messages for
 * @param binding The {@link com.sun.xml.ws.api.model.soap.SOAPBinding} to add the generated messages to
 */
protected void generateSOAPMessages(JavaMethodImpl method, com.sun.xml.ws.api.model.soap.SOAPBinding binding) {
    boolean isDoclit = binding.isDocLit();
    // Message message = portDefinitions.message().name(method.getOperation().getName().getLocalPart());
    Message message = portDefinitions.message().name(method.getRequestMessageName());
    extension.addInputMessageExtension(message, method);
    com.sun.xml.ws.wsdl.writer.document.Part part;
    BindingContext jaxbContext = model.getBindingContext();
    boolean unwrappable = true;
    for (ParameterImpl param : method.getRequestParameters()) {
        if (isDoclit) {
            if (isHeaderParameter(param))
                unwrappable = false;
            part = message.part().name(param.getPartName());
            part.element(param.getName());
        } else {
            if (param.isWrapperStyle()) {
                for (ParameterImpl childParam : ((WrapperParameter) param).getWrapperChildren()) {
                    part = message.part().name(childParam.getPartName());
                    part.type(jaxbContext.getTypeName(childParam.getXMLBridge().getTypeInfo()));
                }
            } else {
                part = message.part().name(param.getPartName());
                part.element(param.getName());
            }
        }
    }
    if (method.getMEP() != MEP.ONE_WAY) {
        message = portDefinitions.message().name(method.getResponseMessageName());
        extension.addOutputMessageExtension(message, method);
        for (ParameterImpl param : method.getResponseParameters()) {
            if (isDoclit) {
                part = message.part().name(param.getPartName());
                part.element(param.getName());
            } else {
                if (param.isWrapperStyle()) {
                    for (ParameterImpl childParam : ((WrapperParameter) param).getWrapperChildren()) {
                        part = message.part().name(childParam.getPartName());
                        part.type(jaxbContext.getTypeName(childParam.getXMLBridge().getTypeInfo()));
                    }
                } else {
                    part = message.part().name(param.getPartName());
                    part.element(param.getName());
                }
            }
        }
    }
    for (CheckedExceptionImpl exception : method.getCheckedExceptions()) {
        QName tagName = exception.getDetailType().tagName;
        String messageName = exception.getMessageName();
        QName messageQName = new QName(model.getTargetNamespace(), messageName);
        if (processedExceptions.contains(messageQName))
            continue;
        message = portDefinitions.message().name(messageName);
        extension.addFaultMessageExtension(message, method, exception);
        // tagName.getLocalPart());
        part = message.part().name("fault");
        part.element(tagName);
        processedExceptions.add(messageQName);
    }
}
Also used : Message(com.sun.xml.ws.wsdl.writer.document.Message) QName(javax.xml.namespace.QName) CheckedExceptionImpl(com.sun.xml.ws.model.CheckedExceptionImpl) WrapperParameter(com.sun.xml.ws.model.WrapperParameter) BindingContext(com.sun.xml.ws.spi.db.BindingContext) ParameterImpl(com.sun.xml.ws.model.ParameterImpl)

Example 4 with WrapperParameter

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

the class TieHandler method createResponseMessageBuilder.

/**
 * prepare objects for creating response {@link Message}
 */
private EndpointResponseMessageBuilder createResponseMessageBuilder(List<MessageFiller> fillers) {
    EndpointResponseMessageBuilder tmpBodyBuilder = null;
    List<ParameterImpl> rp = javaMethodModel.getResponseParameters();
    for (ParameterImpl param : rp) {
        ValueGetter getter = ValueGetter.get(param);
        switch(param.getOutBinding().kind) {
            case BODY:
                if (param.isWrapperStyle()) {
                    if (param.getParent().getBinding().isRpcLit()) {
                        tmpBodyBuilder = new EndpointResponseMessageBuilder.RpcLit((WrapperParameter) param, soapVersion);
                    } else {
                        tmpBodyBuilder = new EndpointResponseMessageBuilder.DocLit((WrapperParameter) param, soapVersion);
                    }
                } else {
                    tmpBodyBuilder = new EndpointResponseMessageBuilder.Bare(param, soapVersion);
                }
                break;
            case HEADER:
                fillers.add(new MessageFiller.Header(param.getIndex(), param.getXMLBridge(), getter));
                break;
            case ATTACHMENT:
                fillers.add(MessageFiller.AttachmentFiller.createAttachmentFiller(param, getter));
                break;
            case UNBOUND:
                break;
            default:
                // impossible
                throw new AssertionError();
        }
    }
    if (tmpBodyBuilder == null) {
        // no parameter binds to body. we create an empty message
        switch(soapVersion) {
            case SOAP_11:
                tmpBodyBuilder = EndpointResponseMessageBuilder.EMPTY_SOAP11;
                break;
            case SOAP_12:
                tmpBodyBuilder = EndpointResponseMessageBuilder.EMPTY_SOAP12;
                break;
            default:
                throw new AssertionError();
        }
    }
    return tmpBodyBuilder;
}
Also used : ParameterImpl(com.sun.xml.ws.model.ParameterImpl) WrapperParameter(com.sun.xml.ws.model.WrapperParameter)

Example 5 with WrapperParameter

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

the class JAXBContextFactory method newContext.

@Override
protected BindingContext newContext(BindingInfo bi) {
    Map<String, Source> extMapping = (Map<String, Source>) bi.properties().get(OXM_XML_OVERRIDE);
    Map<String, Object> properties = new HashMap<>();
    Map<TypeInfo, TypeMappingInfo> map = createTypeMappings(bi.typeInfos());
    // chen workaround for document-literal wrapper - new feature on eclipselink API requested
    for (TypeInfo tinfo : map.keySet()) {
        WrapperParameter wp = (WrapperParameter) tinfo.properties().get(WrapperParameter.class.getName());
        if (wp != null) {
            Class<?> wrpCls = (Class) tinfo.type;
            Element javaAttributes = null;
            for (ParameterImpl p : wp.getWrapperChildren()) {
                Element xmlelem = findXmlElement(p.getTypeInfo().properties());
                if (xmlelem != null) {
                    if (javaAttributes == null) {
                        javaAttributes = javaAttributes(wrpCls, extMapping);
                    }
                    xmlelem = (Element) javaAttributes.getOwnerDocument().importNode(xmlelem, true);
                    String fieldName = getFieldName(p, wrpCls);
                    xmlelem.setAttribute("java-attribute", fieldName);
                    javaAttributes.appendChild(xmlelem);
                }
            }
            if (wrpCls.getPackage() != null)
                wrpCls.getPackage().getName();
        }
    }
    // Source src = extMapping.get("com.sun.xml.ws.test.toplink.jaxws");
    // if (src != null){
    // TransformerFactory tf = TransformerFactory.newInstance();
    // try {
    // Transformer t = tf.newTransformer();
    // java.io.ByteArrayOutputStream bo = new java.io.ByteArrayOutputStream();
    // StreamResult sax = new StreamResult(bo);
    // t.transform(src, sax);
    // System.out.println(new String(bo.toByteArray()));
    // } catch (TransformerConfigurationException e) {
    // e.printStackTrace();
    // throw new WebServiceException(e.getMessage(), e);
    // } catch (TransformerException e) {
    // e.printStackTrace();
    // throw new WebServiceException(e.getMessage(), e);
    // }
    // }
    HashSet<Type> typeSet = new HashSet<>();
    HashSet<TypeMappingInfo> typeList = new HashSet<>();
    for (TypeMappingInfo tmi : map.values()) {
        typeList.add(tmi);
        typeSet.add(tmi.getType());
    }
    for (Class<?> clss : bi.contentClasses()) {
        if (!typeSet.contains(clss) && !WrapperComposite.class.equals(clss)) {
            typeSet.add(clss);
            TypeMappingInfo tmi = new TypeMappingInfo();
            tmi.setType(clss);
            typeList.add(tmi);
        }
    }
    TypeMappingInfo[] types = typeList.toArray(new TypeMappingInfo[0]);
    if (extMapping != null) {
        properties.put(OXM_XML_OVERRIDE, extMapping);
    }
    if (bi.getDefaultNamespace() != null) {
        properties.put(OXM_XML_ELEMENT, bi.getDefaultNamespace());
    }
    try {
        org.eclipse.persistence.jaxb.JAXBContext jaxbContext = (org.eclipse.persistence.jaxb.JAXBContext) org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(types, properties, bi.getClassLoader());
        return new JAXBContextWrapper(jaxbContext, map, bi.getSEIModel());
    } catch (JAXBException e) {
        throw new DatabindingException(e.getMessage(), e);
    }
}
Also used : HashMap(java.util.HashMap) XmlElement(jakarta.xml.bind.annotation.XmlElement) Element(org.w3c.dom.Element) XmlRootElement(jakarta.xml.bind.annotation.XmlRootElement) WrapperParameter(com.sun.xml.ws.model.WrapperParameter) JAXBContext(jakarta.xml.bind.JAXBContext) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source) DatabindingException(com.sun.xml.ws.spi.db.DatabindingException) TypeMappingInfo(org.eclipse.persistence.jaxb.TypeMappingInfo) HashSet(java.util.HashSet) JAXBException(jakarta.xml.bind.JAXBException) TypeInfo(com.sun.xml.ws.spi.db.TypeInfo) GenericArrayType(java.lang.reflect.GenericArrayType) XmlType(jakarta.xml.bind.annotation.XmlType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ParameterImpl(com.sun.xml.ws.model.ParameterImpl) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ParameterImpl (com.sun.xml.ws.model.ParameterImpl)9 WrapperParameter (com.sun.xml.ws.model.WrapperParameter)9 ArrayList (java.util.ArrayList)5 CheckedExceptionImpl (com.sun.xml.ws.model.CheckedExceptionImpl)3 HashSet (java.util.HashSet)3 QName (javax.xml.namespace.QName)3 TypedXmlWriter (com.sun.xml.txw2.TypedXmlWriter)2 SOAPBinding (com.sun.xml.ws.api.model.soap.SOAPBinding)2 BindingOperationType (com.sun.xml.ws.wsdl.writer.document.BindingOperationType)2 Fault (com.sun.xml.ws.wsdl.writer.document.Fault)2 Body (com.sun.xml.ws.wsdl.writer.document.soap.Body)2 SOAPFault (com.sun.xml.ws.wsdl.writer.document.soap.SOAPFault)2 Schema (com.sun.xml.ws.wsdl.writer.document.xsd.Schema)2 WebServiceException (jakarta.xml.ws.WebServiceException)2 HashMap (java.util.HashMap)2 JavaMethodImpl (com.sun.xml.ws.model.JavaMethodImpl)1 BindingContext (com.sun.xml.ws.spi.db.BindingContext)1 DatabindingException (com.sun.xml.ws.spi.db.DatabindingException)1 TypeInfo (com.sun.xml.ws.spi.db.TypeInfo)1 Message (com.sun.xml.ws.wsdl.writer.document.Message)1