Package com.sun.jersey.api.client

Examples of com.sun.jersey.api.client.WebResource.accept()



    private Builder builder( String path ) {
        WebResource resource = client.resource( uri( pathOrAbsolute( path ) ) );
        if (Config.streamingIsEnabled()) return resource.accept(STREAMING_JSON_TYPE).header("X-Stream","true");
        return resource.accept(APPLICATION_JSON_TYPE);
    }

    private String pathOrAbsolute( String path ) {
        if ( path.startsWith( "http://" ) ) return path;
        return baseUri + "/" + path;
View Full Code Here


        WebResource webResource = client2.resource(restURL);
        webResource.addFilter(new HTTPBasicAuthFilter(username, password));
        MultivaluedMap payLoad = new MultivaluedMapImpl();
        payLoad.putSingle("remoteHostName", request.getRemoteHost());

        ClientResponse resp = webResource.accept(RESPONSE_TYPE).post(ClientResponse.class, payLoad);
        RestResponse restResp = RestResponse.getRestResponse(resp);

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

                "red\norange\nyellow\ngreen\nblue\nindigo\nviolet\n", responseMsg);

        // with the query param "match" value "re"
        URI coloursUri = webResource.path("form").path("colours").getURI();
        WebResource coloursResource = webResource.uri(UriBuilder.fromUri(coloursUri).queryParam("match", "re").build());
        responseMsg = coloursResource.accept(MediaType.TEXT_PLAIN).get(String.class);
        assertEquals("Response content doesn't match the expected value with the query param 'match=re'",
                "red\ngreen\n", responseMsg);
    }

    /**
 
View Full Code Here

                7, jsonArray.length());

        // with the query param "match" value "re"
        URI coloursUri = webResource.path("form").path("colours").getURI();
        WebResource coloursResource = webResource.uri(UriBuilder.fromUri(coloursUri).queryParam("match", "re").build());
        jsonArray = coloursResource.accept(MediaType.APPLICATION_JSON).get(JSONArray.class);
        assertEquals("Returned JSONArray doesn't have expected number of entries with the query param 'match=re'",
                2, jsonArray.length());
    }

}
View Full Code Here

        WebResource wr =
            webResource.path(Constants.KUNDERA_API_PATH + Constants.JPA_QUERY_RESOURCE_PATH + "/" + entityClassName
                + "/" + namedQuery + paramsStr);

        WebResource.Builder queryBuilder =
            wr.accept(mediaType).header(Constants.SESSION_TOKEN_HEADER_NAME, sessionToken).type(mediaType);

        ClientResponse queryResponse = (ClientResponse) queryBuilder.get(ClientResponse.class);
        log.debug("Query Response:" + queryResponse.getStatus());

        InputStream is = queryResponse.getEntityInputStream();
View Full Code Here

        WebResource wr =
            webResource.path(Constants.KUNDERA_API_PATH + Constants.NATIVE_QUERY_RESOURCE_PATH + entityClassName + "/"
                + namedNativeQuery + paramsStr);

        WebResource.Builder queryBuilder =
            wr.accept(mediaType).type(mediaType).header(Constants.SESSION_TOKEN_HEADER_NAME, sessionToken);

        ClientResponse queryResponse = (ClientResponse) queryBuilder.get(ClientResponse.class);
        log.debug("Query Response:" + queryResponse.getStatus());

        InputStream is = queryResponse.getEntityInputStream();
View Full Code Here

  @Test
  public void testInvalidUri2() throws JSONException, Exception {
    WebResource r = resource();
    String responseStr = "";
    try {
      responseStr = r.accept(MediaType.APPLICATION_JSON).get(String.class);
      fail("should have thrown exception on invalid uri");
    } catch (UniformInterfaceException ue) {
      ClientResponse response = ue.getResponse();
      assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
      WebServicesTestUtils.checkStringMatch(
View Full Code Here

        @Override
        public Map<String, IAPIStateDTO> call() throws Exception {
          try {
            final WebResource resource = ServiceConstants.REST_CLIENT.resource(API_STATES_URL.toExternalForm());
            resource.addFilter(new RetryClientFilter(RETRY_COUNT));
            final WebResource.Builder builder = resource.accept(MediaType.APPLICATION_JSON_TYPE);
            try {
              final String response = builder.get(String.class).replaceAll(Pattern.quote("\\"), "");
              LOGGER.trace("Retrieved response=" + response);
              final Map<String, IAPIStateDTO> result = GW2StatsService.this.gw2statsDTOFactory.newAPIStatesOf(response);
              if (LOGGER.isDebugEnabled()) {
View Full Code Here

      return this.apieStateDescriptionsCache.get("", new Callable<Map<String, IAPIStateDescriptionDTO>>() {
        @Override
        public Map<String, IAPIStateDescriptionDTO> call() throws Exception {
          final WebResource resource = ServiceConstants.REST_CLIENT.resource(API_STATE_DESCRIPTIONS_URL.toExternalForm());
          resource.addFilter(new RetryClientFilter(RETRY_COUNT));
          final WebResource.Builder builder = resource.accept(MediaType.APPLICATION_JSON_TYPE);
          try {
            final String response = builder.get(String.class);
            LOGGER.trace("Retrieved response=" + response);
            final Map<String, IAPIStateDescriptionDTO> result = GW2StatsService.this.gw2statsDTOFactory.newAPIStateDescriptionsOf(response);
            if (LOGGER.isDebugEnabled()) {
View Full Code Here

      return this.matchesCache.get("", new Callable<Optional<IWVWMatchesDTO>>() {
        @Override
        public Optional<IWVWMatchesDTO> call() throws Exception {
          final WebResource resource = ServiceUtils.REST_CLIENT.resource(MATCHES_URL.toExternalForm());
          resource.addFilter(new RetryClientFilter(ServiceUtils.REST_RETRY_COUNT));
          final WebResource.Builder builder = resource.accept(MediaType.APPLICATION_JSON_TYPE);
          try {
            final String response = builder.get(String.class);
            LOGGER.trace("Retrieved response=" + response);
            final IWVWMatchesDTO result = WVWService.this.wvwDTOFactory.newMatchesOf(response);
            LOGGER.debug("Built result=" + result);
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.