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

The following examples show how to use org.apache.cxf.jaxws.JaxWsServerFactoryBean#setServiceBean() . 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: WSServerTest.java    From cjs_ssms with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 接口测试 wsdl: http://localhost:9000/wSSample?wsdl
 * @param args
 */
public static void main(String[] args) {
  System.out.println("web service 启动中。。。");
  WSSampleImpl implementor = new WSSampleImpl();
  String address = "http://192.168.245.221:9000/wSSample";
  if (TestEnv.onTTrue) {
    address = "http://localhost:9000/wSSample";
  }
  JaxWsServerFactoryBean factoryBean = new JaxWsServerFactoryBean();
  factoryBean.setAddress(address); // 设置地址
  factoryBean.setServiceClass(WSSample.class); // 接口类
  factoryBean.setServiceBean(implementor); // 设置实现类

  factoryBean.create(); // 创建webservice接口
  System.out.println("web service 启动成功。。");
}
 
Example 2
Source File: HelloWorldImplTest.java    From cxf-jaxws with MIT License 6 votes vote down vote up
private static void createServerEndpoint() {
  JaxWsServerFactoryBean jaxWsServerFactoryBean =
      new JaxWsServerFactoryBean();

  // create the loggingFeature
  LoggingFeature loggingFeature = new LoggingFeature();
  loggingFeature.setPrettyLogging(true);

  // add the loggingFeature to print the received/sent messages
  jaxWsServerFactoryBean.getFeatures().add(loggingFeature);

  HelloWorldImpl implementor = new HelloWorldImpl();
  jaxWsServerFactoryBean.setServiceBean(implementor);
  jaxWsServerFactoryBean.setAddress(ENDPOINT_ADDRESS);

  jaxWsServerFactoryBean.create();
}
 
Example 3
Source File: AbstractAegisTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected Server createJaxwsService(Class<?> serviceClass,
                                    Object serviceBean, String address, QName name) {
    if (address == null) {
        address = serviceClass.getSimpleName();
    }
    JaxWsServiceFactoryBean sf = new JaxWsServiceFactoryBean();
    sf.setDataBinding(new AegisDatabinding());
    JaxWsServerFactoryBean serverFactoryBean = new JaxWsServerFactoryBean();
    serverFactoryBean.setServiceClass(serviceClass);

    if (serviceBean != null) {
        serverFactoryBean.setServiceBean(serviceBean);
    }

    serverFactoryBean.setAddress("local://" + address);

    serverFactoryBean.setServiceFactory(sf);
    if (name != null) {
        serverFactoryBean.setEndpointName(name);
    }
    return serverFactoryBean.create();
}
 
Example 4
Source File: SoapCollectorTest.java    From karaf-decanter with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws Exception {
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();

    LoggingFeature loggingFeature = new LoggingFeature();
    loggingFeature.setPrettyLogging(true);
    factory.getFeatures().add(loggingFeature);

    TestServiceImpl testService = new TestServiceImpl();
    factory.setServiceBean(testService);
    factory.setAddress("http://localhost:9090/test");
    cxfServer = factory.create();
    cxfServer.start();

    while (!cxfServer.isStarted()) {
        Thread.sleep(200);
    }
}
 
Example 5
Source File: StaxToDOMSamlTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Service createService() {
    // Create the Service
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setServiceBean(new EchoImpl());
    factory.setAddress("local://Echo");
    factory.setTransportId(LocalTransportFactory.TRANSPORT_ID);
    Server server = factory.create();

    Service service = server.getEndpoint().getService();
    service.getInInterceptors().add(new LoggingInInterceptor());
    service.getOutInterceptors().add(new LoggingOutInterceptor());

    return service;
}
 
Example 6
Source File: AbstractWebServiceTaskTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
protected void initializeProcessEngine() {
    super.initializeProcessEngine();

    webServiceMock = new WebServiceMockImpl();
    JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
    svrFactory.setServiceClass(WebServiceMock.class);
    svrFactory.setAddress("http://localhost:63081/webservicemock");
    svrFactory.setServiceBean(webServiceMock);
    svrFactory.getInInterceptors().add(new LoggingInInterceptor());
    svrFactory.getOutInterceptors().add(new LoggingOutInterceptor());
    server = svrFactory.create();
    server.start();
}
 
Example 7
Source File: HelloWorldImplTest.java    From cxf-jaxws with MIT License 5 votes vote down vote up
private static void createServerEndpoint() {
  // use a CXF JaxWsServerFactoryBean to create JAX-WS endpoints
  JaxWsServerFactoryBean jaxWsServerFactoryBean =
      new JaxWsServerFactoryBean();

  // set the HelloWorld implementation
  HelloWorldImpl implementor = new HelloWorldImpl();
  jaxWsServerFactoryBean.setServiceBean(implementor);

  // set the address at which the HelloWorld endpoint will be exposed
  jaxWsServerFactoryBean.setAddress(ENDPOINT_ADDRESS);

  // create the server
  jaxWsServerFactoryBean.create();
}
 
Example 8
Source File: ServerJMS.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static void launchCxfApi() {
    Object implementor = new HelloWorldImpl();
    JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
    svrFactory.setServiceClass(HelloWorld.class);
    svrFactory.setTransportId(JMSSpecConstants.SOAP_JMS_SPECIFICATION_TRANSPORTID);
    svrFactory.setAddress(JMS_ENDPOINT_URI);
    svrFactory.setServiceBean(implementor);
    svrFactory.setFeatures(Collections.singletonList(new LoggingFeature()));
    svrFactory.create();
}
 
Example 9
Source File: CatastrophicEventSinkImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
public CatastrophicEventSinkImpl(String url) {
    JaxWsServerFactoryBean bean = new JaxWsServerFactoryBean();
    bean.setServiceBean(this);
    bean.setAddress(url);
    this.url = url;
    server = bean.create();
}
 
Example 10
Source File: DOMToStaxSignatureIdentifierTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Service createService() {
    // Create the Service
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setServiceBean(new EchoImpl());
    factory.setAddress("local://Echo");
    factory.setTransportId(LocalTransportFactory.TRANSPORT_ID);
    Server server = factory.create();

    Service service = server.getEndpoint().getService();
    service.getInInterceptors().add(new LoggingInInterceptor());
    service.getOutInterceptors().add(new LoggingOutInterceptor());

    return service;
}
 
Example 11
Source File: TestUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static Server createTeachersResourceFactoryEndpoint(ResourceRemote resource, String port) {
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setServiceClass(ResourceFactory.class);
    factory.setServiceBean(resource);
    factory.setAddress("http://localhost:" + port + "/ResourceTeachers" + TransferConstants.RESOURCE_REMOTE_SUFFIX);
    return factory.create();
}
 
Example 12
Source File: WsdlGetUtilsTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testNewDocumentIsCreatedForEachWsdlRequest() {
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setServiceBean(new StuffImpl());
    factory.setAddress("http://localhost:" + PORT + "/Stuff");
    Server server = factory.create();

    try {
        Message message = new MessageImpl();
        Exchange exchange = new ExchangeImpl();
        exchange.put(Bus.class, getBus());
        exchange.put(Service.class, server.getEndpoint().getService());
        exchange.put(Endpoint.class, server.getEndpoint());
        message.setExchange(exchange);

        Map<String, String> map = UrlUtils.parseQueryString("wsdl");
        String baseUri = "http://localhost:" + PORT + "/Stuff";
        String ctx = "/Stuff";

        WSDLGetUtils utils = new WSDLGetUtils();
        Document doc = utils.getDocument(message, baseUri, map, ctx, server.getEndpoint().getEndpointInfo());

        Document doc2 = utils.getDocument(message, baseUri, map, ctx, server.getEndpoint().getEndpointInfo());

        assertFalse(doc == doc2);
    } finally {
        server.stop();
    }
}
 
Example 13
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 14
Source File: Server.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected Server() throws Exception {
    System.out.println("Starting Server");
    HelloWorldImpl implementor = new HelloWorldImpl();
    JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
    svrFactory.setServiceClass(HelloWorld.class);
    svrFactory.setAddress("http://localhost:9000/helloWorld");
    svrFactory.setServiceBean(implementor);
    svrFactory.getFeatures().add(new LoggingFeature());
    svrFactory.create();
}
 
Example 15
Source File: TestUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static Server createStudentsResource(ResourceManager resourceManager, String port) {
    ResourceLocal resourceLocal = new ResourceLocal();
    resourceLocal.setManager(resourceManager);
    resourceLocal.getResourceTypeIdentifiers().add(
            new XSDResourceTypeIdentifier(
                    new StreamSource(TestUtils.class.getResourceAsStream("/schema/studentPut.xsd")),
                    new XSLTResourceTransformer(
                            new StreamSource(TestUtils.class.getResourceAsStream("/xslt/studentPut.xsl")),
                            new StudentPutResourceValidator())));
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setServiceClass(Resource.class);
    factory.setServiceBean(resourceLocal);
    factory.setAddress("http://localhost:" + port + "/ResourceStudents");
    return factory.create();
}
 
Example 16
Source File: JavaFirstNoWsdlTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void startServer() {
    startBusAndJMS(JavaFirstNoWsdlTest.class);
    JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
    svrFactory.setBus(bus);
    svrFactory.getFeatures().add(cff);
    svrFactory.setServiceClass(Hello.class);
    svrFactory.setAddress(SERVICE_ADDRESS);
    svrFactory.setTransportId(JMSSpecConstants.SOAP_JMS_SPECIFICATION_TRANSPORTID);
    svrFactory.setServiceBean(new HelloImpl());
    svrFactory.create();
}
 
Example 17
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 18
Source File: RoundTripTest.java    From steady with Apache License 2.0 4 votes vote down vote up
@Before
public void setUpService() throws Exception {
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setServiceBean(new EchoImpl());
    factory.setAddress("local://Echo");
    factory.setTransportId(LocalTransportFactory.TRANSPORT_ID);
    Server server = factory.create();
    Service service = server.getEndpoint().getService();
    
    service.getInInterceptors().add(new SAAJInInterceptor());
    service.getInInterceptors().add(new LoggingInInterceptor());
    service.getOutInterceptors().add(new SAAJOutInterceptor());
    service.getOutInterceptors().add(new LoggingOutInterceptor());

    wsIn = new WSS4JInInterceptor();
    wsIn.setProperty(WSHandlerConstants.SIG_PROP_FILE, "insecurity.properties");
    wsIn.setProperty(WSHandlerConstants.DEC_PROP_FILE, "insecurity.properties");
    wsIn.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName());

    service.getInInterceptors().add(wsIn);

    wsOut = new WSS4JOutInterceptor();
    wsOut.setProperty(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
    wsOut.setProperty(WSHandlerConstants.ENC_PROP_FILE, "outsecurity.properties");
    wsOut.setProperty(WSHandlerConstants.USER, "myalias");
    wsOut.setProperty("password", "myAliasPassword");
    wsOut.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName());
    service.getOutInterceptors().add(wsOut);

    // Create the client
    JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
    proxyFac.setServiceClass(Echo.class);
    proxyFac.setAddress("local://Echo");
    proxyFac.getClientFactoryBean().setTransportId(LocalTransportFactory.TRANSPORT_ID);
    
    echo = (Echo)proxyFac.create();

    client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getInInterceptors().add(wsIn);
    client.getInInterceptors().add(new SAAJInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());
    client.getOutInterceptors().add(wsOut);
    client.getOutInterceptors().add(new SAAJOutInterceptor());
}
 
Example 19
Source File: RoundTripTest.java    From steady with Apache License 2.0 4 votes vote down vote up
@Before
public void setUpService() throws Exception {
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setServiceBean(new EchoImpl());
    factory.setAddress("local://Echo");
    factory.setTransportId(LocalTransportFactory.TRANSPORT_ID);
    Server server = factory.create();
    Service service = server.getEndpoint().getService();
    
    service.getInInterceptors().add(new SAAJInInterceptor());
    service.getInInterceptors().add(new LoggingInInterceptor());
    service.getOutInterceptors().add(new SAAJOutInterceptor());
    service.getOutInterceptors().add(new LoggingOutInterceptor());

    wsIn = new WSS4JInInterceptor();
    wsIn.setProperty(WSHandlerConstants.SIG_PROP_FILE, "insecurity.properties");
    wsIn.setProperty(WSHandlerConstants.DEC_PROP_FILE, "insecurity.properties");
    wsIn.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName());

    service.getInInterceptors().add(wsIn);

    wsOut = new WSS4JOutInterceptor();
    wsOut.setProperty(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
    wsOut.setProperty(WSHandlerConstants.ENC_PROP_FILE, "outsecurity.properties");
    wsOut.setProperty(WSHandlerConstants.USER, "myalias");
    wsOut.setProperty("password", "myAliasPassword");
    wsOut.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName());
    service.getOutInterceptors().add(wsOut);

    // Create the client
    JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
    proxyFac.setServiceClass(Echo.class);
    proxyFac.setAddress("local://Echo");
    proxyFac.getClientFactoryBean().setTransportId(LocalTransportFactory.TRANSPORT_ID);
    
    echo = (Echo)proxyFac.create();

    client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getInInterceptors().add(wsIn);
    client.getInInterceptors().add(new SAAJInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());
    client.getOutInterceptors().add(wsOut);
    client.getOutInterceptors().add(new SAAJOutInterceptor());
}
 
Example 20
Source File: RoundTripTest.java    From steady with Apache License 2.0 4 votes vote down vote up
@Before
public void setUpService() throws Exception {
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setServiceBean(new EchoImpl());
    factory.setAddress("local://Echo");
    factory.setTransportId(LocalTransportFactory.TRANSPORT_ID);
    Server server = factory.create();
    Service service = server.getEndpoint().getService();
    
    service.getInInterceptors().add(new SAAJInInterceptor());
    service.getInInterceptors().add(new LoggingInInterceptor());
    service.getOutInterceptors().add(new SAAJOutInterceptor());
    service.getOutInterceptors().add(new LoggingOutInterceptor());

    wsIn = new WSS4JInInterceptor();
    wsIn.setProperty(WSHandlerConstants.SIG_PROP_FILE, "insecurity.properties");
    wsIn.setProperty(WSHandlerConstants.DEC_PROP_FILE, "insecurity.properties");
    wsIn.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName());

    service.getInInterceptors().add(wsIn);

    wsOut = new WSS4JOutInterceptor();
    wsOut.setProperty(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
    wsOut.setProperty(WSHandlerConstants.ENC_PROP_FILE, "outsecurity.properties");
    wsOut.setProperty(WSHandlerConstants.USER, "myalias");
    wsOut.setProperty("password", "myAliasPassword");
    wsOut.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName());
    service.getOutInterceptors().add(wsOut);

    // Create the client
    JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
    proxyFac.setServiceClass(Echo.class);
    proxyFac.setAddress("local://Echo");
    proxyFac.getClientFactoryBean().setTransportId(LocalTransportFactory.TRANSPORT_ID);
    
    echo = (Echo)proxyFac.create();

    client = ClientProxy.getClient(echo);
    client.getInInterceptors().add(new LoggingInInterceptor());
    client.getInInterceptors().add(wsIn);
    client.getInInterceptors().add(new SAAJInInterceptor());
    client.getOutInterceptors().add(new LoggingOutInterceptor());
    client.getOutInterceptors().add(wsOut);
    client.getOutInterceptors().add(new SAAJOutInterceptor());
}