List of usage examples for java.net URI getPath
public String getPath()
From source file:com.arpnetworking.configuration.jackson.JsonNodePaginatedUriSource.java
private JsonNodePaginatedUriSource(final Builder builder) { super(builder); _uri = builder._uri;/*from w w w.j a v a 2 s . c o m*/ _dataKeys = builder._dataKeys.toArray(new String[builder._dataKeys.size()]); _nextPageKeys = builder._nextPageKeys.toArray(new String[builder._nextPageKeys.size()]); final JsonNodeMergingSource.Builder mergingSourceBuilder = new JsonNodeMergingSource.Builder(); try { final URIBuilder uriBuilder = new URIBuilder(_uri); URI currentUri = uriBuilder.build(); while (currentUri != null) { LOGGER.debug().setMessage("Creating JsonNodeUriSource for page").addData("uri", currentUri).log(); // Create a URI source for the page final JsonNodeUriSource uriSource = new JsonNodeUriSource.Builder().setUri(currentUri).build(); mergingSourceBuilder.addSource(uriSource); // Extract the link for the next page final Optional<JsonNode> nextPageNode = uriSource.getValue(_nextPageKeys); if (nextPageNode.isPresent() && !nextPageNode.get().isNull()) { final String nextPagePath = nextPageNode.get().asText(); final URI nextPageUri = URI .create(nextPagePath.startsWith("/") ? nextPagePath : "/" + nextPagePath); final URIBuilder nextPageUriBuilder = new URIBuilder(nextPageUri); currentUri = uriBuilder.setPath(nextPageUri.getPath()) .setParameters(nextPageUriBuilder.getQueryParams()).build(); } else { currentUri = null; } } } catch (final URISyntaxException e) { throw Throwables.propagate(e); } _mergingSource = mergingSourceBuilder.build(); }
From source file:de.shadowhunt.subversion.RepositoryFactory.java
/** * Create a new {@link Repository} for given {@link URI} and use the given {@link HttpClient} with the {@link * HttpClient} to connect to the server. <p>To find the {@link Repository} root the path is tested folder by folder * till the root of the {@link Repository} root is found or no folders are left</p> * * @param repository {@link URI} to any resource of the repository (e.g: http://repository.example.net/svn/test_repo/folderA/subFolderB) * @param client {@link HttpClient} that will handle all requests for this repository * @param context {@link HttpContext} that will be used by all requests to this repository * * @return a new {@link Repository} for given {@link URI} * * @throws NullPointerException if any parameter is {@code null} * @throws SubversionException if an error occurs during {@link Repository} probing and no {@link Repository} can be * created//from w ww. ja v a2 s . co m * @throws de.shadowhunt.subversion.TransmissionException if an error occurs in the underlining communication with * the server */ public Repository probeRepository(final URI repository, final HttpClient client, final HttpContext context) { Validate.notNull(repository, "repository must not be null"); Validate.notNull(client, "client must not be null"); Validate.notNull(context, "context must not be null"); Resource path = Resource.create(repository.getPath()); while (true) { try { final URI saneUri = sanitise(repository, path); return createRepository0(saneUri, client, context); } catch (final SubversionException e) { // ignore these errors while searching the correct repository root if (!isTolerableError(e.getHttpStatusCode())) { throw e; } } if (Resource.ROOT.equals(path)) { break; } path = path.getParent(); } throw new SubversionException("Could not find repository in path: " + repository.getPath()); }
From source file:org.wikipedia.vlsergey.secretary.jwpf.HttpBot.java
protected final void performAction(final ContentProcessable contentProcessable) throws ActionException, ProcessException { List<HttpRequestBase> msgs = contentProcessable.getMessages(); Iterator<HttpRequestBase> it = msgs.iterator(); while (it.hasNext()) { HttpRequestBase httpMethod = it.next(); if (getSite() != null) { URI uri = httpMethod.getURI(); if (!uri.getPath().startsWith("/wiki/")) { try { String str = getSite().getScheme() + "://" + getSite().getHost() + (getSite().getPort() == -1 ? "" : ":" + getSite().getPort()) + getSite().getPath() + uri.getPath() + (uri.getRawQuery() != null ? ("?" + uri.getRawQuery()) : ""); uri = new URI(str); } catch (Exception e) { throw new RuntimeException(e); }/*from ww w .j a v a 2 s . co m*/ httpMethod.setURI(uri); } else { try { String str = getSite().getScheme() + "://" + getSite().getHost() + (getSite().getPort() == -1 ? "" : ":" + getSite().getPort()) + uri.getPath() + (uri.getRawQuery() != null ? ("?" + uri.getRawQuery()) : ""); uri = new URI(str); } catch (Exception e) { throw new RuntimeException(e); } httpMethod.setURI(uri); } // logger.debug("path is: " + httpMethod.getURI()); } try { while (true) { try { if (httpMethod instanceof HttpGet) { get((HttpGet) httpMethod, contentProcessable); } else { post((HttpPost) httpMethod, contentProcessable); } break; } catch (NoHttpResponseException exc) { log.info("NoHttpResponseException, wait 6 seconds"); try { Thread.sleep(5 * 1000); } catch (InterruptedException e) { } } catch (SocketException exc) { log.info("SocketException, wait 5 seconds"); try { Thread.sleep(5 * 1000); } catch (InterruptedException e) { } } catch (ServerErrorException exc) { log.info("ServerErrorException (" + exc.getStatusLine() + "), wait 5 seconds"); try { Thread.sleep(5 * 1000); } catch (InterruptedException e) { } } catch (DatabaseLagException exc) { log.info("Database lag occured: " + exc.databaseLag); int retryAfter = 6; try { retryAfter = Integer.parseInt(exc.retryAfter.getValue()); } catch (Exception exc2) { // ignore } if (retryAfter != 0) { log.info("Waiting for " + retryAfter + " seconds"); try { Thread.sleep(retryAfter * 1000); } catch (InterruptedException e) { } } } } } catch (IOException e1) { throw new ActionException(e1); } } }
From source file:com.eucalyptus.blockstorage.HttpTransfer.java
/** * Constructs the requested method, optionally signing the request via EucaRSA-V2 signing method if signRequest=true * Signing the request can be done later as well by explicitly calling signEucaInternal() and passing it the output of this method. * That case is useful for constructing the request and then adding headers explicitly before signing takes place. * @param verb - The HTTP verb GET|PUT|POST|DELETE|UPDATE * @param addr - THe destination address for the request * @param eucaOperation - The EucaOperation, if any (e.g. StoreSnapshot, GetWalrusSnapshot, or other values from ObjectStorageProperties.StorageOperations) * @param eucaHeader - The Euca Header value, if any. This is not typically used. * @param signRequest - Determines if the request is signed at construction time or must be done explicitly later (boolean) * @return/*from w w w . ja v a 2s. c o m*/ */ public HttpMethodBase constructHttpMethod(String verb, String addr, String eucaOperation, String eucaHeader, boolean signRequest) { String date = DateUtil.formatDate(new Date(), ISO_8601_FORMAT); //String date = new Date().toString(); String httpVerb = verb; String addrPath = null; java.net.URI addrUri = null; try { addrUri = new URL(addr).toURI(); addrPath = addrUri.getPath().toString(); String query = addrUri.getQuery(); if (query != null) { addrPath += "?" + query; } } catch (Exception ex) { LOG.error(ex, ex); return null; } HttpMethodBase method = null; if (httpVerb.equals("PUT")) { method = new PutMethodWithProgress(addr); } else if (httpVerb.equals("DELETE")) { method = new DeleteMethod(addr); } else { method = new GetMethod(addr); } method.setRequestHeader("Date", date); //method.setRequestHeader("Expect", "100-continue"); method.setRequestHeader(EUCALYPTUS_OPERATION, eucaOperation); if (eucaHeader != null) { method.setRequestHeader(EUCALYPTUS_HEADER, eucaHeader); } if (signRequest) { signEucaInternal(method); } return method; }
From source file:com.fatwire.dta.sscrawler.App.java
private HostConfig createHostConfig(final URI uri) { final HostConfig hostConfig = new HostConfig(); hostConfig.setHostname(uri.getHost()); hostConfig.setPort(uri.getPort() == -1 ? 80 : uri.getPort()); hostConfig.setDomain(uri.getPath()); hostConfig.setProtocol(uri.getScheme()); return hostConfig; }
From source file:com.sap.core.odata.testutil.tool.core.AbstractTestClient.java
private HttpRequestBase createRequest(final URI baseUri, final TestRequest testRequest) { RequestHttpMethod method = testRequest.getHttpMethod(); if (method == null) { throw new TestUtilRuntimeException("No HttpMethod set."); }// www . j av a2s.c o m switch (method) { case GET: return new HttpGet(baseUri.getPath() + testRequest.getPath()); case POST: TestPostRequest postRequest = (TestPostRequest) testRequest; HttpPost post = new HttpPost(baseUri.getPath() + testRequest.getPath()); post.setEntity(new InputStreamEntity(postRequest.getContentAsStream(), -1, ContentType.create(postRequest.getContentType()))); return post; default: throw new TestUtilRuntimeException("Unknown HttpMethod '" + method + "' set."); } }
From source file:com.opengamma.web.analytics.rest.WebUiResource.java
@Path("{viewId}/{gridType}/depgraphs") @POST// ww w. ja va 2 s.co m public Response openDependencyGraph(@Context UriInfo uriInfo, @PathParam("viewId") String viewId, @PathParam("gridType") String gridType, @FormParam("requestId") int requestId, @FormParam("row") Integer row, @FormParam("col") Integer col, @FormParam("calcConfigName") String calcConfigName, @FormParam("valueRequirement") ValueRequirementFormParam valueRequirementParam) { int graphId = s_nextId.getAndIncrement(); String graphIdStr = Integer.toString(graphId); URI graphUri = uriInfo.getAbsolutePathBuilder().path(graphIdStr).build(); String callbackId = graphUri.getPath(); if (row != null && col != null) { _viewManager.getView(viewId).openDependencyGraph(requestId, gridType(gridType), graphId, callbackId, row, col); } else if (calcConfigName != null && valueRequirementParam != null) { ValueRequirement req = valueRequirementParam.getValueRequirement(); _viewManager.getView(viewId).openDependencyGraph(requestId, gridType(gridType), graphId, callbackId, calcConfigName, req); } return Response.status(Response.Status.CREATED).build(); }
From source file:io.selendroid.server.model.SelendroidNativeDriver.java
public void get(String url) { URI dest; try {// w w w. j a v a2s .c o m dest = new URI(url); } catch (URISyntaxException exception) { throw new IllegalArgumentException(exception); } if (!"and-activity".equals(dest.getScheme())) { throw new SelendroidException("Unrecognized scheme in URI: " + dest.toString()); } else if (dest.getPath() != null && !dest.getPath().equals("")) { throw new SelendroidException("Unrecognized path in URI: " + dest.toString()); } URI currentUri = getCurrentURI(); if (currentUri != null && dest.getAuthority().endsWith(currentUri.getAuthority())) { // ignore request, activity is already open return; } serverInstrumentation.startActivity(dest.getAuthority()); DefaultSelendroidDriver.sleepQuietly(500); }
From source file:io.cloudslang.lang.cli.utils.CompilerHelperTest.java
@Test public void testUnsupportedExtension() throws Exception { URI flowFilePath = getClass().getResource("/flow.yaml").toURI(); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("must have one of the following extensions"); compilerHelper.compile(flowFilePath.getPath(), null); }
From source file:eu.esdihumboldt.hale.common.core.io.PathUpdate.java
/** * Create an alternative path for the given location if it matches changes * from old to new location. If either old or new location is null, or the * given URI wasn't changed in the same way, this method has no effect. * //from www .j av a 2 s .c om * @param oldSource path where the file was saved to * @return the new URI */ public URI changePath(URI oldSource) { if (oldRaw == null || oldRaw.isEmpty()) { return oldSource; } else { if (oldSource.toString().startsWith(oldRaw)) { return URI.create(oldSource.toString().replace(oldRaw, newRaw)); } else { // try to fix cases where oldRaw matches '<scheme>:///<rest>' // but oldSource matches '<scheme>:/<rest>' or vice versa try { URI oldRawUri = new URI(oldRaw); // URI.normalize() will not remove the additional slashes URI normalizedOldRaw = new URI(oldRawUri.getScheme(), oldRawUri.getHost(), oldRawUri.getPath(), oldRawUri.getQuery(), oldRawUri.getFragment()); URI normalizedOldSource = new URI(oldSource.getScheme(), oldSource.getHost(), oldSource.getPath(), oldSource.getQuery(), oldSource.getFragment()); return URI.create(normalizedOldSource.toString().replace(normalizedOldRaw.toString(), newRaw)); } catch (URISyntaxException e) { // tough luck return oldSource; } } } }