List of usage examples for java.net URI getPort
public int getPort()
From source file:org.keycloak.adapters.cloned.HttpClientBuilder.java
/** * Configures a the proxy to use for auth-server requests if provided. * <p>// w w w .j a v a 2 s .c o m * If the given {@link AdapterHttpClientConfig} contains the attribute {@code proxy-url} we use the * given URL as a proxy server, otherwise the proxy configuration is ignored. * </p> * * @param adapterConfig */ private void configureProxyForAuthServerIfProvided(AdapterHttpClientConfig adapterConfig) { if (adapterConfig == null || adapterConfig.getProxyUrl() == null || adapterConfig.getProxyUrl().trim().isEmpty()) { return; } URI uri = URI.create(adapterConfig.getProxyUrl()); this.proxyHost = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); }
From source file:com.chigix.bio.proxy.buffer.FixedBufferTest.java
License:asdf
@Test public void testURI() { try {//from w w w.j av a2s . co m URI uri = new URI( "http://www.baidu.com/awefawgwage/awefwfa/wefafwef/awdfa?safwefawf=awefaf&afwef=fafwef"); System.out.println(uri.getScheme()); System.out.println(uri.getHost()); System.out.println(uri.getPort()); System.out.println(uri.getQuery()); System.out.println(uri.getPath()); } catch (URISyntaxException ex) { Logger.getLogger(FixedBufferTest.class.getName()).log(Level.SEVERE, null, ex); } String illegalQuery = "http://sclick.baidu.com/w.gif?q=a&fm=se&T=1423492890&y=55DFFF7F&rsv_cache=0&rsv_pre=0&rsv_reh=109_130_149_109_85_195_85_85_85_85|540&rsv_scr=1899_1720_0_0_1080_1920&rsv_sid=10383_1469_12498_10902_11101_11399_11277_11241_11401_12550_11243_11403_12470&cid=0&qid=fd67eec000006821&t=1423492880700&rsv_iorr=1&rsv_tn=baidu&path=http%3A%2F%2Fwww.baidu.com%2Fs%3Fie%3Dutf-8%26f%3D8%26rsv_bp%3D1%26rsv_idx%3D1%26ch%3D%26tn%3Dbaidu%26bar%3D%26wd%3Da%26rn%3D%26rsv_pq%3Dda7dc5fb00004904%26rsv_t%3D55188AMIFp8JX4Jb3hJkfCZHYxQdZOBK%252FhV0kLFfAPijGGrceXBoFpnHzmI%26rsv_enter%3D1%26inputT%3D111"; URI uri; while (true) { try { uri = new URI(illegalQuery); } catch (URISyntaxException ex) { System.out.println(illegalQuery); System.out.println(illegalQuery.charAt(ex.getIndex())); System.out.println(illegalQuery.substring(0, ex.getIndex())); System.out.println(illegalQuery.substring(ex.getIndex() + 1)); try { illegalQuery = illegalQuery.substring(0, ex.getIndex()) + URLEncoder.encode(String.valueOf(illegalQuery.charAt(ex.getIndex())), "utf-8") + illegalQuery.substring(ex.getIndex() + 1); } catch (UnsupportedEncodingException ex1) { } System.out.println(illegalQuery); continue; } break; } System.out.println("SCHEME: " + uri.getScheme()); System.out.println("HOST: " + uri.getHost()); System.out.println("path: " + uri.getRawPath()); System.out.println("query: " + uri.getRawQuery()); System.out.println("PORT: " + uri.getPort()); }
From source file:oracle.custom.ui.servlet.ConfigInputCheck.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w ww. j a v a 2s . co m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("processing ConfigInputCheck request"); try { PrintWriter out = response.getWriter(); String whichform = request.getParameter("whichform"); String domain = request.getParameter("domain"); String idcsUrl = request.getParameter("idcsUrl"); String myUrl = request.getParameter("myUrl"); String clientId = request.getParameter("clientId"); String clientSecret = request.getParameter("clientSecret"); String appId = request.getParameter("appId"); String appSecret = request.getParameter("appSecret"); switch (whichform) { case "checkOpenID": OpenIdConfiguration openidConf = OpenIdConfiguration.getButDontSave(idcsUrl); URIBuilder builder = new URIBuilder(openidConf.getAuthzEndpoint()); builder.addParameter("client_id", clientId); builder.addParameter("response_type", "code"); builder.addParameter("redirect_uri", myUrl + "atreturn/"); builder.addParameter("scope", "urn:opc:idm:t.user.me openid urn:opc:idm:__myscopes__"); builder.addParameter("nonce", UUID.randomUUID().toString()); URI url = builder.build(); System.out.println("URL: " + url.toString()); // now go get it HttpClient client = ServerUtils.getClient(); HttpGet get = new HttpGet(url); HttpHost host = new HttpHost(url.getHost(), url.getPort(), url.getScheme()); HttpResponse httpResponse = client.execute(host, get); try { // IDCS behavior has changed. // older versions returned 303 with a Location: header // current version returns 200 with HTML if ((httpResponse.getStatusLine().getStatusCode() == 303) || (httpResponse.getStatusLine().getStatusCode() == 200)) { System.out.println("Request seems to have worked"); out.print("Success?"); } else throw new ServletException("Invalid status from OAuth AZ URL. Expected 303, got " + httpResponse.getStatusLine().getStatusCode()); } finally { if (response instanceof CloseableHttpResponse) { ((CloseableHttpResponse) response).close(); } } break; default: throw new Exception("Invalid request"); } } catch (Exception e) { e.printStackTrace(); throw new ServletException("Error."); } }
From source file:com.sun.jersey.client.apache.DefaultApacheHttpMethodExecutor.java
private HostConfiguration getHostConfiguration(HttpClient client, Map<String, Object> props) { Object proxy = props.get(ApacheHttpClientConfig.PROPERTY_PROXY_URI); if (proxy != null) { URI proxyUri = getProxyUri(proxy); String proxyHost = proxyUri.getHost(); if (proxyHost == null) { proxyHost = "localhost"; }//w w w . j av a 2 s.c om int proxyPort = proxyUri.getPort(); if (proxyPort == -1) { proxyPort = 8080; } HostConfiguration hostConfig = new HostConfiguration(client.getHostConfiguration()); String setHost = hostConfig.getProxyHost(); int setPort = hostConfig.getProxyPort(); if ((setHost == null) || (!setHost.equals(proxyHost)) || (setPort == -1) || (setPort != proxyPort)) { hostConfig.setProxyHost(new ProxyHost(proxyHost, proxyPort)); } return hostConfig; } else { return null; } }
From source file:com.alibaba.antx.config.resource.DefaultAuthenticationHandler.java
private String getKey(URI uri) { StringBuffer buf = new StringBuffer(); buf.append(uri.getScheme()).append("://"); String user = ResourceUtil.getUsername(uri); if (!StringUtil.isEmpty(user)) { buf.append(user).append("@"); }/* w w w . j a v a 2 s .co m*/ buf.append(uri.getHost()); if (uri.getPort() > 0) { buf.append(":").append(uri.getPort()); } return buf.toString(); }
From source file:org.trancecode.xproc.step.RequestParser.java
public XProcHttpRequest parseRequest(final XdmNode requestNode, final Processor processor) { final String method = requestNode.getAttributeValue(XProcXmlModel.Attributes.METHOD); if (Strings.isNullOrEmpty(method)) { throw XProcExceptions.xc0006(requestNode); }/*from ww w .java 2s. c o m*/ request.setHeaders(parseHeaders(requestNode)); request.setEntity(parseMultipart(requestNode, processor)); if (!request.hasEntity()) { request.setEntity(parseBody(requestNode, processor)); } if (request.hasEntity()) { checkCoherenceHeaders(request.getHeaders(), request.getEntity(), requestNode); if (!(StringUtils.equalsIgnoreCase(HttpPut.METHOD_NAME, method) || StringUtils.equalsIgnoreCase(HttpPost.METHOD_NAME, method))) { throw XProcExceptions.xc0005(requestNode); } } final boolean status = Boolean.valueOf(requestNode.getAttributeValue(XProcXmlModel.Attributes.STATUS_ONLY)); final boolean detailed = Boolean.valueOf(requestNode.getAttributeValue(XProcXmlModel.Attributes.DETAILED)); if (status && !detailed) { throw XProcExceptions.xc0004(requestNode); } request.setDetailled(detailed); request.setStatusOnly(status); final String href = requestNode.getAttributeValue(XProcXmlModel.Attributes.HREF); final URI hrefUri = requestNode.getBaseURI().resolve(href); if (hrefUri.getPort() != -1) { request.setHttpHost(new HttpHost(hrefUri.getHost(), hrefUri.getPort(), hrefUri.getScheme())); } else { request.setHttpHost(new HttpHost(hrefUri.getHost())); } final CredentialsProvider credentialsProvider = parseAuthentication(requestNode); request.setCredentials(credentialsProvider); request.setHttpRequest(constructMethod(method, hrefUri)); request.setOverrideContentType( requestNode.getAttributeValue(XProcXmlModel.Attributes.OVERRIDE_CONTENT_TYPE)); return request; }
From source file:com.switchfly.inputvalidation.sanitizer.UrlStripHtmlSanitizer.java
@Override public String execute(String content) { if (StringUtils.isBlank(content)) { return content; }/*from w w w . java 2 s . co m*/ URI uri; try { uri = new URI(content); } catch (URISyntaxException e) { throw new RuntimeException(e); } List<NameValuePair> cleanedPairs = parse(uri); String queryString = cleanedPairs.isEmpty() ? null : URLEncodedUtils.format(cleanedPairs, ENCODING); try { return URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath(), queryString, uri.getFragment()).toString(); } catch (URISyntaxException e) { throw new RuntimeException(e); } }
From source file:org.apache.storm.scheduler.utils.ArtifactoryConfigLoader.java
private Map loadFromURI(URI uri) throws IOException { String host = uri.getHost();//from w w w . j a v a 2 s. c o m Integer port = uri.getPort(); String location = uri.getPath(); if (location.toLowerCase().startsWith(baseDirectory.toLowerCase())) { location = location.substring(baseDirectory.length()); } if (!cacheInitialized) { makeArtifactoryCache(location); } // Get the most recent artifact as a String, and then parse the yaml String yamlConfig = loadMostRecentArtifact(location, host, port); // If we failed to get anything from Artifactory try to get it from our local cache if (yamlConfig == null) { Map ret = getLatestFromCache(); updateLastReturned(ret); return ret; } // Now parse it and return the map. Yaml yaml = new Yaml(new SafeConstructor()); Map ret = null; try { ret = (Map) yaml.load(yamlConfig); } catch (Exception e) { LOG.error("Could not parse yaml."); return null; } if (ret != null) { LOG.debug("returning a new map from Artifactory"); updateLastReturned(ret); return ret; } return null; }
From source file:fi.mystes.synapse.mediator.ReadFileMediator.java
private InputStream processFtpSftpInput(URI aURI) throws JSchException, SftpException { JSch jsch = new JSch(); Session session = jsch.getSession(aURI.getUserInfo().substring(0, aURI.getUserInfo().indexOf(":")), aURI.getHost(), aURI.getPort()); session.setConfig("StrictHostKeyChecking", "no"); session.setPassword(aURI.getUserInfo().substring(aURI.getUserInfo().indexOf(":") + 1)); session.connect();/*w w w .j av a 2 s . c om*/ Channel channel = session.openChannel("sftp"); channel.connect(); ChannelSftp sftpChannel = (ChannelSftp) channel; return sftpChannel.get(aURI.getPath()); }
From source file:com.github.brandtg.pantopod.crawler.CrawlingEventHandler.java
private URI getNextUri(URI url, String href, String chroot) throws Exception { // if (href.contains("..")) { //// w w w .ja va 2s. com // 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(); }