Package javax.ws.rs.core

Examples of javax.ws.rs.core.UriBuilder


   }

   @Test
   public void testClone()
   {
      UriBuilder ub = UriBuilder.fromUri("http://user@localhost:8080/?query#fragment").path("a");
      URI full = ub.clone().path("b").build();
      URI base = ub.build();

      Assert.assertEquals(URI.create("http://user@localhost:8080/a?query#fragment"), base);
      Assert.assertEquals(URI.create("http://user@localhost:8080/a/b?query#fragment"), full);
   }
View Full Code Here


   public void testBuildFromMapTest5() throws Exception
   {
      StringBuffer sb = new StringBuffer();
      boolean pass = true;
      URI uri;
      UriBuilder ub;

      Map maps = new HashMap();
      maps.put("x", "x%yz");
      maps.put("y", "/path-absolute/test1");
      maps.put("z", "fred@example.com");
      maps.put("w", "path-rootless/test2");

      Map maps1 = new HashMap();
      maps1.put("x", "x%20yz");
      maps1.put("y", "/path-absolute/test1");
      maps1.put("z", "fred@example.com");
      maps1.put("w", "path-rootless/test2");

      Map maps2 = new HashMap();
      maps2.put("x", "x%yz");
      maps2.put("y", "/path-absolute/test1");
      maps2.put("z", "fred@example.com");
      maps2.put("w", "path-rootless/test2");
      maps2.put("v", "xyz");

      String expected_path =
              "path-rootless/test2/x%25yz//path-absolute/test1/fred@example.com/x%25yz";

      String expected_path_1 =
              "path-rootless/test2/x%2520yz//path-absolute/test1/fred@example.com/x%2520yz";

      String expected_path_2 =
              "path-rootless/test2/x%25yz//path-absolute/test1/fred@example.com/x%25yz";

      try
      {
         ub = UriBuilder.fromPath("").path("{w}/{x}/{y}/{z}/{x}");

         uri = ub.buildFromMap(maps);

         if (uri.getRawPath().compareToIgnoreCase(expected_path) != 0)
         {
            pass = false;
            sb.append("Test failed for expected path: " + expected_path +
                    " Got " + uri.getRawPath() + " instead" + "\n");
         }
         else
         {
            sb.append("Got expected path: " + uri.getRawPath() + "\n");
         }

         uri = ub.buildFromMap(maps1);

         if (uri.getRawPath().compareToIgnoreCase(expected_path_1) != 0)
         {
            pass = false;
            sb.append("Test failed for expected path: " + expected_path_1 +
                    " Got " + uri.getRawPath() + " instead" + "\n");
         }
         else
         {
            sb.append("Got expected path: " + uri.getRawPath() + "\n");
         }

         uri = ub.buildFromMap(maps2);

         if (uri.getRawPath().compareToIgnoreCase(expected_path_2) != 0)
         {
            pass = false;
            sb.append("Test failed for expected path: " + expected_path_2 +
View Full Code Here

           throw new RuntimeException(consumerKey + " scopes can not be registered");
       }
   }
  
   private String getCallbackURI() {
       UriBuilder ub = ui.getBaseUriBuilder();
       return ub.path(SubscriberReceiver.class).build().toString();
   }
View Full Code Here

        }
       
        @Override
        protected void setDefaultEntryProperties(Entry entry, List<LogRecord> rs, int entryIndex) {
            super.setDefaultEntryProperties(entry, rs, entryIndex);
            UriBuilder builder = context.getUriInfo().getAbsolutePathBuilder().path("entry");
            Integer realIndex = page == 1 ? entryIndex : page * pageSize + entryIndex;

            entry.addLink(builder.clone().path(realIndex.toString()).build().toString(), "self");
            entry.addLink(builder.path("alternate").path(realIndex.toString()).build().toString(),
                          "alternate");
        }
View Full Code Here

        return callback;
    }
   
    private URI buildCallbackURI(String callback, final Map<String, String> queryParams) {

        UriBuilder builder = UriBuilder.fromUri(callback);
        for (Map.Entry<String, String> entry : queryParams.entrySet()) {
            builder.queryParam(entry.getKey(), entry.getValue());
        }

        return builder.build();
    }
View Full Code Here

    public Response createCategory(Category category) {
        User user = userService.getAuthenticatedUser();

        org.apache.rave.model.Category newCategory = categoryService.create(category.getText(), user);

        UriBuilder builder = UriBuilder.fromResource(CategoriesResource.class).path("/{id}");
        return Response.created(builder.build(newCategory.getId())).entity(new Category(newCategory)).build();
    }
View Full Code Here

    @POST
    @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response create(Person person) {
        dao.create(person);
        UriBuilder builder = UriBuilder.fromUri(uriInfo.getRequestUri()).path("{id}");
        return Response.created(builder.build(person.getId()))
            .entity(person)
            .build();
    }
View Full Code Here

        this.serverUrl = serverUrl;
        this.serverStatus = serverStatus;
    }

    public List<InputSummaryResponse> getPersistedInputs() throws IOException {
        final UriBuilder uriBuilder = UriBuilder.fromUri(serverUrl);
        uriBuilder.path("/system/radios/" + serverStatus.getNodeId().toString() + "/inputs");

        final Request request = httpclient.prepareGet(uriBuilder.build().toString()).build();
        LOG.debug("API Request {} {}", request.getMethod(), request.getUrl());
        final Future<Response> f = httpclient.executeRequest(request);

        final Response r;
        try {
View Full Code Here

        return null;
    }

    // TODO make this use a generic ApiClient class that knows the graylog2-server node address(es) or something.
    public RegisterInputResponse registerInCluster(MessageInput input) throws ExecutionException, InterruptedException, IOException {
        final UriBuilder uriBuilder = UriBuilder.fromUri(serverUrl);
        uriBuilder.path("/system/radios/" + serverStatus.getNodeId().toString() + "/inputs");

        RegisterInputRequest rir = new RegisterInputRequest(input, serverStatus.getNodeId().toString());

        String json;
        try {
            json = mapper.writeValueAsString(rir);
        } catch (IOException e) {
            throw new RuntimeException("Could not create JSON for register input request.", e);
        }

        Future<Response> f = httpclient.preparePost(uriBuilder.build().toString())
                .setBody(json)
                .execute();

        Response r = f.get();
View Full Code Here

        return response;
    }

    public void unregisterInCluster(MessageInput input) throws ExecutionException, InterruptedException, IOException {
        final UriBuilder uriBuilder = UriBuilder.fromUri(serverUrl);
        uriBuilder.path("/system/radios/" + serverStatus.getNodeId().toString() + "/inputs/" + input.getPersistId());

        Future<Response> f = httpclient.prepareDelete(uriBuilder.build().toString()).execute();
        Response r = f.get();
        if (r.getStatusCode() != 204) {
            throw new RuntimeException("Expected HTTP response [204] for input unregistration but got [" + r.getStatusCode() + "].");
        }
    }
View Full Code Here

TOP

Related Classes of javax.ws.rs.core.UriBuilder

Copyright © 2018 www.massapicom. 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.