Search in sources :

Example 11 with HttpPathMethodDTO

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

the class HttpPathConfigJsonBuilder method addPath.

public HttpPathConfigJsonBuilder addPath(String roboUnit, HttpMethod method, List<String> filters) {
    HttpPathMethodDTO document = new HttpPathMethodDTO(roboUnit, method, filters);
    paths.add(document);
    return this;
}
Also used : HttpPathMethodDTO(com.robo4j.socket.http.dto.HttpPathMethodDTO)

Example 12 with HttpPathMethodDTO

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

the class DatagramPathUtils method updateDatagramServerContextPaths.

public static void updateDatagramServerContextPaths(final RoboContext context, final ServerContext serverContext, final Collection<HttpPathMethodDTO> paths) {
    final Map<PathHttpMethod, ServerPathConfig> resultPaths = paths.stream().map(e -> {
        RoboReference<Object> reference = context.getReference(e.getRoboUnit());
        return new ServerPathConfig(toPath(SystemPath.UNITS.getPath(), e.getRoboUnit()), reference, e.getMethod(), e.getCallbacks());
    }).collect(Collectors.toMap(e -> new PathHttpMethod(e.getPath(), null), e -> e));
    serverContext.addPaths(resultPaths);
}
Also used : ClientContext(com.robo4j.socket.http.units.ClientContext) Collection(java.util.Collection) ServerPathConfig(com.robo4j.socket.http.units.ServerPathConfig) HttpPathUtils.toPath(com.robo4j.socket.http.util.HttpPathUtils.toPath) PathHttpMethod(com.robo4j.socket.http.units.PathHttpMethod) Collectors(java.util.stream.Collectors) ServerContext(com.robo4j.socket.http.units.ServerContext) HttpPathMethodDTO(com.robo4j.socket.http.dto.HttpPathMethodDTO) Map(java.util.Map) RoboContext(com.robo4j.RoboContext) ClientPathConfig(com.robo4j.socket.http.units.ClientPathConfig) SystemPath(com.robo4j.socket.http.enums.SystemPath) RoboReference(com.robo4j.RoboReference) RoboReference(com.robo4j.RoboReference) ServerPathConfig(com.robo4j.socket.http.units.ServerPathConfig) PathHttpMethod(com.robo4j.socket.http.units.PathHttpMethod)

Example 13 with HttpPathMethodDTO

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

the class HttpPathUtils method readServerPathDTO.

/**
 * parse json string to mutable path properties
 *
 * @param configurationJson
 *            configuration json
 * @return return server path dto with method and possible properties
 */
public static HttpPathMethodDTO readServerPathDTO(String configurationJson) {
    Class<HttpPathMethodDTO> clazz = HttpPathMethodDTO.class;
    JsonReader jsonReader = new JsonReader(configurationJson);
    JsonDocument document = jsonReader.read();
    return ReflectUtils.createInstanceByClazzAndDescriptorAndJsonDocument(clazz, document);
}
Also used : JsonReader(com.robo4j.socket.http.json.JsonReader) HttpPathMethodDTO(com.robo4j.socket.http.dto.HttpPathMethodDTO) JsonDocument(com.robo4j.socket.http.json.JsonDocument)

Example 14 with HttpPathMethodDTO

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

the class HttpPathUtils method updateHttpServerContextPaths.

public static void updateHttpServerContextPaths(final RoboContext context, final ServerContext serverContext, final Collection<HttpPathMethodDTO> paths) {
    final Map<PathHttpMethod, ServerPathConfig> resultPaths = paths.stream().map(e -> {
        RoboReference<Object> reference = context.getReference(e.getRoboUnit());
        return HttpPathUtils.toHttpPathConfig(e, reference);
    }).collect(Collectors.toMap(e -> new PathHttpMethod(e.getPath(), e.getMethod()), e -> e));
    resultPaths.put(new PathHttpMethod(Utf8Constant.UTF8_SOLIDUS, HttpMethod.GET), new ServerPathConfig(Utf8Constant.UTF8_SOLIDUS, null, HttpMethod.GET));
    serverContext.addPaths(resultPaths);
}
Also used : StringConstants(com.robo4j.util.StringConstants) JsonReader(com.robo4j.socket.http.json.JsonReader) ClientContext(com.robo4j.socket.http.units.ClientContext) Collection(java.util.Collection) ServerPathConfig(com.robo4j.socket.http.units.ServerPathConfig) Set(java.util.Set) PathHttpMethod(com.robo4j.socket.http.units.PathHttpMethod) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ServerContext(com.robo4j.socket.http.units.ServerContext) List(java.util.List) HttpPathMethodDTO(com.robo4j.socket.http.dto.HttpPathMethodDTO) Stream(java.util.stream.Stream) Map(java.util.Map) HttpMethod(com.robo4j.socket.http.HttpMethod) RoboContext(com.robo4j.RoboContext) ClientPathConfig(com.robo4j.socket.http.units.ClientPathConfig) SystemPath(com.robo4j.socket.http.enums.SystemPath) Utf8Constant(com.robo4j.util.Utf8Constant) JsonDocument(com.robo4j.socket.http.json.JsonDocument) Collections(java.util.Collections) RoboReference(com.robo4j.RoboReference) RoboReference(com.robo4j.RoboReference) ServerPathConfig(com.robo4j.socket.http.units.ServerPathConfig) PathHttpMethod(com.robo4j.socket.http.units.PathHttpMethod)

Example 15 with HttpPathMethodDTO

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

the class JsonUtil method toJsonArrayServer.

public static <T> String toJsonArrayServer(List<T> list) {
    return JsonElementStringBuilder.Builder().add(Utf8Constant.UTF8_SQUARE_BRACKET_LEFT).add(list.stream().map(e -> {
        if (e instanceof ResponseAttributeDTO) {
            ResponseAttributeDTO ra = (ResponseAttributeDTO) e;
            switch(ra.getType()) {
                case "java.util.ArrayList":
                    List<HttpPathMethodDTO> tmpList = JsonUtil.readPathConfig(HttpPathMethodDTO.class, ra.getValue());
                    ResponseAttributeListDTO tmpAttr = new ResponseAttributeListDTO();
                    tmpAttr.setId(ra.getId());
                    tmpAttr.setType(ra.getType());
                    tmpAttr.setValue(tmpList);
                    return ReflectUtils.createJson(tmpAttr);
                default:
                    return ReflectUtils.createJson(e);
            }
        } else {
            return ReflectUtils.createJson(e);
        }
    }).collect(Collectors.joining(Utf8Constant.UTF8_COMMA))).add(Utf8Constant.UTF8_SQUARE_BRACKET_RIGHT).build();
}
Also used : ResponseAttributeDTO(com.robo4j.socket.http.dto.ResponseAttributeDTO) ResponseAttributeListDTO(com.robo4j.socket.http.dto.ResponseAttributeListDTO) HttpPathMethodDTO(com.robo4j.socket.http.dto.HttpPathMethodDTO)

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