List of usage examples for java.net URI getScheme
public String getScheme()
From source file:org.geometerplus.android.fbreader.network.BearerAuthenticator.java
@Override protected boolean authenticate(URI uri, Map<String, String> params) { System.err.println("AUTHENTICATE FOR " + uri); if (!"https".equalsIgnoreCase(uri.getScheme())) { return false; }// w w w .j a v a2s . com return GooglePlayServicesUtil.isGooglePlayServicesAvailable(myActivity) == ConnectionResult.SUCCESS ? authenticateToken(uri, params) : authenticateWeb(uri, params); }
From source file:com.grendelscan.commons.http.apache_overrides.client.CustomHttpClient.java
public String getRequestHeadString(final HttpHost originalTarget, final HttpRequest request, final HttpContext originalContext) throws IOException, HttpException { HttpContext context = originalContext; HttpHost target = originalTarget;/*from www. j a va2s. co m*/ if (context == null) { context = createHttpContext(); } if (target == null) { URI uri = ((HttpUriRequest) request).getURI(); target = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); } context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, target); prepareRequest(request); getHttpProcessor().process(request, context); String requestString = request.getRequestLine().toString() + "\n"; for (Header header : request.getAllHeaders()) { requestString += header.toString() + "\n"; } return requestString; }
From source file:org.springframework.ws.transport.http.HttpComponentsMessageSender.java
/** * Sets the maximum number of connections per host for the underlying HttpClient. The maximum number of connections * per host can be set in a form accepted by the {@code java.util.Properties} class, like as follows: * <p/>/*from w w w.j av a2 s . co m*/ * <pre> * https://www.example.com=1 * http://www.example.com:8080=7 * http://www.springframework.org=10 * </pre> * <p/> * The host can be specified as a URI (with scheme and port). * * @param maxConnectionsPerHost a properties object specifying the maximum number of connection * @see org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager#setMaxForRoute(org.apache.http.conn.routing.HttpRoute, * int) */ public void setMaxConnectionsPerHost(Map<String, String> maxConnectionsPerHost) throws URISyntaxException { ClientConnectionManager connectionManager = getHttpClient().getConnectionManager(); if (!(connectionManager instanceof ThreadSafeClientConnManager)) { throw new IllegalArgumentException( "maxConnectionsPerHost is not supported on " + connectionManager.getClass().getName() + ". Use " + ThreadSafeClientConnManager.class.getName() + " instead"); } for (Object o : maxConnectionsPerHost.keySet()) { String host = (String) o; URI uri = new URI(host); HttpHost httpHost = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); int maxHostConnections = Integer.parseInt(maxConnectionsPerHost.get(host)); ((ThreadSafeClientConnManager) connectionManager).setMaxForRoute(new HttpRoute(httpHost), maxHostConnections); } }
From source file:de.betterform.connector.DefaultConnectorFactory.java
/** * Creates a new URI resolver for the specified URI. * * @param uri the relative or absolute URI string. * @param element the element to start with XML Base resolution for relative * URIs./*from w w w. ja v a 2s. co m*/ * @return a new URI resolver for the specified URI. * @throws XFormsException if a relative URI could not be resolved, if no * URI resolver is registered for the specified URI or any error occurred * during URI resolver creation. */ public URIResolver createURIResolver(final String uri, final Element element) throws XFormsException { URI uriObj = getAbsoluteURI(uri, element); if (LOGGER.isDebugEnabled()) { LOGGER.debug("creating uri resolver for '" + uriObj + "'"); } String className = Config.getInstance().getURIResolver(uriObj.getScheme()); if (className == null) { throw new XFormsException("no uri resolver registered for '" + uri + "'"); } Object instance = createInstance(className); if (!(instance instanceof URIResolver)) { throw new XFormsException("object instance of '" + className + "' is no uri resolver"); } URIResolver uriResolver = (URIResolver) instance; uriResolver.setURI(uriObj.toString()); uriResolver.setContext(getContext()); return uriResolver; }
From source file:org.bedework.synch.cnctrs.orgSyncV2.OrgSyncV2ConnectorInstance.java
@Override public URI getUri() throws SynchException { try {//from w w w . j av a 2 s . c om //Get yesterdays date final LocalDate yesterday = LocalDate.now().minus(1, ChronoUnit.DAYS); final String yesterdayStr = yesterday.format(DateTimeFormatter.ISO_LOCAL_DATE); final URI infoUri = new URI(info.getUri()); return new URIBuilder().setScheme(infoUri.getScheme()).setHost(infoUri.getHost()) .setPort(infoUri.getPort()).setPath(infoUri.getPath()) .setParameter("key", cnctr.getSyncher().decrypt(info.getPassword())) .setParameter("start_date", yesterdayStr).build(); } catch (final SynchException se) { throw se; } catch (final Throwable t) { throw new SynchException(t); } }
From source file:com.github.tomakehurst.wiremock.testsupport.WireMockTestClient.java
public WireMockResponse getViaProxy(String url, int proxyPort) { URI targetUri = URI.create(url); HttpHost proxy = new HttpHost(address, proxyPort, targetUri.getScheme()); HttpClient httpClientUsingProxy = HttpClientBuilder.create().disableAuthCaching().disableAutomaticRetries() .disableCookieManagement().disableRedirectHandling().setProxy(proxy).build(); try {//from www . j a v a2 s . c o m HttpHost target = new HttpHost(targetUri.getHost(), targetUri.getPort(), targetUri.getScheme()); HttpGet req = new HttpGet( targetUri.getPath() + (isNullOrEmpty(targetUri.getQuery()) ? "" : "?" + targetUri.getQuery())); req.removeHeaders("Host"); System.out.println("executing request to " + targetUri + "(" + target + ") via " + proxy); HttpResponse httpResponse = httpClientUsingProxy.execute(target, req); return new WireMockResponse(httpResponse); } catch (IOException ioe) { throw new RuntimeException(ioe); } }
From source file:com.ibm.watson.ta.retail.DemoServlet.java
/** * Build an executor for the specified url. This disables cookies and sets * preemptive authentication (creds are sent without waiting for a 401). * //from ww w . j av a 2s . c om * NOTE: This is required to avoid issues with load balancers that use * cookies due to Apache Http Client issue: * https://issues.apache.org/jira/browse/HTTPCLIENT-1451 * * @param url * @return */ private Executor buildExecutor(URI url) { return Executor.newInstance().auth(username, password) .authPreemptive(new HttpHost(url.getHost(), url.getPort(), url.getScheme())) .cookieStore(new CookieStore() { // Noop cookie store. public void addCookie(Cookie arg0) { } public void clear() { } public boolean clearExpired(Date arg0) { return false; } public List<Cookie> getCookies() { return Collections.emptyList(); } }); }
From source file:org.piraso.ui.api.views.URLTabView.java
@Override protected void populateMessage(MessageAwareEntry m) throws Exception { List<URI> urls = URLParser.parseUrls(m.getMessage()); int i = 0;/*from w w w.jav a2s . c o m*/ for (URI uri : urls) { try { if (i != 0) { insertKeyword(txtEditor, "\n\n"); } insertKeyword(txtEditor, String.format("[%d] Scheme: ", ++i)); insertCode(txtEditor, uri.getScheme()); insertKeyword(txtEditor, "\n Host: "); insertCode(txtEditor, uri.getHost()); if (uri.getPort() > 80) { insertKeyword(txtEditor, "\n Port: "); insertCode(txtEditor, String.valueOf(uri.getPort())); } insertKeyword(txtEditor, "\n Path: "); insertCode(txtEditor, uri.getPath()); String queryString = uri.getQuery(); if (StringUtils.isNotBlank(queryString)) { List<NameValuePair> params = URLEncodedUtils.parse(uri, "UTF-8"); insertKeyword(txtEditor, "\n Query String: "); for (NameValuePair nvp : params) { insertCode(txtEditor, "\n "); insertIdentifier(txtEditor, nvp.getName() + ": "); insertCode(txtEditor, nvp.getValue()); } } } catch (Exception e) { e.printStackTrace(); } } }
From source file:com.spotify.scio.util.RemoteFileUtil.java
private Path getDestination(URI src) throws IOException { String scheme = src.getScheme(); if (scheme == null) { scheme = "file"; }/*from w ww .j a v a 2 s . co m*/ // Sparkey expects a pair of ".spi" and ".spl" files with the same path. Hash URI prefix // before filename so that URIs with the same remote path have the same local one. E.g. // gs://bucket/path/data.spi -> /tmp/fd-gs-a1b2c3d4/data.spi // gs://bucket/path/data.spl -> /tmp/fd-gs-a1b2c3d4/data.spl String path = src.toString(); int idx = path.lastIndexOf('/'); String hash = Hashing.sha1().hashString(path.substring(0, idx), Charsets.UTF_8).toString().substring(0, HASH_LENGTH); String filename = path.substring(idx + 1); String tmpDir = System.getProperties().getProperty("java.io.tmpdir"); Path parent = Paths.get(tmpDir, String.format("fd-%s-%s", scheme, hash)); Files.createDirectories(parent); return parent.resolve(filename); }