Search in sources :

Example 16 with ReflectionServiceFactoryBean

use of org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean in project cxf by apache.

the class CodeFirstWSDLTest method testExcludeOnInterface.

@Test
public void testExcludeOnInterface() throws Exception {
    try {
        JaxWsImplementorInfo info = new JaxWsImplementorInfo(HelloExcludeImpl.class);
        ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean(info);
        Bus bus = getBus();
        bean.setBus(bus);
        bean.create();
        fail("WebMethod(exclude=true) is not allowed");
    } catch (JaxWsConfigurationException e) {
        assertTrue(e.getMessage().contains("WebMethod"));
    }
}
Also used : Bus(org.apache.cxf.Bus) JaxWsImplementorInfo(org.apache.cxf.jaxws.support.JaxWsImplementorInfo) JaxWsServiceFactoryBean(org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean) ReflectionServiceFactoryBean(org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean) Test(org.junit.Test)

Example 17 with ReflectionServiceFactoryBean

use of org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean in project cxf by apache.

the class JaxWsClientTest method testEndpoint.

@Test
public void testEndpoint() throws Exception {
    ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean();
    URL resource = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(resource);
    bean.setWsdlURL(resource.toString());
    bean.setBus(getBus());
    bean.setServiceClass(GreeterImpl.class);
    GreeterImpl greeter = new GreeterImpl();
    BeanInvoker invoker = new BeanInvoker(greeter);
    bean.setInvoker(invoker);
    Service service = bean.create();
    String namespace = "http://apache.org/hello_world_soap_http";
    EndpointInfo ei = service.getServiceInfos().get(0).getEndpoint(new QName(namespace, "SoapPort"));
    JaxWsEndpointImpl endpoint = new JaxWsEndpointImpl(getBus(), service, ei);
    ClientImpl client = new ClientImpl(getBus(), endpoint);
    BindingOperationInfo bop = ei.getBinding().getOperation(new QName(namespace, "sayHi"));
    assertNotNull(bop);
    bop = bop.getUnwrappedOperation();
    assertNotNull(bop);
    MessagePartInfo part = bop.getOutput().getMessageParts().get(0);
    assertEquals(0, part.getIndex());
    d.setMessageObserver(new MessageReplayObserver("sayHiResponse.xml"));
    Object[] ret = client.invoke(bop, new Object[] { "hi" }, null);
    assertNotNull(ret);
    assertEquals("Wrong number of return objects", 1, ret.length);
    // test fault handling
    bop = ei.getBinding().getOperation(new QName(namespace, "testDocLitFault"));
    bop = bop.getUnwrappedOperation();
    d.setMessageObserver(new MessageReplayObserver("testDocLitFault.xml"));
    try {
        client.invoke(bop, new Object[] { "BadRecordLitFault" }, null);
        fail("Should have returned a fault!");
    } catch (BadRecordLitFault fault) {
        assertEquals("foo", fault.getFaultInfo().trim());
        assertEquals("Hadrian did it.", fault.getMessage());
    }
    try {
        client.getEndpoint().getOutInterceptors().add(new NestedFaultThrower());
        client.getEndpoint().getOutInterceptors().add(new FaultThrower());
        client.invoke(bop, new Object[] { "BadRecordLitFault" }, null);
        fail("Should have returned a fault!");
    } catch (Fault fault) {
        assertEquals(true, fault.getMessage().indexOf("Foo") >= 0);
    }
    client.close();
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) JaxWsServiceFactoryBean(org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean) QName(javax.xml.namespace.QName) BeanInvoker(org.apache.cxf.service.invoker.BeanInvoker) Service(org.apache.cxf.service.Service) ClientImpl(org.apache.cxf.endpoint.ClientImpl) BadRecordLitFault(org.apache.hello_world_soap_http.BadRecordLitFault) Fault(org.apache.cxf.interceptor.Fault) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) URL(java.net.URL) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) BadRecordLitFault(org.apache.hello_world_soap_http.BadRecordLitFault) JaxWsEndpointImpl(org.apache.cxf.jaxws.support.JaxWsEndpointImpl) GreeterImpl(org.apache.hello_world_soap_http.GreeterImpl) ReflectionServiceFactoryBean(org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean) Test(org.junit.Test)

Example 18 with ReflectionServiceFactoryBean

use of org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean in project cxf by apache.

the class JaxWsServiceFactoryBeanTest method testEndpoint.

@Test
public void testEndpoint() throws Exception {
    ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean();
    URL resource = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(resource);
    bean.setWsdlURL(resource.toString());
    Bus bus = getBus();
    bean.setBus(bus);
    bean.setServiceClass(GreeterImpl.class);
    BeanInvoker invoker = new BeanInvoker(new GreeterImpl());
    bean.setInvoker(invoker);
    Service service = bean.create();
    String ns = "http://apache.org/hello_world_soap_http";
    assertEquals("SOAPService", service.getName().getLocalPart());
    assertEquals(ns, service.getName().getNamespaceURI());
    InterfaceInfo intf = service.getServiceInfos().get(0).getInterface();
    OperationInfo op = intf.getOperation(new QName(ns, "sayHi"));
    Class<?> wrapper = op.getInput().getMessageParts().get(0).getTypeClass();
    assertNotNull(wrapper);
    wrapper = op.getOutput().getMessageParts().get(0).getTypeClass();
    assertNotNull(wrapper);
    assertEquals(invoker, service.getInvoker());
    op = intf.getOperation(new QName(ns, "testDocLitFault"));
    Collection<FaultInfo> faults = op.getFaults();
    assertEquals(2, faults.size());
    FaultInfo f = op.getFault(new QName(ns, "BadRecordLitFault"));
    assertNotNull(f);
    Class<?> c = f.getProperty(Class.class.getName(), Class.class);
    assertNotNull(c);
    assertEquals(1, f.getMessageParts().size());
    MessagePartInfo mpi = f.getMessagePartByIndex(0);
    assertNotNull(mpi.getTypeClass());
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) Bus(org.apache.cxf.Bus) FaultInfo(org.apache.cxf.service.model.FaultInfo) QName(javax.xml.namespace.QName) BeanInvoker(org.apache.cxf.service.invoker.BeanInvoker) Service(org.apache.cxf.service.Service) WebService(javax.jws.WebService) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) URL(java.net.URL) GreeterImpl(org.apache.hello_world_soap_http.GreeterImpl) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) ReflectionServiceFactoryBean(org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean) Test(org.junit.Test) AbstractJaxWsTest(org.apache.cxf.jaxws.AbstractJaxWsTest)

Example 19 with ReflectionServiceFactoryBean

use of org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean in project cxf by apache.

the class JaxWsServiceFactoryBeanTest method testWebSeviceException.

@Test
public void testWebSeviceException() throws Exception {
    ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean();
    Bus bus = getBus();
    bean.setBus(bus);
    bean.setServiceClass(WebServiceExceptionTestImpl.class);
    Service service = bean.create();
    ServiceInfo si = service.getServiceInfos().get(0);
    ServiceWSDLBuilder builder = new ServiceWSDLBuilder(bus, si);
    Definition def = builder.build();
    Document wsdl = WSDLFactory.newInstance().newWSDLWriter().getDocument(def);
    assertInvalid("/wsdl:definitions/wsdl:message[@name='WebServiceException']", wsdl);
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) Bus(org.apache.cxf.Bus) Definition(javax.wsdl.Definition) Service(org.apache.cxf.service.Service) WebService(javax.jws.WebService) Document(org.w3c.dom.Document) ReflectionServiceFactoryBean(org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean) ServiceWSDLBuilder(org.apache.cxf.wsdl11.ServiceWSDLBuilder) Test(org.junit.Test) AbstractJaxWsTest(org.apache.cxf.jaxws.AbstractJaxWsTest)

Example 20 with ReflectionServiceFactoryBean

use of org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean in project cxf by apache.

the class JaxWsServiceFactoryBeanTest method testBareBug.

@Test
public void testBareBug() throws Exception {
    ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean();
    Bus bus = getBus();
    bean.setBus(bus);
    bean.setServiceClass(org.apache.cxf.test.TestInterfacePort.class);
    Service service = bean.create();
    ServiceInfo si = service.getServiceInfos().get(0);
    ServiceWSDLBuilder builder = new ServiceWSDLBuilder(bus, si);
    Definition def = builder.build();
    Document wsdl = WSDLFactory.newInstance().newWSDLWriter().getDocument(def);
    NodeList nodeList = assertValid("/wsdl:definitions/wsdl:types/xsd:schema" + "[@targetNamespace='http://cxf.apache.org/" + "org.apache.cxf.test.TestInterface/xsd']" + "/xsd:element[@name='getMessage']", wsdl);
    assertEquals(1, nodeList.getLength());
    assertValid("/wsdl:definitions/wsdl:message[@name='setMessage']" + "/wsdl:part[@name = 'parameters'][@element='ns1:setMessage']", wsdl);
    assertValid("/wsdl:definitions/wsdl:message[@name='echoCharResponse']" + "/wsdl:part[@name = 'y'][@element='ns1:charEl_y']", wsdl);
    assertValid("/wsdl:definitions/wsdl:message[@name='echoCharResponse']" + "/wsdl:part[@name = 'return'][@element='ns1:charEl_return']", wsdl);
    assertValid("/wsdl:definitions/wsdl:message[@name='echoCharResponse']" + "/wsdl:part[@name = 'z'][@element='ns1:charEl_z']", wsdl);
    assertValid("/wsdl:definitions/wsdl:message[@name='echoChar']" + "/wsdl:part[@name = 'x'][@element='ns1:charEl_x']", wsdl);
    assertValid("/wsdl:definitions/wsdl:message[@name='echoChar']" + "/wsdl:part[@name = 'y'][@element='ns1:charEl_y']", wsdl);
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) Bus(org.apache.cxf.Bus) NodeList(org.w3c.dom.NodeList) Definition(javax.wsdl.Definition) Service(org.apache.cxf.service.Service) WebService(javax.jws.WebService) Document(org.w3c.dom.Document) ReflectionServiceFactoryBean(org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean) ServiceWSDLBuilder(org.apache.cxf.wsdl11.ServiceWSDLBuilder) Test(org.junit.Test) AbstractJaxWsTest(org.apache.cxf.jaxws.AbstractJaxWsTest)

Aggregations

ReflectionServiceFactoryBean (org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean)21 Service (org.apache.cxf.service.Service)13 Test (org.junit.Test)11 WebService (javax.jws.WebService)9 Bus (org.apache.cxf.Bus)9 JaxWsServiceFactoryBean (org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean)8 QName (javax.xml.namespace.QName)6 AbstractJaxWsTest (org.apache.cxf.jaxws.AbstractJaxWsTest)6 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)6 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)6 ServerFactoryBean (org.apache.cxf.frontend.ServerFactoryBean)5 BeanInvoker (org.apache.cxf.service.invoker.BeanInvoker)5 InterfaceInfo (org.apache.cxf.service.model.InterfaceInfo)5 URL (java.net.URL)4 ServiceWSDLBuilder (org.apache.cxf.wsdl11.ServiceWSDLBuilder)4 GreeterImpl (org.apache.hello_world_soap_http.GreeterImpl)4 AegisDatabinding (org.apache.cxf.aegis.databinding.AegisDatabinding)3 ClientImpl (org.apache.cxf.endpoint.ClientImpl)3 BindingInfo (org.apache.cxf.service.model.BindingInfo)3 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)3