Search in sources :

Example 16 with ServiceInfo

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

the class SoapBindingFactoryTest method testFactory.

@Test
public void testFactory() throws Exception {
    Definition d = createDefinition("/wsdl_soap/hello_world.wsdl");
    Bus bus = getMockBus();
    BindingFactoryManager bfm = getBindingFactoryManager(WSDLConstants.NS_SOAP11, bus);
    bus.getExtension(BindingFactoryManager.class);
    expectLastCall().andReturn(bfm).anyTimes();
    DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
    expect(bus.getExtension(DestinationFactoryManager.class)).andStubReturn(dfm);
    control.replay();
    WSDLServiceBuilder builder = new WSDLServiceBuilder(bus);
    ServiceInfo serviceInfo = builder.buildServices(d, new QName("http://apache.org/hello_world_soap_http", "SOAPService")).get(0);
    BindingInfo bi = serviceInfo.getBindings().iterator().next();
    assertTrue(bi instanceof SoapBindingInfo);
    SoapBindingInfo sbi = (SoapBindingInfo) bi;
    assertEquals("document", sbi.getStyle());
    assertTrue(WSDLConstants.NS_SOAP11_HTTP_TRANSPORT.equalsIgnoreCase(sbi.getTransportURI()));
    assertTrue(sbi.getSoapVersion() instanceof Soap11);
    BindingOperationInfo boi = sbi.getOperation(new QName("http://apache.org/hello_world_soap_http", "sayHi"));
    SoapOperationInfo sboi = boi.getExtensor(SoapOperationInfo.class);
    assertNotNull(sboi);
    assertEquals("document", sboi.getStyle());
    assertEquals("", sboi.getAction());
    BindingMessageInfo input = boi.getInput();
    SoapBodyInfo bodyInfo = input.getExtensor(SoapBodyInfo.class);
    assertEquals("literal", bodyInfo.getUse());
    List<MessagePartInfo> parts = bodyInfo.getParts();
    assertNotNull(parts);
    assertEquals(1, parts.size());
}
Also used : Bus(org.apache.cxf.Bus) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) SoapBodyInfo(org.apache.cxf.binding.soap.model.SoapBodyInfo) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager) QName(javax.xml.namespace.QName) Definition(javax.wsdl.Definition) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) BindingInfo(org.apache.cxf.service.model.BindingInfo) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) WSDLServiceBuilder(org.apache.cxf.wsdl11.WSDLServiceBuilder) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) Test(org.junit.Test)

Example 17 with ServiceInfo

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

the class SoapPreProtocolOutInterceptorTest method setUpBindingOperationInfo.

private BindingOperationInfo setUpBindingOperationInfo(String nsuri, String opreq, String opresp, Method method) {
    ServiceInfo si = new ServiceInfo();
    InterfaceInfo iinf = new InterfaceInfo(si, new QName(nsuri, method.getDeclaringClass().getSimpleName()));
    OperationInfo opInfo = iinf.addOperation(new QName(nsuri, method.getName()));
    opInfo.setProperty(Method.class.getName(), method);
    opInfo.setInput(opreq, opInfo.createMessage(new QName(nsuri, opreq), Type.INPUT));
    opInfo.setOutput(opresp, opInfo.createMessage(new QName(nsuri, opresp), Type.INPUT));
    return new BindingOperationInfo(null, opInfo);
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) QName(javax.xml.namespace.QName) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) Method(java.lang.reflect.Method)

Example 18 with ServiceInfo

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

the class JAXBEncoderDecoderTest method testMarshallExceptionWithOrder.

@Test
public void testMarshallExceptionWithOrder() throws Exception {
    Document doc = DOMUtils.getEmptyDocument();
    Element elNode = doc.createElementNS("http://cxf.apache.org", "ExceptionRoot");
    OrderException exception = new OrderException("Mymessage");
    exception.setAValue("avalue");
    exception.setDetail("detail");
    exception.setInfo1("info1");
    exception.setInfo2("info2");
    exception.setIntVal(10000);
    QName elName = new QName("http://cxf.apache.org", "OrderException");
    ServiceInfo serviceInfo = new ServiceInfo();
    InterfaceInfo interfaceInfo = new InterfaceInfo(serviceInfo, null);
    OperationInfo op = interfaceInfo.addOperation(new QName("http://cxf.apache.org", "operation"));
    MessageInfo message = new MessageInfo(op, null, null);
    MessagePartInfo part = new MessagePartInfo(elName, message);
    part.setElement(true);
    part.setElementQName(elName);
    part.setTypeClass(OrderException.class);
    // just need a simple generic context to handle the exceptions internal primitives
    JAXBContext exceptionContext = JAXBContext.newInstance(new Class[] { String.class });
    JAXBEncoderDecoder.marshallException(exceptionContext.createMarshaller(), exception, part, elNode);
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    StaxUtils.writeTo(elNode, bout);
    int a = bout.toString().lastIndexOf("aValue");
    int b = bout.toString().lastIndexOf("detail");
    int c = bout.toString().lastIndexOf("info1");
    int d = bout.toString().lastIndexOf("info2");
    int e = bout.toString().lastIndexOf("intVal");
    assertTrue(a < b);
    assertTrue(b < c);
    assertTrue(c < d);
    assertTrue(d < e);
    assertTrue(bout.toString().indexOf("transientValue") < 0);
    assertTrue(bout.toString(), bout.toString().indexOf("mappedField=\"MappedField\"") > 0);
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) ObjectWithQualifiedElementElement(org.apache.cxf.jaxb_form.ObjectWithQualifiedElementElement) Element(org.w3c.dom.Element) JAXBContext(javax.xml.bind.JAXBContext) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.w3c.dom.Document) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo) Test(org.junit.Test)

Example 19 with ServiceInfo

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

the class CodeFirstWSDLTest method testDocumentationOnImpl.

@Test
public void testDocumentationOnImpl() throws Exception {
    // CXF-3092
    EndpointImpl ep = (EndpointImpl) Endpoint.publish("local://foo", new CXF3092Impl());
    ServiceWSDLBuilder wsdlBuilder = new ServiceWSDLBuilder(bus, ep.getService().getServiceInfos().get(0));
    Definition def = wsdlBuilder.build();
    Document d = bus.getExtension(WSDLManager.class).getWSDLFactory().newWSDLWriter().getDocument(def);
    // org.apache.cxf.helpers.XMLUtils.printDOM(d);
    assertXPathEquals("//wsdl:definitions/wsdl:documentation", "My top level documentation", d.getDocumentElement());
    assertXPathEquals("//wsdl:definitions/wsdl:service/wsdl:documentation", "My Service documentation", d.getDocumentElement());
    assertXPathEquals("//wsdl:definitions/wsdl:binding/wsdl:documentation", "My binding doc", d.getDocumentElement());
    JaxwsServiceBuilder builder = new JaxwsServiceBuilder();
    builder.setServiceClass(CXF3092Impl.class);
    ServiceInfo serviceInfo = builder.createService();
    wsdlBuilder = new ServiceWSDLBuilder(bus, serviceInfo);
    def = wsdlBuilder.build();
    d = bus.getExtension(WSDLManager.class).getWSDLFactory().newWSDLWriter().getDocument(def);
    // org.apache.cxf.helpers.XMLUtils.printDOM(d);
    assertXPathEquals("//wsdl:definitions/wsdl:documentation", "My top level documentation", d.getDocumentElement());
    assertXPathEquals("//wsdl:definitions/wsdl:service/wsdl:documentation", "My Service documentation", d.getDocumentElement());
    assertXPathEquals("//wsdl:definitions/wsdl:binding/wsdl:documentation", "My binding doc", d.getDocumentElement());
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) Definition(javax.wsdl.Definition) WSDLManager(org.apache.cxf.wsdl.WSDLManager) Document(org.w3c.dom.Document) ServiceWSDLBuilder(org.apache.cxf.wsdl11.ServiceWSDLBuilder) Test(org.junit.Test)

Example 20 with ServiceInfo

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

the class JaxWsServiceFactoryBean method initializeWSDLOperationsForProvider.

protected void initializeWSDLOperationsForProvider() {
    Class<?> c = getProviderParameterType(getServiceClass());
    if (c == null) {
        throw new ServiceConstructionException(new Message("INVALID_PROVIDER_EXC", LOG));
    }
    if (getEndpointInfo() == null && isFromWsdl()) {
        // most likely, they specified a WSDL, but for some reason
        // did not give a valid ServiceName/PortName.  For provider,
        // we'll allow this since everything is bound directly to
        // the invoke method, however, this CAN cause other problems
        // such as addresses in the wsdl not getting updated and such
        // so we'll WARN about it.....
        List<QName> enames = new ArrayList<>();
        for (ServiceInfo si : getService().getServiceInfos()) {
            for (EndpointInfo ep : si.getEndpoints()) {
                enames.add(ep.getName());
            }
        }
        LOG.log(Level.WARNING, "COULD_NOT_FIND_ENDPOINT", new Object[] { getEndpointName(), enames });
    }
    try {
        Method invoke = getServiceClass().getMethod("invoke", c);
        QName catchAll = new QName("http://cxf.apache.org/jaxws/provider", "invoke");
        // Bind every operation to the invoke method.
        for (ServiceInfo si : getService().getServiceInfos()) {
            si.setProperty("soap.force.doclit.bare", Boolean.TRUE);
            if (!isFromWsdl()) {
                for (EndpointInfo ei : si.getEndpoints()) {
                    ei.setProperty("soap.no.validate.parts", Boolean.TRUE);
                }
            }
            for (BindingInfo bind : si.getBindings()) {
                for (BindingOperationInfo bop : bind.getOperations()) {
                    OperationInfo o = bop.getOperationInfo();
                    if (bop.isUnwrappedCapable()) {
                        // force to bare, no unwrapping
                        bop.getOperationInfo().setUnwrappedOperation(null);
                        bop.setUnwrappedOperation(null);
                    }
                    if (o.getInput() != null) {
                        final List<MessagePartInfo> messageParts;
                        if (o.getInput().getMessagePartsNumber() == 0) {
                            MessagePartInfo inf = o.getInput().addMessagePart(o.getName());
                            inf.setConcreteName(o.getName());
                            messageParts = o.getInput().getMessageParts();
                            bop.getInput().setMessageParts(messageParts);
                        } else {
                            messageParts = o.getInput().getMessageParts();
                        }
                        for (MessagePartInfo inf : messageParts) {
                            inf.setTypeClass(c);
                            break;
                        }
                    }
                    if (o.getOutput() != null) {
                        final List<MessagePartInfo> messageParts;
                        if (o.getOutput().getMessagePartsNumber() == 0) {
                            MessagePartInfo inf = o.getOutput().addMessagePart(o.getName());
                            inf.setConcreteName(new QName(o.getName().getNamespaceURI(), o.getName().getLocalPart() + "Response"));
                            messageParts = o.getOutput().getMessageParts();
                            bop.getOutput().setMessageParts(messageParts);
                        } else {
                            messageParts = o.getOutput().getMessageParts();
                        }
                        for (MessagePartInfo inf : messageParts) {
                            inf.setTypeClass(c);
                            break;
                        }
                    }
                    getMethodDispatcher().bind(o, invoke);
                }
                BindingOperationInfo bop = bind.getOperation(catchAll);
                if (bop == null) {
                    OperationInfo op = bind.getInterface().getOperation(catchAll);
                    if (op == null) {
                        op = bind.getInterface().addOperation(catchAll);
                        String name = catchAll.getLocalPart();
                        MessageInfo mInfo = op.createMessage(new QName(catchAll.getNamespaceURI(), name + "Request"), MessageInfo.Type.INPUT);
                        op.setInput(catchAll.getLocalPart() + "Request", mInfo);
                        MessagePartInfo mpi = mInfo.addMessagePart("parameters");
                        mpi.setElement(true);
                        mpi.setTypeClass(c);
                        mpi.setTypeQName(Constants.XSD_ANYTYPE);
                        mInfo = op.createMessage(new QName(catchAll.getNamespaceURI(), name + "Response"), MessageInfo.Type.OUTPUT);
                        op.setOutput(name + "Response", mInfo);
                        mpi = mInfo.addMessagePart("parameters");
                        mpi.setElement(true);
                        mpi.setTypeClass(c);
                        mpi.setTypeQName(Constants.XSD_ANYTYPE);
                        BindingOperationInfo bo = new BindingOperationInfo(bind, op);
                        op.setProperty("operation.is.synthetic", Boolean.TRUE);
                        bo.setProperty("operation.is.synthetic", Boolean.TRUE);
                        bind.addOperation(bo);
                    }
                }
            }
        }
    } catch (SecurityException | NoSuchMethodException e) {
        throw new ServiceConstructionException(e);
    }
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Message(org.apache.cxf.common.i18n.Message) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) Method(java.lang.reflect.Method) WebMethod(javax.jws.WebMethod) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) BindingInfo(org.apache.cxf.service.model.BindingInfo)

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