@Override public boolean matches(WebRequest request) { URL url = request.getUrl(); String host = url.getHost(); if (this.hosts.contains(host)) { return true; } int port = url.getPort(); if (port == -1) { port = url.getDefaultPort(); } String hostAndPort = host + ":" + port; return this.hosts.contains(hostAndPort); }
/** * Gets the port from the casServiceURL ensuring to return the proper value if the * default port is being used. * @param casServiceUrl the casServerUrl to be used (i.e. * "https://example.com/context/login/cas") * @return the port that is configured for the casServerUrl */ private static int getServicePort(URL casServiceUrl) { int port = casServiceUrl.getPort(); if (port == -1) { port = casServiceUrl.getDefaultPort(); } return port; } }
private String getPoolKey(URL url) { return StringUtils.format( "%s://%s:%s", url.getProtocol(), url.getHost(), url.getPort() == -1 ? url.getDefaultPort() : url.getPort() ); } }
public static String getClientIp(String serviceUrl) { try { URL url = new URL(serviceUrl); int port = url.getPort(); if (port == -1) { port = url.getDefaultPort(); } try (Socket socket = new Socket(url.getHost(), port)) { return socket.getLocalAddress().getHostAddress(); } } catch (Exception e) { return SystemUtil.getFirstLocalNonLoopbackIpAddress(); } } }
/** * This constructor should only be used by extending classes * * @param authenticationType Pick the one which matches your authentication * @param httpMethod Choose POST / GET * @param loginUrl Full URL of the login page * @param username Username for Authentication * @param password Password for Authentication * * @throws MalformedURLException Make sure your URL is valid */ protected AuthInfo(AuthenticationType authenticationType, MethodType httpMethod, String loginUrl, String username, String password) throws MalformedURLException { this.authenticationType = authenticationType; this.httpMethod = httpMethod; URL url = new URL(loginUrl); this.protocol = url.getProtocol(); this.host = url.getHost(); this.port = url.getPort() == -1 ? url.getDefaultPort() : url.getPort(); this.loginTarget = url.getFile(); this.username = username; this.password = password; }
/** * 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. * @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); } }
public String getEndpoint() { URL url; try { url = new URL(getHost()); } catch (MalformedURLException e) { throw new IllegalArgumentException("Invalid host: " + getHost(), e); } return String.format( "%s:%s", url.getHost(), url.getPort() < 0 ? url.getDefaultPort() : url.getPort()); } }
/** * Constructs the request URI, per section 9.1.2 of the OAuth 1.0 * specification. * * @param request the incoming request to construct the URI from. * @return the constructed URI. */ private URI constructRequestURL(final OAuth1Request request) throws OAuth1SignatureException { try { final URL url = request.getRequestURL(); if (url == null) { throw new OAuth1SignatureException(); } final StringBuilder builder = new StringBuilder(url.getProtocol()).append("://").append(url.getHost().toLowerCase()); final int port = url.getPort(); if (port > 0 && port != url.getDefaultPort()) { builder.append(':').append(port); } builder.append(url.getPath()); return new URI(builder.toString()); } catch (final URISyntaxException mue) { throw new OAuth1SignatureException(mue); } }
if ((requestURL.getPort() >= 0) && (requestURL.getPort() != requestURL.getDefaultPort())) { url.append(":").append(requestURL.getPort());
port = url.getDefaultPort();
if (port == canonicalURL.getDefaultPort()) { port = -1;
private void ports(UriComponents uriComponents, MockHttpServletRequest request) { int serverPort = uriComponents.getPort(); request.setServerPort(serverPort); if (serverPort == -1) { int portConnection = this.webRequest.getUrl().getDefaultPort(); request.setLocalPort(serverPort); request.setRemotePort(portConnection); } else { request.setRemotePort(serverPort); } }
final int port = url.getPort() == -1 ? url.getDefaultPort() : url.getPort(); final ChannelFuture retVal; final ChannelFuture connectFuture = bootstrap.connect(new InetSocketAddress(host, port));
@Override public Object apply(List<Object> objects) { URL url = toUrl(objects.get(0)); if(url == null) { return null; } int port = url.getPort(); return port >= 0?port:url.getDefaultPort(); } }
final int urlPort = url.getPort()==-1?url.getDefaultPort():url.getPort(); final String urlProtocol = url.getProtocol(); final String urlStr = url.toString();
String host = url.getHost(); int port = url.getPort(); port = port > 0 ? port : url.toURL().getDefaultPort(); String path = "/upload" + url.getRawPath(); url = new GenericUrl(scheme + "://" + host + ":" + port + path);
public THttpClient(String url, HttpClient client) throws TTransportException { try { url_ = new URL(url); this.client = client; this.host = new HttpHost(url_.getHost(), -1 == url_.getPort() ? url_.getDefaultPort() : url_.getPort(), url_.getProtocol()); } catch (IOException iox) { throw new TTransportException(iox); } }
public static String getHostAndPort(String urlString) throws HttpException { try { URL url = new URL(urlString); String host = url.getHost(); int port = url.getPort(); if (port == -1) { port = url.getDefaultPort(); } return host + port; } catch (MalformedURLException e) { throw new HttpException("URL is ERROR", e); } } }
&& (urlPort != url.getDefaultPort())) { throw new CertificateException(String.format( "SigningCertificateChainUrl [%s] contains an invalid port [%d]",
int port = serviceUrl.getPort() != -1 ? serviceUrl.getPort() : serviceUrl.getDefaultPort(); HttpRequest request = new BasicHttpEntityEnclosingRequest("POST", path);