Search in sources :

Example 76 with OperationInfo

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

the class DocLiteralInInterceptor method getBindingOperationForEmptyBody.

private void getBindingOperationForEmptyBody(Collection<OperationInfo> operations, Endpoint ep, Exchange exchange) {
    // TO DO : check duplicate operation with no input and also check if the action matches
    for (OperationInfo op : operations) {
        MessageInfo bmsg = op.getInput();
        int bPartsNum = bmsg.getMessagePartsNumber();
        if (bPartsNum == 0 || (bPartsNum == 1 && Constants.XSD_ANYTYPE.equals(bmsg.getFirstMessagePart().getTypeQName()))) {
            BindingOperationInfo boi = ep.getEndpointInfo().getBinding().getOperation(op);
            exchange.put(BindingOperationInfo.class, boi);
            exchange.setOneWay(op.isOneWay());
        }
    }
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) MessageInfo(org.apache.cxf.service.model.MessageInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo)

Example 77 with OperationInfo

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

the class ReflectionServiceFactoryBean method initializeClassInfo.

/**
 * set the holder generic type info into message part info
 *
 * @param o
 * @param method
 */
protected boolean initializeClassInfo(OperationInfo o, Method method, List<String> paramOrder) {
    OperationInfo origOp = o;
    if (isWrapped(method)) {
        if (o.getUnwrappedOperation() == null) {
            // the "normal" algorithm didn't allow for unwrapping,
            // but the annotations say unwrap this.   We'll need to
            // make it.
            WSDLServiceBuilder.checkForWrapped(o, true);
        }
        if (o.getUnwrappedOperation() != null) {
            if (o.hasInput()) {
                MessageInfo input = o.getInput();
                MessagePartInfo part = input.getFirstMessagePart();
                part.setTypeClass(getRequestWrapper(method));
                part.setProperty("REQUEST.WRAPPER.CLASSNAME", getRequestWrapperClassName(method));
                part.setIndex(0);
            }
            if (o.hasOutput()) {
                MessageInfo input = o.getOutput();
                MessagePartInfo part = input.getFirstMessagePart();
                part.setTypeClass(getResponseWrapper(method));
                part.setProperty("RESPONSE.WRAPPER.CLASSNAME", getResponseWrapperClassName(method));
                part.setIndex(0);
            }
            setFaultClassInfo(o, method);
            o = o.getUnwrappedOperation();
        } else {
            LOG.warning(new Message("COULD_NOT_UNWRAP", LOG, o.getName(), method).toString());
            setFaultClassInfo(o, method);
        }
    } else if (o.isUnwrappedCapable()) {
        // remove the unwrapped operation because it will break the
        // the WrapperClassOutInterceptor, and in general makes
        // life more confusing
        o.setUnwrappedOperation(null);
        setFaultClassInfo(o, method);
    }
    o.setProperty(METHOD_PARAM_ANNOTATIONS, method.getParameterAnnotations());
    o.setProperty(METHOD_ANNOTATIONS, method.getAnnotations());
    // Set all out of band indexes to MAX_VALUE, anything left at MAX_VALUE after this is unmapped
    for (MessagePartInfo mpi : o.getInput().getOutOfBandParts()) {
        mpi.setIndex(Integer.MAX_VALUE);
    }
    if (o.hasOutput()) {
        for (MessagePartInfo mpi : o.getOutput().getOutOfBandParts()) {
            mpi.setIndex(Integer.MAX_VALUE);
        }
    }
    Class<?>[] paramTypes = method.getParameterTypes();
    Type[] genericTypes = method.getGenericParameterTypes();
    for (int i = 0; i < paramTypes.length; i++) {
        if (Exchange.class.equals(paramTypes[i])) {
            continue;
        }
        Class<?> paramType = paramTypes[i];
        Type genericType = genericTypes[i];
        if (!initializeParameter(o, method, i, paramType, genericType)) {
            return false;
        }
    }
    setIndexes(o.getInput());
    sendEvent(Event.OPERATIONINFO_IN_MESSAGE_SET, origOp, method, origOp.getInput());
    // Initialize return type
    if (o.hasOutput() && !initializeParameter(o, method, -1, method.getReturnType(), method.getGenericReturnType())) {
        return false;
    }
    if (o.hasOutput()) {
        setIndexes(o.getOutput());
    }
    if (origOp.hasOutput()) {
        sendEvent(Event.OPERATIONINFO_OUT_MESSAGE_SET, origOp, method, origOp.getOutput());
    }
    setFaultClassInfo(o, method);
    return true;
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) UnwrappedOperationInfo(org.apache.cxf.service.model.UnwrappedOperationInfo) GenericArrayType(java.lang.reflect.GenericArrayType) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) Type(java.lang.reflect.Type) XmlMimeType(javax.xml.bind.annotation.XmlMimeType) ParameterizedType(java.lang.reflect.ParameterizedType) Message(org.apache.cxf.common.i18n.Message) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) MessageInfo(org.apache.cxf.service.model.MessageInfo)

Example 78 with OperationInfo

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

the class ReflectionServiceFactoryBean method initializeWSDLOperations.

protected void initializeWSDLOperations() {
    List<OperationInfo> removes = new ArrayList<>();
    Method[] methods = serviceClass.getMethods();
    Arrays.sort(methods, new MethodComparator());
    InterfaceInfo intf = getInterfaceInfo();
    Map<QName, Method> validMethods = new HashMap<>();
    for (Method m : methods) {
        if (isValidMethod(m)) {
            QName opName = getOperationName(intf, m);
            validMethods.put(opName, m);
        }
    }
    for (OperationInfo o : intf.getOperations()) {
        Method selected = null;
        for (Map.Entry<QName, Method> m : validMethods.entrySet()) {
            QName opName = m.getKey();
            if (o.getName().getNamespaceURI().equals(opName.getNamespaceURI()) && isMatchOperation(o.getName().getLocalPart(), opName.getLocalPart())) {
                selected = m.getValue();
                break;
            }
        }
        if (selected == null) {
            LOG.log(Level.WARNING, "NO_METHOD_FOR_OP", o.getName());
            removes.add(o);
        } else {
            initializeWSDLOperation(intf, o, selected);
        }
    }
    for (OperationInfo op : removes) {
        intf.removeOperation(op);
    }
    // Update the bindings.
    for (ServiceInfo service : getService().getServiceInfos()) {
        for (BindingInfo bi : service.getBindings()) {
            List<BindingOperationInfo> biremoves = new ArrayList<>();
            for (BindingOperationInfo binfo : bi.getOperations()) {
                if (removes.contains(binfo.getOperationInfo())) {
                    biremoves.add(binfo);
                } else {
                    binfo.updateUnwrappedOperation();
                }
            }
            for (BindingOperationInfo binfo : biremoves) {
                bi.removeOperation(binfo);
            }
        }
    }
    sendEvent(Event.INTERFACE_CREATED, intf, getServiceClass());
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) UnwrappedOperationInfo(org.apache.cxf.service.model.UnwrappedOperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) BindingInfo(org.apache.cxf.service.model.BindingInfo) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) NamespaceMap(org.apache.ws.commons.schema.utils.NamespaceMap)

Example 79 with OperationInfo

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

the class ReflectionServiceFactoryBean method initializeWrappedSchema.

protected void initializeWrappedSchema(ServiceInfo serviceInfo) {
    for (OperationInfo op : serviceInfo.getInterface().getOperations()) {
        if (op.getUnwrappedOperation() != null) {
            if (op.hasInput()) {
                MessagePartInfo fmpi = op.getInput().getFirstMessagePart();
                if (fmpi.getTypeClass() == null) {
                    QName wrapperBeanName = fmpi.getElementQName();
                    XmlSchemaElement e = null;
                    for (SchemaInfo s : serviceInfo.getSchemas()) {
                        e = s.getElementByQName(wrapperBeanName);
                        if (e != null) {
                            fmpi.setXmlSchema(e);
                            break;
                        }
                    }
                    if (e == null) {
                        createWrappedSchema(serviceInfo, op.getInput(), op.getUnwrappedOperation().getInput(), wrapperBeanName);
                    }
                }
                for (MessagePartInfo mpi : op.getInput().getMessageParts()) {
                    if (Boolean.TRUE.equals(mpi.getProperty(HEADER))) {
                        QName qn = (QName) mpi.getProperty(ELEMENT_NAME);
                        mpi.setElement(true);
                        mpi.setElementQName(qn);
                        checkForElement(serviceInfo, mpi);
                    }
                }
            }
            if (op.hasOutput()) {
                MessagePartInfo fmpi = op.getOutput().getFirstMessagePart();
                if (fmpi.getTypeClass() == null) {
                    QName wrapperBeanName = fmpi.getElementQName();
                    XmlSchemaElement e = null;
                    for (SchemaInfo s : serviceInfo.getSchemas()) {
                        e = s.getElementByQName(wrapperBeanName);
                        if (e != null) {
                            break;
                        }
                    }
                    if (e == null) {
                        createWrappedSchema(serviceInfo, op.getOutput(), op.getUnwrappedOperation().getOutput(), wrapperBeanName);
                    }
                }
                for (MessagePartInfo mpi : op.getOutput().getMessageParts()) {
                    if (Boolean.TRUE.equals(mpi.getProperty(HEADER))) {
                        QName qn = (QName) mpi.getProperty(ELEMENT_NAME);
                        mpi.setElement(true);
                        mpi.setElementQName(qn);
                        checkForElement(serviceInfo, mpi);
                    }
                }
            }
        }
    }
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) UnwrappedOperationInfo(org.apache.cxf.service.model.UnwrappedOperationInfo) QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) SchemaInfo(org.apache.cxf.service.model.SchemaInfo)

Example 80 with OperationInfo

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

the class ReflectionServiceFactoryBean method buildServiceFromClass.

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);
            }
        }
    }
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) UnwrappedOperationInfo(org.apache.cxf.service.model.UnwrappedOperationInfo) FaultInfo(org.apache.cxf.service.model.FaultInfo) Message(org.apache.cxf.common.i18n.Message) ServiceImpl(org.apache.cxf.service.ServiceImpl) QName(javax.xml.namespace.QName) ServiceModelSchemaValidator(org.apache.cxf.service.ServiceModelSchemaValidator) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) Method(java.lang.reflect.Method) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) MimeSerializer(org.apache.cxf.databinding.source.mime.MimeSerializer) CatalogXmlSchemaURIResolver(org.apache.cxf.catalog.CatalogXmlSchemaURIResolver) SchemaCollection(org.apache.cxf.common.xmlschema.SchemaCollection)

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