Search in sources :

Example 1 with ResponseDecoderUnitDTO

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

the class RoboRequestFactory method processGet.

// FIXME correct available methods according to the configuration
@Override
public Object processGet(ServerPathConfig pathConfig) {
    final RoboReference<?> unitRef = pathConfig.getRoboUnit();
    final SocketDecoder<?, ?> decoder = codecRegistry.getDecoder(unitRef.getMessageType());
    if (unitRef.getMessageType().equals(Object.class) || decoder == null) {
        List<ResponseAttributeDTO> attrList = unitRef.getKnownAttributes().stream().map(d -> {
            try {
                Object val = unitRef.getAttribute(d).get();
                ResponseAttributeDTO attributeDTO = new ResponseAttributeDTO();
                attributeDTO.setId(d.getAttributeName());
                attributeDTO.setType(d.getAttributeType().getTypeName());
                attributeDTO.setValue(String.valueOf(val));
                if (d.getAttributeName().equals(HttpServerUnit.ATTR_PATHS)) {
                    attributeDTO.setType("java.util.ArrayList");
                }
                return attributeDTO;
            } catch (InterruptedException | ExecutionException e) {
                SimpleLoggingUtil.error(getClass(), e.getMessage());
                return null;
            }
        }).filter(Objects::nonNull).collect(Collectors.toList());
        return JsonUtil.toJsonArrayServer(attrList);
    } else {
        final ResponseDecoderUnitDTO result = new ResponseDecoderUnitDTO();
        result.setId(unitRef.getId());
        result.setCodec(decoder.getDecodedClass().getName());
        result.setMethods(GET_POST_METHODS);
        return ReflectUtils.createJson(result);
    }
}
Also used : ResponseAttributeDTO(com.robo4j.socket.http.dto.ResponseAttributeDTO) ExecutionException(java.util.concurrent.ExecutionException) ResponseDecoderUnitDTO(com.robo4j.socket.http.dto.ResponseDecoderUnitDTO)

Aggregations

ResponseAttributeDTO (com.robo4j.socket.http.dto.ResponseAttributeDTO)1 ResponseDecoderUnitDTO (com.robo4j.socket.http.dto.ResponseDecoderUnitDTO)1 ExecutionException (java.util.concurrent.ExecutionException)1