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

The following examples show how to use org.apache.cxf.service.model.OperationInfo#getOutput() . 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 getActionFromOutputMessage(final OperationInfo operation) {
    MessageInfo outputMessage = operation.getOutput();
    if (outputMessage != null && outputMessage.getExtensionAttributes() != null) {
        String outputAction = InternalContextUtils.getAction(outputMessage);
        if (!StringUtils.isEmpty(outputAction)) {
            return outputAction;
        }
    }
    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: ServiceJavascriptBuilder.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public void end(OperationInfo op) {
    // we only process the wrapped operation, not the unwrapped alternative.
    if (op.isUnwrapped()) {
        isInUnwrappedOperation = false;
        return;
    }

    isWrapped = op.isUnwrappedCapable();

    StringBuilder parameterList = new StringBuilder();

    inputParameterNames = new ArrayList<>();

    if (isWrapped) {
        collectWrapperElementInfo();
    } else {
        collectUnwrappedInputInfo();
    }

    buildParameterList(parameterList);

    MessageInfo outputMessage = op.getOutput();
    nonVoidOutput = outputMessage != null && outputMessage.getMessageParts().size() != 0;

    if (!op.isOneWay()) {
        buildSuccessFunction(outputMessage);
        buildErrorFunction(); // fault part some day.
    }

    buildOperationFunction(parameterList);

    createInputSerializer();

    if (nonVoidOutput) {
        createResponseDeserializer(outputMessage);
    }
}
 
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: XMLFormatValidator.java    From cxf with Apache License 2.0 4 votes vote down vote up
private boolean checkXMLFormat(BindingInfo binding) {
    Collection<BindingOperationInfo> bos = binding.getOperations();
    boolean result = true;
    boolean needRootNode = false;
    for (BindingOperationInfo bo : bos) {
        OperationInfo op = binding.getInterface().getOperation(bo.getName());
        needRootNode = false;
        final int inputPartsNum = op.getInput().getMessagePartsNumber();
        if (inputPartsNum == 0 || inputPartsNum > 1) {
            needRootNode = true;
        }
        if (needRootNode) {
            String path = "Binding(" + binding.getName().getLocalPart()
                + "):BindingOperation(" + bo.getName() + ")";
            List<XMLBindingMessageFormat> inExtensors =
                bo.getInput().getExtensors(XMLBindingMessageFormat.class);
            Iterator<XMLBindingMessageFormat> itIn = null;
            if (inExtensors != null) {
                itIn = inExtensors.iterator();
            }
            if (!findXMLFormatRootNode(itIn, bo, path + "-input")) {
                return false;
            }
            // Input check correct, continue to check output binding
            if (op.getOutput() != null) {
                needRootNode = false;
                final int outputPartsNum = op.getOutput().getMessagePartsNumber();
                if (outputPartsNum == 0 || outputPartsNum > 1) {
                    needRootNode = true;
                }
                if (needRootNode) {
                    List<XMLBindingMessageFormat> outExtensors =
                        bo.getOutput().getExtensors(XMLBindingMessageFormat.class);
                    Iterator<XMLBindingMessageFormat> itOut = null;
                    if (outExtensors != null) {
                        itOut = outExtensors.iterator();
                    }
                    result = result
                        && findXMLFormatRootNode(itOut, bo, path + "-Output");
                    if (!result) {
                        return false;
                    }
                }
            }
        }
    }
    return true;
}
 
Example 9
Source File: ServiceWSDLBuilder.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected void buildPortTypeOperation(PortType portType,
                                      Collection<OperationInfo> operationInfos,
                                      final Definition def) {
    for (OperationInfo operationInfo : operationInfos) {
        Operation operation = null;
        try {
            operation = operationInfo.getProperty(
                WSDLServiceBuilder.WSDL_OPERATION, Operation.class);
        } catch (ClassCastException e) {
            // do nothing
        }

        if (operation == null) {
            operation = def.createOperation();
            addDocumentation(operation, operationInfo.getDocumentation());
            operation.setUndefined(false);
            operation.setName(operationInfo.getName().getLocalPart());
            addNamespace(operationInfo.getName().getNamespaceURI(), def);
            if (operationInfo.isOneWay()) {
                operation.setStyle(OperationType.ONE_WAY);
            }
            addExtensibilityElements(def, operation, getWSDL11Extensors(operationInfo));
            Input input = def.createInput();
            addDocumentation(input, operationInfo.getInput().getDocumentation());
            input.setName(operationInfo.getInputName());
            Message message = def.createMessage();
            buildMessage(message, operationInfo.getInput(), def);
            this.addExtensibilityAttributes(def, input, getInputExtensionAttributes(operationInfo));
            this.addExtensibilityElements(def, input, getWSDL11Extensors(operationInfo.getInput()));
            input.setMessage(message);
            operation.setInput(input);
            operation.setParameterOrdering(operationInfo.getParameterOrdering());

            if (operationInfo.getOutput() != null) {
                Output output = def.createOutput();
                addDocumentation(output, operationInfo.getOutput().getDocumentation());
                output.setName(operationInfo.getOutputName());
                message = def.createMessage();
                buildMessage(message, operationInfo.getOutput(), def);
                this.addExtensibilityAttributes(def, output, getOutputExtensionAttributes(operationInfo));
                this.addExtensibilityElements(def, output, getWSDL11Extensors(operationInfo.getOutput()));
                output.setMessage(message);
                operation.setOutput(output);
            }
            //loop to add fault
            Collection<FaultInfo> faults = operationInfo.getFaults();
            Fault fault = null;
            for (FaultInfo faultInfo : faults) {
                fault = def.createFault();
                addDocumentation(fault, faultInfo.getDocumentation());
                fault.setName(faultInfo.getFaultName().getLocalPart());
                message = def.createMessage();
                buildMessage(message, faultInfo, def);
                this.addExtensibilityAttributes(def, fault, faultInfo.getExtensionAttributes());
                this.addExtensibilityElements(def, fault, getWSDL11Extensors(faultInfo));
                fault.setMessage(message);
                operation.addFault(fault);
            }
        }
        portType.addOperation(operation);
    }
}
 
Example 10
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 11
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 12
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));
        }
    }
}