List of usage examples for java.net URI getPath
public String getPath()
From source file:org.fao.geonet.utils.AbstractHttpRequest.java
protected String getSentData(HttpRequestBase httpMethod) { URI uri = httpMethod.getURI(); StringBuilder sentData = new StringBuilder(httpMethod.getMethod()).append(" ").append(uri.getPath()); if (uri.getQuery() != null) { sentData.append("?" + uri.getQuery()); }/* ww w. j a va2 s . c om*/ sentData.append("\r\n"); for (Header h : httpMethod.getAllHeaders()) { sentData.append(h); } sentData.append("\r\n"); if (httpMethod instanceof HttpPost) { sentData.append(postData); } return sentData.toString(); }
From source file:com.adaptris.core.ftp.FileTransferConnection.java
/** * <p>/*from w w w . jav a 2 s . co m*/ * Returns the directory root for the passed host URL. * </p> * * @param hostUrl the host URL * @return the directory root for the passed host URL */ public String getDirectoryRoot(String hostUrl) { String result = ""; try { URI uri = new URI(hostUrl); if (acceptProtocol(uri.getScheme())) { result = uri.getPath() != null ? uri.getPath() : ""; } } catch (URISyntaxException e) { ; } if (forceRelativePath()) { result = "." + result; } return result; }
From source file:com.mirth.connect.connectors.file.FileConnector.java
/** * URI.getPath() does not retrieve the desired result for relative paths. The first directory * would be omitted and the second directory would be used with the system's root as the base. * Thus for connectors using the FILE scheme, we retrieve the path using an alternate method. *//*from ww w . j av a 2 s . c o m*/ protected String getPathPart(URI uri) { if (scheme == FileScheme.FILE) { // In //xyz, return xyz. return uri.getSchemeSpecificPart().substring(2); } else { // For the remaining cases, getPath seems to do the right thing. return uri.getPath(); } }
From source file:edu.stanford.junction.provider.jx.Junction.java
public Junction(URI uri, ActivityScript script, final JunctionActor actor) throws JunctionException { this.setActor(actor); mAcceptedInvitation = uri;/*from w w w.j a v a2 s . c om*/ mActivityScript = script; mSession = uri.getPath().substring(1); String host = uri.getHost(); int port = uri.getPort(); if (port == -1) port = JXServer.SERVER_PORT; // TODO: one connection per host (multiple subscriptions through one socket) // handle in Provider try { try { String my_ip = JunctionProvider.getLocalIpAddress(); if (my_ip.equals(host)) { Log.d(TAG, "Starting local switchboard service"); mSwitchboardServer = new JXServer(); mSwitchboardServer.start(); } } catch (Exception e) { Log.e(TAG, "Could not start local switchboard service", e); } Socket socket = new Socket(host, port); mConnectedThread = new ConnectedThread(socket); mConnectedThread.start(); } catch (IOException e) { Log.e(TAG, "Error connecting to socket", e); } int MAX_TIME = 20000; synchronized (mJoinLock) { if (!mJoinComplete) { try { mJoinLock.wait(MAX_TIME); } catch (InterruptedException e) { // Ignored } } } if (!mJoinComplete) { throw new JunctionException("Timeout while joining Junction session."); } triggerActorJoin(mActivityCreator); }
From source file:com.fredhopper.core.connector.index.upload.impl.RestPublishingStrategy.java
@Override public String checkStatus(final InstanceConfig config, final URI triggerUrl) throws ResponseStatusException { Preconditions.checkArgument(config != null); Preconditions.checkArgument(triggerUrl != null); final RestTemplate restTemplate = restTemplateProvider.createTemplate(config.getHost(), config.getPort(), config.getUsername(), config.getPassword()); final URI url = triggerUrl.resolve(triggerUrl.getPath() + STATUS_PATH); final HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.TEXT_PLAIN); final HttpEntity<String> httpEntity = new HttpEntity<>(headers); final ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, httpEntity, String.class); final HttpStatus status = response.getStatusCode(); if (status.equals(HttpStatus.OK)) { return response.getBody(); } else {/*from ww w . ja v a 2s . c om*/ throw new ResponseStatusException( "HttpStatus " + status.toString() + " response received. Load trigger monitoring failed."); } }
From source file:com.sra.biotech.submittool.persistence.service.SubmissionServiceImpl.java
public URI assignSample(URI submissionUri, Sample sample) { ObjectMapper objectMapper = restTemplateService.getObjectMapperWithHalModule(); String samplesUri = RestClientConfiguration.BASE_URL + "/" + "samples"; ObjectNode jsonNodeSample = (ObjectNode) objectMapper.valueToTree(sample); jsonNodeSample.put("submission", submissionUri.getPath()); URI sampleUri = restTemplate.postForLocation(samplesUri, jsonNodeSample); ResponseEntity<Resource<Sample>> sampleResponseEntity = restTemplate.exchange(sampleUri, HttpMethod.GET, null, new ParameterizedTypeReference<Resource<Sample>>() { });//from ww w . j a v a 2s . com Resource<Sample> studyResource = sampleResponseEntity.getBody(); Link submissionLinkThroughSample = studyResource.getLink("submission"); System.out.println("Submission Link through Sample = " + submissionLinkThroughSample); return sampleUri; }
From source file:com.github.brandtg.pantopod.crawler.CrawlingEventHandler.java
private URI getNextUri(URI url, String href, String chroot) throws Exception { // if (href.contains("..")) { ///*from w ww. j a v a 2 s . co m*/ // throw new IllegalArgumentException("Relative URI not allowed: " + href); // } URI hrefUri = URI.create(href.trim().replaceAll(" ", "+")); URIBuilder builder = new URIBuilder(); builder.setScheme(hrefUri.getScheme() == null ? url.getScheme() : hrefUri.getScheme()); builder.setHost(hrefUri.getHost() == null ? url.getHost() : hrefUri.getHost()); builder.setPort(hrefUri.getPort() == -1 ? url.getPort() : hrefUri.getPort()); if (hrefUri.getPath() != null) { StringBuilder path = new StringBuilder(); if (hrefUri.getHost() == null && chroot != null) { path.append(chroot); } // Ensure no two slashes if (hrefUri.getPath() != null && hrefUri.getPath().length() > 0 && hrefUri.getPath().charAt(0) == '/' && path.length() > 0 && path.charAt(path.length() - 1) == '/') { path.setLength(path.length() - 1); } path.append(hrefUri.getPath()); builder.setPath(chroot == null ? "" : chroot + hrefUri.getPath()); } if (hrefUri.getQuery() != null) { builder.setCustomQuery(hrefUri.getQuery()); } if (hrefUri.getFragment() != null) { builder.setFragment(hrefUri.getFragment()); } return builder.build(); }
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestResourceServiceImpl.java
private URI resolveAsDirectoryURI(URI relativeTo) { URI userRoot = getUserRoot(); if (relativeTo == null || StringUtils.isBlank(relativeTo.getPath())) { return userRoot; }/*from www .ja v a 2 s. co m*/ return URI .create(UriComponentsBuilder.fromUri(userRoot).path(relativeTo.getPath()).path(SLASH).toUriString()) .normalize(); }
From source file:de.catma.ui.repository.wizard.FileTypePanel.java
private ArrayList<SourceDocumentResult> makeSourceDocumentResultsFromInputFile(TechInfoSet inputTechInfoSet) throws MalformedURLException, IOException { ArrayList<SourceDocumentResult> output = new ArrayList<SourceDocumentResult>(); FileType inputFileType = FileType.getFileType(inputTechInfoSet.getMimeType()); if (inputFileType != FileType.ZIP) { SourceDocumentResult outputSourceDocumentResult = new SourceDocumentResult(); String sourceDocumentID = repository.getIdFromURI(inputTechInfoSet.getURI()); outputSourceDocumentResult.setSourceDocumentID(sourceDocumentID); SourceDocumentInfo outputSourceDocumentInfo = outputSourceDocumentResult.getSourceDocumentInfo(); outputSourceDocumentInfo.setTechInfoSet(new TechInfoSet(inputTechInfoSet)); outputSourceDocumentInfo.setContentInfoSet(new ContentInfoSet()); outputSourceDocumentInfo.getTechInfoSet().setFileType(inputFileType); output.add(outputSourceDocumentResult); } else { //TODO: put this somewhere sensible URI uri = inputTechInfoSet.getURI(); ZipFile zipFile = new ZipFile(uri.getPath()); Enumeration<ZipArchiveEntry> entries = zipFile.getEntries(); String tempDir = ((CatmaApplication) UI.getCurrent()).getTempDirectory(); IDGenerator idGenerator = new IDGenerator(); while (entries.hasMoreElements()) { ZipArchiveEntry entry = entries.nextElement(); String fileName = FilenameUtils.getName(entry.getName()); String fileId = idGenerator.generate(); File entryDestination = new File(tempDir, fileId); if (entryDestination.exists()) { entryDestination.delete(); }// www . j a v a2 s . c om entryDestination.getParentFile().mkdirs(); if (entry.isDirectory()) { entryDestination.mkdirs(); } else { BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry)); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(entryDestination)); IOUtils.copy(bis, bos); IOUtils.closeQuietly(bis); IOUtils.closeQuietly(bos); SourceDocumentResult outputSourceDocumentResult = new SourceDocumentResult(); URI newURI = entryDestination.toURI(); String repositoryId = repository.getIdFromURI(newURI); // we need to do this as a catma:// is appended outputSourceDocumentResult.setSourceDocumentID(repositoryId); SourceDocumentInfo outputSourceDocumentInfo = outputSourceDocumentResult .getSourceDocumentInfo(); TechInfoSet newTechInfoSet = new TechInfoSet(fileName, null, newURI); // TODO: MimeType detection ? FileType newFileType = FileType.getFileTypeFromName(fileName); newTechInfoSet.setFileType(newFileType); outputSourceDocumentInfo.setTechInfoSet(newTechInfoSet); outputSourceDocumentInfo.setContentInfoSet(new ContentInfoSet()); output.add(outputSourceDocumentResult); } } ZipFile.closeQuietly(zipFile); } for (SourceDocumentResult sdr : output) { TechInfoSet sdrTechInfoSet = sdr.getSourceDocumentInfo().getTechInfoSet(); String sdrSourceDocumentId = sdr.getSourceDocumentID(); ProtocolHandler protocolHandler = getProtocolHandlerForUri(sdrTechInfoSet.getURI(), sdrSourceDocumentId, sdrTechInfoSet.getMimeType()); String mimeType = protocolHandler.getMimeType(); sdrTechInfoSet.setMimeType(mimeType); FileType sdrFileType = FileType.getFileType(mimeType); sdrTechInfoSet.setFileType(sdrFileType); if (sdrFileType.isCharsetSupported()) { Charset charset = Charset.forName(protocolHandler.getEncoding()); sdrTechInfoSet.setCharset(charset); } else { sdrTechInfoSet.setFileOSType(FileOSType.INDEPENDENT); } loadSourceDocumentAndContent(sdr); } return output; }