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();
}
}
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));
}
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());
}
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());
}
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);
}
Aggregations