List of usage examples for java.net URI toString
public String toString()
From source file:com.googlecode.sardine.AuthenticationTest.java
@Test public void testBasicPreemptiveAuthHeader() throws Exception { final DefaultHttpClient client = new DefaultHttpClient(); client.addRequestInterceptor(new HttpRequestInterceptor() { public void process(final HttpRequest r, final HttpContext context) throws HttpException, IOException { assertNotNull(r.getHeaders(HttpHeaders.AUTHORIZATION)); assertEquals(1, r.getHeaders(HttpHeaders.AUTHORIZATION).length); client.removeRequestInterceptorByClass(this.getClass()); }//from ww w . ja v a2 s .c o m }); Sardine sardine = new SardineImpl(client); sardine.setCredentials("anonymous", null); // mod_dav supports Range headers for PUT final URI url = URI.create("http://sardine.googlecode.com/svn/trunk/README.html"); sardine.enablePreemptiveAuthentication(url.getHost()); assertTrue(sardine.exists(url.toString())); }
From source file:craterdog.marketplace.DigitalMarketplaceClient.java
@Override public RetrieveLedgerResponse retrieveLedger(URI ledgerLocation) { logger.entry(ledgerLocation);/*from www .j a va 2 s .c o m*/ RetrieveLedgerResponse response = restTemplate.getForObject(ledgerLocation.toString(), RetrieveLedgerResponse.class); logger.exit(response); return response; }
From source file:com.exzogeni.dk.http.cache.DiscCacheStore.java
@Nullable @Override/*from w ww.j a v a2 s. c o m*/ public InputStream get(@NonNull URI uri, @Nullable Map<String, List<String>> headers) throws IOException { final File cacheFile = new File(mCacheDir, Digest.getInstance().hash(uri.toString())); final File metaFile = new File(mCacheDir, "." + cacheFile.getName()); if (cacheFile.exists() && metaFile.exists()) { if (headers == null) { return new AtomicFile(cacheFile).openRead(); } else { final long expireTime = readMetaFile(metaFile, headers); Logger.debug("expireTime=%s, systemTime=%s", HttpDate.format(expireTime), HttpDate.format(System.currentTimeMillis())); if (expireTime > System.currentTimeMillis()) { return new AtomicFile(cacheFile).openRead(); } } } return null; }
From source file:de.betterform.xml.xslt.impl.CachingTransformerService.java
private String getXsltName(URI uri) { String s = uri.toString(); return s.substring(s.lastIndexOf("/") + 1); }
From source file:com.create.controller.AuthenticationIT.java
public OAuth2ProtectedResourceDetails getLocalOAuth2RemoteResourceWithInvalidPassword() { final URI expandedAccessTokenUri = localHostUriTemplateHandler.expand(accessTokenUri); return ResourceOwnerPasswordResourceDetailsBuilder.aResourceOwnerPasswordResourceDetails() .withAccessTokenUri(expandedAccessTokenUri.toString()).withClientId(clientId) .withClientSecret(clientSecret).withUsername(TICKET_SERVICE_USER).withPassword("invalid_password") .withGrantTypePassword().build(); }
From source file:com.create.controller.AuthenticationIT.java
public OAuth2ProtectedResourceDetails getLocalOAuth2RemoteResourceWithInvalidClientPassword() { final URI expandedAccessTokenUri = localHostUriTemplateHandler.expand(accessTokenUri); return ResourceOwnerPasswordResourceDetailsBuilder.aResourceOwnerPasswordResourceDetails() .withAccessTokenUri(expandedAccessTokenUri.toString()).withClientId(clientId) .withClientSecret("invalid_password").withUsername(TICKET_SERVICE_USER).withPassword(USER_PASSWORD) .withGrantTypePassword().build(); }
From source file:org.ambraproject.article.action.BrowseIssueAction.java
@Override @Transactional(readOnly = true)//www . j av a2 s . c o m public String execute() { // Was Issue specified? If not, then use Current Issue. // If no Current Issue, then use most recent Issue from the most recent Volume. if (issue == null || issue.length() == 0) { // JournalService, OTM usage wants to be in a Transaction Journal currentJournal = journalService.getJournal(getCurrentJournal()); if (currentJournal != null) { URI currentIssueUri = currentJournal.getCurrentIssue(); if (currentIssueUri != null) { issue = currentIssueUri.toString().trim(); issueInfo = browseService.getIssueInfo(currentIssueUri); // Get data on this Issue. } if (issueInfo == null) { // Current Issue has not been set for this Journal, // so get the most recent issue from the most recent volume. currentIssueUri = browseService.getLatestIssueFromLatestVolume(currentJournal); if (currentIssueUri != null) { issue = currentIssueUri.toString(); issueInfo = browseService.getIssueInfo(currentIssueUri); // Get data on this Issue. } } } } else { // An Issue was specified. issueInfo = browseService.getIssueInfo(URI.create(issue)); // Get data on this Issue. } //If no issue is found, return 404 if (issue == null || issue.length() == 0) { return NONE; } else if (issueInfo == null) { log.error("Found issue, Failed to retrieve IssueInfo for issue id='" + issue + "'"); return ERROR; } // Issue should always have a parent Volume. volumeInfo = browseService.getVolumeInfo(issueInfo.getParentVolume(), this.getCurrentJournal()); // Translate the currentIssue description to HTML if (issueInfo.getDescription() != null) { try { issueDescription = secondaryObjectService.getTransformedDescription(issueInfo.getDescription()); } catch (ApplicationException e) { log.error("Failed to translate issue description to HTML.", e); // Just use the untranslated issue description issueDescription = issueInfo.getDescription(); } } else { log.error("The currentIssue description was null. Issue DOI='" + issueInfo.getId() + "'"); issueDescription = "No description found for this issue"; } articleGroups = browseService.getArticleGrpList(URI.create(issue), getAuthId()); return SUCCESS; }
From source file:cn.ctyun.amazonaws.http.HttpRequestFactory.java
/** * Creates an HttpClient method object based on the specified request and * populates any parameters, headers, etc. from the original request. * * @param request// ww w. jav a2s. c om * The request to convert to an HttpClient method object. * @param previousEntity * The optional, previous HTTP entity to reuse in the new * request. * @param context * The execution context of the HTTP method to be executed * * @return The converted HttpClient method object with any parameters, * headers, etc. from the original request set. */ HttpRequestBase createHttpRequest(Request<?> request, ClientConfiguration clientConfiguration, HttpEntity previousEntity, ExecutionContext context) { URI endpoint = request.getEndpoint(); String uri = endpoint.toString(); if (request.getResourcePath() != null && request.getResourcePath().length() > 0) { if (request.getResourcePath().startsWith("/")) { if (uri.endsWith("/")) { uri = uri.substring(0, uri.length() - 1); } } else if (!uri.endsWith("/")) { uri += "/"; } uri += HttpUtils.urlEncode(request.getResourcePath(), true); } else if (!uri.endsWith("/")) { uri += "/"; } String encodedParams = HttpUtils.encodeParameters(request); /* * For all non-POST requests, and any POST requests that already have a * payload, we put the encoded params directly in the URI, otherwise, * we'll put them in the POST request's payload. */ boolean requestHasNoPayload = request.getContent() != null; boolean requestIsPost = request.getHttpMethod() == HttpMethodName.POST; boolean putParamsInUri = !requestIsPost || requestHasNoPayload; if (encodedParams != null && putParamsInUri) { uri += "?" + encodedParams; } HttpRequestBase httpRequest; if (request.getHttpMethod() == HttpMethodName.POST) { HttpPost postMethod = new HttpPost(uri); /* * If there isn't any payload content to include in this request, * then try to include the POST parameters in the query body, * otherwise, just use the query string. For all AWS Query services, * the best behavior is putting the params in the request body for * POST requests, but we can't do that for S3. */ if (request.getContent() == null && encodedParams != null) { postMethod.setEntity(newStringEntity(encodedParams)); } else { postMethod.setEntity(new RepeatableInputStreamRequestEntity(request)); } httpRequest = postMethod; } else if (request.getHttpMethod() == HttpMethodName.PUT) { HttpPut putMethod = new HttpPut(uri); httpRequest = putMethod; /* * Enable 100-continue support for PUT operations, since this is * where we're potentially uploading large amounts of data and want * to find out as early as possible if an operation will fail. We * don't want to do this for all operations since it will cause * extra latency in the network interaction. */ putMethod.getParams().setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, true); if (previousEntity != null) { putMethod.setEntity(previousEntity); } else if (request.getContent() != null) { HttpEntity entity = new RepeatableInputStreamRequestEntity(request); if (request.getHeaders().get("Content-Length") == null) { entity = newBufferedHttpEntity(entity); } putMethod.setEntity(entity); } } else if (request.getHttpMethod() == HttpMethodName.GET) { httpRequest = new HttpGet(uri); } else if (request.getHttpMethod() == HttpMethodName.DELETE) { httpRequest = new HttpDelete(uri); } else if (request.getHttpMethod() == HttpMethodName.HEAD) { httpRequest = new HttpHead(uri); } else { throw new AmazonClientException("Unknown HTTP method name: " + request.getHttpMethod()); } configureHeaders(httpRequest, request, context, clientConfiguration); return httpRequest; }
From source file:pt.lunacloud.http.HttpRequestFactory.java
/** * Creates an HttpClient method object based on the specified request and * populates any parameters, headers, etc. from the original request. * * @param request//from w w w.j a va2 s .c o m * The request to convert to an HttpClient method object. * @param previousEntity * The optional, previous HTTP entity to reuse in the new * request. * @param context * The execution context of the HTTP method to be executed * * @return The converted HttpClient method object with any parameters, * headers, etc. from the original request set. */ HttpRequestBase createHttpRequest(Request<?> request, ClientConfiguration clientConfiguration, HttpEntity previousEntity, ExecutionContext context) { URI endpoint = request.getEndpoint(); String uri = endpoint.toString(); if (request.getResourcePath() != null && request.getResourcePath().length() > 0) { if (request.getResourcePath().startsWith("/")) { if (uri.endsWith("/")) { uri = uri.substring(0, uri.length() - 1); } } else if (!uri.endsWith("/")) { uri += "/"; } uri += request.getResourcePath(); } else if (!uri.endsWith("/")) { uri += "/"; } String encodedParams = HttpUtils.encodeParameters(request); /* * For all non-POST requests, and any POST requests that already have a * payload, we put the encoded params directly in the URI, otherwise, * we'll put them in the POST request's payload. */ boolean requestHasNoPayload = request.getContent() != null; boolean requestIsPost = request.getHttpMethod() == HttpMethodName.POST; boolean putParamsInUri = !requestIsPost || requestHasNoPayload; if (encodedParams != null && putParamsInUri) { uri += "?" + encodedParams; } HttpRequestBase httpRequest; if (request.getHttpMethod() == HttpMethodName.POST) { HttpPost postMethod = new HttpPost(uri); /* * If there isn't any payload content to include in this request, * then try to include the POST parameters in the query body, * otherwise, just use the query string. For all AWS Query services, * the best behavior is putting the params in the request body for * POST requests, but we can't do that for S3. */ if (request.getContent() == null && encodedParams != null) { postMethod.setEntity(newStringEntity(encodedParams)); } else { postMethod.setEntity(new RepeatableInputStreamRequestEntity(request)); } httpRequest = postMethod; } else if (request.getHttpMethod() == HttpMethodName.PUT) { HttpPut putMethod = new HttpPut(uri); httpRequest = putMethod; /* * Enable 100-continue support for PUT operations, since this is * where we're potentially uploading large amounts of data and want * to find out as early as possible if an operation will fail. We * don't want to do this for all operations since it will cause * extra latency in the network interaction. */ putMethod.getParams().setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, true); if (previousEntity != null) { putMethod.setEntity(previousEntity); } else if (request.getContent() != null) { HttpEntity entity = new RepeatableInputStreamRequestEntity(request); if (request.getHeaders().get("Content-Length") == null) { entity = newBufferedHttpEntity(entity); } putMethod.setEntity(entity); } } else if (request.getHttpMethod() == HttpMethodName.GET) { httpRequest = new HttpGet(uri); } else if (request.getHttpMethod() == HttpMethodName.DELETE) { httpRequest = new HttpDelete(uri); } else if (request.getHttpMethod() == HttpMethodName.HEAD) { httpRequest = new HttpHead(uri); } else { throw new LunacloudClientException("Unknown HTTP method name: " + request.getHttpMethod()); } configureHeaders(httpRequest, request, context, clientConfiguration); return httpRequest; }
From source file:org.sakaiproject.shortenedurl.impl.BitlyUrlService.java
/** * Make a GET request and append the Map of parameters onto the query string. * @param address the fully qualified URL to make the request to * @param parameters the Map of parameters, ie key,value pairs * @return/*from w w w. ja v a 2s . c o m*/ */ private String doGet(String address, Map<String, String> parameters) { try { List<NameValuePair> queryParams = new ArrayList<NameValuePair>(); for (Map.Entry<String, String> entry : parameters.entrySet()) { queryParams.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); } URI uri = URIUtils.createURI(null, address, -1, null, URLEncodedUtils.format(queryParams, "UTF-8"), null); log.info(uri.toString()); return doGet(uri.toString()); } catch (URISyntaxException e) { log.error(e.getClass() + ":" + e.getMessage()); } return null; }