Java Code Examples for org.apache.cxf.service.model.MessagePartInfo#isElement()

The following examples show how to use org.apache.cxf.service.model.MessagePartInfo#isElement() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HeaderUtil.java    From cxf with Apache License 2.0 6 votes vote down vote up
private static Set<QName> getHeaderQNames(BindingMessageInfo bmi) {
    Set<QName> set = new HashSet<>();
    List<MessagePartInfo> mps = bmi.getMessageInfo().getMessageParts();
    List<ExtensibilityElement> extList = bmi.getExtensors(ExtensibilityElement.class);
    if (extList != null) {
        for (ExtensibilityElement ext : extList) {
            if (SOAPBindingUtil.isSOAPHeader(ext)) {
                SoapHeader header = SOAPBindingUtil.getSoapHeader(ext);
                String pn = header.getPart();
                for (MessagePartInfo mpi : mps) {
                    if (pn.equals(mpi.getName().getLocalPart())) {
                        if (mpi.isElement()) {
                            set.add(mpi.getElementQName());
                        } else {
                            set.add(mpi.getTypeQName());
                        }
                        break;
                    }
                }
            }
        }
    }
    return set;
}
 
Example 2
Source File: WebFaultInInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private MessagePartInfo getFaultMessagePart(QName qname, OperationInfo op) {
    if (op.isUnwrapped() && (op instanceof UnwrappedOperationInfo)) {
        op = ((UnwrappedOperationInfo)op).getWrappedOperation();
    }

    for (FaultInfo faultInfo : op.getFaults()) {
        for (MessagePartInfo mpi : faultInfo.getMessageParts()) {
            String ns = null;
            if (mpi.isElement()) {
                ns = mpi.getElementQName().getNamespaceURI();
            } else {
                ns = mpi.getTypeQName().getNamespaceURI();
            }
            if (qname.getLocalPart().equals(mpi.getConcreteName().getLocalPart())
                    && qname.getNamespaceURI().equals(ns)) {
                return mpi;
            }
        }

    }
    return null;
}
 
Example 3
Source File: ServiceWSDLBuilder.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void buildMessage(Message message,
                            AbstractMessageContainer messageContainer,
                            final Definition def) {
    addDocumentation(message, messageContainer.getMessageDocumentation());
    message.setQName(messageContainer.getName());
    message.setUndefined(false);
    def.addMessage(message);

    List<MessagePartInfo> messageParts = messageContainer.getMessageParts();
    Part messagePart = null;
    for (MessagePartInfo messagePartInfo : messageParts) {
        messagePart = def.createPart();
        messagePart.setName(messagePartInfo.getName().getLocalPart());
        if (messagePartInfo.isElement()) {
            messagePart.setElementName(messagePartInfo.getElementQName());
            addNamespace(messagePartInfo.getElementQName().getNamespaceURI(), def);
        } else if (messagePartInfo.getTypeQName() != null) {
            messagePart.setTypeName(messagePartInfo.getTypeQName());
            addNamespace(messagePartInfo.getTypeQName().getNamespaceURI(), def);
        }
        message.addPart(messagePart);
    }
}
 
Example 4
Source File: CorbaStreamFaultInInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected FaultInfo getFaultInfo(OperationInfo opInfo, QName faultName) {
    Iterator<FaultInfo> faults = opInfo.getFaults().iterator();
    while (faults.hasNext()) {
        FaultInfo fault = faults.next();
        MessagePartInfo partInfo = fault.getMessageParts().get(0);
        if (partInfo.isElement()
            && partInfo.getElementQName().getLocalPart().equals(faultName.getLocalPart())) {
            return fault;
        } else if (partInfo.getTypeQName().getLocalPart().equals(faultName.getLocalPart())) {
            return fault;
        }
    }
    return null;
}
 
Example 5
Source File: XMLBindingFactory.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void adjustConcreteNames(MessageInfo mi) {
    if (mi != null) {
        for (MessagePartInfo mpi : mi.getMessageParts()) {
            if (!mpi.isElement()) {
                //if it's not an element, we need to make it one
                mpi.setConcreteName(mpi.getName());
            }
        }
    }
}
 
Example 6
Source File: CorbaStreamInInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected String getWrappedParamNamespace(MessageInfo msgInfo) {
    MessagePartInfo part = msgInfo.getMessageParts().get(0);
    if (part.isElement()) {
        return part.getElementQName().getNamespaceURI();
    }
    return part.getName().getNamespaceURI();
}
 
Example 7
Source File: CorbaStreamInInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected QName getMessageParamQName(MessageInfo msgInfo,
                                     String paramName,
                                     int index) {
    QName paramQName = null;
    MessagePartInfo part = msgInfo.getMessageParts().get(index);
    if (part != null && part.isElement()) {
        paramQName = part.getElementQName();
    } else if (part != null) {
        paramQName = part.getName();
    }
    return paramQName;
}
 
Example 8
Source File: CorbaStreamOutEndingInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected String getWrappedParamNamespace(MessageInfo msgInfo) {
    MessagePartInfo part = msgInfo.getMessageParts().get(0);
    if (part.isElement()) {
        return part.getElementQName().getNamespaceURI();
    }
    return part.getName().getNamespaceURI();
}
 
Example 9
Source File: CorbaStreamOutEndingInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected QName getMessageParamQName(MessageInfo msgInfo,
                                     String paramName,
                                     int index) {
    QName paramQName = null;
    MessagePartInfo part = msgInfo.getMessageParts().get(index);
    if (part != null && part.isElement()) {
        paramQName = part.getElementQName();
    } else if (part != null)  {
        paramQName = part.getName();
    }
    return paramQName;
}
 
Example 10
Source File: CorbaStreamFaultOutInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected MessagePartInfo getFaultMessagePartInfo(OperationInfo opInfo, QName faultName) {
    Iterator<FaultInfo> faults = opInfo.getFaults().iterator();
    while (faults.hasNext()) {
        FaultInfo fault = faults.next();
        MessagePartInfo partInfo = fault.getMessageParts().get(0);
        if (partInfo.isElement()
            && partInfo.getElementQName().getLocalPart().equals(faultName.getLocalPart())) {
            return partInfo;
        } else if (partInfo.getTypeQName().getLocalPart().equals(faultName.getLocalPart())) {
            return partInfo;
        }
    }
    return null;
}
 
Example 11
Source File: JAXBDataBase.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected final boolean honorJAXBAnnotations(MessagePartInfo part) {
    if (part == null) {
        return false;
    }
    if (!part.isElement()) {
        //RPC-Lit always needs to look for these
        return true;
    }
    //certain cases that use XmlJavaTypeAdapters will require this and the
    //JAXBSchemaInitializer will set this.
    Boolean b = (Boolean)part.getProperty("honor.jaxb.annotations");
    return b != null && b;
}
 
Example 12
Source File: ParameterMapper.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static void processXmlSchemaSimpleType(XmlSchemaSimpleType xmlSchema, JavaMethod jm,
                                               JavaParameter parameter, MessagePartInfo part) {
    if (xmlSchema.getContent() instanceof XmlSchemaSimpleTypeList
        && (!part.isElement() || !jm.isWrapperStyle())) {
        parameter.annotate(new XmlListAnotator(jm.getInterface()));
    }
    if (Constants.XSD_HEXBIN.equals(xmlSchema.getQName())
        && (!part.isElement() || !jm.isWrapperStyle())) {
        parameter.annotate(new XmlJavaTypeAdapterAnnotator(jm.getInterface(), HexBinaryAdapter.class));
    }
}
 
Example 13
Source File: ParameterProcessor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static void processXmlSchemaSimpleType(XmlSchemaSimpleType xmlSchema, JavaMethod method,
                                               MessagePartInfo part) {
    if (xmlSchema.getContent() instanceof XmlSchemaSimpleTypeList
        && (!part.isElement() || !method.isWrapperStyle())) {
        method.annotate(new XmlListAnotator(method.getInterface()));
    }
    if (Constants.XSD_HEXBIN.equals(xmlSchema.getQName())
        && (!part.isElement() || !method.isWrapperStyle())) {
        method.annotate(new XmlJavaTypeAdapterAnnotator(method.getInterface(), HexBinaryAdapter.class));
    }
}
 
Example 14
Source File: ProcessorUtil.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static String resolvePartType(MessagePartInfo part, ToolContext context, boolean fullName) {
    DataBindingProfile dataBinding = context.get(DataBindingProfile.class);
    if (dataBinding == null) {
        String primitiveType = JAXBUtils.builtInTypeToJavaType(part.getTypeQName().getLocalPart());
        if (part.getTypeQName() != null &&  primitiveType != null) {
            return primitiveType;
        }
        return resolvePartType(part);
    }
    String name = "";
    if (part.isElement()) {
        name = dataBinding.getType(getElementName(part), true);
    } else {
        name = dataBinding.getType(part.getTypeQName(), false);
    }
    if (name == null) {
        String namespace = resolvePartNamespace(part);
        if ("http://www.w3.org/2005/08/addressing".equals(namespace)) {
            //The ws-addressing stuff isn't mapped in jaxb as jax-ws specifies they
            //need to be mapped differently
            String pn = part.getConcreteName().getLocalPart();
            if ("EndpointReference".equals(pn)
                || "ReplyTo".equals(pn)
                || "From".equals(pn)
                || "FaultTo".equals(pn)) {

                name = "javax.xml.ws.wsaddressing.W3CEndpointReference";
            }
        }

    }
    return name;
}
 
Example 15
Source File: ProcessorUtil.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static String getType(MessagePartInfo part, ToolContext context, boolean fullname) {
    String type = "";
    DataBindingProfile dataBinding = context.get(DataBindingProfile.class);
    if (part.isElement()) {
        type = dataBinding.getType(getElementName(part), true);
    } else {
        type = dataBinding.getType(part.getTypeQName(), false);
    }
    if (type == null) {
        type = resolvePartType(part);
    }
    return type;
}
 
Example 16
Source File: ReflectionServiceFactoryBean.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected void buildServiceFromClass() {
    Object o = getBus().getProperty("requireExplicitContractLocation");
    if (o != null
        && ("true".equals(o) || Boolean.TRUE.equals(o))) {
        throw new ServiceConstructionException(new Message("NO_WSDL_PROVIDED", LOG,
                                                           getServiceClass().getName()));
    }
    if (LOG.isLoggable(Level.INFO)) {
        LOG.info("Creating Service " + getServiceQName() + " from class " + getServiceClass().getName());
    }
    populateFromClass = true;

    if (Proxy.isProxyClass(this.getServiceClass())) {
        LOG.log(Level.WARNING, "USING_PROXY_FOR_SERVICE", getServiceClass());
    }

    sendEvent(Event.CREATE_FROM_CLASS, getServiceClass());

    ServiceInfo serviceInfo = new ServiceInfo();
    SchemaCollection col = serviceInfo.getXmlSchemaCollection();
    col.getXmlSchemaCollection().setSchemaResolver(new CatalogXmlSchemaURIResolver(this.getBus()));
    col.getExtReg().registerSerializer(MimeAttribute.class, new MimeSerializer());

    ServiceImpl service = new ServiceImpl(serviceInfo);
    setService(service);
    setServiceProperties();

    serviceInfo.setName(getServiceQName());
    serviceInfo.setTargetNamespace(serviceInfo.getName().getNamespaceURI());

    sendEvent(Event.SERVICE_SET, getService());

    createInterface(serviceInfo);


    Set<?> wrapperClasses = this.getExtraClass();
    for (ServiceInfo si : getService().getServiceInfos()) {
        if (wrapperClasses != null && !wrapperClasses.isEmpty()) {
            si.setProperty(EXTRA_CLASS, wrapperClasses);
        }
    }
    initializeDataBindings();

    boolean isWrapped = isWrapped() || hasWrappedMethods(serviceInfo.getInterface());
    if (isWrapped) {
        initializeWrappedSchema(serviceInfo);
    }

    for (OperationInfo opInfo : serviceInfo.getInterface().getOperations()) {
        Method m = (Method)opInfo.getProperty(METHOD);
        if (!isWrapped(m) && !isRPC(m) && opInfo.getInput() != null) {
            createBareMessage(serviceInfo, opInfo, false);
        }

        if (!isWrapped(m) && !isRPC(m) && opInfo.getOutput() != null) {
            createBareMessage(serviceInfo, opInfo, true);
        }

        if (opInfo.hasFaults()) {
            // check to make sure the faults are elements
            for (FaultInfo fault : opInfo.getFaults()) {
                QName qn = (QName)fault.getProperty("elementName");
                MessagePartInfo part = fault.getFirstMessagePart();
                if (!part.isElement()) {
                    part.setElement(true);
                    part.setElementQName(qn);
                    checkForElement(serviceInfo, part);
                }
            }
        }
    }
    if (LOG.isLoggable(Level.FINE) || isValidate()) {
        ServiceModelSchemaValidator validator = new ServiceModelSchemaValidator(serviceInfo);
        validator.walk();
        String validationComplaints = validator.getComplaints();
        if (!"".equals(validationComplaints)) {
            if (isValidate()) {
                LOG.warning(validationComplaints);
            } else {
                LOG.fine(validationComplaints);
            }
        }
    }
}
 
Example 17
Source File: ServiceWSDLBuilder.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected void buildService(ServiceInfo serviceInfo, Definition definition) {

        Map<QName, MessageInfo> messages = serviceInfo.getMessages();
        for (Map.Entry<QName, MessageInfo> mie : messages.entrySet()) {
            if (!mie.getKey().getNamespaceURI().equals(definition.getTargetNamespace())) {
                continue;
            }
            if (definition.getMessage(mie.getKey()) != null) {
                continue;
            }
            Message message = definition.createMessage();
            addDocumentation(message, mie.getValue().getMessageDocumentation());
            message.setUndefined(false);
            message.setQName(mie.getKey());
            for (MessagePartInfo mpi : mie.getValue().getMessageParts()) {
                Part part = definition.createPart();
                boolean elemental = mpi.isElement();
                // RFSB will turn on isElement bogusly.
                if (elemental
                    && null == serviceInfo.getXmlSchemaCollection().
                        getElementByQName(mpi.getElementQName())) {
                    elemental = false;
                }
                if (elemental) {
                    part.setElementName(mpi.getElementQName());
                } else {
                    part.setTypeName(mpi.getTypeQName());
                }
                part.setName(mpi.getName().getLocalPart());
                message.addPart(part);
            }

            definition.addMessage(message);
        }

        addDocumentation(definition, serviceInfo.getTopLevelDoc());
        Service serv = definition.createService();
        addDocumentation(serv, serviceInfo.getDocumentation());
        serv.setQName(serviceInfo.getName());
        addNamespace(serviceInfo.getName().getNamespaceURI(), definition);
        addExtensibilityElements(definition, serv, getWSDL11Extensors(serviceInfo));
        definition.addService(serv);

        for (EndpointInfo ei : serviceInfo.getEndpoints()) {
            addNamespace(ei.getTransportId(), definition);
            Port port = definition.createPort();
            addDocumentation(port, ei.getDocumentation());
            port.setName(ei.getName().getLocalPart());
            port.setBinding(definition.getBinding(ei.getBinding().getName()));
            addExtensibilityElements(definition, port, getWSDL11Extensors(ei));
            serv.addPort(port);
        }
    }
 
Example 18
Source File: DocLiteralInInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void validatePart(MessagePartInfo p, QName elName, Message m) {
    if (p == null) {
        throw new Fault(new org.apache.cxf.common.i18n.Message("NO_PART_FOUND", LOG, elName),
                        Fault.FAULT_CODE_CLIENT);

    }

    boolean synth = false;
    if (p.getMessageInfo() != null && p.getMessageInfo().getOperation() != null) {
        OperationInfo op = p.getMessageInfo().getOperation();
        Boolean b = (Boolean)op.getProperty("operation.is.synthetic");
        if (b != null) {
            synth = b;
        }
    }

    if (MessageUtils.getContextualBoolean(m, "soap.no.validate.parts", false)) {
        // something like a Provider service or similar that is forcing a
        // doc/lit/bare on an endpoint that may not really be doc/lit/bare.
        // we need to just let these through per spec so the endpoint
        // can process it
        synth = true;
    }
    if (synth) {
        return;
    }
    if (p.isElement()) {
        if (p.getConcreteName() != null
            && !elName.equals(p.getConcreteName())
            && !synth) {
            throw new Fault("UNEXPECTED_ELEMENT", LOG, null, elName,
                            p.getConcreteName());
        }
    } else {
        if (!(elName.equals(p.getName()) || elName.equals(p.getConcreteName()))
            && !synth) {
            throw new Fault("UNEXPECTED_ELEMENT", LOG, null, elName,
                            p.getConcreteName());
        }
    }
}
 
Example 19
Source File: DataWriterImpl.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void write(Object obj, MessagePartInfo part, T output) {
    boolean honorJaxbAnnotation = honorJAXBAnnotations(part);
    if (part != null && !part.isElement() && part.getTypeClass() != null) {
        honorJaxbAnnotation = true;
    }
    checkPart(part, obj);

    if (obj != null
        || !(part.getXmlSchema() instanceof XmlSchemaElement)) {

        if (obj instanceof Exception
            && part != null
            && Boolean.TRUE.equals(part.getProperty(JAXBDataBinding.class.getName()
                                                    + ".CUSTOM_EXCEPTION"))) {
            JAXBEncoderDecoder.marshallException(createMarshaller(obj, part),
                                                 (Exception)obj,
                                                 part,
                                                 output);
            onCompleteMarshalling();
        } else {
            Annotation[] anns = getJAXBAnnotation(part);
            if (!honorJaxbAnnotation || anns.length == 0) {
                JAXBEncoderDecoder.marshall(createMarshaller(obj, part), obj, part, output);
                onCompleteMarshalling();
            } else if (honorJaxbAnnotation && anns.length > 0) {
                //RpcLit will use the JAXB Bridge to marshall part message when it is
                //annotated with @XmlList,@XmlAttachmentRef,@XmlJavaTypeAdapter
                //TODO:Cache the JAXBRIContext

                JAXBEncoderDecoder.marshalWithBridge(part.getConcreteName(),
                                                     part.getTypeClass(),
                                                     anns,
                                                     databinding.getContextClasses(),
                                                     obj,
                                                     output,
                                                     getAttachmentMarshaller());
            }
        }
    } else if (needToRender(part)) {
        JAXBEncoderDecoder.marshallNullElement(createMarshaller(null, part),
                                               output, part);

        onCompleteMarshalling();
    }
}
 
Example 20
Source File: ReflectionServiceFactoryBean.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected void createBareMessage(ServiceInfo serviceInfo, OperationInfo opInfo, boolean isOut) {

        MessageInfo message = isOut ? opInfo.getOutput() : opInfo.getInput();

        final List<MessagePartInfo> messageParts = message.getMessageParts();
        if (messageParts.isEmpty()) {
            return;
        }

        Method method = (Method)opInfo.getProperty(METHOD);
        int paraNumber = 0;
        for (MessagePartInfo mpi : messageParts) {
            SchemaInfo schemaInfo = null;
            XmlSchema schema = null;

            QName qname = (QName)mpi.getProperty(ELEMENT_NAME);
            if (messageParts.size() == 1 && qname == null) {
                qname = !isOut ? getInParameterName(opInfo, method, -1)
                        : getOutParameterName(opInfo, method, -1);

                if (qname.getLocalPart().startsWith("arg") || qname.getLocalPart().startsWith("return")) {
                    qname = isOut
                        ? new QName(qname.getNamespaceURI(), method.getName() + "Response") : new QName(qname
                            .getNamespaceURI(), method.getName());
                }
            } else if (isOut && messageParts.size() > 1 && qname == null) {
                while (!isOutParam(method, paraNumber)) {
                    paraNumber++;
                }
                qname = getOutParameterName(opInfo, method, paraNumber);
            } else if (qname == null) {
                qname = getInParameterName(opInfo, method, paraNumber);
            }

            for (SchemaInfo s : serviceInfo.getSchemas()) {
                if (s.getNamespaceURI().equals(qname.getNamespaceURI())) {
                    schemaInfo = s;
                    break;
                }
            }

            if (schemaInfo == null) {
                schemaInfo = getOrCreateSchema(serviceInfo, qname.getNamespaceURI(), true);
                schema = schemaInfo.getSchema();
            } else {
                schema = schemaInfo.getSchema();
                if (schema != null && schema.getElementByName(qname) != null) {
                    mpi.setElement(true);
                    mpi.setElementQName(qname);
                    mpi.setXmlSchema(schema.getElementByName(qname));
                    paraNumber++;
                    continue;
                }
            }

            schemaInfo.setElement(null); //cached element is now invalid
            XmlSchemaElement el = new XmlSchemaElement(schema, true);
            el.setName(qname.getLocalPart());
            el.setNillable(true);

            if (mpi.isElement()) {
                XmlSchemaElement oldEl = (XmlSchemaElement)mpi.getXmlSchema();
                if (null != oldEl && !oldEl.getQName().equals(qname)) {
                    el.setSchemaTypeName(oldEl.getSchemaTypeName());
                    el.setSchemaType(oldEl.getSchemaType());
                    if (oldEl.getSchemaTypeName() != null) {
                        addImport(schema, oldEl.getSchemaTypeName().getNamespaceURI());
                    }
                }
                mpi.setElement(true);
                mpi.setXmlSchema(el);
                mpi.setElementQName(qname);
                mpi.setConcreteName(qname);
                continue;
            }
            if (null == mpi.getTypeQName() && mpi.getXmlSchema() == null) {
                throw new ServiceConstructionException(new Message("UNMAPPABLE_PORT_TYPE", LOG,
                                                                   method.getDeclaringClass().getName(),
                                                                   method.getName(),
                                                                   mpi.getName()));
            }
            if (mpi.getTypeQName() != null) {
                el.setSchemaTypeName(mpi.getTypeQName());
            } else {
                el.setSchemaType((XmlSchemaType)mpi.getXmlSchema());
            }
            mpi.setXmlSchema(el);
            mpi.setConcreteName(qname);
            if (mpi.getTypeQName() != null) {
                addImport(schema, mpi.getTypeQName().getNamespaceURI());
            }

            mpi.setElement(true);
            mpi.setElementQName(qname);
            paraNumber++;
        }
    }