List of usage examples for java.net URI getScheme
public String getScheme()
From source file:com.kloudtek.kloudmake.service.filestore.FileStore.java
public synchronized DataFile create(@NotNull String uri) throws IOException, TemplateException { URI u = URI.create(uri); if (isEmpty(u.getScheme())) { throw new IllegalArgumentException("Invalid uri " + uri); }/*from w w w . j a va 2s . co m*/ if (u.getScheme().equals("libfile")) { return new LocalDataFile(u.getSchemeSpecificPart()); } else { return null; } }
From source file:com.abiquo.abiserver.pojo.service.RemoteService.java
/** * Sets the uri.//w w w . j av a 2 s .com * * @param uri the new uri */ public void setUri(final String uri) { this.uri = uri; URI u = URI.create(uri); this.protocol = fixProtocol(u.getScheme()); this.domainName = u.getHost(); this.port = u.getPort(); if (port == -1) { port = 80; } this.serviceMapping = u.getPath(); if (serviceMapping.startsWith("/")) { serviceMapping = serviceMapping.replaceFirst("/", ""); } }
From source file:functionalTests.multiprotocol.TestVFSProviderMultiProtocol.java
/** * Testing the File server deployment using multi-protocol * @throws Exception//from www .j a va 2 s .c o m */ @Test public void testVFSProviderMP() throws Exception { logger.info("**************** Testing deploying dataspace server with protocol list : " + protocolsToTest); CentralPAPropertyRepository.PA_COMMUNICATION_PROTOCOL.setValue(protocolsToTest.get(0)); String add_str = protocolsToTest.get(1); for (int i = 2; i < protocolsToTest.size(); i++) { add_str += "," + protocolsToTest.get(i); } CentralPAPropertyRepository.PA_COMMUNICATION_ADDITIONAL_PROTOCOLS.setValue(add_str); FileSystemServerDeployer deployer = new FileSystemServerDeployer("space name", SERVER_PATH.getAbsolutePath(), true); try { String[] urls = deployer.getVFSRootURLs(); logger.info("Received urls :" + Arrays.asList(urls)); Assert.assertEquals( "Number of urls of the FileSystemServerDeployer should match the number of protocols + the file protocol", protocolsToTest.size() + 1, urls.length); // check the file server uris URI receiveduri = new URI(urls[0]); Assert.assertEquals("protocol of first uri " + receiveduri + " should be file", "file", receiveduri.getScheme()); for (int i = 1; i < urls.length; i++) { receiveduri = new URI(urls[i]); Assert.assertEquals("protocol of uri " + urls[i] + " should match the expected protocol", "pap" + protocolsToTest.get(i - 1), receiveduri.getScheme()); } // use the file server for (int i = 0; i < urls.length; i++) { File f = new File(System.getProperty("java.io.tmpdir"), "testfile_" + i); f.createNewFile(); logger.info("Trying to use : " + urls[i]); FileObject source = fileSystemManager.resolveFile(f.toURI().toURL().toExternalForm()); FileObject dest = fileSystemManager.resolveFile(urls[i] + "/" + f.getName()); dest.copyFrom(source, Selectors.SELECT_SELF); Assert.assertTrue("Copy successful of " + source.getURL() + " to " + dest.getURL(), dest.exists()); } } finally { deployer.terminate(); } }
From source file:com.eviware.soapui.impl.rest.actions.oauth.OltuOAuth2ClientFacade.java
private void appendAccessTokenToQuery(HttpRequestBase request, OAuthBearerClientRequest oAuthClientRequest) throws OAuthSystemException { String queryString = getQueryStringFromOAuthClientRequest(oAuthClientRequest); URI oldUri = request.getURI(); String requestQueryString = oldUri.getQuery() != null ? oldUri.getQuery() + "&" + queryString : queryString; try {/* www. jav a 2 s . co m*/ request.setURI(URIUtils.createURI(oldUri.getScheme(), oldUri.getHost(), oldUri.getPort(), oldUri.getRawPath(), requestQueryString, oldUri.getFragment())); } catch (URISyntaxException e) { throw new OAuthSystemException(e); } }
From source file:net.i2cat.netconf.NetconfSession.java
public NetconfSession(SessionContext sessionContext, TransportFactory transportFactory) throws TransportNotRegisteredException, ConfigurationException { this.transportFactory = transportFactory; this.sessionContext = sessionContext; URI uri = sessionContext.getURI(); if (uri.getScheme() == null || uri.getHost() == null || uri.getUserInfo() == null) throw new ConfigurationException("Insufficient information in session context's URI: " + uri); if (!transportFactory.isAwareOfScheme(uri.getScheme())) { throw new TransportNotRegisteredException( "Scheme '" + uri.getScheme() + "' given in URI has not been registered with TransportFactory."); }//w w w.jav a 2 s. co m }
From source file:com.github.fge.jsonschema.load.URIManager.java
/** * Get the content at a given URI as a {@link JsonNode} * * @param uri the URI/*from w w w . j av a 2 s . com*/ * @return the content * @throws ProcessingException scheme is not registered, failed to get * content, or content is not JSON */ public JsonNode getContent(final URI uri) throws ProcessingException { Preconditions.checkNotNull(uri, "null URI"); final URI target = schemaRedirects.containsKey(uri) ? schemaRedirects.get(uri) : uri; if (!target.isAbsolute()) throw new ProcessingException(BUNDLE.message("uriNotAbsolute").put("uri", uri)); final String scheme = target.getScheme(); final URIDownloader downloader = downloaders.get(scheme); if (downloader == null) throw new ProcessingException(BUNDLE.message("unhandledScheme").put("uri", uri).put("scheme", scheme)); final InputStream in; try { in = downloader.fetch(target); return READER.readTree(in); } catch (JsonProcessingException e) { throw new ProcessingException( BUNDLE.message("uriNotJson").put("uri", uri).put("parsingMessage", e.getOriginalMessage())); } catch (IOException e) { throw new ProcessingException( BUNDLE.message("uriIOError").put("uri", uri).put("exceptionMessage", e.getMessage())); } }
From source file:com.linkedin.r2.message.rest.QueryTunnelUtil.java
/** * @param request a RestRequest object to be encoded as a tunneled POST * @param requestContext a RequestContext object associated with the request * @param threshold the size of the query params above which the request will be encoded * * @return an encoded RestRequest//w w w . ja v a2 s . c o m */ public static RestRequest encode(final RestRequest request, RequestContext requestContext, int threshold) throws URISyntaxException, MessagingException, IOException { URI uri = request.getURI(); // Check to see if we should tunnel this request by testing the length of the query // if the query is NULL, we won't bother to encode. // 0 length is a special case that could occur with a url like http://www.foo.com? // which we don't want to encode, because we'll lose the "?" in the process // Otherwise only encode queries whose length is greater than or equal to the // threshold value. String query = uri.getRawQuery(); boolean forceQueryTunnel = requestContext.getLocalAttr(R2Constants.FORCE_QUERY_TUNNEL) != null && (Boolean) requestContext.getLocalAttr(R2Constants.FORCE_QUERY_TUNNEL); if (query == null || query.length() == 0 || (query.length() < threshold && !forceQueryTunnel)) { return request; } RestRequestBuilder requestBuilder = new RestRequestBuilder(request); // reconstruct URI without query uri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), null, uri.getFragment()); // If there's no existing body, just pass the request as x-www-form-urlencoded ByteString entity = request.getEntity(); if (entity == null || entity.length() == 0) { requestBuilder.setHeader(HEADER_CONTENT_TYPE, FORM_URL_ENCODED); requestBuilder.setEntity(ByteString.copyString(query, Data.UTF_8_CHARSET)); } else { // If we have a body, we must preserve it, so use multipart/mixed encoding MimeMultipart multi = createMultiPartEntity(entity, request.getHeader(HEADER_CONTENT_TYPE), query); requestBuilder.setHeader(HEADER_CONTENT_TYPE, multi.getContentType()); ByteArrayOutputStream os = new ByteArrayOutputStream(); multi.writeTo(os); requestBuilder.setEntity(ByteString.copy(os.toByteArray())); } // Set the base uri, supply the original method in the override header, and change method to POST requestBuilder.setURI(uri); requestBuilder.setHeader(HEADER_METHOD_OVERRIDE, requestBuilder.getMethod()); requestBuilder.setMethod(RestMethod.POST); return requestBuilder.build(); }
From source file:eionet.gdem.utils.Utils.java
/** * Utility method for checking whether the resource exists. The resource can be web or file system resource that matches the URI * with "http", "https" or "file" schemes Returns false, if the resource does not exist * * @param strUri/*from ww w . jav a 2 s. c o m*/ * @return */ public static boolean resourceExists(String strUri) { strUri = StringUtils.replace(strUri, "\\", "/"); try { URI uri = new URI(strUri); String scheme = uri.getScheme(); if (scheme.startsWith("http")) { return HttpUtils.urlExists(strUri); } else if (scheme.equals("file")) { File f = new File(uri.getPath()); return f.exists(); } } catch (URISyntaxException e) { e.printStackTrace(); return false; } return false; }
From source file:com.seajas.search.attender.service.mail.MailService.java
/** * Switch the e-mail sender to the inputted mail server, if applicable. *//*from w w w . j a v a2 s .c o m*/ public void updateWorkingMailServer() { // Use the mail-server override if one has been entered and validated if (attenderService.validateCurrentMailServerDetails()) try { MailSettings settings = attenderService.getMailServerDetails(); URI hostnameURI = settings.getHostnameUri(); ((JavaMailSenderImpl) sender).setHost(hostnameURI.getHost()); Integer schemeStandardPort = "smtps".equals(hostnameURI.getScheme()) ? 465 : 25; ((JavaMailSenderImpl) sender) .setPort(hostnameURI.getPort() != -1 ? hostnameURI.getPort() : schemeStandardPort); if (!StringUtils.isEmpty(settings.getUsername())) ((JavaMailSenderImpl) sender).setUsername(settings.getUsername()); if (!StringUtils.isEmpty(settings.getPassword())) ((JavaMailSenderImpl) sender).setPassword(settings.getPassword()); ((JavaMailSenderImpl) sender).setProtocol(hostnameURI.getScheme()); if (StringUtils.isEmpty(settings.getUsername()) && StringUtils.isEmpty(settings.getPassword())) ((JavaMailSenderImpl) sender).getJavaMailProperties() .setProperty("mail." + hostnameURI.getScheme() + ".auth", "true"); fromAddress = settings.getSender(); } catch (URISyntaxException e) { logger.error("Could not set the given mail settings."); } }
From source file:cn.isif.util_plus.http.client.util.URIBuilder.java
private void digestURI(final URI uri) { this.scheme = uri.getScheme(); this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart(); this.encodedAuthority = uri.getRawAuthority(); this.host = uri.getHost(); this.port = uri.getPort(); this.encodedUserInfo = uri.getRawUserInfo(); this.userInfo = uri.getUserInfo(); this.encodedPath = uri.getRawPath(); this.path = uri.getPath(); this.encodedQuery = uri.getRawQuery(); this.queryParams = parseQuery(uri.getRawQuery()); this.encodedFragment = uri.getRawFragment(); this.fragment = uri.getFragment(); }