Java Code Examples for org.apache.cxf.service.model.OperationInfo#getInput()

The following examples show how to use org.apache.cxf.service.model.OperationInfo#getInput() . 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: OperationProcessor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void setWrapper(OperationInfo operation) {
    MessagePartInfo inputPart = null;
    if (operation.getInput() != null) {
        inputPart = operation.getInput().getFirstMessagePart();
    }
    MessagePartInfo outputPart = null;
    if (operation.getOutput() != null) {
        outputPart = operation.getOutput().getFirstMessagePart();
    }

    if (inputPart != null) {
        wrapperRequest = new JavaParameter();
        wrapperRequest.setName(ProcessorUtil.resolvePartName(inputPart));
        wrapperRequest.setType(ProcessorUtil.getPartType(inputPart));
        wrapperRequest.setTargetNamespace(ProcessorUtil.resolvePartNamespace(inputPart));

        wrapperRequest.setClassName(ProcessorUtil.getFullClzName(inputPart,
                                                                 context, false));

    }
    if (outputPart != null) {
        wrapperResponse = new JavaParameter();
        wrapperResponse.setName(ProcessorUtil.resolvePartName(outputPart));
        wrapperResponse.setType(ProcessorUtil.getPartType(outputPart));
        wrapperResponse.setTargetNamespace(ProcessorUtil.resolvePartNamespace(outputPart));

        wrapperResponse.setClassName(ProcessorUtil.getFullClzName(outputPart,
                                                                  context, false));
    }
}
 
Example 2
Source File: ServiceProcessor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private MessageInfo getMessage(QName operationName, boolean isIn) {
    for (OperationInfo operation : service.getInterface().getOperations()) {
        if (operationName.equals(operation.getName()) && isIn) {
            return operation.getInput();
        }
        return operation.getOutput();
    }
    return null;
}
 
Example 3
Source File: MAPAggregatorImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
private String getActionFromInputMessage(final OperationInfo operation) {
    MessageInfo inputMessage = operation.getInput();

    if (inputMessage.getExtensionAttributes() != null) {
        String inputAction = InternalContextUtils.getAction(inputMessage);
        if (!StringUtils.isEmpty(inputAction)) {
            return inputAction;
        }
    }
    return null;
}
 
Example 4
Source File: ColocUtil.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static MessageInfo getMessageInfo(Message message) {
    OperationInfo oi = message.getExchange().getBindingOperationInfo().getOperationInfo();
    if (MessageUtils.isOutbound(message)) {
        return oi.getOutput();
    }
    return oi.getInput();
}
 
Example 5
Source File: DocLiteralInInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
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());
        }
    }
}
 
Example 6
Source File: AbstractInDatabindingInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected MessageInfo getMessageInfo(Message message, BindingOperationInfo operation, boolean requestor) {
    MessageInfo msgInfo;
    OperationInfo intfOp = operation.getOperationInfo();
    if (requestor) {
        msgInfo = intfOp.getOutput();
        message.put(MessageInfo.class, intfOp.getOutput());
    } else {
        msgInfo = intfOp.getInput();
        message.put(MessageInfo.class, intfOp.getInput());
    }
    return msgInfo;
}
 
Example 7
Source File: OperationProcessor.java    From cxf with Apache License 2.0 4 votes vote down vote up
void processMethod(JavaMethod method,
                   OperationInfo operation) throws ToolException {
    if (isAsyncMethod(method)) {
        return;
    }
    MessageInfo inputMessage = operation.getInput();
    MessageInfo outputMessage = operation.getOutput();

    if (inputMessage == null) {
        LOG.log(Level.WARNING, "NO_INPUT_MESSAGE", new Object[] {operation.getName()});
        org.apache.cxf.common.i18n.Message msg
            = new org.apache.cxf.common.i18n.Message("INVALID_MEP", LOG,
                                                           new Object[] {operation.getName()});
        throw new ToolException(msg);
    }

    ParameterProcessor paramProcessor = new ParameterProcessor(context);
    method.clear();

    JAXWSBinding opBinding = operation.getExtensor(JAXWSBinding.class);
    JAXWSBinding ptBinding = operation.getInterface().getExtensor(JAXWSBinding.class);
    JAXWSBinding defBinding = operation.getInterface().getService()
        .getDescription().getExtensor(JAXWSBinding.class);

    boolean enableAsync = false;
    boolean enableMime = false;
    boolean enableWrapper = method.isWrapperStyle();
    if (defBinding != null) {
        if (defBinding.isSetEnableMime()) {
            enableMime = defBinding.isEnableMime();
        }
        if (defBinding.isSetEnableAsyncMapping()) {
            enableAsync = defBinding.isEnableAsyncMapping();
        }
        if (defBinding.isSetEnableWrapperStyle()) {
            enableWrapper = defBinding.isEnableWrapperStyle();
        }
    }
    if (ptBinding != null) {
        if (ptBinding.isSetEnableMime()) {
            enableMime = ptBinding.isEnableMime();
        }
        if (ptBinding.isSetEnableAsyncMapping()) {
            enableAsync = ptBinding.isEnableAsyncMapping();
        }
        if (ptBinding.isSetEnableWrapperStyle()) {
            enableWrapper = ptBinding.isEnableWrapperStyle();
        }
    }
    if (opBinding != null) {
        if (opBinding.isSetEnableMime()) {
            enableMime = opBinding.isEnableMime();
        }
        if (opBinding.isSetEnableAsyncMapping()) {
            enableAsync = opBinding.isEnableAsyncMapping();
        }
        if (opBinding.isSetEnableWrapperStyle()) {
            enableWrapper = opBinding.isEnableWrapperStyle();
        }
    }

    enableWrapper = checkEnableWrapper(enableWrapper, method);
    enableAsync = checkEnableAsync(enableAsync, method);
    enableMime = checkEnableMime(enableMime, method);

    method.setWrapperStyle(enableWrapper && method.isWrapperStyle());


    paramProcessor.process(method,
                           inputMessage,
                           outputMessage,
                           operation.getParameterOrdering());

    if (method.isWrapperStyle()) {
        setWrapper(operation);
        method.annotate(new WrapperAnnotator(wrapperRequest, wrapperResponse));
    }

    method.annotate(new WebMethodAnnotator());


    method.annotate(new WebResultAnnotator());


    if (!method.isOneWay()
        && enableAsync && !isAddedAsycMethod(method)) {
        addAsyncMethod(method);
    }
    if (enableMime) {
        method.setMimeEnable(true);
    }
}
 
Example 8
Source File: ColocUtil.java    From cxf with Apache License 2.0 4 votes vote down vote up
public static boolean isAssignableOperationInfo(OperationInfo oi, Class<?> cls) {
    MessageInfo mi = oi.getInput();
    List<MessagePartInfo> mpis = mi.getMessageParts();
    return mpis.size() == 1 && cls.isAssignableFrom(mpis.get(0).getTypeClass());
}
 
Example 9
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 10
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++;
        }
    }
 
Example 11
Source File: WSDLServiceBuilderTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void assertPortTypeOperationMessageExtensions(OperationInfo oi, boolean expectExtensions,
    boolean hasOutput, QName fault) {

    MessageInfo mi = oi.getInput();
    if (expectExtensions) {
        assertEquals(1, mi.getExtensionAttributes().size());
        assertNotNull(mi.getExtensionAttribute(EXTENSION_ATTR_STRING));
        assertEquals(1, mi.getExtensors(UnknownExtensibilityElement.class).size());
        assertEquals(EXTENSION_ELEM, mi.getExtensor(UnknownExtensibilityElement.class).getElementType());
    } else {
        assertNull(mi.getExtensionAttributes());
        assertNull(mi.getExtensionAttribute(EXTENSION_ATTR_STRING));
        assertNull(mi.getExtensors(UnknownExtensibilityElement.class));
        assertNull(mi.getExtensor(UnknownExtensibilityElement.class));
    }

    if (hasOutput) {
        mi = oi.getOutput();
        if (expectExtensions) {
            assertEquals(1, mi.getExtensionAttributes().size());
            assertNotNull(mi.getExtensionAttribute(EXTENSION_ATTR_STRING));
            assertEquals(1, mi.getExtensors(UnknownExtensibilityElement.class).size());
            assertEquals(EXTENSION_ELEM,
                mi.getExtensor(UnknownExtensibilityElement.class).getElementType());
        } else {
            assertNull(mi.getExtensionAttributes());
            assertNull(mi.getExtensionAttribute(EXTENSION_ATTR_STRING));
            assertNull(mi.getExtensors(UnknownExtensibilityElement.class));
            assertNull(mi.getExtensor(UnknownExtensibilityElement.class));
        }
    }

    if (null != fault) {
        FaultInfo fi = oi.getFault(fault);
        if (expectExtensions) {
            assertEquals(1, fi.getExtensionAttributes().size());
            assertNotNull(fi.getExtensionAttribute(EXTENSION_ATTR_STRING));
            assertEquals(1, fi.getExtensors(UnknownExtensibilityElement.class).size());
            assertEquals(EXTENSION_ELEM,
                fi.getExtensor(UnknownExtensibilityElement.class).getElementType());
        } else {
            assertNull(fi.getExtensionAttributes());
            assertNull(fi.getExtensionAttribute(EXTENSION_ATTR_STRING));
            assertNull(fi.getExtensors(UnknownExtensibilityElement.class));
            assertNull(fi.getExtensor(UnknownExtensibilityElement.class));
        }
    }
}