Search in sources :

Example 86 with OperationInfo

use of org.apache.cxf.service.model.OperationInfo in project cxf by apache.

the class JAXRSServiceImpl method getServiceInfos.

public List<ServiceInfo> getServiceInfos() {
    if (!createServiceModel) {
        return Collections.emptyList();
    }
    // try to convert to WSDL-centric model so that CXF DataBindings can get initialized
    // might become useful too if we support wsdl2
    // make databindings to use databinding-specific information
    // like @XmlRootElement for ex to select a namespace
    this.put("org.apache.cxf.databinding.namespace", "true");
    List<ServiceInfo> infos = new ArrayList<>();
    for (ClassResourceInfo cri : classResourceInfos) {
        ServiceInfo si = new ServiceInfo();
        infos.add(si);
        QName qname = JAXRSUtils.getClassQName(cri.getServiceClass());
        si.setName(qname);
        InterfaceInfo inf = new InterfaceInfo(si, qname);
        si.setInterface(inf);
        for (OperationResourceInfo ori : cri.getMethodDispatcher().getOperationResourceInfos()) {
            Method m = ori.getMethodToInvoke();
            QName oname = new QName(qname.getNamespaceURI(), m.getName());
            OperationInfo oi = inf.addOperation(oname);
            createMessagePartInfo(oi, m.getReturnType(), qname, m, false);
            for (Parameter pm : ori.getParameters()) {
                if (pm.getType() == ParameterType.REQUEST_BODY) {
                    createMessagePartInfo(oi, ori.getMethodToInvoke().getParameterTypes()[pm.getIndex()], qname, m, true);
                }
            }
        }
    }
    return infos;
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) Parameter(org.apache.cxf.jaxrs.model.Parameter) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) Method(java.lang.reflect.Method)

Example 87 with OperationInfo

use of org.apache.cxf.service.model.OperationInfo in project cxf by apache.

the class JAXBContextInitializer method begin.

@Override
public void begin(MessagePartInfo part) {
    Class<?> clazz = part.getTypeClass();
    if (clazz == null) {
        return;
    }
    if (Exception.class.isAssignableFrom(clazz)) {
        // exceptions are handled special, make sure we mark it
        part.setProperty(JAXBDataBinding.class.getName() + ".CUSTOM_EXCEPTION", Boolean.TRUE);
    }
    boolean isFromWrapper = part.getMessageInfo().getOperation().isUnwrapped();
    if (isFromWrapper && !Boolean.TRUE.equals(part.getProperty("messagepart.isheader"))) {
        UnwrappedOperationInfo uop = (UnwrappedOperationInfo) part.getMessageInfo().getOperation();
        OperationInfo op = uop.getWrappedOperation();
        MessageInfo inf = null;
        if (uop.getInput() == part.getMessageInfo()) {
            inf = op.getInput();
        } else if (uop.getOutput() == part.getMessageInfo()) {
            inf = op.getOutput();
        }
        if (inf != null && inf.getFirstMessagePart().getTypeClass() != null) {
            // wrapper type (unless it's a header which wouldn't be in the wrapper)
            return;
        }
    }
    if (isFromWrapper && clazz.isArray() && !Byte.TYPE.equals(clazz.getComponentType())) {
        clazz = clazz.getComponentType();
    }
    Annotation[] a = (Annotation[]) part.getProperty("parameter.annotations");
    checkForAdapter(clazz, a);
    Type genericType = (Type) part.getProperty("generic.type");
    if (genericType != null) {
        boolean isList = Collection.class.isAssignableFrom(clazz);
        if (isFromWrapper) {
            if (genericType instanceof Class && ((Class<?>) genericType).isArray()) {
                Class<?> cl2 = (Class<?>) genericType;
                if (cl2.isArray() && !Byte.TYPE.equals(cl2.getComponentType())) {
                    genericType = cl2.getComponentType();
                }
                addType(genericType);
            } else if (!isList) {
                addType(genericType);
            }
        } else {
            addType(genericType, true);
        }
        if (isList && genericType instanceof ParameterizedType) {
            ParameterizedType pt = (ParameterizedType) genericType;
            if (pt.getActualTypeArguments().length > 0 && pt.getActualTypeArguments()[0] instanceof Class) {
                Class<? extends Object> arrayCls = Array.newInstance((Class<?>) pt.getActualTypeArguments()[0], 0).getClass();
                clazz = arrayCls;
                part.setTypeClass(clazz);
                if (isFromWrapper) {
                    addType(clazz.getComponentType(), true);
                }
            } else if (pt.getActualTypeArguments().length > 0 && pt.getActualTypeArguments()[0] instanceof GenericArrayType) {
                GenericArrayType gat = (GenericArrayType) pt.getActualTypeArguments()[0];
                gat.getGenericComponentType();
                Class<? extends Object> arrayCls = Array.newInstance((Class<?>) gat.getGenericComponentType(), 0).getClass();
                clazz = Array.newInstance(arrayCls, 0).getClass();
                part.setTypeClass(clazz);
                if (isFromWrapper) {
                    addType(clazz.getComponentType(), true);
                }
            }
        }
        if (isFromWrapper && isList) {
            clazz = null;
        }
    }
    if (clazz != null) {
        if (!isFromWrapper && clazz.getAnnotation(XmlRootElement.class) == null && clazz.getAnnotation(XmlType.class) != null && StringUtils.isEmpty(clazz.getAnnotation(XmlType.class).name())) {
            Object ref = createTypeReference(part.getName(), clazz);
            if (ref != null) {
                typeReferences.add(ref);
            }
        }
        addClass(clazz);
    }
}
Also used : UnwrappedOperationInfo(org.apache.cxf.service.model.UnwrappedOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) UnwrappedOperationInfo(org.apache.cxf.service.model.UnwrappedOperationInfo) GenericArrayType(java.lang.reflect.GenericArrayType) Annotation(java.lang.annotation.Annotation) MessageInfo(org.apache.cxf.service.model.MessageInfo) XmlType(javax.xml.bind.annotation.XmlType) ParameterizedType(java.lang.reflect.ParameterizedType) GenericArrayType(java.lang.reflect.GenericArrayType) WildcardType(java.lang.reflect.WildcardType) XmlType(javax.xml.bind.annotation.XmlType) XmlAccessType(javax.xml.bind.annotation.XmlAccessType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type)

Example 88 with OperationInfo

use of org.apache.cxf.service.model.OperationInfo in project cxf by apache.

the class JAXBDataBase method getReturnMethodAnnotations.

private Annotation[] getReturnMethodAnnotations(MessagePartInfo mpi) {
    AbstractMessageContainer mi = mpi.getMessageInfo();
    if (mi == null || !isOutputMessage(mi)) {
        return null;
    }
    OperationInfo oi = mi != null ? mi.getOperation() : null;
    return oi != null ? (Annotation[]) oi.getProperty("method.return.annotations") : null;
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) AbstractMessageContainer(org.apache.cxf.service.model.AbstractMessageContainer) Annotation(java.lang.annotation.Annotation)

Example 89 with OperationInfo

use of org.apache.cxf.service.model.OperationInfo in project cxf by apache.

the class SoapBindingFactory method createBindingInfo.

public BindingInfo createBindingInfo(ServiceInfo si, String bindingid, Object conf) {
    SoapBindingConfiguration config;
    if (conf instanceof SoapBindingConfiguration) {
        config = (SoapBindingConfiguration) conf;
    } else {
        config = new SoapBindingConfiguration();
    }
    if (WSDLConstants.NS_SOAP12.equals(bindingid) || WSDLConstants.NS_SOAP12_HTTP_BINDING.equals(bindingid)) {
        config.setVersion(Soap12.getInstance());
        config.setTransportURI(WSDLConstants.NS_SOAP_HTTP_TRANSPORT);
    }
    SoapBindingInfo info = new SoapBindingInfo(si, bindingid, config.getVersion());
    info.setName(config.getBindingName(si));
    info.setStyle(config.getStyle());
    info.setTransportURI(config.getTransportURI());
    if (config.isMtomEnabled()) {
        info.setProperty(Message.MTOM_ENABLED, Boolean.TRUE);
    }
    for (OperationInfo op : si.getInterface().getOperations()) {
        SoapOperationInfo sop = new SoapOperationInfo();
        sop.setAction(config.getSoapAction(op));
        sop.setStyle(config.getStyle(op));
        BindingOperationInfo bop = info.buildOperation(op.getName(), op.getInputName(), op.getOutputName());
        bop.addExtensor(sop);
        info.addOperation(bop);
        BindingMessageInfo bInput = bop.getInput();
        if (bInput != null) {
            MessageInfo input = null;
            BindingMessageInfo unwrappedMsg = bInput;
            if (bop.isUnwrappedCapable()) {
                input = bop.getOperationInfo().getUnwrappedOperation().getInput();
                unwrappedMsg = bop.getUnwrappedOperation().getInput();
            } else {
                input = bop.getOperationInfo().getInput();
            }
            setupHeaders(bop, bInput, unwrappedMsg, input, config);
        }
        BindingMessageInfo bOutput = bop.getOutput();
        if (bOutput != null) {
            MessageInfo output = null;
            BindingMessageInfo unwrappedMsg = bOutput;
            if (bop.isUnwrappedCapable()) {
                output = bop.getOperationInfo().getUnwrappedOperation().getOutput();
                unwrappedMsg = bop.getUnwrappedOperation().getOutput();
            } else {
                output = bop.getOperationInfo().getOutput();
            }
            setupHeaders(bop, bOutput, unwrappedMsg, output, config);
        }
    }
    try {
        createSoapBinding(info);
    } catch (WSDLException e) {
        e.printStackTrace();
    }
    return info;
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) WSDLException(javax.wsdl.WSDLException) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo)

Example 90 with OperationInfo

use of org.apache.cxf.service.model.OperationInfo in project cxf by apache.

the class SoapBindingFactory method addOutOfBandParts.

private void addOutOfBandParts(final BindingOperationInfo bop, final javax.wsdl.Message msg, final SchemaCollection schemas, boolean isInput, final String partName) {
    MessageInfo minfo = null;
    MessageInfo.Type type;
    int nextId = 0;
    minfo = bop.getOperationInfo().getInput();
    if (minfo != null) {
        for (MessagePartInfo part : minfo.getMessageParts()) {
            if (part.getIndex() >= nextId) {
                nextId = part.getIndex() + 1;
            }
        }
    }
    minfo = bop.getOperationInfo().getOutput();
    if (minfo != null) {
        for (MessagePartInfo part : minfo.getMessageParts()) {
            if (part.getIndex() >= nextId) {
                nextId = part.getIndex() + 1;
            }
        }
    }
    if (isInput) {
        type = MessageInfo.Type.INPUT;
        minfo = bop.getOperationInfo().getInput();
    } else {
        type = MessageInfo.Type.OUTPUT;
        minfo = bop.getOperationInfo().getOutput();
    }
    if (minfo == null) {
        minfo = new MessageInfo(bop.getOperationInfo(), type, msg.getQName());
    }
    buildMessage(minfo, msg, schemas, nextId, partName);
    // for wrapped style
    OperationInfo unwrapped = bop.getOperationInfo().getUnwrappedOperation();
    if (unwrapped == null) {
        return;
    }
    nextId = 0;
    if (isInput) {
        minfo = unwrapped.getInput();
        type = MessageInfo.Type.INPUT;
        if (minfo != null) {
            for (MessagePartInfo part : minfo.getMessageParts()) {
                if (part.getIndex() >= nextId) {
                    nextId = part.getIndex() + 1;
                }
            }
        }
    } else {
        minfo = unwrapped.getOutput();
        type = MessageInfo.Type.OUTPUT;
        if (minfo != null) {
            for (MessagePartInfo part : minfo.getMessageParts()) {
                if (part.getIndex() >= nextId) {
                    nextId = part.getIndex() + 1;
                }
            }
        }
    }
    if (minfo == null) {
        minfo = new MessageInfo(unwrapped, type, msg.getQName());
    }
    buildMessage(minfo, msg, schemas, nextId, partName);
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) MessageInfo(org.apache.cxf.service.model.MessageInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo)

Aggregations

OperationInfo (org.apache.cxf.service.model.OperationInfo)135 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)87 QName (javax.xml.namespace.QName)58 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)44 MessageInfo (org.apache.cxf.service.model.MessageInfo)40 Test (org.junit.Test)38 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)36 InterfaceInfo (org.apache.cxf.service.model.InterfaceInfo)31 Method (java.lang.reflect.Method)25 Endpoint (org.apache.cxf.endpoint.Endpoint)24 Service (org.apache.cxf.service.Service)22 BindingInfo (org.apache.cxf.service.model.BindingInfo)21 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)19 SoapOperationInfo (org.apache.cxf.binding.soap.model.SoapOperationInfo)17 Exchange (org.apache.cxf.message.Exchange)17 ArrayList (java.util.ArrayList)13 UnwrappedOperationInfo (org.apache.cxf.service.model.UnwrappedOperationInfo)13 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)12 Fault (org.apache.cxf.interceptor.Fault)10 Message (org.apache.cxf.message.Message)10