List of usage examples for java.net URI toString
public String toString()
From source file:org.wrml.runtime.rest.RestUtils.java
public static final MediaType extractMediaTypeFromDimensions(final Context context, final Dimensions dimensions) { final URI defaultFormatUri = context.getFormatLoader().getDefaultFormatUri(); final Map<String, String> mediaTypeParameters = new LinkedHashMap<>(6); mediaTypeParameters.put(SystemMediaType.PARAMETER_NAME_SCHEMA, dimensions.getSchemaUri().toString()); mediaTypeParameters.put(SystemMediaType.PARAMETER_NAME_FORMAT, defaultFormatUri.toString()); final List<String> embeddedLinkSlotNames = dimensions.getEmbeddedLinkSlotNames(); if (embeddedLinkSlotNames != null && !embeddedLinkSlotNames.isEmpty()) { mediaTypeParameters.put(SystemMediaType.PARAMETER_NAME_EMBED, RestUtils.formatListString(embeddedLinkSlotNames)); }/*from ww w . j a va 2s.c o m*/ final List<String> excludedSlotNames = dimensions.getExcludedSlotNames(); if (excludedSlotNames != null && !excludedSlotNames.isEmpty()) { mediaTypeParameters.put(SystemMediaType.PARAMETER_NAME_EXCLUDE, RestUtils.formatListString(excludedSlotNames)); } else { // INCLUDE and EXCLUDE are mutually exclusive paramaters, with precedence given to exclude (if both are // present). final List<String> includedSlotNames = dimensions.getIncludedSlotNames(); if (includedSlotNames != null && !includedSlotNames.isEmpty()) { mediaTypeParameters.put(SystemMediaType.PARAMETER_NAME_INCLUDE, RestUtils.formatListString(includedSlotNames)); } } final MediaType mediaType = new MediaType(SystemMediaType.TYPE_APPLICATION, SystemMediaType.SUBTYPE_WRML, mediaTypeParameters); return mediaType; }
From source file:org.altchain.neo4j.database.Database.java
public static URI getNodeFromIndexKey(String indexName, String key, Object value) { String indexUri = NODE_INDEX_ROOT + indexName + "/" + key + "/" + value.toString(); WebResource resource = Client.create().resource(indexUri); ClientResponse clientResponse = resource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON) .get(ClientResponse.class); String jsonString = clientResponse.getEntity(String.class); Object JSONResponse = JSONValue.parse(jsonString); // now get the node URI out of the object URI location = null; try {// ww w .j a v a 2s . c o m String path = (String) ((JSONObject) ((JSONArray) JSONResponse).get(0)).get("self"); location = URI.create(path); } catch (Exception e) { // didnt find anything return null; } logger.debug(String.format("GET from [%s], status code [%d], location header [%s]", indexUri, clientResponse.getStatus(), location.toString())); clientResponse.close(); return location; }
From source file:UriUtils.java
/** * Resolves the specified URI, and returns the file represented by the URI. * * @param uri The URI for which to return an absolute path. * @return The {@link File} instance represented by the specified URI. * @throws IllegalArgumentException <ul><li>The URI cannot be null.</li><li>Wrong URI scheme for path resolution; * only file:// URIs are supported.</li></ul> *///from w ww . j a va 2s . com public static File getFile(URI uri) throws IllegalArgumentException { if (uri == null) throw new IllegalArgumentException("The URI cannot be null."); if (!"file".equals(uri.getScheme())) throw new IllegalArgumentException("Wrong URI scheme for path resolution, expected \"file\" " + "and got \"" + uri.getScheme() + "\""); // Workaround for the following bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5086147 // Remove (or add, take your pick...) extra slashes after the scheme part. if (uri.getAuthority() != null) try { uri = new URI(uri.toString().replace("file://", "file:/")); } catch (URISyntaxException e) { throw new IllegalArgumentException( "The specified URI contains an authority, but could not be " + "normalized.", e); } return new File(uri); }
From source file:com.microsoft.alm.common.utils.UrlHelper.java
public static URI getCollectionURI(final URI serverUri, final String collectionName) { if (isVSO(serverUri) && getVSOAccountURI(collectionName).equals(serverUri)) { //collection in the domain case on VSTS return serverUri; }// ww w . ja va 2 s.com return UrlHelper.createUri(serverUri.toString().concat(URL_SEPARATOR).concat(collectionName)); }
From source file:com.ibm.amc.FileManager.java
/** * If the URI represents a temporary file, attempt to delete the corresponding file. * /*from w w w.j av a 2 s.c o m*/ * @param uri */ public static void deleteIfTemporaryFile(URI uri) { if (uri != null && uri.getScheme().equals(SCHEME)) { if (getFileForUri(uri).delete()) { if (logger.isDebugEnabled()) logger.debug("deleteIfTemporaryFile", "Deleted temporary file " + uri.toString()); } else { if (logger.isDebugEnabled()) logger.debug("deleteIfTemporaryFile", "Failed to delete temporary file " + uri.toString()); } // Check for unzip directory final File unzipDirectory = new File(getDownloadDirectory(), uri.getSchemeSpecificPart()); if (unzipDirectory.exists()) { try { FileUtils.deleteDirectory(unzipDirectory); if (logger.isDebugEnabled()) logger.debug("deleteIfTemporaryFile", "Deleted temporary directory " + unzipDirectory); } catch (final IOException e) { if (logger.isDebugEnabled()) logger.debug("deleteIfTemporaryFile", "Failed to delete temporary directory " + unzipDirectory); } } } }
From source file:com.adaptris.core.management.jetty.FromXmlConfig.java
private static URL createUrlFromString(String s) throws Exception { String destToConvert = backslashToSlash(s); URI configuredUri = null; try {/*from w w w. ja va 2s . c o m*/ configuredUri = new URI(destToConvert); } catch (URISyntaxException e) { // Specifically here to cope with file:///c:/ (which is // technically illegal according to RFC2396 but we need // to support it if (destToConvert.split(":").length >= 3) { configuredUri = new URI(URLEncoder.encode(destToConvert, "UTF-8")); } else { throw e; } } return configuredUri.getScheme() == null ? relativeConfig(configuredUri) : new URL(configuredUri.toString()); }
From source file:com.google.caja.precajole.StaticPrecajoleMap.java
public static String normalizeUri(String uri) { try {// w w w . j a va2s . co m URI u = new URI(uri).normalize(); if (u.getHost() != null) { u = new URI(lowercase(u.getScheme()), u.getUserInfo(), lowercase(u.getHost()), u.getPort(), u.getPath(), u.getQuery(), u.getFragment()); } else if (u.getScheme() != null) { u = new URI(lowercase(u.getScheme()), u.getSchemeSpecificPart(), u.getFragment()); } return u.toString(); } catch (URISyntaxException e) { return uri; } }
From source file:com.microsoft.tfs.client.clc.prompt.Prompt.java
/** * Makes an {@link UsernamePasswordCredentials} from OAuth2 flow * /*w w w. j ava2 s . co m*/ * Prompting the user with a browser * * @param display * the display to use (must not be <code>null</code>) * * @param persistCredentials * caller intend to persist the retrieved credential * * @return an {@link UsernamePasswordCredentials} object or * <code>null</code> if there was an error retrieving the credential * from OAuth2 flow. (for example, user closed the browser, or is * running on a Java runtime that does not support JavaFx) */ public static UsernamePasswordCredentials getCredentialsInteractively(final URI serverURI, final Display display, final boolean persistCredentials) { Check.notNull(display, "display"); //$NON-NLS-1$ Check.notNull(serverURI, "serverURI"); //$NON-NLS-1$ log.debug("Interactively retrieving credential based on oauth2 flow for " + serverURI.toString()); //$NON-NLS-1$ final SecretStore<TokenPair> accessTokenStore = new InsecureInMemoryStore<TokenPair>(); final SecretStore<Token> tokenStore = new InsecureInMemoryStore<Token>(); final Action<DeviceFlowResponse> deviceFlowCallback = new Action<DeviceFlowResponse>() { @Override public void call(final DeviceFlowResponse response) { display.printLine("------------------------------------"); //$NON-NLS-1$ display.printLine(Messages.getString("Command.DeviceFlowCallbackTitle")); //$NON-NLS-1$ display.printLine("------------------------------------"); //$NON-NLS-1$ display.printLine(Messages.getString("Command.DeviceFlowCallbackInstructionUrl")); //$NON-NLS-1$ display.printLine(response.getVerificationUri().toString()); display.printLine( MessageFormat.format(Messages.getString("Command.DeviceFlowCallbackInstructionCodeFormat"), //$NON-NLS-1$ response.getExpiresIn() / 60)); display.printLine(response.getUserCode()); display.printLine(Messages.getString("Command.DeviceFlowCallbackInstructionContinue")); //$NON-NLS-1$ display.printLine(MessageFormat.format( Messages.getString("Command.DeviceFlowCallbackInstructionBypassFormat"), //$NON-NLS-1$ EnvironmentVariables.BYPASS_INTERACTIVE_BROWSER_LOGIN)); } }; final OAuth2Authenticator oauth2Authenticator = OAuth2Authenticator.getAuthenticator(CLIENT_ID, REDIRECT_URL, accessTokenStore, deviceFlowCallback); final Authenticator authenticator; final Options options = Options.getDefaultOptions(); if (persistCredentials) { log.debug("Trying to persist credential, generating a PAT"); //$NON-NLS-1$ /* * If this credential is to be persisted, then let's create a PAT */ authenticator = new VstsPatAuthenticator(oauth2Authenticator, tokenStore); options.patGenerationOptions.displayName = getPATDisplayName(); } else { log.debug("Do not try to persist, generating oauth2 token."); //$NON-NLS-1$ /* * Not persisting this credential, simply create an oauth2 token */ authenticator = oauth2Authenticator; } final UserPasswordCredentialProvider provider = new UserPasswordCredentialProvider(authenticator); final Credential tokenCreds = provider.getCredentialFor(serverURI, PromptBehavior.AUTO, options); if (tokenCreds != null && tokenCreds.Username != null && tokenCreds.Password != null) { return new UsernamePasswordCredentials(tokenCreds.Username, tokenCreds.Password); } else { log.warn(Messages.getString("Command.InteractiveAuthenticationFailedDetailedLog1")); //$NON-NLS-1$ log.warn(Messages.getString("Command.InteractiveAuthenticationFailedDetailedLog2")); //$NON-NLS-1$ log.warn(Messages.getString("Command.InteractiveAuthenticationFailedDetailedLog3")); //$NON-NLS-1$ display.printLine( MessageFormat.format(Messages.getString("Command.InteractiveAuthenticationFailedFormat"), //$NON-NLS-1$ EnvironmentVariables.BYPASS_INTERACTIVE_BROWSER_LOGIN)); } // Failed to get credential, return null return null; }
From source file:com.adito.activedirectory.ActiveDirectoryUserDatabaseConfiguration.java
private static String getKerbrosController(URI url) { String toParse = url.toString(); return toParse.substring(LDAP_PROTOCOL.length(), toParse.lastIndexOf(PORT_SEPARATOR)); }
From source file:Neo4JDataExporter.java
private static void doTraversal(URI startNode) throws URISyntaxException { // START SNIPPET: traversalDesc // TraversalDescription turns into JSON to send to the Server TraversalDescription t = new TraversalDescription(); t.setOrder(TraversalDescription.DEPTH_FIRST); t.setUniqueness(TraversalDescription.NODE); t.setMaxDepth(10);// w w w .ja v a 2 s.com t.setReturnFilter(TraversalDescription.ALL); t.setRelationships(new Relationship("singer", Relationship.OUT)); // END SNIPPET: traversalDesc // START SNIPPET: traverse URI traverserUri = new URI(startNode.toString() + "/traverse/node"); WebResource resource = Client.create().resource(traverserUri); String jsonTraverserPayload = t.toJson(); ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON) .entity(jsonTraverserPayload).post(ClientResponse.class); System.out.println(String.format( "POST [%s] to [%s], status code [%d], returned data: " + System.getProperty("line.separator") + "%s", jsonTraverserPayload, traverserUri, response.getStatus(), response.getEntity(String.class))); response.close(); // END SNIPPET: traverse }