Search in sources :

Example 1 with HttpDecoratedRequest

use of com.robo4j.socket.http.message.HttpDecoratedRequest in project robo4j by Robo4J.

the class ReadSelectionKeyHandler method handle.

@Override
public SelectionKey handle() {
    SocketChannel channel = (SocketChannel) key.channel();
    lock.lock();
    try {
        final HttpDecoratedRequest decoratedRequest = channelRequestBuffer.getHttpDecoratedRequestByChannel(channel);
        final RoboRequestFactory factory = new RoboRequestFactory(codecRegistry);
        final RoboRequestCallable callable = new RoboRequestCallable(context, serverContext, decoratedRequest, factory);
        final Future<HttpResponseProcess> futureResult = context.getScheduler().submit(callable);
        final HttpResponseProcess result = extractRoboResponseProcess(futureResult);
        outBuffers.put(key, result);
        registerSelectionKey(channel);
        return key;
    } catch (IOException e) {
        throw new SocketException(e.getMessage());
    } finally {
        lock.unlock();
    }
}
Also used : HttpDecoratedRequest(com.robo4j.socket.http.message.HttpDecoratedRequest) SocketChannel(java.nio.channels.SocketChannel) SocketException(com.robo4j.socket.http.SocketException) RoboRequestCallable(com.robo4j.socket.http.request.RoboRequestCallable) HttpResponseProcess(com.robo4j.socket.http.request.HttpResponseProcess) IOException(java.io.IOException) RoboRequestFactory(com.robo4j.socket.http.request.RoboRequestFactory)

Example 2 with HttpDecoratedRequest

use of com.robo4j.socket.http.message.HttpDecoratedRequest in project robo4j by Robo4J.

the class RoboHttpDynamicTests method pingExternalSystem.

/**
 * testing ping external system
 *
 * @throws Exception
 *             exception
 */
@Disabled("intent to run manual")
@Test
void pingExternalSystem() throws Exception {
    RoboBuilder pingSystemBuilder = getHttpClientRobotBuilder("127.0.0.1", 8080);
    pingSystemBuilder.add(StringConsumer.class, StringConsumer.NAME);
    RoboContext pingSystemContext = pingSystemBuilder.build();
    pingSystemContext.start();
    System.out.println("PingSystem state after start:");
    System.out.println(SystemUtil.printStateReport(pingSystemContext));
    RoboReference<HttpDecoratedRequest> httpClient = pingSystemContext.getReference(ID_CLIENT_UNIT);
    Thread.sleep(1000);
    for (int i = 0; i < 1; i++) {
        HttpRequestDenominator denominator = new HttpRequestDenominator(HttpMethod.GET, "/noparams", HttpVersion.HTTP_1_1);
        HttpDecoratedRequest request = new HttpDecoratedRequest(denominator);
        request.addCallback(StringConsumer.NAME);
        httpClient.sendMessage(request);
    }
    Thread.sleep(1000);
    pingSystemContext.stop();
    System.out.println("PingSystem state after stop:");
    System.out.println(SystemUtil.printStateReport(pingSystemContext));
}
Also used : HttpDecoratedRequest(com.robo4j.socket.http.message.HttpDecoratedRequest) RoboBuilder(com.robo4j.RoboBuilder) RoboContext(com.robo4j.RoboContext) HttpRequestDenominator(com.robo4j.socket.http.message.HttpRequestDenominator) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 3 with HttpDecoratedRequest

use of com.robo4j.socket.http.message.HttpDecoratedRequest in project robo4j by Robo4J.

the class ByteBufferTests method byteBufferFromRequestTest.

@Test
void byteBufferFromRequestTest() {
    String bodyMessage = "this is test message";
    String host = "localhost";
    String clientPath = "/test";
    HttpDenominator denominator = new HttpRequestDenominator(HttpMethod.POST, clientPath, HttpVersion.HTTP_1_1);
    String postMessage = HttpMessageBuilder.Build().setDenominator(denominator).addHeaderElement(HttpHeaderFieldNames.CONTENT_LENGTH, String.valueOf(bodyMessage.length())).addHeaderElement(HttpHeaderFieldNames.HOST, RoboHttpUtils.createHost(host, ProtocolType.HTTP.getPort())).build(bodyMessage);
    HttpDecoratedRequest decoratedRequest = ChannelBufferUtils.extractDecoratedRequestByStringMessage(postMessage);
    assertNotNull(postMessage);
    assertEquals(postMessage.length(), decoratedRequest.getLength());
    assertEquals(clientPath, decoratedRequest.getPathMethod().getPath());
    assertEquals(bodyMessage, decoratedRequest.getMessage());
}
Also used : HttpDecoratedRequest(com.robo4j.socket.http.message.HttpDecoratedRequest) HttpDenominator(com.robo4j.socket.http.message.HttpDenominator) HttpRequestDenominator(com.robo4j.socket.http.message.HttpRequestDenominator) Test(org.junit.jupiter.api.Test)

Example 4 with HttpDecoratedRequest

use of com.robo4j.socket.http.message.HttpDecoratedRequest in project robo4j by Robo4J.

the class ByteBufferTests method testPostmanMessage.

@Test
void testPostmanMessage() {
    HttpDecoratedRequest decoratedRequest = ChannelBufferUtils.extractDecoratedRequestByStringMessage(TEST_POSTMAN_STRING);
    decoratedRequest.addMessage(TEST_POSTMAN_MESSAGE);
    assertNotNull(decoratedRequest.getHeader());
    assertTrue(!decoratedRequest.getHeader().isEmpty());
    assertNotNull(decoratedRequest.getMessage());
    System.out.println("HEADER: " + decoratedRequest.getHeader());
    System.out.println("BODY: " + decoratedRequest.getMessage());
}
Also used : HttpDecoratedRequest(com.robo4j.socket.http.message.HttpDecoratedRequest) Test(org.junit.jupiter.api.Test)

Example 5 with HttpDecoratedRequest

use of com.robo4j.socket.http.message.HttpDecoratedRequest in project robo4j by Robo4J.

the class HttpClientNetConfigUnit method onMessage.

@Override
public void onMessage(Map message) {
    Map<String, String> map = (Map<String, String>) message;
    SimpleLoggingUtil.info(getClass(), "RECEIVED: " + map);
    String host = map.get(RoboHttpUtils.PROPERTY_HOST);
    Integer port = Integer.valueOf(map.get(RoboHttpUtils.PROPERTY_SOCKET_PORT));
    RoboReference<HttpDecoratedRequest> httpUnitRef = getContext().getReference(target);
    HttpDecoratedRequest confMessage = new HttpDecoratedRequest();
    confMessage.setHost(host);
    confMessage.setPort(port);
    httpUnitRef.sendMessage(confMessage);
}
Also used : HttpDecoratedRequest(com.robo4j.socket.http.message.HttpDecoratedRequest) Map(java.util.Map)

Aggregations

HttpDecoratedRequest (com.robo4j.socket.http.message.HttpDecoratedRequest)11 HttpRequestDenominator (com.robo4j.socket.http.message.HttpRequestDenominator)7 Test (org.junit.jupiter.api.Test)3 RoboContext (com.robo4j.RoboContext)2 SocketChannel (java.nio.channels.SocketChannel)2 ConfigurationException (com.robo4j.ConfigurationException)1 RoboBuilder (com.robo4j.RoboBuilder)1 HttpMethod (com.robo4j.socket.http.HttpMethod)1 SocketException (com.robo4j.socket.http.SocketException)1 HttpDecoratedResponse (com.robo4j.socket.http.message.HttpDecoratedResponse)1 HttpDenominator (com.robo4j.socket.http.message.HttpDenominator)1 HttpResponseProcess (com.robo4j.socket.http.request.HttpResponseProcess)1 RoboRequestCallable (com.robo4j.socket.http.request.RoboRequestCallable)1 RoboRequestFactory (com.robo4j.socket.http.request.RoboRequestFactory)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 Map (java.util.Map)1 Disabled (org.junit.jupiter.api.Disabled)1