Java Code Examples for org.apache.cxf.endpoint.Server#stop()

The following examples show how to use org.apache.cxf.endpoint.Server#stop() . 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: JAXRSClientFactoryBeanTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testVoidResponseAcceptWildcard() throws Exception {
    String address = "local://store";
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setServiceBean(new BookStore());
    sf.setAddress(address);
    Server s = sf.create(); 

    BookStore store = JAXRSClientFactory.create(address, BookStore.class);
    store.addBook(new Book());

    s.stop();

    ResponseImpl response = (ResponseImpl) WebClient.client(store).getResponse();
    Map<String, List<String>> headers =
        CastUtils.cast((Map<?, ?>) response.getOutMessage().get(Message.PROTOCOL_HEADERS));
    assertTrue(headers.get(HttpHeaders.ACCEPT).contains(MediaType.WILDCARD));
}
 
Example 2
Source File: RESTLoggingTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testEvents() throws MalformedURLException {
    LoggingFeature loggingFeature = new LoggingFeature();
    loggingFeature.setLogBinary(true);
    TestEventSender sender = new TestEventSender();
    loggingFeature.setSender(sender);
    Server server = createService(SERVICE_URI, new TestServiceRest(), loggingFeature);
    server.start();
    WebClient client = createClient(SERVICE_URI, loggingFeature);
    String result = client.get(String.class);
    Assert.assertEquals("test1", result);

    List<LogEvent> events = sender.getEvents();
    await().until(() -> events.size(), is(4));
    server.stop();
    server.destroy();

    Assert.assertEquals(4, events.size());
    checkRequestOut(events.get(0));
    checkRequestIn(events.get(1));
    checkResponseOut(events.get(2));
    checkResponseIn(events.get(3));
}
 
Example 3
Source File: RestOrderServer.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    // create dummy backend
    DummyOrderService dummy = new DummyOrderService();
    dummy.setupDummyOrders();

    // create CXF REST service and inject the dummy backend
    RestOrderService rest = new RestOrderService();
    rest.setOrderService(dummy);

    // setup Apache CXF REST server on port 9000
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(RestOrderService.class);
    sf.setResourceProvider(RestOrderService.class, new SingletonResourceProvider(rest));
    // to use jackson for json
    sf.setProvider(JacksonJsonProvider.class);
    sf.setAddress("http://localhost:9000/");

    // create and start the CXF server (non blocking)
    Server server = sf.create();
    server.start();

    // keep the JVM running
    Console console = System.console();
    System.out.println("Server started on http://localhost:9000/");
    System.out.println("");

    // If you run the main class from IDEA/Eclipse then you may not have a console, which is null)
    if (console != null) {
        System.out.println("  Press ENTER to stop server");
        console.readLine();
    } else {
        System.out.println("  Stopping after 5 minutes or press ctrl + C to stop");
        Thread.sleep(5 * 60 * 1000);
    }

    // stop CXF server
    server.stop();
    System.exit(0);
}
 
Example 4
Source File: RESTLoggingTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testBinary() throws IOException, InterruptedException {
    LoggingFeature loggingFeature = new LoggingFeature();
    TestEventSender sender = new TestEventSender();
    loggingFeature.setSender(sender);
    Server server = createService(SERVICE_URI_BINARY, new TestServiceRestBinary(), loggingFeature);
    server.start();
    WebClient client = createClient(SERVICE_URI_BINARY, loggingFeature);
    client.get(InputStream.class).close();
    loggingFeature.setLogBinary(true);
    client.get(InputStream.class).close();
    client.close();
    List<LogEvent> events = sender.getEvents();
    await().until(() -> events.size(), is(8));
    server.stop();
    server.destroy();

    Assert.assertEquals(8, events.size());
    
    // First call with binary logging false
    assertContentLogged(events.get(0));
    assertContentLogged(events.get(1));
    assertContentNotLogged(events.get(2));
    assertContentNotLogged(events.get(3));
    
    // Second call with binary logging true
    assertContentLogged(events.get(4));
    assertContentLogged(events.get(5));
    assertContentLogged(events.get(6));
    assertContentLogged(events.get(7));
}
 
Example 5
Source File: StopEndpointCommand.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public Object execute() throws Exception {
    Bus b = getBus(busName);
    ServerRegistry reg = b.getExtension(ServerRegistry.class);
    List<Server> servers = reg.getServers();
    for (Server serv : servers) {
        if (endpoint.equals(serv.getEndpoint().getEndpointInfo().getName().getLocalPart())) {
            serv.stop();
        }
    }
    return null;
}
 
Example 6
Source File: NoSpringServletClientTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void stopServer() {
    ServerRegistry reg = serverBus.getExtension(ServerRegistry.class);
    List<Server> servers = reg.getServers();
    for (Server serv : servers) {
        serv.stop();
    }
}
 
Example 7
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 8
Source File: EndpointCreationLoop3.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void iteration() {
    JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
    sf.setAddress("http://localhost:9000/test");
    sf.setServiceClass(org.apache.cxf.systest.jaxb.service.TestServiceImpl.class);
    sf.setStart(false);

    Server server = sf.create();
    server.start();
    server.stop();
}
 
Example 9
Source File: RestOrderServer.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    // create dummy backend
    DummyOrderService dummy = new DummyOrderService();
    dummy.setupDummyOrders();

    // create CXF REST service and inject the dummy backend
    RestOrderService rest = new RestOrderService();
    rest.setOrderService(dummy);

    // setup Apache CXF REST server on port 9000
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(RestOrderService.class);
    sf.setResourceProvider(RestOrderService.class, new SingletonResourceProvider(rest));
    sf.setAddress("http://localhost:9000/");

    // create and start the CXF server (non blocking)
    Server server = sf.create();
    server.start();

    // keep the JVM running
    Console console = System.console();
    System.out.println("Server started on http://localhost:9000/");
    System.out.println("");

    // If you run the main class from IDEA/Eclipse then you may not have a console, which is null)
    if (console != null) {
        System.out.println("  Press ENTER to stop server");
        console.readLine();
    } else {
        System.out.println("  Stopping after 5 minutes or press ctrl + C to stop");
        Thread.sleep(5 * 60 * 1000);
    }

    // stop CXF server
    server.stop();
    System.exit(0);
}
 
Example 10
Source File: SseEventSourceImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@AfterClass
public static void stopServer() {
    for (Server server : SERVERS.values()) {
        server.stop();
        server.destroy();
    }
}
 
Example 11
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);
}
 
Example 12
Source File: JavaFirstSchemaValidationTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@AfterClass
public static void cleanup() throws Exception {
    for (Server server : serverList) {
        server.stop();
    }
}
 
Example 13
Source File: NotificationTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void basicReceptionOfEvents() throws IOException {
    NotificatorService service = createNotificatorService();
    Subscribe subscribe = new Subscribe();
    ExpirationType exp = new ExpirationType();
    exp.setValue(
            DurationAndDateUtil.convertToXMLString(DurationAndDateUtil.parseDurationOrTimestamp("PT0S")));
    subscribe.setExpires(exp);

    EndpointReferenceType eventSinkERT = new EndpointReferenceType();

    AttributedURIType eventSinkAddr = new AttributedURIType();
    String url = TestUtil.generateRandomURLWithHttpTransport(NOTIFICATION_TEST_PORT);
    eventSinkAddr.setValue(url);
    eventSinkERT.setAddress(eventSinkAddr);
    subscribe.setDelivery(new DeliveryType());
    subscribe.getDelivery().getContent()
        .add(new ObjectFactory().createNotifyTo(eventSinkERT));


    eventSourceClient.subscribeOp(subscribe);
    eventSourceClient.subscribeOp(subscribe);
    eventSourceClient.subscribeOp(subscribe);

    Server eventSinkServer = createEventSink(url);
    TestingEventSinkImpl.RECEIVED_FIRES.set(0);

    service.start();
    Emitter emitter = new EmitterImpl(service);
    emitter.dispatch(new FireEvent("Canada", 8));
    for (int i = 0; i < 10; i++) {
        if (TestingEventSinkImpl.RECEIVED_FIRES.get() == 3) {
            break;
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }
    }
    eventSinkServer.stop();
    if (TestingEventSinkImpl.RECEIVED_FIRES.get() != 3) {
        Assert.fail("TestingEventSinkImpl should have received 3 events but received "
            + TestingEventSinkImpl.RECEIVED_FIRES.get());
    }
}
 
Example 14
Source File: NotificationTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void basicReceptionOfWrappedEvents() throws IOException {
    NotificatorService service = createNotificatorService();
    Subscribe subscribe = new Subscribe();
    ExpirationType exp = new ExpirationType();
    exp.setValue(
            DurationAndDateUtil.convertToXMLString(DurationAndDateUtil.parseDurationOrTimestamp("PT0S")));
    subscribe.setExpires(exp);

    EndpointReferenceType eventSinkERT = new EndpointReferenceType();

    AttributedURIType eventSinkAddr = new AttributedURIType();
    String url = TestUtil.generateRandomURLWithHttpTransport(NOTIFICATION_TEST_PORT);
    eventSinkAddr.setValue(url);
    eventSinkERT.setAddress(eventSinkAddr);
    subscribe.setDelivery(new DeliveryType());
    subscribe.getDelivery().getContent().add(new ObjectFactory().createNotifyTo(eventSinkERT));
    FormatType formatType = new FormatType();
    formatType.setName(EventingConstants.DELIVERY_FORMAT_WRAPPED);
    subscribe.setFormat(formatType);

    eventSourceClient.subscribeOp(subscribe);
    eventSourceClient.subscribeOp(subscribe);
    eventSourceClient.subscribeOp(subscribe);

    Server eventSinkServer = createWrappedEventSink(url);
    TestingWrappedEventSinkImpl.RECEIVED_FIRES.set(0);

    service.start();
    Emitter emitter = new EmitterImpl(service);
    emitter.dispatch(new FireEvent("Canada", 8));
    for (int i = 0; i < 10; i++) {
        if (TestingWrappedEventSinkImpl.RECEIVED_FIRES.get() == 3) {
            break;
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }
    }
    eventSinkServer.stop();
    if (TestingWrappedEventSinkImpl.RECEIVED_FIRES.get() != 3) {
        Assert.fail("TestingWrappedEventSinkImpl should have received 3 events but received "
            + TestingWrappedEventSinkImpl.RECEIVED_FIRES.get());
    }
}
 
Example 15
Source File: NotificationTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void withWSAAction() throws Exception {
    NotificatorService service = createNotificatorService();
    Subscribe subscribe = new Subscribe();
    ExpirationType exp = new ExpirationType();
    exp.setValue(
            DurationAndDateUtil.convertToXMLString(DurationAndDateUtil.parseDurationOrTimestamp("PT0S")));
    subscribe.setExpires(exp);

    EndpointReferenceType eventSinkERT = new EndpointReferenceType();

    AttributedURIType eventSinkAddr = new AttributedURIType();
    String url = TestUtil.generateRandomURLWithHttpTransport(NOTIFICATION_TEST_PORT);
    eventSinkAddr.setValue(url);
    eventSinkERT.setAddress(eventSinkAddr);
    subscribe.setDelivery(new DeliveryType());
    subscribe.getDelivery().getContent().add(new ObjectFactory().createNotifyTo(eventSinkERT));

    eventSourceClient.subscribeOp(subscribe);

    Server eventSinkServer = createEventSinkWithWSAActionAssertion(url, "http://www.fire.com");
    TestingEventSinkImpl.RECEIVED_FIRES.set(0);
    service.start();
    Emitter emitter = new EmitterImpl(service);
    emitter.dispatch(new FireEvent("Canada", 8));
    for (int i = 0; i < 10; i++) {
        if (TestingEventSinkImpl.RECEIVED_FIRES.get() == 1) {
            break;
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }
    }
    eventSinkServer.stop();
    if (TestingEventSinkImpl.RECEIVED_FIRES.get() != 1) {
        Assert.fail("TestingEventSinkImpl should have received 1 events but received "
                + TestingEventSinkImpl.RECEIVED_FIRES.get());
    }
}
 
Example 16
Source File: NotificationTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void withReferenceParameters() throws Exception {
    NotificatorService service = createNotificatorService();
    Subscribe subscribe = new Subscribe();
    ExpirationType exp = new ExpirationType();
    exp.setValue(
            DurationAndDateUtil.convertToXMLString(DurationAndDateUtil.parseDurationOrTimestamp("PT0S")));
    subscribe.setExpires(exp);

    EndpointReferenceType eventSinkERT = new EndpointReferenceType();

    JAXBElement<String> idqn
        = new JAXBElement<>(new QName("http://www.example.org", "MyReferenceParameter"),
            String.class,
            "380");
    JAXBElement<String> idqn2
        = new JAXBElement<>(new QName("http://www.example.org", "MyReferenceParameter2"),
            String.class,
            "381");
    eventSinkERT.setReferenceParameters(new ReferenceParametersType());
    eventSinkERT.getReferenceParameters().getAny().add(idqn);
    eventSinkERT.getReferenceParameters().getAny().add(idqn2);
    AttributedURIType eventSinkAddr = new AttributedURIType();
    String url = TestUtil.generateRandomURLWithHttpTransport(NOTIFICATION_TEST_PORT);
    eventSinkAddr.setValue(url);
    eventSinkERT.setAddress(eventSinkAddr);
    subscribe.setDelivery(new DeliveryType());
    subscribe.getDelivery().getContent().add(new ObjectFactory().createNotifyTo(eventSinkERT));

    eventSourceClient.subscribeOp(subscribe);

    Server eventSinkServer = createEventSinkWithReferenceParametersAssertion(url,
            eventSinkERT.getReferenceParameters());
    TestingEventSinkImpl.RECEIVED_FIRES.set(0);
    service.start();
    Emitter emitter = new EmitterImpl(service);
    emitter.dispatch(new FireEvent("Canada", 8));
    for (int i = 0; i < 10; i++) {
        if (TestingEventSinkImpl.RECEIVED_FIRES.get() == 1) {
            break;
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }
    }
    eventSinkServer.stop();
    int received = TestingEventSinkImpl.RECEIVED_FIRES.get();
    if (received != 1) {
        Assert.fail("TestingEventSinkImpl should have received 1 events but received "
                + received);
    }
}
 
Example 17
Source File: NotificationTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
/**
 * We request only to receive notifications about fires in Canada
 * and there will be a fire in Canada. We should receive
 * this notification.
 */
@Test
public void withFilter() throws IOException {
    NotificatorService service = createNotificatorService();
    Subscribe subscribe = new Subscribe();
    ExpirationType exp = new ExpirationType();
    exp.setValue(
            DurationAndDateUtil.convertToXMLString(DurationAndDateUtil.parseDurationOrTimestamp("PT0S")));
    subscribe.setExpires(exp);

    EndpointReferenceType eventSinkERT = new EndpointReferenceType();

    AttributedURIType eventSinkAddr = new AttributedURIType();
    String url = TestUtil.generateRandomURLWithHttpTransport(NOTIFICATION_TEST_PORT);
    eventSinkAddr.setValue(url);
    eventSinkERT.setAddress(eventSinkAddr);
    subscribe.setDelivery(new DeliveryType());
    subscribe.getDelivery().getContent().add(new ObjectFactory().createNotifyTo(eventSinkERT));

    subscribe.setFilter(new FilterType());
    subscribe.getFilter().getContent().add("//*[local-name()='fire' and "
            + "namespace-uri()='http://www.events.com']/location[text()='Canada']");


    eventSourceClient.subscribeOp(subscribe);

    Server eventSinkServer = createEventSink(url);
    TestingEventSinkImpl.RECEIVED_FIRES.set(0);

    service.start();
    Emitter emitter = new EmitterImpl(service);
    emitter.dispatch(new FireEvent("Canada", 8));
    for (int i = 0; i < 10; i++) {
        if (TestingEventSinkImpl.RECEIVED_FIRES.get() == 1) {
            break;
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }
    }
    eventSinkServer.stop();
    if (TestingEventSinkImpl.RECEIVED_FIRES.get() != 1) {
        Assert.fail("TestingEventSinkImpl should have received 1 events but received "
                + TestingEventSinkImpl.RECEIVED_FIRES.get());
    }
}
 
Example 18
Source File: NotificationTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
/**
 * We request only to receive notifications about fires in Russia
 * and there will be only a fire in Canada. We should not receive
 * this notification.
 */
@Test
public void withFilterNegative() throws IOException {
    NotificatorService service = createNotificatorService();
    Subscribe subscribe = new Subscribe();
    ExpirationType exp = new ExpirationType();
    exp.setValue(
            DurationAndDateUtil.convertToXMLString(DurationAndDateUtil.parseDurationOrTimestamp("PT0S")));
    subscribe.setExpires(exp);

    EndpointReferenceType eventSinkERT = new EndpointReferenceType();

    AttributedURIType eventSinkAddr = new AttributedURIType();
    String url = TestUtil.generateRandomURLWithHttpTransport(NOTIFICATION_TEST_PORT);
    eventSinkAddr.setValue(url);
    eventSinkERT.setAddress(eventSinkAddr);
    subscribe.setDelivery(new DeliveryType());
    subscribe.getDelivery().getContent().add(new ObjectFactory().createNotifyTo(eventSinkERT));

    subscribe.setFilter(new FilterType());
    subscribe.getFilter().getContent().add("/*[local-name()='fire']/location[text()='Russia']");


    eventSourceClient.subscribeOp(subscribe);

    Server eventSinkServer = createEventSink(url);
    TestingEventSinkImpl.RECEIVED_FIRES.set(0);

    service.start();
    Emitter emitter = new EmitterImpl(service);
    emitter.dispatch(new FireEvent("Canada", 8));

    try {
        Thread.sleep(2000);
    } catch (InterruptedException ex) {
        ex.printStackTrace();
    }

    eventSinkServer.stop();
    if (TestingEventSinkImpl.RECEIVED_FIRES.get() != 0) {
        Assert.fail("TestingEventSinkImpl should have received 0 events but received "
                + TestingEventSinkImpl.RECEIVED_FIRES.get());
    }
}
 
Example 19
Source File: NotificationTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
/**
 * We request only to receive notifications about earthquakes in Russia with Richter scale equal to 3.5
 * and there will be one fire in Canada and one earthquake in Russia. We should
 * receive only one notification.
 */
@Test
public void withFilter2() throws IOException {
    NotificatorService service = createNotificatorService();
    Subscribe subscribe = new Subscribe();
    ExpirationType exp = new ExpirationType();
    exp.setValue(
            DurationAndDateUtil.convertToXMLString(DurationAndDateUtil.parseDurationOrTimestamp("PT0S")));
    subscribe.setExpires(exp);

    EndpointReferenceType eventSinkERT = new EndpointReferenceType();

    AttributedURIType eventSinkAddr = new AttributedURIType();
    String url = TestUtil.generateRandomURLWithHttpTransport(NOTIFICATION_TEST_PORT);
    eventSinkAddr.setValue(url);
    eventSinkERT.setAddress(eventSinkAddr);
    subscribe.setDelivery(new DeliveryType());
    subscribe.getDelivery().getContent().add(new ObjectFactory().createNotifyTo(eventSinkERT));

    subscribe.setFilter(new FilterType());
    subscribe.getFilter().getContent()
            .add("//*[local-name()='earthquake']/location[text()='Russia']/"
                    + "../richterScale[contains(text(),'3.5')]");

    eventSourceClient.subscribeOp(subscribe);

    Server eventSinkServer = createEventSink(url);
    TestingEventSinkImpl.RECEIVED_FIRES.set(0);
    TestingEventSinkImpl.RECEIVED_EARTHQUAKES.set(0);

    service.start();
    Emitter emitter = new EmitterImpl(service);
    emitter.dispatch(new FireEvent("Canada", 8));
    emitter.dispatch(new EarthquakeEvent(3.5f, "Russia"));
    for (int i = 0; i < 10; i++) {
        if (TestingEventSinkImpl.RECEIVED_EARTHQUAKES.get() == 1) {
            break;
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }
    }
    eventSinkServer.stop();
    if (TestingEventSinkImpl.RECEIVED_EARTHQUAKES.get() != 1) {
        Assert.fail("TestingEventSinkImpl should have received 1 earthquake event but received "
                + TestingEventSinkImpl.RECEIVED_EARTHQUAKES.get());
    }
    if (TestingEventSinkImpl.RECEIVED_FIRES.get() != 0) {
        Assert.fail("TestingEventSinkImpl should have not received a fire event"
                + TestingEventSinkImpl.RECEIVED_FIRES.get());
    }
}
 
Example 20
Source File: SubscriptionEndTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void doTest() throws IOException {
    NotificatorService service = createNotificatorService();
    service.start();

    Subscribe subscribe = new Subscribe();

    EndpointReferenceType eventSinkERT = new EndpointReferenceType();
    AttributedURIType eventSinkAddr = new AttributedURIType();
    String eventSinkURL = TestUtil.generateRandomURLWithLocalTransport();
    eventSinkAddr.setValue(eventSinkURL);
    eventSinkERT.setAddress(eventSinkAddr);
    subscribe.setDelivery(new DeliveryType());
    subscribe.getDelivery().getContent().add(new ObjectFactory().createNotifyTo(eventSinkERT));

    JAXBElement<String> idqn
        = new JAXBElement<>(new QName("http://www.example.org", "MyReferenceParameter"),
            String.class,
            "380");
    ReferenceParametersType myParams = new ReferenceParametersType();
    myParams.getAny().add(idqn);
    eventSinkERT.setReferenceParameters(myParams);

    EndpointReferenceType endToERT = new EndpointReferenceType();
    AttributedURIType endToAddr = new AttributedURIType();
    String endToURL = TestUtil.generateRandomURLWithLocalTransport();
    endToAddr.setValue(endToURL);
    endToERT.setAddress(endToAddr);
    subscribe.setEndTo(endToERT);

    SubscribeResponse response = eventSourceClient.subscribeOp(subscribe);
    Element referenceParams = (Element)response.getSubscriptionManager()
            .getReferenceParameters().getAny().get(0);

    Server endToEndpoint = createEndToEndpointWithReferenceParametersAssertion(endToURL, myParams);

    TestingEndToEndpointImpl.RECEIVED_ENDS.set(0);

    SingletonSubscriptionManagerContainer.getInstance()
            .subscriptionEnd(UUID.fromString(referenceParams.getTextContent()), "Sorry, "
                    + "but we don't like you anymore",
                    SubscriptionEndStatus.SOURCE_CANCELLING);

    for (int i = 0; i < 10; i++) {
        if (TestingEndToEndpointImpl.RECEIVED_ENDS.get() == 1) {
            break;
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }
    }
    endToEndpoint.stop();
    if (TestingEndToEndpointImpl.RECEIVED_ENDS.get() != 1) {
        Assert.fail("TestingEndToEndpointImpl should have received 1 subscription end notification but received "
                + TestingEndToEndpointImpl.RECEIVED_ENDS.get());
    }
}