List of usage examples for org.apache.http.client.utils URIBuilder getPort
public int getPort()
From source file:com.github.autermann.wps.streaming.ProcessConfiguration.java
private static URI createSocketURI() { try {// w w w .j av a 2 s . c o m String wpsEndpoint = CapabilitiesConfiguration.ENDPOINT_URL; URIBuilder builder = new URIBuilder(wpsEndpoint); switch (builder.getScheme()) { case HTTP_SCHEME: builder.setScheme(WS_SCHEME); if (builder.getPort() == DEFAULT_HTTP_PORT) { builder.setPort(INVALID_PORT); } break; case HTTPS_SCHEME: builder.setScheme(WSS_SCHEME); if (builder.getPort() == DEFAULT_HTTPS_PORT) { builder.setPort(INVALID_PORT); } break; } String webappPath = normalizePath(WebProcessingService.WEBAPP_PATH); String servletPath = normalizePath(StreamingSocketEndpoint.PATH); if (webappPath != null) { builder.setPath(webappPath + servletPath); } else { builder.setPath(servletPath); } return builder.build(); } catch (URISyntaxException ex) { return URI.create("ws://localhost:8080/streaming"); } }
From source file:com.esri.geoevent.transport.websocket.WebsocketInboundTransport.java
private URI getURI(String uriString) throws URISyntaxException { // check the port - default to 80 for unsecure and 443 for secure connections URIBuilder uriBuilder = new URIBuilder(uriString); if (uriBuilder.getPort() == -1 || uriBuilder.getPort() == 0) { if (StringUtils.isNotEmpty(uriBuilder.getScheme())) { if (uriBuilder.getScheme().equalsIgnoreCase("wss")) { uriBuilder.setPort(DEFAULT_SECURE_PORT); } else if (uriBuilder.getScheme().equalsIgnoreCase("ws")) { uriBuilder.setPort(DEFAULT_UNSECURE_PORT); }//from ww w . jav a2 s . c om } } return uriBuilder.build(); }
From source file:com.linagora.james.mailets.GuessClassificationMailet.java
private Executor createHttpExecutor() throws MailetException { try {//w ww. j ava 2s. co m URIBuilder uriBuilder = new URIBuilder(serviceUrl); HttpHost host = new HttpHost(uriBuilder.getHost(), uriBuilder.getPort(), uriBuilder.getScheme()); return Executor.newInstance().authPreemptive(host).auth(host, new UsernamePasswordCredentials(serviceUsername, servicePassword)); } catch (URISyntaxException e) { throw new MailetException("invalid 'serviceUrl'", e); } }
From source file:com.qualinsight.plugins.sonarqube.badges.internal.QualityGateStatusRetriever.java
private String responseBodyForKey(final String key) throws IOException, URISyntaxException { final URIBuilder uriBuilder = new URIBuilder(this.settings.getString(SERVER_BASE_URL_KEY)); final String uriQuery = new StringBuilder().append("resource=").append(key) .append("&metrics=quality_gate_details&format=json").toString(); this.httpGet.setURI(new URI(uriBuilder.getScheme(), null, uriBuilder.getHost(), uriBuilder.getPort(), StringUtils.removeEnd(uriBuilder.getPath(), URI_SEPARATOR) + "/api/resources/index/", uriQuery, null));/*w w w . j a v a2 s. co m*/ LOGGER.debug("Http GET request line: {}", this.httpGet.getRequestLine()); final String responseBody = this.httpclient.execute(this.httpGet, this.responseHandler); LOGGER.debug("Http GET response body: {}", responseBody); return responseBody; }
From source file:org.aicer.hibiscus.http.client.HttpClient.java
/** * A URI representing the Absolute URL for the Request * * @param uri/*from www . jav a2 s . c om*/ * @return */ public HttpClient setURI(final URI uri) { final URIBuilder builder = new URIBuilder(uri); this.scheme = builder.getScheme(); this.host = builder.getHost(); this.port = builder.getPort(); this.path = builder.getPath(); this.fragment = builder.getFragment(); this.resetQueryParameters(); for (NameValuePair nvp : builder.getQueryParams()) { this.queryParameters.add(new BasicNameValuePair(nvp.getName(), nvp.getValue())); } return this; }
From source file:org.blocks4j.reconf.infra.http.layer.SimpleHttpRequest.java
SimpleHttpRequest(String method, String pathBase, String... pathParam) throws URISyntaxException { this.httpMethod = method; URIBuilder baseBuilder = new URIBuilder(pathBase); if (baseBuilder.getScheme() == null) { baseBuilder = new URIBuilder("http://" + pathBase); }//from www . j av a 2s .c o m final StringBuilder pathBuilder = new StringBuilder(baseBuilder.getPath()); for (String param : pathParam) { pathBuilder.append("/").append(param); } this.setURI(new URI(baseBuilder.getScheme(), baseBuilder.getUserInfo(), baseBuilder.getHost(), baseBuilder.getPort(), pathBuilder.toString(), null, null)); }
From source file:org.apache.ignite.console.agent.handlers.RestHandler.java
/** * @param uri Url.// ww w . j ava2s. c om * @param params Params. * @param demo Use demo node. * @param mtd Method. * @param headers Headers. * @param body Body. */ protected RestResult executeRest(String uri, Map<String, Object> params, boolean demo, String mtd, Map<String, Object> headers, String body) throws IOException, URISyntaxException { if (log.isDebugEnabled()) log.debug("Start execute REST command [method=" + mtd + ", uri=/" + (uri == null ? "" : uri) + ", parameters=" + params + "]"); final URIBuilder builder; if (demo) { // try start demo if needed. AgentClusterDemo.testDrive(cfg); // null if demo node not started yet. if (cfg.demoNodeUri() == null) return RestResult.fail("Demo node is not started yet.", 404); builder = new URIBuilder(cfg.demoNodeUri()); } else builder = new URIBuilder(cfg.nodeUri()); if (builder.getPort() == -1) builder.setPort(DFLT_NODE_PORT); if (uri != null) { if (!uri.startsWith("/") && !cfg.nodeUri().endsWith("/")) uri = '/' + uri; builder.setPath(uri); } if (params != null) { for (Map.Entry<String, Object> entry : params.entrySet()) { if (entry.getValue() != null) builder.addParameter(entry.getKey(), entry.getValue().toString()); } } HttpRequestBase httpReq = null; try { if ("GET".equalsIgnoreCase(mtd)) httpReq = new HttpGet(builder.build()); else if ("POST".equalsIgnoreCase(mtd)) { HttpPost post; if (body == null) { List<NameValuePair> nvps = builder.getQueryParams(); builder.clearParameters(); post = new HttpPost(builder.build()); if (!nvps.isEmpty()) post.setEntity(new UrlEncodedFormEntity(nvps)); } else { post = new HttpPost(builder.build()); post.setEntity(new StringEntity(body)); } httpReq = post; } else throw new IOException("Unknown HTTP-method: " + mtd); if (headers != null) { for (Map.Entry<String, Object> entry : headers.entrySet()) httpReq.addHeader(entry.getKey(), entry.getValue() == null ? null : entry.getValue().toString()); } try (CloseableHttpResponse resp = httpClient.execute(httpReq)) { ByteArrayOutputStream out = new ByteArrayOutputStream(); resp.getEntity().writeTo(out); Charset charset = Charsets.UTF_8; Header encodingHdr = resp.getEntity().getContentEncoding(); if (encodingHdr != null) { String encoding = encodingHdr.getValue(); charset = Charsets.toCharset(encoding); } return RestResult.success(resp.getStatusLine().getStatusCode(), new String(out.toByteArray(), charset)); } catch (ConnectException e) { log.info("Failed connect to node and execute REST command [uri=" + builder.build() + "]"); return RestResult.fail("Failed connect to node and execute REST command.", 404); } } finally { if (httpReq != null) httpReq.reset(); } }
From source file:com.blackducksoftware.tools.commonframework.core.config.ConfigurationManager.java
/** * Provides information from the server URL. * * @param urlInfo//from ww w . j a v a 2 s .c om * the url info * @return the string */ @Override public String findURLInformation(final URL_INFORMATION urlInfo) { String returnString = null; try { final URIBuilder builder = new URIBuilder(serverURL); if (urlInfo == URL_INFORMATION.HOST) { returnString = builder.getHost(); } else if (urlInfo == URL_INFORMATION.PORT) { returnString = Integer.toString(builder.getPort()); } else if (urlInfo == URL_INFORMATION.PROTOCOL) { returnString = builder.getScheme(); } } catch (final Exception e) { log.warn("Unable to determine host name for: " + serverURL, e); } return returnString; }
From source file:nl.nn.adapterframework.http.HttpSenderBase.java
protected int getPort(URIBuilder uri) { int port = uri.getPort(); if (port < 1) { try {/* www . j a va2s . c o m*/ log.debug(getLogPrefix() + "looking up protocol for scheme [" + uri.getScheme() + "]"); URL url = uri.build().toURL(); port = url.getDefaultPort(); } catch (Exception e) { log.debug(getLogPrefix() + "protocol for scheme [" + uri.getScheme() + "] not found, setting port to 80", e); port = 80; } } return port; }