Refactor code using JAX-RS

Asked

Viewed 22 times

0

I’m starting out in the programming world and I have to refactor a routine using another library. The routine uses apache lib to make Http requests org.apache.http.*, I have to refactor using Jax-RS.

Here’s an example of the routine I have to rewrite:

final SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(
            new BBRSocketFactory(config).getContext());
    try (final CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(sslSocketFactory)
            .build()) {
        final HttpPost request = new HttpPost(config.getAmbiente().getUrl());
        request.setHeader("Content-Type", "application/pkcs7-signature");
        request.setEntity(new StringEntity(dadoEntradaAssinadoBase64));

        final HttpResponse response = httpClient.execute(request);
        System.out.println("Response status: " + response.getStatusLine().getStatusCode());
        final String stringResposta = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
        System.out.println("Resposta string: " + stringResposta);

Doubts:

  • Which is the equivalent lib / Documentation.
  • What are the corresponding methods.

Could someone help me with directing how to do, or even with some example ?

  • You will need to worry (i.e., search) about 3 questions from your example code: 1) how to make a POST request using JAX-RS, also known as Jersey; 2) how to set this request to use the SSL protocol and 3) how to set headers (headers) of your request.

  • Very good! So far I believe I can do the post and set the header. I am searching how to set the protocol in the request.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.