実装が必要なREST APIエンドポイントがあり、いくつかの情報を取得し、バックエンド要求を別のサーバに送信し、バックエンドサーバからの応答を送信します最終的な応答に設定する必要があります。私の問題はjavax.ws.rs.core.Responseで応答本文を設定する方法ですか?ここで設定方法javax.ws.rs.core.Responseのレスポンスボディ
@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);
}
}
メッセージは私が設定する必要があるものです。しかし、私はいくつかの方法を試みました。それらのどれも働かなかった。トリックを行う必要があり、次のソリューションの
'return Response.ok(message).build()'? –