List of usage examples for java.net URI getScheme
public String getScheme()
From source file:de.thingweb.client.ClientFactory.java
private void checkUri(String suri, int uriIndex, List<Client> clients) throws URISyntaxException { URI uri = new URI(suri); if (isCoapScheme(uri.getScheme())) { clients.add(new CoapClientImpl(thing, uriIndex)); log.info("Found matching client '" + CoapClientImpl.class.getName() + "'"); } else if (isHttpScheme(uri.getScheme())) { clients.add(new HttpClientImpl(thing, uriIndex)); log.info("Found matching client '" + HttpClientImpl.class.getName() + "'"); }//from ww w . j a va2 s. c o m }
From source file:ddf.catalog.plugin.groomer.metacard.StandardMetacardGroomerPlugin.java
private boolean isCatalogResourceUri(URI uri) { return uri != null && ContentItem.CONTENT_SCHEME.equals(uri.getScheme()); }
From source file:ru.histone.spring.mvc.HistoneWebAppResourceLoader.java
@Override public Resource load(String location, String baseLocation, Node... args) throws ResourceLoadException { URI fullLocation = makeFullLocation(location, baseLocation); Resource resource = null;//from w w w. j a v a2 s . c om if (fullLocation.getScheme().equals("webapp")) { resource = loadWebAppResource(fullLocation.getPath()); } else { resource = super.load(location, baseLocation, args); } return resource; }
From source file:com.subgraph.vega.impl.scanner.handlers.DirIPSCheck.java
private HttpUriRequest createRequest(IPathState ps, String query) { final URI baseUri = ps.getPath().getUri(); try {//w w w.j a va2s . com final URI newUri = new URI(baseUri.getScheme(), baseUri.getAuthority(), baseUri.getPath(), query, null); return new HttpGet(newUri); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } }
From source file:com.collective.celos.ci.deploy.JScpWorker.java
URI getURIRespectingUsername(URI uri) throws URISyntaxException { if (userName != null && uri.getUserInfo() == null) { uri = new URI(uri.getScheme(), userName, uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment());// ww w. ja v a2 s . co m } return uri; }
From source file:org.koboc.collect.android.utilities.WebUtils.java
/** * Common method for returning a parsed xml document given a url and the * http context and client objects involved in the web connection. * * @param urlString//ww w .j a v a 2 s.c o m * @param localContext * @param httpclient * @return */ public static DocumentFetchResult getXmlDocument(String urlString, HttpContext localContext, HttpClient httpclient) { URI u = null; try { URL url = new URL(urlString); u = url.toURI(); } catch (Exception e) { e.printStackTrace(); return new DocumentFetchResult(e.getLocalizedMessage() // + app.getString(R.string.while_accessing) + urlString); + ("while accessing") + urlString, 0); } if (u.getHost() == null) { return new DocumentFetchResult("Invalid server URL (no hostname): " + urlString, 0); } // if https then enable preemptive basic auth... if (u.getScheme().equals("https")) { enablePreemptiveBasicAuth(localContext, u.getHost()); } // set up request... HttpGet req = WebUtils.createOpenRosaHttpGet(u); HttpResponse response = null; try { response = httpclient.execute(req, localContext); int statusCode = response.getStatusLine().getStatusCode(); HttpEntity entity = response.getEntity(); if (statusCode != HttpStatus.SC_OK) { WebUtils.discardEntityBytes(response); if (statusCode == HttpStatus.SC_UNAUTHORIZED) { // clear the cookies -- should not be necessary? Collect.getInstance().getCookieStore().clear(); } String webError = response.getStatusLine().getReasonPhrase() + " (" + statusCode + ")"; return new DocumentFetchResult(u.toString() + " responded with: " + webError, statusCode); } if (entity == null) { String error = "No entity body returned from: " + u.toString(); Log.e(t, error); return new DocumentFetchResult(error, 0); } if (!entity.getContentType().getValue().toLowerCase(Locale.ENGLISH) .contains(WebUtils.HTTP_CONTENT_TYPE_TEXT_XML)) { WebUtils.discardEntityBytes(response); String error = "ContentType: " + entity.getContentType().getValue() + " returned from: " + u.toString() + " is not text/xml. This is often caused a network proxy. Do you need to login to your network?"; Log.e(t, error); return new DocumentFetchResult(error, 0); } // parse response Document doc = null; try { InputStream is = null; InputStreamReader isr = null; try { is = entity.getContent(); isr = new InputStreamReader(is, "UTF-8"); doc = new Document(); KXmlParser parser = new KXmlParser(); parser.setInput(isr); parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); doc.parse(parser); isr.close(); isr = null; } finally { if (isr != null) { try { // ensure stream is consumed... final long count = 1024L; while (isr.skip(count) == count) ; } catch (Exception e) { // no-op } try { isr.close(); } catch (Exception e) { // no-op } } if (is != null) { try { is.close(); } catch (Exception e) { // no-op } } } } catch (Exception e) { e.printStackTrace(); String error = "Parsing failed with " + e.getMessage() + "while accessing " + u.toString(); Log.e(t, error); return new DocumentFetchResult(error, 0); } boolean isOR = false; Header[] fields = response.getHeaders(WebUtils.OPEN_ROSA_VERSION_HEADER); if (fields != null && fields.length >= 1) { isOR = true; boolean versionMatch = false; boolean first = true; StringBuilder b = new StringBuilder(); for (Header h : fields) { if (WebUtils.OPEN_ROSA_VERSION.equals(h.getValue())) { versionMatch = true; break; } if (!first) { b.append("; "); } first = false; b.append(h.getValue()); } if (!versionMatch) { Log.w(t, WebUtils.OPEN_ROSA_VERSION_HEADER + " unrecognized version(s): " + b.toString()); } } return new DocumentFetchResult(doc, isOR); } catch (Exception e) { clearHttpConnectionManager(); e.printStackTrace(); String cause; Throwable c = e; while (c.getCause() != null) { c = c.getCause(); } cause = c.toString(); String error = "Error: " + cause + " while accessing " + u.toString(); Log.w(t, error); return new DocumentFetchResult(error, 0); } }
From source file:com.microsoft.tfs.core.util.URIUtils.java
/** * <p>//from w ww . j av a 2s .c o m * Ensures that the specified {@link URI}'s path component ends with a slash * character (<code>/</code>). * </p> * * <p> * {@link URI}s that will be resolved against should always have a trailing * slash in their path component. For more information, see Sun Java bug * 4666701 (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4666701). * </p> * * <p> * If the specified {@link URI} is opaque, it is returned. If the specified * {@link URI} is hierarchical and its path component already ends in a * slash, it is returned. Otherwise, a new {@link URI} is returned that is * identical to the specified {@link URI} except in its path component, * which will have a slash appended on. * </p> * * @param uri * a {@link URI} to check (must not be <code>null</code>) * @return a {@link URI} as described above (never <code>null</code>) */ public static URI ensurePathHasTrailingSlash(final URI uri) { Check.notNull(uri, "uri"); //$NON-NLS-1$ if (uri.isOpaque()) { return uri; } String path = uri.getPath(); if (path != null && path.endsWith("/")) //$NON-NLS-1$ { return uri; } if (path == null) { path = "/"; //$NON-NLS-1$ } else { path = path + "/"; //$NON-NLS-1$ } return newURI(uri.getScheme(), uri.getAuthority(), path, uri.getQuery(), uri.getFragment()); }
From source file:org.piraso.client.net.HttpBasicAuthenticationTest.java
@Test public void testAuthenticate() throws Exception { AbstractHttpClient client = mock(AbstractHttpClient.class); HttpContext context = mock(HttpContext.class); CredentialsProvider credentials = mock(CredentialsProvider.class); doReturn(credentials).when(client).getCredentialsProvider(); HttpBasicAuthentication auth = new HttpBasicAuthentication(client, context); auth.setUserName("username"); auth.setPassword("password"); URI uri = URI.create("http://localhost:8080/test"); auth.setTargetHost(new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme())); auth.execute();/*w w w.j a v a 2 s . c o m*/ verify(credentials).setCredentials(Matchers.<AuthScope>any(), Matchers.<Credentials>any()); verify(context).setAttribute(Matchers.<String>any(), any()); }
From source file:com.ibm.team.build.internal.hjplugin.util.HttpUtils.java
/** * For Basic auth, configure the context to do pre-emptive auth with the * credentials given./* ww w . ja v a 2 s. c om*/ * @param httpContext The context in use for the requests. * @param serverURI The RTC server we will be authenticating against * @param userId The userId to login with * @param password The password for the User * @param listener A listen to log messages to, Not required * @throws IOException Thrown if anything goes wrong */ private static void handleBasicAuthChallenge(HttpClientContext httpContext, String serverURI, String userId, String password, TaskListener listener) throws IOException { URI uri; try { uri = new URI(serverURI); } catch (URISyntaxException e) { throw new IOException(Messages.HttpUtils_invalid_server(serverURI), e); } HttpHost target = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(target.getHostName(), target.getPort()), new UsernamePasswordCredentials(userId, password)); httpContext.setAttribute(HttpClientContext.CREDS_PROVIDER, credsProvider); // Create AuthCache instance AuthCache authCache = new BasicAuthCache(); // Generate BASIC scheme object and add it to the local auth cache BasicScheme basicAuth = new BasicScheme(); authCache.put(target, basicAuth); // Add AuthCache to the execution context httpContext.setAuthCache(authCache); }
From source file:com.bazaarvoice.seo.sdk.util.BVUtilty.java
public static String removeBVQuery(String queryUrl) { final URI uri; try {//from w ww . j a v a 2 s. co m uri = new URI(queryUrl); } catch (URISyntaxException e) { return queryUrl; } try { String newQuery = null; if (uri.getQuery() != null && uri.getQuery().length() > 0) { List<NameValuePair> newParameters = new ArrayList<NameValuePair>(); List<NameValuePair> parameters = URLEncodedUtils.parse(uri.getQuery(), Charset.forName("UTF-8")); List<String> bvParameters = Arrays.asList("bvrrp", "bvsyp", "bvqap", "bvpage"); for (NameValuePair parameter : parameters) { if (!bvParameters.contains(parameter.getName())) { newParameters.add(parameter); } } newQuery = newParameters.size() > 0 ? URLEncodedUtils.format(newParameters, Charset.forName("UTF-8")) : null; } return new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), newQuery, null).toString(); } catch (URISyntaxException e) { return queryUrl; } }