List of usage examples for java.net URI toString
public String toString()
From source file:HTTPChunkLocator.java
private InputStream openStream(final URI aUri) throws IOException { final GetMethod method = new GetMethod(aUri.toString()); method.setFollowRedirects(true);/*w w w . j a v a 2 s . com*/ client.executeMethod(method); final int statusCode = method.getStatusCode(); if (statusCode != 200) { method.abort(); throw new IOException(String.format("HTTP Status Code %s for URL %s", statusCode, aUri)); } return method.getResponseBodyAsStream(); }
From source file:org.opencredo.couchdb.inbound.CouchDbAllDocumentsMessageSource.java
Map<String, String> createHeaderMap(URI uri, int skip, int limit) { Map<String, String> headers = new HashMap<String, String>(4); headers.put("couchdb-uri", uri.toString()); headers.put("couchdb-skip", String.valueOf(skip)); headers.put("couchdb-limit", String.valueOf(limit)); return headers; }
From source file:com.buaa.cfs.fs.AbstractFileSystem.java
protected static synchronized Map<URI, FileSystem.Statistics> getAllStatistics() { Map<URI, FileSystem.Statistics> statsMap = new HashMap<URI, FileSystem.Statistics>(STATISTICS_TABLE.size()); for (Map.Entry<URI, FileSystem.Statistics> pair : STATISTICS_TABLE.entrySet()) { URI key = pair.getKey(); FileSystem.Statistics value = pair.getValue(); FileSystem.Statistics newStatsObj = new FileSystem.Statistics(value); statsMap.put(URI.create(key.toString()), newStatsObj); }/*from w ww . j ava 2s. c o m*/ return statsMap; }
From source file:de.raion.xmppbot.plugin.TfsIssuePlugin.java
private void processMessage(XmppContext xmppContext, Message message) { Matcher matcher = pattern.matcher(message.getBody()); while (matcher.find()) { String issue = matcher.group(2); log.debug("issue: {}", issue); try {/*from w ww . j a v a2s .c o m*/ URI issueUri = config.getIssueURI(issue); log.debug("issueURI={}", issueUri.toString()); ClientResponse response = client.resource(issueUri).get(ClientResponse.class); if (response.getClientResponseStatus() == Status.OK) { issueNode = mapper.readValue(response.getEntityInputStream(), JsonNode.class); String issueSummary = issueNode.findValue("__wrappedArray").get(0).findValue("fields") .findValue("1").textValue(); StringBuilder builder = new StringBuilder(); builder.append("[TFS-").append(issue).append("] - "); builder.append(issueSummary).append(" : "); builder.append(config.getIssueBrowseURI(issue).toString()).append("\n"); log.debug(builder.toString()); xmppContext.print(builder.toString()); } } catch (Exception e) { log.error("processMessage(XmppContext, Message)", e.getMessage()); } } }
From source file:com.subgraph.vega.impl.scanner.ScanProbe.java
private String createRedirectExceptionMessage(URI targetURI, URI location, Exception e) { final StringBuilder sb = new StringBuilder(); sb.append("Target address "); sb.append(targetURI.toString()); sb.append(" redirected to address "); sb.append(location.toString());/*w w w . j av a 2 s . c om*/ sb.append(" which was not reachable"); sb.append(e.getMessage()); return sb.toString(); }
From source file:org.jasig.portlet.emailpreview.dao.exchange.AutodiscoverRedirectStrategy.java
/** * Overrides behavior to follow redirects for POST messages, AND to have the redirect be a POST. Behavior of * <code>DefaultRedirectStrategy</code> is to use a GET for the redirect (though against spec this is the * de-facto standard, see http://www.mail-archive.com/httpclient-users@hc.apache.org/msg06327.html and * http://www.alanflavell.org.uk/www/post-redirect.html). * * For our application, we want to follow the redirect for a 302 as long as it is to a safe location and * have the redirect be a POST.//from w w w . j a va 2 s.c om * * This code is modified from http-components' http-client 4.2.5. Since we only use POST the code for the * other HTTP methods has been removed to simplify this method. * * @param request Http request * @param response Http response * @param context Http context * @return Request to issue to the redirected location * @throws ProtocolException protocol exception */ @Override public HttpUriRequest getRedirect(final HttpRequest request, final HttpResponse response, final HttpContext context) throws ProtocolException { URI uri = getLocationURI(request, response, context); log.info("Following redirect to {}", uri.toString()); String method = request.getRequestLine().getMethod(); int status = response.getStatusLine().getStatusCode(); // Insure location is safe if (matchesPatternSet(uri, unsafeUriPatterns)) { log.warn("Not following to URI {} - matches a configured unsafe URI pattern", uri.toString()); throw new EmailPreviewException("Autodiscover redirected to unsafe URI " + uri.toString()); } if (!matchesPatternSet(uri, uriRequirementPatterns) && uriRequirementPatterns.size() > 0) { log.warn("Not following to URI {} - URI does not match a required URI pattern", uri.toString()); throw new EmailPreviewException( "Autodiscover redirected to URI not matching required pattern. URI=" + uri.toString()); } // Follow forwards for 301 and 302 in addition to 307, to validate the redirect location, // and to use a POST method. if (status == HttpStatus.SC_TEMPORARY_REDIRECT || status == HttpStatus.SC_MOVED_PERMANENTLY || status == HttpStatus.SC_MOVED_TEMPORARILY) { if (method.equalsIgnoreCase(HttpPost.METHOD_NAME)) { return copyEntity(new HttpPost(uri), request); } } // Should not get here, but return sensible value just in case. A GET will likely fail. return new HttpGet(uri); }
From source file:org.nekorp.workflow.desktop.data.access.rest.ClienteDAOImp.java
@Override public void guardar(Cliente dato) { if (dato.getId() == null) { URI resource = factory.getTemplate().postForLocation(factory.getRootUlr() + "/clientes", dato); String[] uri = StringUtils.split(resource.toString(), '/'); String id = uri[uri.length - 1]; dato.setId(Long.valueOf(id)); } else {/*from w w w .j ava2 s . c o m*/ Map<String, Object> map = new HashMap<>(); map.put("id", dato.getId()); factory.getTemplate().postForLocation(factory.getRootUlr() + "/clientes/{id}", dato, map); } }
From source file:com.easarrive.aws.plugins.common.service.impl.TestS3Service.java
@Test public void getObject() { S3Object object = s3Service.getObject(client, bucketName, key); System.out.println(object);/* w ww .ja va 2 s.c om*/ URI uri = object.getObjectContent().getHttpRequest().getURI(); String url = uri.toASCIIString(); System.out.println(url); String url2 = uri.toString(); System.out.println(url2); }
From source file:gov.nih.nci.caarray.util.URIUserType.java
/** * {@inheritDoc}//from ww w .j av a 2s. c o m */ @Override public void nullSafeSet(PreparedStatement inPreparedStatement, Object o, int i) throws SQLException { final URI val = (URI) o; String uri = null; if (val != null) { uri = StringUtils.defaultString(val.toString()); } inPreparedStatement.setString(i, uri); }
From source file:org.openlmis.fulfillment.service.referencedata.RightReferenceDataServiceTest.java
@Test public void shouldReturnNullIfRightCannotBeFound() throws Exception { // given//from ww w.j av a 2s. c o m String name = "testRight"; RightDto[] rights = new RightDto[0]; RightReferenceDataService service = (RightReferenceDataService) prepareService(); ResponseEntity<RightDto[]> response = mock(ResponseEntity.class); // when when(restTemplate.exchange(any(URI.class), eq(HttpMethod.GET), any(HttpEntity.class), eq(service.getArrayResultClass()))).thenReturn(response); when(response.getBody()).thenReturn(rights); RightDto right = service.findRight(name); // then verify(restTemplate).exchange(uriCaptor.capture(), eq(HttpMethod.GET), entityCaptor.capture(), eq(service.getArrayResultClass())); URI uri = uriCaptor.getValue(); String url = service.getServiceUrl() + service.getUrl() + "search?name=" + name; assertThat(uri.toString(), is(equalTo(url))); assertThat(right, is(nullValue())); assertAuthHeader(entityCaptor.getValue()); assertThat(entityCaptor.getValue().getBody(), is(nullValue())); }