Comment définir le corps de la Réponse dans javax.ws.rs.de base.Réponse

Il y a une API REST d'extrémité qui doit être mise en œuvre est utilisée pour obtenir des informations et de les envoyer backend demande à un autre serveur, et la réponse qui vient de serveur d'arrière-plan doit définir la réponse finale. Mon problème est comment définir le corps de la réponse dans javax.ws.rs.de base.Réponse?

@Path("analytics")
@GET
@Produces("application/json")
public Response getDeviceStats(@QueryParam("deviceType") String deviceType,
@QueryParam("deviceIdentifier") String deviceIdentifier,
@QueryParam("username") String user, @QueryParam("from") long from,
@QueryParam("to") long to) {
//Trust own CA and all self-signed certs
SSLContext sslcontext = null;
try {
sslcontext = SSLContexts.custom()
.loadTrustMaterial(new File(getClientTrustStoretFilePath()), "password## Heading ##".toCharArray(),
new TrustSelfSignedStrategy())
.build();
} catch (NoSuchAlgorithmException e) {
log.error(e);
} catch (KeyManagementException e) {
log.error(e);
} catch (KeyStoreException e) {
log.error(e);
} catch (CertificateException e) {
log.error(e);
} catch (IOException e) {
log.error(e);
}
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
sslcontext,
new String[] { "TLSv1" },
null,
SSLConnectionSocketFactory.getDefaultHostnameVerifier());
CloseableHttpClient httpclient = HttpClients.custom()
.setSSLSocketFactory(sslsf)
.build();
HttpResponse response = null;
try {
HttpGet httpget = new HttpGet(URL);
httpget.setHeader("Authorization", "Basic YWRtaW46YWRtaW4=");
httpget.addHeader("content-type", "application/json");
response = httpclient.execute(httpget);
String message = EntityUtils.toString(response.getEntity(), "UTF-8");
} catch (ClientProtocolException e) {
log.error(e);
} catch (IOException e) {
log.error(e);
} 
}  

Ici message est celui que je dois mettre. Mais j'ai essayé plusieurs méthodes. Ne fonctionne pas l'un d'eux.

return Response.ok(message).build()?

OriginalL'auteur GPrathap | 2016-03-22