Package javax.ws.rs.client

Examples of javax.ws.rs.client.WebTarget.request()


    }

    protected Response getResponse(String uri, int retries) {
        String fullUri = getBaseURI() + uri;
        WebTarget resource = client.target(fullUri);
        Invocation.Builder builder = resource.request(MediaType.APPLICATION_JSON);
        if (sessionToken != null && sessionToken.get() != null && !sessionToken.get().isEmpty()) {
            builder.cookie(new Cookie("gfresttoken", sessionToken.get()));
        }
        return builder.get(Response.class);
    }
View Full Code Here


  @Test
  public void shouldCheckForH2G2Verbose() throws URISyntaxException {

    Client client = ClientBuilder.newClient();
    WebTarget target = client.target("http://localhost:8282/03/book");
    assertEquals(Response.Status.OK.getStatusCode(), target.request(MediaType.TEXT_PLAIN).get().getStatus());
    URI uri = new URI("http://localhost:8282/03/book");
    target = client.target(uri);
    assertEquals(Response.Status.OK.getStatusCode(), target.request(MediaType.TEXT_PLAIN).get().getStatus());
  }
View Full Code Here

    Client client = ClientBuilder.newClient();
    WebTarget target = client.target("http://localhost:8282/03/book");
    assertEquals(Response.Status.OK.getStatusCode(), target.request(MediaType.TEXT_PLAIN).get().getStatus());
    URI uri = new URI("http://localhost:8282/03/book");
    target = client.target(uri);
    assertEquals(Response.Status.OK.getStatusCode(), target.request(MediaType.TEXT_PLAIN).get().getStatus());
  }

  @Test
  public void shouldCheckForH2G2WithWebTarget() {
View Full Code Here

  @Test
  public void shouldCheckForH2G2WithWebTarget() {

    Client client = ClientBuilder.newClient();
    WebTarget target = client.target("http://localhost:8282/03/book");
    Invocation.Builder builder = target.request(MediaType.TEXT_PLAIN);
    Response response = builder.get();
    String entity = response.readEntity(String.class);

    assertEquals("H2G2", entity);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
View Full Code Here

  @Test
  public void shouldCheckForH2G2WithInvocation() {

    Client client = ClientBuilder.newClient();
    WebTarget target = client.target("http://localhost:8282/03/book");
    Invocation invocation = target.request(MediaType.TEXT_PLAIN).buildGet();
    Response response = invocation.invoke();
    String entity = response.readEntity(String.class);

    assertEquals("H2G2", entity);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
View Full Code Here

        WebTarget target = client2.target(restURL);
        target.register(new HttpBasicAuthFilter(username, password));
        MultivaluedMap payLoad = new MultivaluedHashMap();
        payLoad.putSingle("remoteHostName", request.getRemoteHost());

        Response resp = target.request(RESPONSE_TYPE).post(Entity.entity(payLoad, MediaType.APPLICATION_FORM_URLENCODED), Response.class);
        RestResponse restResp = RestResponse.getRestResponse(resp);

        // Check to see if successful..
        if (restResp.isSuccess()) {
            // Username and Password sent in... validate them!
View Full Code Here

    }

    public static Response getRequestFromServlet(HttpServletRequest request, String endpoint, Map<String, Object> attrs) {
        String token = (String) request.getSession().getAttribute(AdminConsoleAuthModule.REST_TOKEN);
        WebTarget target = targetWithQueryParams(JERSEY_CLIENT.target(endpoint), attrs);
        Response cr = target
                .request().cookie(new Cookie(REST_TOKEN_COOKIE, token))
                .get(Response.class);

        return cr;
    }
View Full Code Here

    }

    public static void getRestRequestFromServlet(HttpServletRequest request, String endpoint, Map<String, Object> attrs, boolean quiet, boolean throwException) {
        String token = (String) request.getSession().getAttribute(AdminConsoleAuthModule.REST_TOKEN);
        WebTarget target = targetWithQueryParams(JERSEY_CLIENT.target(endpoint), attrs);
        Response cr = target
                .request(RESPONSE_TYPE)
                .cookie(new Cookie(REST_TOKEN_COOKIE, token))
                .get(Response.class);
        RestResponse rr = RestResponse.getRestResponse(cr);
        parseResponse(rr, null, endpoint, attrs, quiet, throwException);
View Full Code Here

    public static RestResponse get(String address, Map<String, Object> payload) {
        if (address.startsWith("/")) {
            address = FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("REST_URL") + address;
        }
        WebTarget target = targetWithQueryParams(getJerseyClient().target(address), payload);
        Response resp = target
                .request(RESPONSE_TYPE)
                .cookie(new Cookie(REST_TOKEN_COOKIE, getRestToken()))
                .get(Response.class);
        return RestResponse.getRestResponse(resp);
    }
View Full Code Here

            contentType = MediaType.APPLICATION_JSON;
        }
        if (payload instanceof Map) {
            payload = buildMultivalueMap((Map<String, Object>) payload);
        }
        Response cr = target.request(RESPONSE_TYPE).header("Content-Type", contentType)
                .cookie(new Cookie(REST_TOKEN_COOKIE, getRestToken()))
                //                .header("Content-type", MediaType.APPLICATION_FORM_URLENCODED)
                .post(Entity.entity(payload, contentType), Response.class);
        RestResponse rr = RestResponse.getRestResponse(cr);
        return rr;
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.