Package javax.ws.rs.core

Examples of javax.ws.rs.core.UriBuilder


        ObjectMapper mapper = new ObjectMapper();

        ObjectNode rootNode = mapper.createObjectNode();
        rootNode.put("rest_transport_address", ourUri.toString());

        final UriBuilder uriBuilder = UriBuilder.fromUri(server);
        uriBuilder.path("/system/radios/" + radioId + "/ping");

        Future<Response> f = client.preparePut(uriBuilder.build().toString())
                .setBody(rootNode.toString())
                .execute();

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


            Preconditions.checkNotNull(pathTemplate, "path() needs to be set to a non-null value.");

            URI builtUrl;
            try {
                String path = MessageFormat.format(pathTemplate, pathParams.toArray());
                final UriBuilder uriBuilder = UriBuilder.fromUri(target.getTransportAddress());
                uriBuilder.path(path);
                for (F.Tuple<String, String> queryParam : queryParams) {
                    uriBuilder.queryParam(queryParam._1, queryParam._2);
                }

                if (unauthenticated && sessionId != null) {
                    LOG.error("Both session() and unauthenticated() are set for this request, this is a bug, using session id.", new Throwable());
                }
                if (sessionId != null) {
                    // pass the current session id via basic auth and special "password"
                    uriBuilder.userInfo(sessionId + ":session");
                }
                builtUrl = uriBuilder.build();
                return builtUrl.toURL();
            } catch (MalformedURLException e) {
                // TODO handle this properly
                LOG.error("Could not build target URL", e);
                throw new RuntimeException(e);
View Full Code Here

      logger.finer(" get USERs is here !");
      mf = (ModelFacade)getServletContext().getAttribute(WebConstants.MF_KEY);
      List<Person> allUsers = mf.getAllPersons();
       JSONArray uriArray = new JSONArray();
        for (Person userEntity : allUsers) {
            UriBuilder ub = uriInfo.getAbsolutePathBuilder();
            URI userUri = ub.
                    path(userEntity.getUserName()).
                    build();
            uriArray.put(userUri.toASCIIString());
        }
        return uriArray;
View Full Code Here

          model.getBatch());
      scanners.put(id, instance);
      if (LOG.isDebugEnabled()) {
        LOG.debug("new scanner: " + id);
      }
      UriBuilder builder = uriInfo.getAbsolutePathBuilder();
      URI uri = builder.path(id).build();
      return Response.created(uri).build();
    } catch (IOException e) {
      throw new WebApplicationException(e,
              Response.Status.SERVICE_UNAVAILABLE);
    } catch (Exception e) {
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

        ServletContext context = request.getSession().getServletContext();
               
        // substitute $$sgs.server with the sgs server URL
        String serverURL = ServletPropertyUtil.getProperty("jnlp.wonderland.server.url", context);
        if (serverURL == null) {
            UriBuilder builder = UriBuilder.fromUri(request.getRequestURL().toString());
            serverURL = builder.replacePath("/").build().toString();
           
            /*try {
                serverName = InetAddress.getLocalHost().getCanonicalHostName();
            } catch (UnknownHostException uhe) {
                logger.log(Level.WARNING, "Error getting local host", uhe);
                serverName = "localhost";
            }*/
        }
        jnlpTemplate = substitute(jnlpTemplate, "$$wonderland.server.url", serverURL);

        // substitute in the config directory
        String configDirURL = ServletPropertyUtil.getProperty("jnlp.wonderland.client.config.dir", context);
        if (configDirURL == null) {
            UriBuilder builder = UriBuilder.fromUri(request.getRequestURL().toString());
            configDirURL = builder.replacePath("/wonderland-web-front/config/").build().toString();
        }
        jnlpTemplate = substitute(jnlpTemplate, "$$wonderland.client.config.dir", configDirURL);

        // add in additional properties
        StringBuilder props = new StringBuilder();
View Full Code Here

    /**
     * Get the URL for this server
     * @return the server URL
     */
    protected String getServerURL() {
        UriBuilder b = uriInfo.getBaseUriBuilder();
        b.replacePath("");

        return b.build().toString();
    }
View Full Code Here

        Object entity = null;
        Object[] args = msg.getBody();

        URI uri = URI.create(binding.getURI());
        UriBuilder uriBuilder = UriBuilder.fromUri(uri);

        Method method = ((JavaOperation)operation).getJavaMethod();

        if (method.isAnnotationPresent(Path.class)) {
            // Only for resource method
            uriBuilder.path(method);
        }

        if (!JAXRSHelper.isResourceMethod(method)) {
            // This is RPC over GET
            uriBuilder.replaceQueryParam("method", method.getName());
        }

        Map<String, Object> pathParams = new HashMap<String, Object>();
        Map<String, Object> matrixParams = new HashMap<String, Object>();
        Map<String, Object> queryParams = new HashMap<String, Object>();
        Map<String, Object> headerParams = new HashMap<String, Object>();
        Map<String, Object> formParams = new HashMap<String, Object>();
        Map<String, Object> cookieParams = new HashMap<String, Object>();

        for (int i = 0; i < method.getParameterTypes().length; i++) {
            boolean isEntity = true;
            Annotation[] annotations = method.getParameterAnnotations()[i];
            PathParam pathParam = getAnnotation(annotations, PathParam.class);
            if (pathParam != null) {
                isEntity = false;
                pathParams.put(pathParam.value(), args[i]);
            }
            MatrixParam matrixParam = getAnnotation(annotations, MatrixParam.class);
            if (matrixParam != null) {
                isEntity = false;
                matrixParams.put(matrixParam.value(), args[i]);
            }
            QueryParam queryParam = getAnnotation(annotations, QueryParam.class);
            if (queryParam != null) {
                isEntity = false;
                queryParams.put(queryParam.value(), args[i]);
            }
            HeaderParam headerParam = getAnnotation(annotations, HeaderParam.class);
            if (headerParam != null) {
                isEntity = false;
                headerParams.put(headerParam.value(), args[i]);
            }
            FormParam formParam = getAnnotation(annotations, FormParam.class);
            if (formParam != null) {
                isEntity = false;
                formParams.put(formParam.value(), args[i]);
            }
            CookieParam cookieParam = getAnnotation(annotations, CookieParam.class);
            if (cookieParam != null) {
                isEntity = false;
                cookieParams.put(cookieParam.value(), args[i]);
            }
            if (isEntity) {
                entity = args[i];
            }
        }

        for (Map.Entry<String, Object> p : queryParams.entrySet()) {
            uriBuilder.replaceQueryParam(p.getKey(), p.getValue());
        }
        for (Map.Entry<String, Object> p : matrixParams.entrySet()) {
            uriBuilder.replaceMatrixParam(p.getKey(), p.getValue());
        }

        uri = uriBuilder.buildFromMap(pathParams);
        Resource resource = restClient.resource(uri);

        for (Map.Entry<String, Object> p : headerParams.entrySet()) {
            resource.header(p.getKey(), String.valueOf(p.getValue()));
        }
View Full Code Here

        }
        return map;
    }

    public URI getRequestUri() {
        UriBuilder builder = getAbsolutePathBuilder();
        String query = messageContext.getAttribute(HttpServletRequest.class).getQueryString();
        builder.replaceQuery(query);
        return builder.build();
    }
View Full Code Here

    protected UriBuilder initUriBuilder() {
        return initUriBuilder(resourcePath);
    }

    protected UriBuilder initUriBuilder(String path) {
        UriBuilder builder = null;
        if (relativize) {
            builder = UriBuilder.fromPath(path);
        } else {
            builder = UriBuilder.fromUri(baseUri);
            // special treatment if the path resulting from the base uri equals
            // "/"
            if (baseUri.getPath() != null && baseUri.getPath().equals("/")) {
                builder.replacePath(path);
            } else {
                builder.path(path);
            }
        }
        return builder;
    }
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.