org.apache.cxf.jaxws.JAXWSMethodInvoker Java Examples

The following examples show how to use org.apache.cxf.jaxws.JAXWSMethodInvoker. 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: ProviderImpl.java    From cxf with Apache License 2.0 6 votes vote down vote up
public Endpoint createEndpoint(String bindingId, Class<?> implementorClass,
                               Invoker invoker, WebServiceFeature ... features) {
    if (EndpointUtils.isValidImplementor(implementorClass)) {
        Bus bus = BusFactory.getThreadDefaultBus();
        JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
        if (features != null) {
            factory.getJaxWsServiceFactory().setWsFeatures(Arrays.asList(features));
        }
        if (invoker != null) {
            factory.setInvoker(new JAXWSMethodInvoker(invoker));
            try {
                invoker.inject(new WebServiceContextImpl());
            } catch (Exception e) {
                throw new WebServiceException(new Message("ENDPOINT_CREATION_FAILED_MSG",
                                                          LOG).toString(), e);
            }
        }
        EndpointImpl ep = new EndpointImpl(bus, null, factory);
        ep.setImplementorClass(implementorClass);
        return ep;
    }
    throw new WebServiceException(new Message("INVALID_IMPLEMENTOR_EXC", LOG).toString());
}
 
Example #2
Source File: JaxWsServiceFactoryBean.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
protected Invoker createInvoker() {
    Class<?> cls = getServiceClass();
    if (cls.isInterface()) {
        return null;
    }
    return new JAXWSMethodInvoker(new SingletonFactory(getServiceClass()));
}
 
Example #3
Source File: ProviderServiceFactoryTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testFromWSDL() throws Exception {
    URL resource = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(resource);

    JaxWsImplementorInfo implInfo = new JaxWsImplementorInfo(HWSoapMessageProvider.class);
    JaxWsServiceFactoryBean bean = new JaxWsServiceFactoryBean(implInfo);
    bean.setWsdlURL(resource.toString());

    Bus bus = getBus();
    bean.setBus(bus);
    bean.setServiceClass(HWSoapMessageProvider.class);

    Service service = bean.create();
    assertTrue(service.getInvoker() instanceof JAXWSMethodInvoker);

    assertEquals("SOAPService", service.getName().getLocalPart());
    assertEquals("http://apache.org/hello_world_soap_http", service.getName().getNamespaceURI());

    InterfaceInfo intf = service.getServiceInfos().get(0).getInterface();
    assertNotNull(intf);

    JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
    svrFactory.setBus(bus);
    svrFactory.setServiceFactory(bean);
    svrFactory.setStart(false);

    ServerImpl server = (ServerImpl)svrFactory.create();
    assertTrue(server.getEndpoint().getService().getInvoker() instanceof JAXWSMethodInvoker);

    Endpoint endpoint = server.getEndpoint();
    Binding binding = endpoint.getBinding();
    assertTrue(binding instanceof SoapBinding);
}
 
Example #4
Source File: ProviderServiceFactoryTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testXMLBindingFromCode() throws Exception {
    JaxWsServiceFactoryBean bean = new JaxWsServiceFactoryBean();
    bean.setServiceClass(DOMSourcePayloadProvider.class);
    bean.setBus(getBus());
    bean.setInvoker(new JAXWSMethodInvoker(new DOMSourcePayloadProvider()));

    Service service = bean.create();

    assertEquals("DOMSourcePayloadProviderService", service.getName().getLocalPart());

    InterfaceInfo intf = service.getServiceInfos().get(0).getInterface();
    assertNotNull(intf);

    JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
    svrFactory.setBus(getBus());
    svrFactory.setServiceFactory(bean);
    String address = "http://localhost:9000/test";
    svrFactory.setAddress(address);
    svrFactory.setTransportId(LocalTransportFactory.TRANSPORT_ID);

    ServerImpl server = (ServerImpl)svrFactory.create();

    assertEquals(1, service.getServiceInfos().get(0).getEndpoints().size());

    Endpoint endpoint = server.getEndpoint();
    Binding binding = endpoint.getBinding();
    assertTrue(binding instanceof XMLBinding);

    Node res = invoke(address, LocalTransportFactory.TRANSPORT_ID,
                      "/org/apache/cxf/jaxws/provider/sayHi.xml");

    addNamespace("j", "http://service.jaxws.cxf.apache.org/");
    assertValid("/j:sayHi", res);
}
 
Example #5
Source File: ProviderServiceFactoryTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testSOAPBindingFromCode() throws Exception {
    JaxWsServiceFactoryBean bean = new JaxWsServiceFactoryBean();
    bean.setServiceClass(SOAPSourcePayloadProvider.class);
    bean.setBus(getBus());
    bean.setInvoker(new JAXWSMethodInvoker(new SOAPSourcePayloadProvider()));

    Service service = bean.create();

    assertEquals("SOAPSourcePayloadProviderService", service.getName().getLocalPart());

    InterfaceInfo intf = service.getServiceInfos().get(0).getInterface();
    assertNotNull(intf);
    assertEquals(1, intf.getOperations().size());

    JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
    svrFactory.setBus(getBus());
    svrFactory.setServiceFactory(bean);
    String address = "local://localhost:9000/test";
    svrFactory.setAddress(address);

    ServerImpl server = (ServerImpl)svrFactory.create();

    // See if our endpoint was created correctly
    assertEquals(1, service.getServiceInfos().get(0).getEndpoints().size());

    Endpoint endpoint = server.getEndpoint();
    Binding binding = endpoint.getBinding();
    assertTrue(binding instanceof SoapBinding);

    SoapBindingInfo sb = (SoapBindingInfo)endpoint.getEndpointInfo().getBinding();
    assertEquals("document", sb.getStyle());
    assertFalse(bean.isWrapped());

    assertEquals(1, sb.getOperations().size());
    Node res = invoke(address, LocalTransportFactory.TRANSPORT_ID, "/org/apache/cxf/jaxws/sayHi.xml");

    addNamespace("j", "http://service.jaxws.cxf.apache.org/");
    assertValid("/s:Envelope/s:Body/j:sayHi", res);
}
 
Example #6
Source File: ProviderServiceFactoryTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testSAAJProviderCodeFirst() throws Exception {
    JaxWsServiceFactoryBean bean = new JaxWsServiceFactoryBean();
    bean.setServiceClass(SAAJProvider.class);
    bean.setBus(getBus());
    bean.setInvoker(new JAXWSMethodInvoker(new SAAJProvider()));

    Service service = bean.create();

    assertEquals("SAAJProviderService", service.getName().getLocalPart());

    InterfaceInfo intf = service.getServiceInfos().get(0).getInterface();
    assertNotNull(intf);
    assertEquals(1, intf.getOperations().size());

    JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
    svrFactory.setBus(getBus());
    svrFactory.setServiceFactory(bean);
    String address = "local://localhost:9000/test";
    svrFactory.setAddress(address);

    ServerImpl server = (ServerImpl)svrFactory.create();

    Endpoint endpoint = server.getEndpoint();
    Binding binding = endpoint.getBinding();
    assertTrue(binding instanceof SoapBinding);

    SoapBindingInfo sb = (SoapBindingInfo)endpoint.getEndpointInfo().getBinding();
    assertEquals("document", sb.getStyle());
    assertFalse(bean.isWrapped());

    assertEquals(1, sb.getOperations().size());
    Node res = invoke(address, LocalTransportFactory.TRANSPORT_ID, "/org/apache/cxf/jaxws/sayHi.xml");

    addNamespace("j", "http://service.jaxws.cxf.apache.org/");
    assertValid("/s:Envelope/s:Body/j:sayHi", res);
}
 
Example #7
Source File: MEXInInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private synchronized Endpoint createEndpoint(Message message) {
    if (mexEndpoint == null) {
        MEXJaxWsServerFactoryBean factory
            = new MEXJaxWsServerFactoryBean(message.getExchange().getBus());
        try {
            Endpoint endpoint = factory.createEndpoint();
            endpoint.getService().setInvoker(new JAXWSMethodInvoker(ep));

            mexEndpoint = endpoint;
        } catch (Exception ex) {
            throw new Fault(ex);
        }
    }
    return mexEndpoint;
}