List of usage examples for java.net URL getDefaultPort
public int getDefaultPort()
From source file:org.springframework.security.oauth.provider.CoreOAuthProviderSupport.java
/** * Normalize the URL for use in the signature. The OAuth spec says the URL protocol and host are to be lower-case, * and the query and fragments are to be stripped. * * @param url The URL./* w ww . j a va 2 s .c om*/ * @return The URL normalized for use in the signature. */ protected String normalizeUrl(String url) { try { URL requestURL = new URL(url); StringBuilder normalized = new StringBuilder(requestURL.getProtocol().toLowerCase()).append("://") .append(requestURL.getHost().toLowerCase()); if ((requestURL.getPort() >= 0) && (requestURL.getPort() != requestURL.getDefaultPort())) { normalized.append(":").append(requestURL.getPort()); } normalized.append(requestURL.getPath()); return normalized.toString(); } catch (MalformedURLException e) { throw new IllegalStateException("Illegal URL for calculating the OAuth signature.", e); } }
From source file:com.tingtingapps.securesms.mms.LegacyMmsConnection.java
protected CloseableHttpClient constructHttpClient() throws IOException { RequestConfig config = RequestConfig.custom().setConnectTimeout(20 * 1000) .setConnectionRequestTimeout(20 * 1000).setSocketTimeout(20 * 1000).setMaxRedirects(20).build(); URL mmsc = new URL(apn.getMmsc()); CredentialsProvider credsProvider = new BasicCredentialsProvider(); if (apn.hasAuthentication()) { credsProvider.setCredentials(/*from w w w. ja v a2 s.c o m*/ new AuthScope(mmsc.getHost(), mmsc.getPort() > -1 ? mmsc.getPort() : mmsc.getDefaultPort()), new UsernamePasswordCredentials(apn.getUsername(), apn.getPassword())); } return HttpClients.custom().setConnectionReuseStrategy(new NoConnectionReuseStrategyHC4()) .setRedirectStrategy(new LaxRedirectStrategy()) .setUserAgent(TextSecurePreferences.getMmsUserAgent(context, USER_AGENT)) .setConnectionManager(new BasicHttpClientConnectionManager()).setDefaultRequestConfig(config) .setDefaultCredentialsProvider(credsProvider).build(); }
From source file:org.smssecure.smssecure.mms.LegacyMmsConnection.java
protected CloseableHttpClient constructHttpClient() throws IOException { RequestConfig config = RequestConfig.custom().setConnectTimeout(20 * 1000) .setConnectionRequestTimeout(20 * 1000).setSocketTimeout(20 * 1000).setMaxRedirects(20).build(); URL mmsc = new URL(apn.getMmsc()); CredentialsProvider credsProvider = new BasicCredentialsProvider(); if (apn.hasAuthentication()) { credsProvider.setCredentials(//from w w w. j a va 2 s . com new AuthScope(mmsc.getHost(), mmsc.getPort() > -1 ? mmsc.getPort() : mmsc.getDefaultPort()), new UsernamePasswordCredentials(apn.getUsername(), apn.getPassword())); } return HttpClients.custom().setConnectionReuseStrategy(new NoConnectionReuseStrategyHC4()) .setRedirectStrategy(new LaxRedirectStrategy()) .setUserAgent(SilencePreferences.getMmsUserAgent(context, USER_AGENT)) .setConnectionManager(new BasicHttpClientConnectionManager()).setDefaultRequestConfig(config) .setDefaultCredentialsProvider(credsProvider).build(); }
From source file:com.predic8.membrane.core.rules.SOAPProxy.java
/** * @return error or null for success/* w ww . j a va2 s . c om*/ */ private void parseWSDL() throws Exception { WSDLParserContext ctx = new WSDLParserContext(); ctx.setInput(ResolverMap.combine(router.getBaseLocation(), wsdl)); try { WSDLParser wsdlParser = new WSDLParser(); wsdlParser.setResourceResolver(resolverMap.toExternalResolver().toExternalResolver()); Definitions definitions = wsdlParser.parse(ctx); List<Service> services = definitions.getServices(); if (services.size() != 1) throw new IllegalArgumentException("There are " + services.size() + " services defined in the WSDL, but exactly 1 is required for soapProxy."); Service service = services.get(0); if (StringUtils.isEmpty(name)) name = StringUtils.isEmpty(service.getName()) ? definitions.getName() : service.getName(); List<Port> ports = service.getPorts(); Port port = selectPort(ports, portName); String location = port.getAddress().getLocation(); if (location == null) throw new IllegalArgumentException("In the WSDL, there is no @location defined on the port."); try { URL url = new URL(location); target.setHost(url.getHost()); if (url.getPort() != -1) target.setPort(url.getPort()); else target.setPort(url.getDefaultPort()); if (key.getPath() == null) { key.setUsePathPattern(true); key.setPathRegExp(false); key.setPath(url.getPath()); } else { targetPath = url.getPath(); } if (location.startsWith("https")) { SSLParser sslOutboundParser = new SSLParser(); target.setSslParser(sslOutboundParser); } ((ServiceProxyKey) key).setMethod("*"); } catch (MalformedURLException e) { throw new IllegalArgumentException("WSDL endpoint location '" + location + "' is not an URL.", e); } return; } catch (Exception e) { Throwable f = e; while (f.getCause() != null && !(f instanceof ResourceRetrievalException)) f = f.getCause(); if (f instanceof ResourceRetrievalException) { ResourceRetrievalException rre = (ResourceRetrievalException) f; if (rre.getStatus() >= 400) throw rre; Throwable cause = rre.getCause(); if (cause != null) { if (cause instanceof UnknownHostException) throw (UnknownHostException) cause; else if (cause instanceof ConnectException) throw (ConnectException) cause; } } throw new IllegalArgumentException("Could not download the WSDL '" + wsdl + "'.", e); } }
From source file:savant.agp.HTTPBrowser.java
public HTTPBrowser(URL rootURL) throws IOException { host = rootURL.getHost();/*from w w w .j a v a 2s. c o m*/ int p = rootURL.getPort(); port = p != -1 ? p : rootURL.getDefaultPort(); rootDir = new File(rootURL.getPath()); curDir = rootDir; setLayout(new BorderLayout()); addressLabel = new JLabel(); add(addressLabel, BorderLayout.NORTH); add(getToolBar(), BorderLayout.SOUTH); table = new JTable(); updateDirectory(); table.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent evt) { if (evt.getClickCount() == 2) { String f = ((HTTPTableModel) table.getModel()).getEntry(table.rowAtPoint(evt.getPoint())); if (f.equals("..")) { // Going up a directory. curDir = curDir.getParentFile(); updateDirectory(); } else if (!f.contains(".")) { if (f.startsWith("/")) { curDir = new File(f); } else { curDir = new File(curDir, f); } updateDirectory(); } else { openIndexAs(table.rowAtPoint(evt.getPoint()), OpenAsOption.TRACK); } } } }); JScrollPane scrollPane = new JScrollPane(table); scrollPane.getViewport().setBackground(Color.WHITE); scrollPane.setPreferredSize(new Dimension(800, 500)); add(scrollPane, BorderLayout.CENTER); this.setPreferredSize(new Dimension(800, 500)); }
From source file:org.spiffyui.server.AuthServlet.java
/** * The JDK will return -1 for the port number if no port is specified, but the URLs can * also have a default port. This method handles getting the port number including the * default ports for the URL./*from www.j a v a2s. c om*/ * * @param url the URL to get the port for * * @return the port from the URL */ private int getPort(URL url) { if (url.getPort() == -1) { return url.getDefaultPort(); } else { return url.getPort(); } }
From source file:jeeves.utils.XmlRequest.java
public XmlRequest(URL url) { this(url.getHost(), url.getPort() == -1 ? url.getDefaultPort() : url.getPort(), url.getProtocol()); address = url.getPath();// w w w. j a v a 2 s .c o m query = url.getQuery(); }
From source file:jeeves.utils.XmlRequest.java
public void setUrl(URL url) { host = url.getHost();//from w w w. j av a 2 s.c o m port = (url.getPort() == -1) ? url.getDefaultPort() : url.getPort(); protocol = url.getProtocol(); address = url.getPath(); query = url.getQuery(); }
From source file:IntergrationTest.OCSPIntegrationTest.java
private byte[] httpGetBin(URI uri, boolean bActiveCheckUnknownHost) throws Exception { InputStream is = null;/*from www .j a v a 2 s . com*/ InputStream is_temp = null; try { if (uri == null) return null; URL url = uri.toURL(); if (bActiveCheckUnknownHost) { url.getProtocol(); String host = url.getHost(); int port = url.getPort(); if (port == -1) port = url.getDefaultPort(); InetSocketAddress isa = new InetSocketAddress(host, port); if (isa.isUnresolved()) { //fix JNLP popup error issue throw new UnknownHostException("Host Unknown:" + isa.toString()); } } HttpURLConnection uc = (HttpURLConnection) url.openConnection(); uc.setDoInput(true); uc.setAllowUserInteraction(false); uc.setInstanceFollowRedirects(true); setTimeout(uc); String contentEncoding = uc.getContentEncoding(); int len = uc.getContentLength(); // is = uc.getInputStream(); if (contentEncoding != null && contentEncoding.toLowerCase().indexOf("gzip") != -1) { is_temp = uc.getInputStream(); is = new GZIPInputStream(is_temp); } else if (contentEncoding != null && contentEncoding.toLowerCase().indexOf("deflate") != -1) { is_temp = uc.getInputStream(); is = new InflaterInputStream(is_temp); } else { is = uc.getInputStream(); } if (len != -1) { int ch, i = 0; byte[] res = new byte[len]; while ((ch = is.read()) != -1) { res[i++] = (byte) (ch & 0xff); } return res; } else { ArrayList<byte[]> buffer = new ArrayList<>(); int buf_len = 1024; byte[] res = new byte[buf_len]; int ch, i = 0; while ((ch = is.read()) != -1) { res[i++] = (byte) (ch & 0xff); if (i == buf_len) { //rotate buffer.add(res); i = 0; res = new byte[buf_len]; } } int total_len = buffer.size() * buf_len + i; byte[] buf = new byte[total_len]; for (int j = 0; j < buffer.size(); j++) { System.arraycopy(buffer.get(j), 0, buf, j * buf_len, buf_len); } if (i > 0) { System.arraycopy(res, 0, buf, buffer.size() * buf_len, i); } return buf; } } catch (Exception e) { e.printStackTrace(); return null; } finally { closeInputStream(is_temp); closeInputStream(is); } }