List of usage examples for java.net URI getRawPath
public String getRawPath()
From source file:org.mule.endpoint.AbstractEndpoint.java
@Override public String toString() { // Use the interface to retrieve the string and set // the endpoint uri to a default value String sanitizedEndPointUri = null; URI uri = null; if (endpointUri != null) { sanitizedEndPointUri = endpointUri.toString(); uri = endpointUri.getUri();//from ww w . j a va 2 s . c o m } // The following will further sanitize the endpointuri by removing // the embedded password. This will only remove the password if the // uri contains all the necessary information to successfully rebuild the url if (uri != null && (uri.getRawUserInfo() != null) && (uri.getScheme() != null) && (uri.getHost() != null) && (uri.getRawPath() != null)) { // build a pattern up that matches what we need tp strip out the password Pattern sanitizerPattern = Pattern.compile("(.*):.*"); Matcher sanitizerMatcher = sanitizerPattern.matcher(uri.getRawUserInfo()); if (sanitizerMatcher.matches()) { sanitizedEndPointUri = new StringBuffer(uri.getScheme()).append("://") .append(sanitizerMatcher.group(1)).append(":<password>").append("@").append(uri.getHost()) .append(uri.getRawPath()).toString(); } if (uri.getRawQuery() != null) { sanitizedEndPointUri = sanitizedEndPointUri + "?" + uri.getRawQuery(); } } return ClassUtils.getClassName(getClass()) + "{endpointUri=" + sanitizedEndPointUri + ", connector=" + connector + ", name='" + name + "', mep=" + messageExchangePattern + ", properties=" + properties + ", transactionConfig=" + transactionConfig + ", deleteUnacceptedMessages=" + deleteUnacceptedMessages + ", initialState=" + initialState + ", responseTimeout=" + responseTimeout + ", endpointEncoding=" + endpointEncoding + ", disableTransportTransformer=" + disableTransportTransformer + "}"; }
From source file:com.unboundid.scim2.client.ScimService.java
/** * Resolve a URL (relative or absolute) to a web target. * * @param url The URL to resolve./*from w w w. j a v a 2 s . c om*/ * @return The WebTarget. */ private WebTarget resolveWebTarget(final URI url) { URI relativePath; if (url.isAbsolute()) { relativePath = baseTarget.getUri().relativize(url); if (relativePath.equals(url)) { // The given resource's location is from another service provider throw new IllegalArgumentException("Given resource's location " + url + " is not under this service's " + "base path " + baseTarget.getUri()); } } else { relativePath = url; } return baseTarget.path(relativePath.getRawPath()); }
From source file:com.joyent.manta.client.UriSigner.java
/** * Signs an arbitrary URL using the Manta-compatible HTTP signature * method./*from w w w . j a v a 2s. c om*/ * * @param uri URI with no query pointing to a downloadable resource * @param method HTTP request method to be used in the signature * @param expires epoch time in seconds when the resource will no longer * be available * @return a signed version of the input URI * @throws IOException thrown when we can't sign or read char data */ public URI signURI(final URI uri, final String method, final long expires) throws IOException { Validate.notNull(method, "Method must not be null"); Validate.notNull(uri, "URI must not be null"); Validate.isTrue(StringUtils.isEmpty(uri.getQuery()), "Query must be null or empty. URI: %s", uri); final ThreadLocalSigner signer = authConfig.getSigner(); final String charset = "UTF-8"; final String algorithm = signer.get().getHttpHeaderAlgorithm().toUpperCase(); final String keyId = String.format("/%s/keys/%s", authConfig.getMantaUser(), KeyFingerprinter.md5Fingerprint(authConfig.getKeyPair())); final String keyIdEncoded = URLEncoder.encode(keyId, charset); StringBuilder sigText = new StringBuilder(); sigText.append(method).append(StringUtils.LF).append(uri.getHost()).append(StringUtils.LF) .append(uri.getRawPath()).append(StringUtils.LF).append("algorithm=").append(algorithm).append("&") .append("expires=").append(expires).append("&").append("keyId=").append(keyIdEncoded); StringBuilder request = new StringBuilder(); final byte[] sigBytes = sigText.toString().getBytes(StandardCharsets.UTF_8); // first parameter isn't actually used for anything, just checked for nullness final byte[] signed = signer.get().sign("", authConfig.getKeyPair(), sigBytes); final String encoded = new String(Base64.encode(signed), charset); final String urlEncoded = URLEncoder.encode(encoded, charset); request.append(uri).append("?").append("algorithm=").append(algorithm).append("&").append("expires=") .append(expires).append("&").append("keyId=").append(keyIdEncoded).append("&").append("signature=") .append(urlEncoded); return URI.create(request.toString()); }
From source file:org.kitodo.production.forms.MassImportForm.java
private void removeImportFileNameFromSelectedFileNames(ImportObject io) { URI importFileName = io.getImportFileName(); Helper.setErrorMessage("importFailedError", new Object[] { io.getProcessTitle(), io.getErrorMessage() }); if (Objects.nonNull(importFileName) && !ServiceManager.getFileService().getFileName(importFileName).isEmpty() && Objects.nonNull(selectedFilenames) && !selectedFilenames.isEmpty()) { selectedFilenames.remove(importFileName.getRawPath()); }/*from w w w .j a v a 2 s . co m*/ }
From source file:org.apache.camel.component.http4.HttpProducer.java
/** * Creates the HttpMethod to use to call the remote server, either its GET or POST. * * @param exchange the exchange/*from www.j ava 2 s .co m*/ * @return the created method as either GET or POST * @throws URISyntaxException is thrown if the URI is invalid * @throws CamelExchangeException is thrown if error creating RequestEntity */ protected HttpRequestBase createMethod(Exchange exchange) throws URISyntaxException, CamelExchangeException { String url = HttpHelper.createURL(exchange, getEndpoint()); URI uri = new URI(url); HttpEntity requestEntity = createRequestEntity(exchange); HttpMethods methodToUse = HttpHelper.createMethod(exchange, getEndpoint(), requestEntity != null); // is a query string provided in the endpoint URI or in a header (header overrules endpoint) String queryString = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class); if (queryString == null) { queryString = getEndpoint().getHttpUri().getRawQuery(); } StringBuilder builder = new StringBuilder(uri.getScheme()).append("://").append(uri.getHost()); if (uri.getPort() != -1) { builder.append(":").append(uri.getPort()); } if (uri.getPath() != null) { builder.append(uri.getRawPath()); } if (queryString != null) { builder.append('?'); builder.append(queryString); } HttpRequestBase httpRequest = methodToUse.createMethod(builder.toString()); if (methodToUse.isEntityEnclosing()) { ((HttpEntityEnclosingRequestBase) httpRequest).setEntity(requestEntity); if (requestEntity != null && requestEntity.getContentType() == null) { if (LOG.isDebugEnabled()) { LOG.debug("No Content-Type provided for URL: " + url + " with exchange: " + exchange); } } } return httpRequest; }
From source file:org.apache.manifoldcf.agents.output.filesystem.FileOutputConnector.java
/** * @param documentURI/*from w w w .ja va2s .c om*/ * @return * @throws URISyntaxException * @throws NullPointerException */ final private String documentURItoFilePath(String documentURI) throws URISyntaxException, NullPointerException { StringBuffer path = new StringBuffer(); URI uri = null; uri = new URI(documentURI); if (uri.getScheme() != null) { path.append(uri.getScheme()); path.append("/"); } if (uri.getHost() != null) { path.append(uri.getHost()); if (uri.getPort() != -1) { path.append(":"); path.append(uri.getPort()); } if (uri.getRawPath() != null) { if (uri.getRawPath().length() == 0) { path.append("/"); } else if (uri.getRawPath().equals("/")) { path.append(uri.getRawPath()); } else { for (String name : uri.getRawPath().split("/")) { if (name.length() > 0) { path.append("/"); path.append(convertString(name)); } } } } if (uri.getRawQuery() != null) { path.append("?"); path.append(convertString(uri.getRawQuery())); } } else { if (uri.getRawSchemeSpecificPart() != null) { for (String name : uri.getRawSchemeSpecificPart().split("/")) { if (name.length() > 0) { path.append("/"); path.append(convertString(name)); } } } } if (path.toString().endsWith("/")) { path.append(".content"); } return path.toString(); }
From source file:org.kitodo.production.forms.MassImportForm.java
private void addProcessToList(ImportObject importObject) throws IOException { URI importFileName = importObject.getImportFileName(); Process process = JobCreation.generateProcess(importObject, this.template); if (Objects.isNull(process)) { if (Objects.nonNull(importFileName) && !ServiceManager.getFileService().getFileName(importFileName).isEmpty() && Objects.nonNull(selectedFilenames) && !selectedFilenames.isEmpty()) { selectedFilenames.remove(importFileName.getRawPath()); }/*from w w w . ja v a 2 s . co m*/ Helper.setErrorMessage( "import failed for " + importObject.getProcessTitle() + ", process generation failed"); } else { Helper.setMessage( ImportReturnValue.EXPORT_FINISHED.getValue() + " for " + importObject.getProcessTitle()); this.processList.add(process); } }
From source file:com.nesscomputing.service.discovery.client.ServiceURI.java
public ServiceURI(final URI uri) throws URISyntaxException { if (!"srvc".equals(uri.getScheme())) { throw new URISyntaxException(uri.toString(), "ServiceURI only supports srvc:// URIs"); }/* w ww . jav a2 s . co m*/ if (!StringUtils.startsWith(uri.getSchemeSpecificPart(), "//")) { throw new URISyntaxException(uri.toString(), "ServiceURI only supports srvc:// URIs"); } final String schemeSpecificPart = uri.getSchemeSpecificPart().substring(2); final int slashIndex = schemeSpecificPart.indexOf('/'); if (slashIndex == -1) { throw new URISyntaxException(uri.toString(), "ServiceURI requires a slash at the end of the service!"); } final int colonIndex = schemeSpecificPart.indexOf(':'); if (colonIndex == -1 || colonIndex > slashIndex) { serviceName = schemeSpecificPart.substring(0, slashIndex); serviceType = null; } else { serviceName = schemeSpecificPart.substring(0, colonIndex); serviceType = schemeSpecificPart.substring(colonIndex + 1, slashIndex); } path = uri.getRawPath(); query = uri.getRawQuery(); fragment = uri.getRawFragment(); }
From source file:org.kitodo.production.services.data.LdapServerService.java
/** * Retrieve home directory of given user. * * @param user//from w ww.j a v a 2 s . c om * User object * @return path as URI */ public URI getUserHomeDirectory(User user) { String userFolderBasePath = ConfigCore.getParameter(ParameterCore.DIR_USERS); if (ConfigCore.getBooleanParameterOrDefaultValue(ParameterCore.LDAP_USE_LOCAL_DIRECTORY)) { return Paths.get(userFolderBasePath, user.getLogin()).toUri(); } Hashtable<String, String> env = initializeWithLdapConnectionSettings(user.getLdapGroup().getLdapServer()); if (ConfigCore.getBooleanParameterOrDefaultValue(ParameterCore.LDAP_USE_TLS)) { return getUserHomeDirectoryWithTLS(env, userFolderBasePath, user); } if (ConfigCore.getBooleanParameter(ParameterCore.LDAP_USE_SIMPLE_AUTH, false)) { env.put(Context.SECURITY_AUTHENTICATION, "none"); } DirContext ctx; URI userFolderPath = null; try { ctx = new InitialDirContext(env); Attributes attrs = ctx.getAttributes(buildUserDN(user)); Attribute ldapAttribute = attrs.get("homeDirectory"); userFolderPath = URI.create((String) ldapAttribute.get(0)); ctx.close(); } catch (NamingException e) { logger.error(e.getMessage(), e); } if (Objects.nonNull(userFolderPath) && !userFolderPath.isAbsolute()) { if (userFolderPath.getPath().startsWith("/")) { userFolderPath = ServiceManager.getFileService().deleteFirstSlashFromPath(userFolderPath); } return Paths.get(userFolderBasePath, userFolderPath.getRawPath()).toUri(); } else { return userFolderPath; } }
From source file:org.eclipse.ice.item.nuclear.MOOSE.java
/** * (non-Javadoc)//from w w w . j a v a 2s . c o m * * @see org.eclipse.ice.item.Item#process(java.lang.String) */ @Override public FormStatus process(String actionName) { // Local Declarations FormStatus retStatus = FormStatus.InfoError; // Set our outputFile as the MooseLauncher's output file // so we can see the streaming output outputFile = mooseLauncher.getOutputFile(); // Parse the action name if ("Launch the Job".equals(actionName)) { // FIXME WE NEED TO DO A CHECK FOR ALL THE REQUIRED BLOCKS!!!! // Add the ICEUpdater tree block to Outputs TreeComposite outputs = getTreeByName("Outputs"); TreeComposite postProcessors = getTreeByName("Postprocessors"); // First check to see if we have any post processors to // watch for. if (postProcessors.isActive() && postProcessors.getNumberOfChildren() > 0) { // If we do, we should add an ICEUpdater boolean iNeedUpdater = true; // If we already have one, then we shouldn't add another one for (int i = 0; i < outputs.getNumberOfChildren(); i++) { if ("ICEUpdater".equals(outputs.getChildAtIndex(i).getName())) { // But if the current one is not configured correctly // then we should add a new one, Here we make sure the // Item Id is correct... TreeComposite iceUpdater = outputs.getChildAtIndex(i); DataComponent data = (DataComponent) iceUpdater.getDataNodes().get(0); Entry itemIdEntry = data.retrieveEntry("item_id"); if (Integer.valueOf(itemIdEntry.getValue()) != getId()) { itemIdEntry.setValue(String.valueOf(getId())); } // Now we have a valid ICEUpdater, so we don't need // to create a new one. iNeedUpdater = false; break; } } if (iNeedUpdater) { for (int i = 0; i < outputs.getChildExemplars().size(); i++) { if ("ICEUpdater".equals(outputs.getChildExemplars().get(i).getName())) { TreeComposite updater = (TreeComposite) outputs.getChildExemplars().get(i).clone(); outputs.setNextChild(updater); DataComponent data = (DataComponent) updater.getDataNodes().get(0); data.retrieveEntry("item_id").setValue(String.valueOf(getId())); data.retrieveEntry("url") .setValue("http://localhost:" + System.getProperty("org.eclipse.equinox.http.jetty.http.port") + "/ice/update"); updater.setActive(true); updater.setActiveDataNode(data); break; } } } } // Get a reference to the Launchers files component DataComponent launcherFiles = (DataComponent) mooseLauncher.getForm().getComponent(1); // Grab the file name the user has specified for the input file String fileName = modelFiles.retrieveEntry("Output File Name").getValue(); // Write the Moose file if it doesn't exist retStatus = mooseModel.process("Write MOOSE File"); if (!retStatus.equals(FormStatus.Processed)) { return retStatus; } // Set the value of the input file to the user-specified // file name launcherFiles.retrieveEntry("Input File").setValue(fileName); // Update the MooseLauncher's set of input files... mooseLauncher.update(launcherFiles.retrieveEntry("Input File")); for (Entry e : modelFiles.retrieveAllEntries()) { Entry launcherFile = launcherFiles.retrieveEntry(e.getName()); if (launcherFile != null) { launcherFile.setValue(e.getValue()); } } // Get the application URI URI appUri = URI.create(modelFiles.retrieveEntry("MOOSE-Based Application").getValue()); // Check if we're local or remote if ("ssh".equals(appUri.getScheme())) { mooseLauncher.setExecutable(Paths.get(appUri.getRawPath()).getFileName().toString(), "", appUri.getRawPath() + " -i ${inputFile} --no-color"); // Setup the hosts table to use the remote host TableComponent hostsTable = (TableComponent) mooseLauncher.getForm() .getComponent(JobLauncherForm.parallelId + 1); IRemoteConnection remoteConnection = mooseLauncher.getRemoteConnection(appUri.getHost()); String hostname = remoteConnection.getService(IRemoteConnectionHostService.class).getHostname(); int index = hostsTable.addRow(); ArrayList<Entry> row = hostsTable.getRow(index); ArrayList<Integer> selected = new ArrayList<Integer>(); selected.add(new Integer(index)); row.get(0).setValue(hostname); hostsTable.setSelectedRows(selected); } else { // Set the executable string mooseLauncher.setExecutable(new File(appUri).getName(), "", appUri.getPath() + " -i ${inputFile} --no-color"); } // Register as a listener of the resource component // so we can add the resources to our resource component ((ResourceComponent) mooseLauncher.getForm().getComponent(JobLauncherForm.outputId)).register(this); // Launch the Moose application retStatus = mooseLauncher.process(actionName); } else if ("Write MOOSE File".equals(actionName)) { // Simply pass this along to the Model retStatus = mooseModel.process(actionName); } // Set the status flag. status = retStatus; // Keep the status in sync if (status.equals(FormStatus.Processing)) { Thread statusThread = new Thread(new Runnable() { @Override public void run() { while (!status.equals(FormStatus.Processed)) { // Sleep for a bit Thread.currentThread(); try { Thread.sleep(100); } catch (InterruptedException e) { logger.error(getClass().getName() + " Exception!", e); } // Set the status status = mooseLauncher.getStatus(); } return; } }); statusThread.start(); } return retStatus; }