Search in sources :

Example 16 with HttpPathMethodDTO

use of com.robo4j.socket.http.dto.HttpPathMethodDTO in project robo4j by Robo4J.

the class OutboundHttpSocketChannelHandler method start.

@Override
public void start() {
    // FIXME: 1/24/18 (miro) -> client context
    final HttpPathMethodDTO pathMethod = new HttpPathMethodDTO(message.getPathMethod().getPath(), message.getPathMethod().getMethod(), message.getCallbacks());
    // @formatter:off
    final String resultMessage = HttpMessageBuilder.Build().setDenominator(message.getDenominator()).addHeaderElements(message.getHeader()).build(message.getMessage());
    // @formatter:on
    final ByteBuffer buffer = ChannelBufferUtils.getByteBufferByString(resultMessage);
    ChannelUtils.handleWriteChannelAndBuffer("client send message", byteChannel, buffer);
    decoratedResponse = getDecoratedResponse(byteChannel, pathMethod);
}
Also used : HttpPathMethodDTO(com.robo4j.socket.http.dto.HttpPathMethodDTO) ByteBuffer(java.nio.ByteBuffer)

Example 17 with HttpPathMethodDTO

use of com.robo4j.socket.http.dto.HttpPathMethodDTO in project robo4j by Robo4J.

the class ReflectUtilTests method serverAttributesResponse.

@Test
void serverAttributesResponse() {
    ResponseAttributeListDTO tmpAttr = new ResponseAttributeListDTO();
    tmpAttr.setType("Type");
    tmpAttr.setId("ID");
    // String roboUnit, HttpMethod method, List<String> callbacks
    tmpAttr.addValue(new HttpPathMethodDTO("testUnit", HttpMethod.GET, Collections.singletonList("test")));
    String result = ReflectUtils.createJson(tmpAttr);
    System.out.println("result:" + result);
}
Also used : ResponseAttributeListDTO(com.robo4j.socket.http.dto.ResponseAttributeListDTO) HttpPathMethodDTO(com.robo4j.socket.http.dto.HttpPathMethodDTO) Test(org.junit.jupiter.api.Test)

Example 18 with HttpPathMethodDTO

use of com.robo4j.socket.http.dto.HttpPathMethodDTO in project robo4j by Robo4J.

the class HttpPathUtilTests method parseJsonPathMethod.

@Test
void parseJsonPathMethod() {
    List<String> jsonList = Arrays.asList("{\"roboUnit\":\"imageController\", \"method\":\"POST\", \"callbacks\":[\"callbackPOSTController\"]}", "{\"roboUnit\":\"imageController\", \"method\" : \"POST\", \"callbacks\" : [ \"callbackPOSTController\" ]}", "{ \"roboUnit\": \"imageController\", \"method\": \"POST\", \"callbacks\" :[\"callbackPOSTController\"] }");
    jsonList.forEach(json -> {
        HttpPathMethodDTO pathMethod = JsonUtil.getPathMethodByJson(json);
        assertNotNull(pathMethod, json);
        assertEquals("imageController", pathMethod.getRoboUnit(), json);
        assertEquals(HttpMethod.POST, pathMethod.getMethod(), json);
        assertTrue(pathMethod.getCallbacks().contains("callbackPOSTController"), json);
    });
}
Also used : HttpPathMethodDTO(com.robo4j.socket.http.dto.HttpPathMethodDTO) Test(org.junit.jupiter.api.Test)

Example 19 with HttpPathMethodDTO

use of com.robo4j.socket.http.dto.HttpPathMethodDTO in project robo4j by Robo4J.

the class HttpPathUtilTests method parseJsonArrayPathMethodToList.

@Test
void parseJsonArrayPathMethodToList() {
    final int observedElement = 2;
    final String jsonArray = "[{\"roboUnit\":\"imageController\", \"method\":\"POST\",\"callbacks\":[\"callbackPOSTController\"]}," + "{\"roboUnit\":\"imageController\",\"method\":\"GET\",\"callbacks\":[\"callbackGETController\"]}," + "{\"roboUnit\":\"cameraController\",\"method\":\"POST\",\"callbacks\":[\"callbackPOSTController\"]}," + "{\"roboUnit\":\"cameraController\",\"method\":\"POST\",\"callbacks\":[\"callbackPOSTController\"]}," + "{\"roboUnit\":\"cameraController\",\"method\":\"GET\",\"callbacks\":[\"callbackGETController\"]}," + "{\"roboUnit\":\"emptyController\",\"method\":\"GET\"}]";
    HttpPathMethodDTO duplicate = new HttpPathMethodDTO("cameraController", HttpMethod.POST, Collections.singletonList("callbackPOSTController"));
    List<HttpPathMethodDTO> result = JsonUtil.toListFromJsonArray(HttpPathMethodDTO.class, jsonArray);
    System.out.println("result: " + result);
    assertNotNull(result);
    assertEquals(6, result.size());
    assertEquals("cameraController", result.get(observedElement).getRoboUnit());
    assertEquals(HttpMethod.POST, result.get(observedElement).getMethod());
    assertTrue(result.get(observedElement).getCallbacks().contains("callbackPOSTController"));
    assertTrue(result.contains(duplicate));
}
Also used : HttpPathMethodDTO(com.robo4j.socket.http.dto.HttpPathMethodDTO) Test(org.junit.jupiter.api.Test)

Aggregations

HttpPathMethodDTO (com.robo4j.socket.http.dto.HttpPathMethodDTO)19 Test (org.junit.jupiter.api.Test)11 RoboContext (com.robo4j.RoboContext)2 RoboReference (com.robo4j.RoboReference)2 ResponseAttributeListDTO (com.robo4j.socket.http.dto.ResponseAttributeListDTO)2 SystemPath (com.robo4j.socket.http.enums.SystemPath)2 JsonDocument (com.robo4j.socket.http.json.JsonDocument)2 JsonReader (com.robo4j.socket.http.json.JsonReader)2 ClientContext (com.robo4j.socket.http.units.ClientContext)2 ClientPathConfig (com.robo4j.socket.http.units.ClientPathConfig)2 PathHttpMethod (com.robo4j.socket.http.units.PathHttpMethod)2 ServerContext (com.robo4j.socket.http.units.ServerContext)2 ServerPathConfig (com.robo4j.socket.http.units.ServerPathConfig)2 Collection (java.util.Collection)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 RoboBuilder (com.robo4j.RoboBuilder)1 HttpMethod (com.robo4j.socket.http.HttpMethod)1 ResponseAttributeDTO (com.robo4j.socket.http.dto.ResponseAttributeDTO)1 HttpPathUtils.toPath (com.robo4j.socket.http.util.HttpPathUtils.toPath)1