Examples of UriBuilder


Examples of javax.ws.rs.core.UriBuilder

    /**
     * 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

Examples of javax.ws.rs.core.UriBuilder

        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

Examples of javax.ws.rs.core.UriBuilder

        }
        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

Examples of javax.ws.rs.core.UriBuilder

    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

Examples of juzu.impl.common.UriBuilder

  }

  public String render() {
    try {
      StringBuilder sb = new StringBuilder();
      UriBuilder writer = new UriBuilder(sb, MimeType.PLAIN);
      render(writer);
      return sb.toString();
    }
    catch (IOException e) {
      throw new UndeclaredIOException(e);
View Full Code Here

Examples of org.apache.http.client.utils.URIBuilder

                ReplicationActionType.fromName(action),
                paths);
    }

    public static URI appendReplicationRequest(URI uri, ReplicationRequest replicationRequest) throws URISyntaxException {
        URIBuilder uriBuilder = new URIBuilder(uri);
        uriBuilder.addParameter(ReplicationParameter.ACTION.toString(), replicationRequest.getAction().getName());
        for (String path : replicationRequest.getPaths()) {
            uriBuilder.addParameter(ReplicationParameter.PATH.toString(), path);
        }
        return uriBuilder.build();
    }
View Full Code Here

Examples of org.apache.http.client.utils.URIBuilder

        this.configuration = configuration;
    }

    @Override
    public void doRun() {
        final URIBuilder uri;
        final HttpGet get;
        try {
            uri = new URIBuilder(configuration.getVersionchecksUri());
            uri.addParameter("anonid", DigestUtils.sha256Hex(serverStatus.getNodeId().toString()));
            uri.addParameter("version", ServerVersion.VERSION.toString());

            get = new HttpGet(uri.build());
            get.setHeader("User-Agent",
                          "graylog2-server ("
                                  + System.getProperty("java.vendor") + ", "
                                  + System.getProperty("java.version") + ", "
                                  + System.getProperty("os.name") + ", "
                                  + System.getProperty("os.version") + ")");
            final RequestConfig.Builder configBuilder = RequestConfig.custom()
                    .setConnectTimeout(configuration.getVersionchecksConnectTimeOut())
                    .setSocketTimeout(configuration.getVersionchecksSocketTimeOut())
                    .setConnectionRequestTimeout(configuration.getVersionchecksConnectionRequestTimeOut());
            if (configuration.getHttpProxyUri() != null) {
                try {
                    final URIBuilder uriBuilder = new URIBuilder(configuration.getHttpProxyUri());
                    final URI proxyURI = uriBuilder.build();

                    configBuilder.setProxy(new HttpHost(proxyURI.getHost(), proxyURI.getPort(), proxyURI.getScheme()));
                } catch (Exception e) {
                    LOG.error("Invalid version check proxy URI: " + configuration.getHttpProxyUri(), e);
                    return;
View Full Code Here

Examples of org.apache.http.client.utils.URIBuilder

            return;
        }

        final HttpPost post;
        try {
            post = new HttpPost(new URIBuilder(configuration.getTelemetryServiceUri()).build());
            post.setHeader("User-Agent", "graylog2-server");
            post.setHeader("Content-Type", "application/json");
            post.setHeader("Content-Encoding", "gzip");
            post.setEntity(postBody);

            final RequestConfig.Builder configBuilder = RequestConfig.custom()
                    .setConnectTimeout(configuration.getTelemetryServiceConnectTimeOut())
                    .setSocketTimeout(configuration.getTelemetryServiceSocketTimeOut())
                    .setConnectionRequestTimeout(configuration.getTelemetryServiceConnectionRequestTimeOut());

            if (configuration.getHttpProxyUri() != null) {
                try {
                    final URIBuilder uriBuilder = new URIBuilder(configuration.getHttpProxyUri());
                    final URI proxyURI = uriBuilder.build();

                    configBuilder.setProxy(new HttpHost(proxyURI.getHost(), proxyURI.getPort(), proxyURI.getScheme()));
                } catch (Exception e) {
                    LOG.error("Invalid telemetry service proxy URI: {}", configuration.getHttpProxyUri(), e);
                    return;
View Full Code Here

Examples of org.apache.http.client.utils.URIBuilder

  }
 
  protected URI getURI(String path, List<NameValuePair> params) throws ApplicationException {
    URI uri = null;
    try {
      URIBuilder uriBuilder = new URIBuilder();
      uriBuilder.setScheme(HTTP);
      uriBuilder.setHost(HOST);
      uriBuilder.setPath(path);
      for (NameValuePair param : params) {
        uriBuilder.addParameter(param.getName(), param.getValue());
      }
      uri = uriBuilder.build();
    } catch (URISyntaxException e) {
      throw new ApplicationException("Could not create MusicBrainz URI!", e);
    }
    return uri;
  }
View Full Code Here

Examples of org.apache.http.client.utils.URIBuilder

   * Assemble URI for the Last.fm web service.
   */
  protected URI getURI(List<NameValuePair> params) throws ApplicationException {
    URI uri = null;
    try {
      URIBuilder uriBuilder = new URIBuilder();
      uriBuilder.setScheme(HTTP);
      uriBuilder.setHost(HOST);
      uriBuilder.setPath(PATH);
      for (NameValuePair param : params) {
        uriBuilder.addParameter(param.getName(), param.getValue());
      }
      uri = uriBuilder.build();
    } catch (URISyntaxException e) {
      throw new ApplicationException("Could not create Last.fm URI!", e);
    }
    return uri;
  }
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.