Example usage for org.springframework.http HttpStatus OK

List of usage examples for org.springframework.http HttpStatus OK

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus OK.

Prototype

HttpStatus OK

To view the source code for org.springframework.http HttpStatus OK.

Click Source Link

Document

200 OK .

Usage

From source file:org.tommy.stationery.moracle.core.client.load.StompWebSocketLoadTestClient.java

public static void main(String[] args) throws Exception {

    // Modify host and port below to match wherever StompWebSocketServer.java is running!!
    // When StompWebSocketServer starts it prints the selected available

    String host = "localhost";
    if (args.length > 0) {
        host = args[0];/*from   w w w . ja v a2  s.c  o m*/
    }

    int port = 59984;
    if (args.length > 1) {
        port = Integer.valueOf(args[1]);
    }

    String url = "http://" + host + ":" + port + "/home";
    logger.debug("Sending warm-up HTTP request to " + url);
    HttpStatus status = new RestTemplate().getForEntity(url, Void.class).getStatusCode();
    Assert.state(status == HttpStatus.OK);

    final CountDownLatch connectLatch = new CountDownLatch(NUMBER_OF_USERS);
    final CountDownLatch subscribeLatch = new CountDownLatch(NUMBER_OF_USERS);
    final CountDownLatch messageLatch = new CountDownLatch(NUMBER_OF_USERS);
    final CountDownLatch disconnectLatch = new CountDownLatch(NUMBER_OF_USERS);

    final AtomicReference<Throwable> failure = new AtomicReference<Throwable>();

    Executor executor = Executors.newFixedThreadPool(THREAD_POOL_SIZE);
    org.eclipse.jetty.websocket.client.WebSocketClient jettyClient = new WebSocketClient(executor);
    JettyWebSocketClient webSocketClient = new JettyWebSocketClient(jettyClient);
    webSocketClient.start();

    HttpClient jettyHttpClient = new HttpClient();
    jettyHttpClient.setMaxConnectionsPerDestination(1000);
    jettyHttpClient.setExecutor(new QueuedThreadPool(1000));
    jettyHttpClient.start();

    List<Transport> transports = new ArrayList<>();
    transports.add(new WebSocketTransport(webSocketClient));
    transports.add(new JettyXhrTransport(jettyHttpClient));

    SockJsClient sockJsClient = new SockJsClient(transports);

    try {
        URI uri = new URI("ws://" + host + ":" + port + "/stomp");
        WebSocketStompClient stompClient = new WebSocketStompClient(uri, null, sockJsClient);
        stompClient.setMessageConverter(new StringMessageConverter());

        logger.debug("Connecting and subscribing " + NUMBER_OF_USERS + " users ");
        StopWatch stopWatch = new StopWatch("STOMP Broker Relay WebSocket Load Tests");
        stopWatch.start();

        List<ConsumerStompMessageHandler> consumers = new ArrayList<>();
        for (int i = 0; i < NUMBER_OF_USERS; i++) {
            consumers.add(new ConsumerStompMessageHandler(BROADCAST_MESSAGE_COUNT, connectLatch, subscribeLatch,
                    messageLatch, disconnectLatch, failure));
            stompClient.connect(consumers.get(i));
        }

        if (failure.get() != null) {
            throw new AssertionError("Test failed", failure.get());
        }
        if (!connectLatch.await(5000, TimeUnit.MILLISECONDS)) {
            logger.info("Not all users connected, remaining: " + connectLatch.getCount());
        }
        if (!subscribeLatch.await(5000, TimeUnit.MILLISECONDS)) {
            logger.info("Not all users subscribed, remaining: " + subscribeLatch.getCount());
        }

        stopWatch.stop();
        logger.debug("Finished: " + stopWatch.getLastTaskTimeMillis() + " millis");

        logger.debug("Broadcasting " + BROADCAST_MESSAGE_COUNT + " messages to " + NUMBER_OF_USERS + " users ");
        stopWatch.start();

        ProducerStompMessageHandler producer = new ProducerStompMessageHandler(BROADCAST_MESSAGE_COUNT,
                failure);
        stompClient.connect(producer);

        if (failure.get() != null) {
            throw new AssertionError("Test failed", failure.get());
        }
        if (!messageLatch.await(1 * 60 * 1000, TimeUnit.MILLISECONDS)) {
            for (ConsumerStompMessageHandler consumer : consumers) {
                if (consumer.messageCount.get() < consumer.expectedMessageCount) {
                    logger.debug(consumer);
                }
            }
        }
        if (!messageLatch.await(1 * 60 * 1000, TimeUnit.MILLISECONDS)) {
            logger.info("Not all handlers received every message, remaining: " + messageLatch.getCount());
        }

        producer.session.disconnect();
        if (!disconnectLatch.await(5000, TimeUnit.MILLISECONDS)) {
            logger.info("Not all disconnects completed, remaining: " + disconnectLatch.getCount());
        }

        stopWatch.stop();
        logger.debug("Finished: " + stopWatch.getLastTaskTimeMillis() + " millis");

        System.out.println("\nPress any key to exit...");
        System.in.read();
    } catch (Throwable t) {
        t.printStackTrace();
    } finally {
        webSocketClient.stop();
        jettyHttpClient.stop();
    }

    logger.debug("Exiting");
    System.exit(0);
}

From source file:com.api.Responses.java

public static ResponseEntity ok() {
    return new ResponseEntity(HttpStatus.OK);
}

From source file:fr.gmjgav.GooglePlacesManager.java

public static ListAndStatus getPlaces(BarRepository barRepository, Coordinates coord) {
    HttpStatus responseCode = HttpStatus.OK;
    List<Place> places = GOOGLE_CLIENT.getNearbyPlaces(coord.getLat(), coord.getLng(), RADIUS, LIMIT,
            Param.name("types").value("bar"));
    List<Bar> createdBars = new ArrayList<>();
    for (Place tmpPlace : places) {
        if (barRepository.findByReference(tmpPlace.getPlaceId()).isEmpty()) {
            Bar generatedBar = new Bar(tmpPlace.getName(), tmpPlace.getPlaceId());
            createdBars.add(generatedBar);
        }/*from  w  w w .  j  a va  2 s .co  m*/
    }
    if (!createdBars.isEmpty()) {
        responseCode = HttpStatus.CREATED;
        barRepository.save(createdBars);
    }

    return new ListAndStatus(places, responseCode);
}

From source file:com.api.Responses.java

public static <T> ResponseEntity<T> ok(T model) {
    return new ResponseEntity<T>(model, HttpStatus.OK);
}

From source file:com.carlomicieli.jtrains.infrastructure.web.Responses.java

public static <T> ResponseEntity<T> ok(T body) {
    return new ResponseEntity<>(body, HttpStatus.OK);
}

From source file:fi.hsl.parkandride.itest.CacheHeadersTest.java

@Test
public void api_urls_are_not_cached() {
    when().get("api/v1/facilities").then().statusCode(HttpStatus.OK.value()).header("Cache-Control",
            "no-cache");
}

From source file:com.xinferin.controller.LicencesController.java

@RequestMapping(value = "/get", method = RequestMethod.POST, consumes = "application/json")
@ResponseStatus(HttpStatus.OK)
public LicenceReply get(@RequestBody KeyRequest keyRequest) {
    return daoLicence.get(keyRequest);
}

From source file:edu.infsci2560.LoginHelper.java

private static HttpHeaders getHeaders(TestRestTemplate template, String route) {
    // todo : write getHeaders test
    HttpHeaders headers = new HttpHeaders();
    ResponseEntity<String> page = template.getForEntity(route, String.class);
    assertThat(page.getStatusCode()).isEqualTo(HttpStatus.OK);

    String cookie = page.getHeaders().getFirst("Set-Cookie");
    headers.set("Cookie", cookie);

    Pattern pattern = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*");
    Matcher matcher = pattern.matcher(page.getBody());
    assertThat(matcher.matches()).as(page.getBody()).isTrue();
    headers.set("X-CSRF-TOKEN", matcher.group(1));
    return headers;
}

From source file:be.boyenvaesen.RestControllers.HumidityRestController.java

@RequestMapping("/humidity")
@ResponseBody/*from   ww w .  jav a2s.co m*/
public ResponseEntity<List<Humidity>> getAll() {
    return new ResponseEntity<>(service.getAll(), HttpStatus.OK);

}

From source file:com.sms.server.controller.SettingsController.java

@RequestMapping(value = "/version", method = RequestMethod.GET)
public ResponseEntity<String> getVersion() {
    return new ResponseEntity<>(SettingsService.getVersion().toString(), HttpStatus.OK);
}