Search in sources :

Example 76 with ServiceInfo

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

the class ReflectionServiceFactoryBean method buildServiceFromWSDL.

protected void buildServiceFromWSDL(String url) {
    sendEvent(Event.CREATE_FROM_WSDL, url);
    if (LOG.isLoggable(Level.INFO)) {
        LOG.info("Creating Service " + getServiceQName() + " from WSDL: " + url);
    }
    populateFromClass = false;
    WSDLServiceFactory factory = new WSDLServiceFactory(getBus(), url, getServiceQName());
    boolean setEPName = true;
    if (features != null) {
        for (Feature f : features) {
            if (f.getClass().isAnnotationPresent(EvaluateAllEndpoints.class)) {
                setEPName = false;
            }
        }
    }
    if (setEPName) {
        // CXF will only evaluate this endpoint
        factory.setEndpointName(getEndpointName(false));
    }
    sendEvent(Event.WSDL_LOADED, factory.getDefinition());
    setService(factory.create());
    setServiceProperties();
    sendEvent(Event.SERVICE_SET, getService());
    EndpointInfo epInfo = getEndpointInfo();
    if (epInfo != null) {
        serviceConfigurations.add(new WSDLBasedServiceConfiguration(getEndpointInfo().getBinding()));
    }
    initializeWSDLOperations();
    Set<Class<?>> cls = getExtraClass();
    if (cls != null && !cls.isEmpty()) {
        for (ServiceInfo si : getService().getServiceInfos()) {
            si.setProperty(EXTRA_CLASS, cls);
        }
    }
    initializeDataBindings();
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) WSDLServiceFactory(org.apache.cxf.wsdl11.WSDLServiceFactory) Feature(org.apache.cxf.feature.Feature)

Example 77 with ServiceInfo

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

the class BareInInterceptor method handleMessage.

public void handleMessage(Message message) {
    if (isGET(message) && message.getContent(List.class) != null) {
        LOG.fine("BareInInterceptor skipped in HTTP GET method");
        return;
    }
    DepthXMLStreamReader xmlReader = getXMLStreamReader(message);
    Exchange exchange = message.getExchange();
    DataReader<XMLStreamReader> dr = getDataReader(message);
    MessageContentsList parameters = new MessageContentsList();
    Endpoint ep = exchange.getEndpoint();
    BindingOperationInfo bop = exchange.getBindingOperationInfo();
    ServiceInfo si = ep.getEndpointInfo().getService();
    BindingMessageInfo msgInfo = null;
    boolean client = isRequestor(message);
    Collection<OperationInfo> ops = null;
    if (bop == null) {
        ops = new ArrayList<>();
        ops.addAll(si.getInterface().getOperations());
        if (xmlReader.getEventType() == XMLStreamConstants.END_ELEMENT && !client) {
            // TO DO : check duplicate operation with no input
            for (OperationInfo op : ops) {
                MessageInfo bmsg = op.getInput();
                if (bmsg.getMessagePartsNumber() == 0) {
                    BindingOperationInfo boi = ep.getEndpointInfo().getBinding().getOperation(op);
                    exchange.put(BindingOperationInfo.class, boi);
                    exchange.setOneWay(op.isOneWay());
                }
            }
        }
    } else {
        getMessageInfo(message, bop);
        if (client) {
            msgInfo = bop.getOutput();
        } else {
            msgInfo = bop.getInput();
        }
    }
    int paramNum = 0;
    while (StaxUtils.toNextElement(xmlReader)) {
        QName elName = xmlReader.getName();
        final MessagePartInfo p;
        if (msgInfo != null && msgInfo.getMessageParts() != null) {
            assert msgInfo.getMessageParts().size() > paramNum;
            p = msgInfo.getMessageParts().get(paramNum);
        } else {
            p = findMessagePart(exchange, ops, elName, client, paramNum, message);
        }
        if (p == null) {
            throw new Fault(new org.apache.cxf.common.i18n.Message("NO_PART_FOUND", LOG, elName), Fault.FAULT_CODE_CLIENT);
        }
        final Object o;
        try {
            o = dr.read(p, xmlReader);
        } catch (Fault fault) {
            if (!isRequestor(message)) {
                fault.setFaultCode(Fault.FAULT_CODE_CLIENT);
            }
            throw fault;
        }
        if (o != null) {
            parameters.put(p, o);
        }
        paramNum++;
    }
    if (!parameters.isEmpty()) {
        message.setContent(List.class, parameters);
    }
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) XMLStreamReader(javax.xml.stream.XMLStreamReader) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) MessageContentsList(org.apache.cxf.message.MessageContentsList) QName(javax.xml.namespace.QName) Fault(org.apache.cxf.interceptor.Fault) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) 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) Exchange(org.apache.cxf.message.Exchange) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) Endpoint(org.apache.cxf.endpoint.Endpoint)

Example 78 with ServiceInfo

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

the class DocLiteralInInterceptor method handleMessage.

public void handleMessage(Message message) {
    if (isGET(message) && message.getContent(List.class) != null) {
        LOG.fine("DocLiteralInInterceptor skipped in HTTP GET method");
        return;
    }
    DepthXMLStreamReader xmlReader = getXMLStreamReader(message);
    MessageContentsList parameters = new MessageContentsList();
    Exchange exchange = message.getExchange();
    BindingOperationInfo bop = exchange.getBindingOperationInfo();
    boolean client = isRequestor(message);
    // operation anymore, just return
    if (bop != null && !StaxUtils.toNextElement(xmlReader)) {
        // body may be empty for partial response to decoupled request
        return;
    }
    Service service = ServiceModelUtil.getService(message.getExchange());
    bop = getBindingOperationInfo(xmlReader, exchange, bop, client);
    boolean forceDocLitBare = false;
    if (bop != null && bop.getBinding() != null) {
        forceDocLitBare = Boolean.TRUE.equals(bop.getBinding().getService().getProperty("soap.force.doclit.bare"));
    }
    DataReader<XMLStreamReader> dr = getDataReader(message);
    try {
        if (!forceDocLitBare && bop != null && bop.isUnwrappedCapable()) {
            ServiceInfo si = bop.getBinding().getService();
            // Wrapped case
            MessageInfo msgInfo = setMessage(message, bop, client, si);
            setDataReaderValidation(service, message, dr);
            // Determine if we should keep the parameters wrapper
            if (shouldWrapParameters(msgInfo, message)) {
                QName startQName = xmlReader.getName();
                MessagePartInfo mpi = msgInfo.getFirstMessagePart();
                if (!mpi.getConcreteName().equals(startQName)) {
                    throw new Fault("UNEXPECTED_WRAPPER_ELEMENT", LOG, null, startQName, mpi.getConcreteName());
                }
                Object wrappedObject = dr.read(mpi, xmlReader);
                parameters.put(mpi, wrappedObject);
            } else {
                // Unwrap each part individually if we don't have a wrapper
                bop = bop.getUnwrappedOperation();
                msgInfo = setMessage(message, bop, client, si);
                List<MessagePartInfo> messageParts = msgInfo.getMessageParts();
                Iterator<MessagePartInfo> itr = messageParts.iterator();
                // stuck
                if (xmlReader.getEventType() == XMLStreamConstants.START_ELEMENT) {
                    StaxUtils.nextEvent(xmlReader);
                }
                // loop through each child element
                getPara(xmlReader, dr, parameters, itr, message);
            }
        } else {
            // Bare style
            BindingMessageInfo msgInfo = null;
            Endpoint ep = exchange.getEndpoint();
            ServiceInfo si = ep.getEndpointInfo().getService();
            if (bop != null) {
                // for xml binding or client side
                if (client) {
                    msgInfo = bop.getOutput();
                } else {
                    msgInfo = bop.getInput();
                    if (bop.getOutput() == null) {
                        exchange.setOneWay(true);
                    }
                }
                if (msgInfo == null) {
                    return;
                }
                setMessage(message, bop, client, si, msgInfo.getMessageInfo());
            }
            final Collection<OperationInfo> operations = new ArrayList<>(si.getInterface().getOperations());
            if (xmlReader == null || !StaxUtils.toNextElement(xmlReader)) {
                // empty input
                getBindingOperationForEmptyBody(operations, ep, exchange);
                return;
            }
            setDataReaderValidation(service, message, dr);
            int paramNum = 0;
            do {
                QName elName = xmlReader.getName();
                MessagePartInfo p;
                if (!client && msgInfo != null && msgInfo.getMessageParts() != null && msgInfo.getMessageParts().isEmpty()) {
                    // no input messagePartInfo
                    return;
                }
                if (msgInfo != null && msgInfo.getMessageParts() != null && msgInfo.getMessageParts().size() > 0) {
                    if (msgInfo.getMessageParts().size() > paramNum) {
                        p = msgInfo.getMessageParts().get(paramNum);
                    } else {
                        p = null;
                    }
                } else {
                    p = findMessagePart(exchange, operations, elName, client, paramNum, message);
                }
                if (!forceDocLitBare) {
                    // Make sure the elName found on the wire is actually OK for
                    // the purpose we need it
                    validatePart(p, elName, message);
                }
                final Object o = dr.read(p, xmlReader);
                if (forceDocLitBare && parameters.isEmpty()) {
                    // webservice provider does not need to ensure size
                    parameters.add(o);
                } else {
                    parameters.put(p, o);
                }
                paramNum++;
                if (message.getContent(XMLStreamReader.class) == null || o == xmlReader) {
                    xmlReader = null;
                }
            } while (xmlReader != null && StaxUtils.toNextElement(xmlReader));
        }
        message.setContent(List.class, parameters);
    } catch (Fault f) {
        if (!isRequestor(message)) {
            f.setFaultCode(Fault.FAULT_CODE_CLIENT);
        }
        throw f;
    }
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) XMLStreamReader(javax.xml.stream.XMLStreamReader) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) MessageContentsList(org.apache.cxf.message.MessageContentsList) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Service(org.apache.cxf.service.Service) Fault(org.apache.cxf.interceptor.Fault) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) 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) Exchange(org.apache.cxf.message.Exchange) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) Endpoint(org.apache.cxf.endpoint.Endpoint)

Example 79 with ServiceInfo

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

the class ValidatorUtil method getSchema.

public static SchemaCollection getSchema(final Definition def) {
    ServiceInfo serviceInfo = new ServiceInfo();
    new SchemaUtil(BusFactory.getThreadDefaultBus(), new HashMap<String, Element>()).getSchemas(def, serviceInfo);
    return serviceInfo.getXmlSchemaCollection();
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) HashMap(java.util.HashMap) SchemaUtil(org.apache.cxf.wsdl11.SchemaUtil)

Example 80 with ServiceInfo

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

the class JaxwsServiceBuilderRPCTest method testGreeter.

@Test
public void testGreeter() throws Exception {
    builder.setServiceClass(org.apache.cxf.tools.fortest.jaxws.rpc.Greeter.class);
    ServiceInfo service = builder.createService();
    generator.setServiceModel(service);
    File wsdlFile = new File(output, "rpc_greeter.wsdl");
    assertNotNull(wsdlFile);
    generator.generate(wsdlFile);
    assertTrue(wsdlFile.exists());
    InputStream expectedFile = getClass().getResourceAsStream("expected/rpc_greeter.wsdl");
    // MOXy doesn't put a final attribute on the array types, we can ignore that
    // for the purpose of this test
    List<String> ignores = new ArrayList<>(DEFAULT_IGNORE_ATTR);
    ignores.add("final");
    assertWsdlEquals(expectedFile, wsdlFile, ignores, DEFAULT_IGNORE_TAG);
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.junit.Test)

Aggregations

ServiceInfo (org.apache.cxf.service.model.ServiceInfo)195 QName (javax.xml.namespace.QName)89 Test (org.junit.Test)76 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)63 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)47 BindingInfo (org.apache.cxf.service.model.BindingInfo)43 OperationInfo (org.apache.cxf.service.model.OperationInfo)37 InterfaceInfo (org.apache.cxf.service.model.InterfaceInfo)36 Service (org.apache.cxf.service.Service)33 Endpoint (org.apache.cxf.endpoint.Endpoint)31 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)29 File (java.io.File)28 ArrayList (java.util.ArrayList)27 Bus (org.apache.cxf.Bus)26 InputStream (java.io.InputStream)23 Definition (javax.wsdl.Definition)20 Method (java.lang.reflect.Method)16 SchemaCollection (org.apache.cxf.common.xmlschema.SchemaCollection)15 HTTPTransportFactory (org.apache.cxf.transport.http.HTTPTransportFactory)15 IOException (java.io.IOException)12