List of usage examples for org.apache.http.client.utils URIBuilder getScheme
public String getScheme()
From source file:com.github.autermann.wps.streaming.ProcessConfiguration.java
private static URI createSocketURI() { try {/*from ww w . j av a 2 s.c om*/ 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:it.txt.ens.core.util.parser.ENSResourceURIParser.java
public static ENSResource parse(URI ensResourceURI, ENSResourceFactory factory) throws URIParseException, IllegalArgumentException { // LOGGER.fine("1.1"); URIBuilder builder = new URIBuilder(ensResourceURI); // LOGGER.fine("1.2"); String scheme = builder.getScheme(); // LOGGER.fine("1.3"); if (ENSResource.URI_SCHEME.equals(scheme)) { // LOGGER.fine("1.4"); List<NameValuePair> parameters = builder.getQueryParams(); // LOGGER.fine("1.5"); if (parameters.size() == NUMBER_OF_QUERY_PARAMETERS) { // LOGGER.fine("1.6"); String namespace;//from ww w.j ava2 s . co m String pattern; NameValuePair param1 = parameters.get(0); // LOGGER.fine("1.7"); NameValuePair param2 = parameters.get(1); // LOGGER.fine("1.8"); if (ENSResource.NAMESPACE_PARAMETER_NAME.equals(param1.getName())) { // LOGGER.fine("1.8.1.1"); namespace = param1.getValue(); // LOGGER.fine("1.8.1.2"); } else if (ENSResource.NAMESPACE_PARAMETER_NAME.equals(param2.getName())) { // LOGGER.fine("1.8.2.1"); namespace = param2.getValue(); // LOGGER.fine("1.8.2.2"); } else throw new URIParseException( MessageFormat.format(MESSAGES.getString("URIParser.parse.missingQueryParameter"), ENSResource.NAMESPACE_PARAMETER_NAME)); // LOGGER.fine("1.9"); if (ENSResource.PATTERN_PARAMETER_NAME.equals(param1.getName())) { // LOGGER.fine("1.9.1.1"); pattern = param1.getValue(); // LOGGER.fine("1.9.1.2"); } else if (ENSResource.PATTERN_PARAMETER_NAME.equals(param2.getName())) { // LOGGER.fine("1.9.2.1"); pattern = param2.getValue(); // LOGGER.fine("1.9.2.2"); } else throw new URIParseException( MessageFormat.format(MESSAGES.getString("URIParser.parse.missingQueryParameter"), ENSResource.PATTERN_PARAMETER_NAME)); try { // LOGGER.fine("1.10"); builder.getHost(); // LOGGER.fine("1.11"); builder.getPath(); // LOGGER.fine("1.12"); return factory.create(builder.getHost(), builder.getPath(), namespace, pattern); } catch (URIBuildingException e) { throw new URIParseException("An unexpected exception occurred while creating the ENS resource", e); } } else throw new URIParseException( MessageFormat.format(MESSAGES.getString("URIParser.parse.unexpectedNumberOfQueryParams"), parameters.size(), NUMBER_OF_QUERY_PARAMETERS)); } else throw new URIParseException(MessageFormat.format(MESSAGES.getString("URIParser.parse.unexpectedScheme"), scheme, ENSResource.URI_SCHEME)); }
From source file:com.mbeddr.pluginmanager.com.intellij.ide.plugins.RepositoryHelper.java
@NotNull public static List<IdeaPluginDescriptor> loadPlugins(@Nullable String repositoryUrl, @Nullable BuildNumber buildnumber, @Nullable String channel, boolean forceHttps, @Nullable final ProgressIndicator indicator) throws IOException { String url;// w w w. j a v a 2s. c o m final File pluginListFile; final String host; try { URIBuilder uriBuilder; if (repositoryUrl == null) { uriBuilder = new URIBuilder(ApplicationInfoImpl.getShadowInstance().getPluginsListUrl()); pluginListFile = new File(PathManager.getPluginsPath(), channel == null ? PLUGIN_LIST_FILE : channel + "_" + PLUGIN_LIST_FILE); if (pluginListFile.length() > 0) { uriBuilder.addParameter("crc32", Files.hash(pluginListFile, Hashing.crc32()).toString()); } } else { uriBuilder = new URIBuilder(repositoryUrl); pluginListFile = null; } if (!URLUtil.FILE_PROTOCOL.equals(uriBuilder.getScheme())) { uriBuilder.addParameter("build", (buildnumber != null ? buildnumber.asString() : ApplicationInfoImpl.getShadowInstance().getApiVersion())); if (channel != null) uriBuilder.addParameter("channel", channel); } host = uriBuilder.getHost(); url = uriBuilder.build().toString(); } catch (URISyntaxException e) { throw new IOException(e); } if (indicator != null) { indicator.setText2(IdeBundle.message("progress.connecting.to.plugin.manager", host)); } RequestBuilder request = HttpRequests.request(url).forceHttps(forceHttps); return process(repositoryUrl, request.connect(new HttpRequests.RequestProcessor<List<IdeaPluginDescriptor>>() { @Override public List<IdeaPluginDescriptor> process(@NotNull HttpRequests.Request request) throws IOException { if (indicator != null) { indicator.checkCanceled(); } URLConnection connection = request.getConnection(); if (pluginListFile != null && pluginListFile.length() > 0 && connection instanceof HttpURLConnection && ((HttpURLConnection) connection) .getResponseCode() == HttpURLConnection.HTTP_NOT_MODIFIED) { return loadPluginList(pluginListFile); } if (indicator != null) { indicator.checkCanceled(); indicator.setText2(IdeBundle.message("progress.downloading.list.of.plugins", host)); } if (pluginListFile != null) { synchronized (RepositoryHelper.class) { FileUtil.ensureExists(pluginListFile.getParentFile()); request.saveToFile(pluginListFile, indicator); return loadPluginList(pluginListFile); } } else { return parsePluginList(request.getReader()); } } })); }
From source file:com.thoughtworks.go.agent.common.AgentBootstrapperBackwardCompatibility.java
public String sslServerUrl(String sslPort) { String serverUrl = serverUrl(); try {//from w ww . ja v a 2s.c o m // backward compatibility, since the agent.jar requires an ssl url, but the old bootstrapper does not have one. URIBuilder url = new URIBuilder(serverUrl); if (url.getScheme().equals("http")) { url.setPort(Integer.valueOf(sslPort)); url.setScheme("https"); } return url.toString(); } catch (URISyntaxException e) { throw bomb(e); } }
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 w ww . 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:cd.go.contrib.elasticagents.docker.executors.GoServerURLField.java
@Override public String doValidate(String input) { if (StringUtils.isBlank(input)) { return this.displayName + " must not be blank."; }// w w w .ja v a 2 s .c o m URIBuilder uriBuilder = null; try { uriBuilder = new URIBuilder(input); } catch (URISyntaxException e) { return this.displayName + " must be a valid URL (https://example.com:8154/go)"; } if (!uriBuilder.getScheme().equalsIgnoreCase("https")) { return this.displayName + " must be a valid HTTPs URL (https://example.com:8154/go)"; } if (uriBuilder.getHost().equalsIgnoreCase("localhost") || uriBuilder.getHost().equalsIgnoreCase("127.0.0.1")) { return this.displayName + " must not be localhost, since this gets resolved on the agents"; } return null; }
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 .j a v a 2 s . c om*/ } } return uriBuilder.build(); }
From source file:com.linagora.james.mailets.GuessClassificationMailet.java
private Executor createHttpExecutor() throws MailetException { try {/*from www . j ava2 s. c o 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));/*from w ww .j ava2 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 w w w . ja va 2 s .co m * @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; }