Java Code Examples for org.apache.cxf.jaxws.JaxWsServerFactoryBean#setBus()

The following examples show how to use org.apache.cxf.jaxws.JaxWsServerFactoryBean#setBus() . 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: IntegrationBaseTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected Server createRemoteResource(ResourceManager manager) {
    ResourceRemote implementor = new ResourceRemote();
    implementor.setManager(manager);
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();

    Map<String, Object> props = factory.getProperties(true);
    props.put("jaxb.additionalContextClasses",
            org.apache.cxf.ws.transfer.dialect.fragment.ExpressionType.class);
    factory.setProperties(props);

    factory.setBus(bus);
    factory.setServiceClass(ResourceFactory.class);
    factory.setAddress(RESOURCE_REMOTE_MANAGER_ADDRESS);
    factory.setServiceBean(implementor);
    return factory.create();
}
 
Example 2
Source File: DualOutServiceTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testWSDL() throws Exception {
    JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
    sf.setServiceClass(DualOutService.class);
    sf.setAddress("local://DualOutService");
    sf.setBus(getBus());
    setupAegis(sf);
    sf.create();

    Document wsdl = getWSDLDocument("DualOutService");
    assertNotNull(wsdl);

    addNamespace("xsd", Constants.URI_2001_SCHEMA_XSD);

    assertValid(
                "//xsd:complexType[@name='getValuesResponse']//xsd:element"
                + "[@name='return'][@type='xsd:string']",
                wsdl);
    assertValid(
                "//xsd:complexType[@name='getValuesResponse']//xsd:element"
                + "[@name='return1'][@type='xsd:string']",
                wsdl);
}
 
Example 3
Source File: ProviderServiceFactoryTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testSourceMessageProviderCodeFirst() throws Exception {
    JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
    svrFactory.setServiceClass(SourceMessageProvider.class);
    svrFactory.setBus(getBus());
    svrFactory.setServiceBean(new SourceMessageProvider());
    String address = "local://localhost:9000/test";
    svrFactory.setAddress(address);

    svrFactory.create();

    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 4
Source File: ProviderServiceFactoryTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testStreamSourceProviderCodeFirst() throws Exception {
    JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
    svrFactory.setServiceClass(StreamSourcePayloadProvider.class);
    svrFactory.setBus(getBus());
    svrFactory.setServiceBean(new StreamSourcePayloadProvider());
    String address = "http://localhost:9000/test";
    svrFactory.setAddress(address);
    svrFactory.setTransportId(LocalTransportFactory.TRANSPORT_ID);

    svrFactory.create();

    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 5
Source File: MultipleServiceShareClassTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void registerService(final Class<?> service, final Object serviceImpl) {
    final JaxWsServerFactoryBean builder = new JaxWsServerFactoryBean();
    builder.setBus(getBus());
    builder.setAddress("http://localhost:" + PORT + "/" + service.getSimpleName());
    builder.setServiceBean(serviceImpl);
    builder.setServiceClass(service);
    builder.create();
}
 
Example 6
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 7
Source File: AbstractConnectionITHelper.java    From tracee with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected JaxWsServerFactoryBean createJaxWsServer() {
	JaxWsServerFactoryBean serverFactoryBean = new JaxWsServerFactoryBean();
	serverFactoryBean.setServiceClass(HelloWorldTestServiceImpl.class);
	serverFactoryBean.setAddress(endpointAddress);
	serverFactoryBean.setServiceBean(new HelloWorldTestServiceImpl(serverBackend));
	serverFactoryBean.setBus(CXFBusFactory.getDefaultBus());
	return serverFactoryBean;
}
 
Example 8
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 9
Source File: AnnotationInterceptorTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    fb = new ServerFactoryBean();
    fb.setAddress("local://localhost");
    fb.setBus(getBus());

    jfb = new JaxWsServerFactoryBean();
    jfb.setAddress("local://localhost");
    jfb.setBus(getBus());
}
 
Example 10
Source File: HolderTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testServer() throws Exception {
    JaxWsServerFactoryBean svr = new JaxWsServerFactoryBean();
    svr.setBus(getBus());
    svr.setServiceBean(new HolderServiceImpl());
    svr.setAddress(ADDRESS);
    svr.create();

    addNamespace("h", "http://holder.jaxws.cxf.apache.org/");
    Node response;

    response = invoke(ADDRESS, LocalTransportFactory.TRANSPORT_ID, "echo.xml");

    assertNotNull(response);
    assertValid("//h:echoResponse/return[text()='one']", response);
    assertValid("//h:echoResponse/return1[text()='two']", response);
    assertNoFault(response);

    response = invoke(ADDRESS, LocalTransportFactory.TRANSPORT_ID, "echo2.xml");

    assertNotNull(response);
    assertNoFault(response);
    assertValid("//h:echo2Response/return[text()='one']", response);
    assertValid("//h:echo2Response/return1[text()='two']", response);

    // test holder with in/out header
    response = invoke(ADDRESS, LocalTransportFactory.TRANSPORT_ID, "echo3.xml");

    assertNotNull(response);
    assertNoFault(response);
    assertValid("//h:echo3Response/return[text()='one']", response);
    assertValid("//s:Header/h:header[text()='header']", response);

}
 
Example 11
Source File: SimpleEventingIntegrationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected Server createEventSink(String address) {
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setBus(bus);
    factory.setServiceBean(new TestingEventSinkImpl());
    factory.setAddress(address);
    return factory.create();
}
 
Example 12
Source File: SimpleEventingIntegrationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected Server createEventSinkWithReferenceParametersAssertion(String address, ReferenceParametersType params) {
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setBus(bus);
    factory.setServiceBean(new TestingEventSinkImpl());
    factory.setAddress(address);
    factory.getHandlers().add(new ReferenceParametersAssertingHandler(params));
    return factory.create();
}
 
Example 13
Source File: IntegrationBaseTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected Server createLocalResourceFactory(ResourceManager manager) {
    ResourceFactoryImpl implementor = new ResourceFactoryImpl();
    implementor.setResourceResolver(new SimpleResourceResolver(RESOURCE_ADDRESS, manager));
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setBus(bus);
    factory.setServiceClass(ResourceFactory.class);
    factory.setAddress(RESOURCE_FACTORY_ADDRESS);
    factory.setServiceBean(implementor);

    return factory.create();
}
 
Example 14
Source File: IntegrationBaseTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected Server createRemoteResourceFactory() {
    ResourceFactoryImpl implementor = new ResourceFactoryImpl();
    implementor.setResourceResolver(new SimpleResourceResolver(RESOURCE_REMOTE_ADDRESS, null));
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setBus(bus);
    factory.setServiceClass(ResourceFactory.class);
    factory.setAddress(RESOURCE_FACTORY_ADDRESS);
    factory.setServiceBean(implementor);
    return factory.create();
}
 
Example 15
Source File: WSAFeatureTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testServerFactory() {
    JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
    sf.getFeatures().add(new WSAddressingFeature());
    sf.setServiceBean(new GreeterImpl());
    sf.setAddress("http://localhost:" + PORT + "/test");
    sf.setStart(false);
    sf.setBus(getBus());

    Server server = sf.create();

    Endpoint endpoint = server.getEndpoint();
    checkAddressInterceptors(endpoint.getInInterceptors());

}
 
Example 16
Source File: PolicyAnnotationTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@org.junit.Test
public void testAnnotations() throws Exception {
    Bus bus = BusFactory.getDefaultBus();
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setBus(bus);
    factory.setServiceBean(new TestImpl());
    factory.setStart(false);
    List<String> tp = Arrays.asList(
        "http://schemas.xmlsoap.org/soap/http",
        "http://schemas.xmlsoap.org/wsdl/http/",
        "http://schemas.xmlsoap.org/wsdl/soap/http",
        "http://www.w3.org/2003/05/soap/bindings/HTTP/",
        "http://cxf.apache.org/transports/http/configuration",
        "http://cxf.apache.org/bindings/xformat");

    LocalTransportFactory f = new LocalTransportFactory();
    f.getUriPrefixes().add("http");
    f.setTransportIds(tp);

    Server s = factory.create();

    try {
        ServiceWSDLBuilder builder = new ServiceWSDLBuilder(bus,
                                                            s.getEndpoint().getService()
                                                                .getServiceInfos());
        Definition def = builder.build();
        WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class)
            .getWSDLFactory().newWSDLWriter();
        def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry());
        Element wsdl = wsdlWriter.getDocument(def).getDocumentElement();

        Map<String, String> ns = new HashMap<>();
        ns.put("wsdl", WSDLConstants.NS_WSDL11);
        ns.put("wsu",
               "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
        ns.put("wsp", Constants.URI_POLICY_13_NS);
        XPathUtils xpu = new XPathUtils(ns);
        //org.apache.cxf.helpers.XMLUtils.printDOM(wsdl);
        check(xpu, wsdl, "/wsdl:definitions/wsdl:service/wsdl:port", "TestImplPortPortPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/", "TestInterfacePortTypePolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/wsdl:operation/", "echoIntPortTypeOpPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/wsdl:operation/wsdl:input",
              "echoIntPortTypeOpInputPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/wsdl:operation/wsdl:output",
              "echoIntPortTypeOpOutputPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/", "TestImplServiceSoapBindingBindingPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/wsdl:operation/", "echoIntBindingOpPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/wsdl:operation/wsdl:input",
              "echoIntBindingOpInputPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/wsdl:operation/wsdl:output",
              "echoIntBindingOpOutputPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:service/", "TestImplServiceServicePolicy");

        assertEquals(1,
                     xpu.getValueList("/wsdl:definitions/wsdl:binding/wsdl:operation/"
                                          + "wsp:PolicyReference[@URI='#echoIntBindingOpPolicy']", wsdl)
                         .getLength());

        EndpointPolicy policy = bus.getExtension(PolicyEngine.class)
            .getServerEndpointPolicy(s.getEndpoint().getEndpointInfo(), null, null);
        assertNotNull(policy);
        assertEquals(1, policy.getChosenAlternative().size());
    } finally {
        bus.shutdown(true);
    }
}
 
Example 17
Source File: PolicyAnnotationTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@org.junit.Test
public void testAnnotationsInterfaceAsClass() throws Exception {
    Bus bus = BusFactory.getDefaultBus();
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setBus(bus);
    factory.setServiceBean(new TestImpl());
    factory.setServiceClass(TestInterface.class);
    factory.setStart(false);
    List<String> tp = Arrays.asList(
        "http://schemas.xmlsoap.org/soap/http",
        "http://schemas.xmlsoap.org/wsdl/http/",
        "http://schemas.xmlsoap.org/wsdl/soap/http",
        "http://www.w3.org/2003/05/soap/bindings/HTTP/",
        "http://cxf.apache.org/transports/http/configuration",
        "http://cxf.apache.org/bindings/xformat");

    LocalTransportFactory f = new LocalTransportFactory();
    f.getUriPrefixes().add("http");
    f.setTransportIds(tp);


    Server s = factory.create();

    try {
        ServiceWSDLBuilder builder = new ServiceWSDLBuilder(bus,
                                                            s.getEndpoint().getService()
                                                                .getServiceInfos());
        Definition def = builder.build();
        WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class)
            .getWSDLFactory().newWSDLWriter();
        def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry());
        Element wsdl = wsdlWriter.getDocument(def).getDocumentElement();

        Map<String, String> ns = new HashMap<>();
        ns.put("wsdl", WSDLConstants.NS_WSDL11);
        ns.put("wsu",
               "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
        ns.put("wsp", Constants.URI_POLICY_13_NS);
        XPathUtils xpu = new XPathUtils(ns);
        //org.apache.cxf.helpers.XMLUtils.printDOM(wsdl);
        check(xpu, wsdl, "/wsdl:definitions/wsdl:service/wsdl:port", "TestInterfacePortPortPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/", "TestInterfacePortTypePolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/wsdl:operation/", "echoIntPortTypeOpPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/wsdl:operation/wsdl:input",
              "echoIntPortTypeOpInputPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/wsdl:operation/wsdl:output",
              "echoIntPortTypeOpOutputPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/",
              "TestInterfaceServiceSoapBindingBindingPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/wsdl:operation/", "echoIntBindingOpPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/wsdl:operation/wsdl:input",
              "echoIntBindingOpInputPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/wsdl:operation/wsdl:output",
              "echoIntBindingOpOutputPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:service/", "TestInterfaceServiceServicePolicy");

        assertEquals(1,
                     xpu.getValueList("/wsdl:definitions/wsdl:binding/wsdl:operation/"
                                          + "wsp:PolicyReference[@URI='#echoIntBindingOpPolicy']", wsdl)
                         .getLength());

    } finally {
        bus.shutdown(true);
    }
}
 
Example 18
Source File: CXFWebservicePublisher.java    From kumuluzee with MIT License 4 votes vote down vote up
public Server publish(final Endpoint endpoint, final Bus bus, final boolean cdiPresent) {

        final Class<?> clazz = endpoint.getImplementationClass();
        final String url = endpoint.getUrl();

        //inject resources into WS instance
        Stream.of(clazz.getDeclaredFields())
                .filter(f -> f.getType() == WebServiceContext.class)
                .forEach(f -> injectWebServiceResource(f, clazz));

        final Object targetBean = getBean(clazz, cdiPresent);

        AnnotationHandlerChainBuilder builder = new AnnotationHandlerChainBuilder(bus);
        InjectionHelper.injectWebServiceContext(targetBean, KumuluzWebServiceContext.getInstance());

        final Invoker invoker = new KumuluzWSInvoker(clazz, targetBean);

        final JaxWsServerFactoryBean fb = new JaxWsServerFactoryBean();

        fb.setBlockPostConstruct(true);
        fb.setAddress(url);
        fb.setBus(bus);
        fb.setServiceClass(clazz);
        fb.setInvoker(invoker);
        fb.setHandlers(builder.buildHandlerChainFromClass(clazz, fb.getEndpointName(), fb.getServiceName(), fb.getBindingId()));

        if (endpoint.wsdlLocation() != null) {
            //top-down approach
            fb.setWsdlLocation(endpoint.wsdlLocation());
        }

        Server server = fb.create();

        LOG.info("Webservice endpoint published with address=" + fb.getAddress() +
                ", wsdlLocation=" + fb.getWsdlURL() +
                ", implementor=" + clazz.getName() +
                ", serviceName=" + endpoint.serviceName() +
                ", portName=" + endpoint.portName());

        return server;
    }
 
Example 19
Source File: PolicyAnnotationTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@org.junit.Test
public void testAnnotationImplNoInterfacePolicies() throws Exception {
    Bus bus = BusFactory.getDefaultBus();
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setBus(bus);
    factory.setServiceBean(new TestImplWithPoliciesNoInterface());
    factory.setStart(false);
    List<String> tp = Arrays.asList("http://schemas.xmlsoap.org/soap/http", "http://schemas.xmlsoap.org/wsdl/http/",
            "http://schemas.xmlsoap.org/wsdl/soap/http", "http://www.w3.org/2003/05/soap/bindings/HTTP/",
            "http://cxf.apache.org/transports/http/configuration", "http://cxf.apache.org/bindings/xformat");

    LocalTransportFactory f = new LocalTransportFactory();
    f.getUriPrefixes().add("http");
    f.setTransportIds(tp);

    Server s = factory.create();

    try {
        ServiceWSDLBuilder builder = new ServiceWSDLBuilder(bus, s.getEndpoint().getService().getServiceInfos());
        Definition def = builder.build();
        WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class).getWSDLFactory().newWSDLWriter();
        def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry());
        Element wsdl = wsdlWriter.getDocument(def).getDocumentElement();

        Map<String, String> ns = new HashMap<>();
        ns.put("wsdl", WSDLConstants.NS_WSDL11);
        ns.put("wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
        ns.put("wsp", Constants.URI_POLICY_13_NS);
        XPathUtils xpu = new XPathUtils(ns);

        // org.apache.cxf.helpers.XMLUtils.printDOM(wsdl);
        assertEquals(1,
                xpu.getValueList("/wsdl:definitions/wsdl:binding/"
                + "wsp:PolicyReference[@URI='#TestImplWithPoliciesNoInterfaceServiceSoapBindingBindingPolicy']",
                        wsdl).getLength());
        final EndpointPolicy policy = bus.getExtension(PolicyEngine.class)
                .getServerEndpointPolicy(s.getEndpoint().getEndpointInfo(), null, null);
        assertNotNull(policy);
    } finally {
        bus.shutdown(true);
    }
}
 
Example 20
Source File: PublishedEndpointUrlTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testPublishedEndpointUrl() throws Exception {

    Greeter implementor = new org.apache.hello_world_soap_http.GreeterImpl();
    String publishedEndpointUrl = "http://cxf.apache.org/publishedEndpointUrl";
    Bus bus = BusFactory.getDefaultBus();
    JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
    svrFactory.setBus(bus);
    svrFactory.setServiceClass(Greeter.class);
    svrFactory.setAddress("http://localhost:" + PORT + "/publishedEndpointUrl");
    svrFactory.setPublishedEndpointUrl(publishedEndpointUrl);
    svrFactory.setServiceBean(implementor);

    Server server = svrFactory.create();

    WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader();
    wsdlReader.setFeature("javax.wsdl.verbose", false);

    URL url = new URL(svrFactory.getAddress() + "?wsdl=1");
    HttpURLConnection connect = (HttpURLConnection)url.openConnection();
    assertEquals(500, connect.getResponseCode());

    Definition wsdl = wsdlReader.readWSDL(svrFactory.getAddress() + "?wsdl");
    assertNotNull(wsdl);

    Collection<Service> services = CastUtils.cast(wsdl.getAllServices().values());
    final String failMesg = "WSDL provided incorrect soap:address location";

    for (Service service : services) {
        Collection<Port> ports = CastUtils.cast(service.getPorts().values());
        for (Port port : ports) {
            List<?> extensions = port.getExtensibilityElements();
            for (Object extension : extensions) {
                String actualUrl = null;
                if (extension instanceof SOAP12Address) {
                    actualUrl = ((SOAP12Address)extension).getLocationURI();
                } else if (extension instanceof SOAPAddress) {
                    actualUrl = ((SOAPAddress)extension).getLocationURI();
                }

                //System.out.println("Checking url: " + actualUrl + " against " + publishedEndpointUrl);
                assertEquals(failMesg, publishedEndpointUrl, actualUrl);
            }
        }
    }
    server.stop();
    server.destroy();
    bus.shutdown(true);
}