Básicamente voy a mostrar dos maneras, en el caso en que el WS nos devuelva un JSON y lo queramos tratar como tal en el cliente, este es el bloque de código adecuado
ClientConfig clientConfig = new DefaultClientConfig(); clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); Client client = Client.create(clientConfig); WebResource webResource = client.resource("http://localhost:8080/WS_SMSReceiver/SmsService/getSmsMessage"); ClientResponse response = webResource.accept("application/json").type("application/json").get(ClientResponse.class); String output = response.getEntity(String.class); JSONObject jsonObject = new JSONObject(output);
En el caso, altamente útil que ya vimos en el post anterior, que el WS nos devuelva una lista de objetos que nostros hayamos definido previamente, en formato JSON, el código para recibirlo y tratarlo será el siguiente
ClientConfig clientConfig = new DefaultClientConfig(); clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); Client client = Client.create(clientConfig); WebResource webResource = client.resource("http://localhost:8080/WS_SMSReceiver/SmsService/getSmsMessage"); Listlist = webResource.accept("application/json").type("application/json").get(new GenericType >(){});
No hay comentarios:
Publicar un comentario