List of usage examples for org.apache.http.client.utils URIBuilder setPort
public URIBuilder setPort(final int port)
From source file:org.n52.sos.service.it.SosITBase.java
/** * Get URI for the relative sos path and query using test host, port, and * basepath/*from w w w .j av a 2 s .c om*/ * * @param path * The relative test endpoint * @param query * Query parameters to add to the request * @return Constructed URI * @throws URISyntaxException */ protected URI getURI(String path, String query) throws URISyntaxException { URIBuilder b = new URIBuilder(); b.setScheme("http"); b.setHost(host); b.setPort(port); b.setPath(getPath(path)); b.setQuery(query); b.setFragment(null); return b.build(); }
From source file:com.github.brandtg.pantopod.crawler.CrawlingEventHandler.java
private URI getNextUri(URI url, String href, String chroot) throws Exception { // if (href.contains("..")) { ////from ww w .ja va2s .c o m // throw new IllegalArgumentException("Relative URI not allowed: " + href); // } URI hrefUri = URI.create(href.trim().replaceAll(" ", "+")); URIBuilder builder = new URIBuilder(); builder.setScheme(hrefUri.getScheme() == null ? url.getScheme() : hrefUri.getScheme()); builder.setHost(hrefUri.getHost() == null ? url.getHost() : hrefUri.getHost()); builder.setPort(hrefUri.getPort() == -1 ? url.getPort() : hrefUri.getPort()); if (hrefUri.getPath() != null) { StringBuilder path = new StringBuilder(); if (hrefUri.getHost() == null && chroot != null) { path.append(chroot); } // Ensure no two slashes if (hrefUri.getPath() != null && hrefUri.getPath().length() > 0 && hrefUri.getPath().charAt(0) == '/' && path.length() > 0 && path.charAt(path.length() - 1) == '/') { path.setLength(path.length() - 1); } path.append(hrefUri.getPath()); builder.setPath(chroot == null ? "" : chroot + hrefUri.getPath()); } if (hrefUri.getQuery() != null) { builder.setCustomQuery(hrefUri.getQuery()); } if (hrefUri.getFragment() != null) { builder.setFragment(hrefUri.getFragment()); } return builder.build(); }
From source file:com.net.plus.common.http.transport.AbstractHttpClientTransport.java
public URI getSendUrl() { try {//from www . j a v a 2 s.c o m if (StringUtils.hasText(url)) { return new URIBuilder(url).build(); } URIBuilder builder = new URIBuilder(); if (StringUtils.hasText(protocol)) { builder.setScheme(protocol); } if (StringUtils.hasText(host)) { builder.setHost(host); } if (port != -1) { builder.setPort(port); } if (StringUtils.hasText(target)) { builder.setPath(target); } if (StringUtils.hasText(queryString)) { builder.setQuery(queryString); } return builder.build(); } catch (Exception e) { 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 av a2 s .c o m*/ } } return uriBuilder.build(); }
From source file:com.github.woz_dialog.ros_woz_dialog_project.TTSHTTPClient.java
/** * Builds the REST clients for speech recognition and synthesis. * * @//from ww w.ja v a 2 s . c om */ private void buildClients() { // Initialize the HTTP clients asrClient = HttpClientBuilder.create().build(); ttsClient = HttpClientBuilder.create().build(); try { URIBuilder builder = new URIBuilder(); builder.setScheme("https"); builder.setHost("dictation.nuancemobility.net"); builder.setPort(443); builder.setPath("/NMDPAsrCmdServlet/dictation"); builder.setParameter("appId", APP_ID); builder.setParameter("appKey", APP_KEY); builder.setParameter("id", "0000"); asrURI = builder.build(); builder.setHost("tts.nuancemobility.net"); builder.setPath("/NMDPTTSCmdServlet/tts"); builder.setParameter("ttsLang", LANGUAGE); builder.setParameter("voice", VOICE); ttsURI = builder.build(); } catch (Exception e) { throw new RuntimeException("cannot build client: " + e); } }
From source file:org.duracloud.durastore.rest.ManifestRest.java
protected URI buildURI(String adminSpace, String contentId) throws URISyntaxException { String host = request.getAttribute(Constants.SERVER_HOST).toString(); int port = (Integer) request.getAttribute(Constants.SERVER_PORT); String context = request.getContextPath(); URIBuilder builder = new URIBuilder().setHost(host).setScheme("http" + (port == 443 ? "s" : "")) .setPath(context + "/" + adminSpace + "/" + contentId); if (port != 443 && port != 80) { builder = builder.setPort(port); }/*from w w w . j a v a2 s.com*/ return builder.build(); }
From source file:opendial.plugins.NuanceSpeech.java
/** * Builds the REST clients for speech recognition and synthesis. * /*w ww. ja v a2 s .c om*/ * @ */ private void buildClients() { // Initialize the HTTP clients asrClient = HttpClientBuilder.create().build(); ttsClient = HttpClientBuilder.create().build(); try { URIBuilder builder = new URIBuilder(); builder.setScheme("https"); builder.setHost("dictation.nuancemobility.net"); builder.setPort(443); builder.setPath("/NMDPAsrCmdServlet/dictation"); builder.setParameter("appId", system.getSettings().params.getProperty("id")); builder.setParameter("appKey", system.getSettings().params.getProperty("key")); builder.setParameter("id", system.getSettings().params.getProperty("0000")); asrURI = builder.build(); builder.setHost("tts.nuancemobility.net"); builder.setPath("/NMDPTTSCmdServlet/tts"); builder.setParameter("ttsLang", system.getSettings().params.getProperty("lang")); ttsURI = builder.build(); } catch (Exception e) { throw new RuntimeException("cannot build client: " + e); } }
From source file:org.zaizi.manifoldcf.authorities.authorities.alfresco.AlfrescoAuthorityConnector.java
/** * Check connection for sanity.//w ww .j a va2s . co m */ @Override public String check() throws ManifoldCFException { URIBuilder uri = new URIBuilder(); uri.setScheme(protocol); uri.setHost(server); uri.setPort(Integer.parseInt(port)); uri.setPath(path + USER_AUTHORITIES_URI); try { HttpResponse response = httpClient.execute(new HttpGet(uri.build())); EntityUtils.consume(response.getEntity()); if (response.getStatusLine().getStatusCode() != 200) { return "Connection not working! Check Configuration"; } } catch (Exception e) { return "Connection not working! Check Configuration"; } return super.check(); }