List of usage examples for java.net URI create
public static URI create(String str)
From source file:com.olacabs.fabric.compute.builder.impl.HttpJarDownloader.java
public Path download(final String url) { HttpGet httpGet = new HttpGet(URI.create(url)); CloseableHttpResponse response = null; try {/*www.jav a 2s.c om*/ response = httpClient.execute(httpGet); if (HttpStatus.SC_OK != response.getStatusLine().getStatusCode()) { throw new RuntimeException(String.format("Server returned [%d][%s] for url: %s", response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase(), url)); } Header[] headers = response.getHeaders("Content-Disposition"); String filename = null; if (null != headers) { for (Header header : headers) { for (HeaderElement headerElement : header.getElements()) { if (!headerElement.getName().equalsIgnoreCase("attachment")) { continue; } NameValuePair attachment = headerElement.getParameterByName("filename"); if (attachment != null) { filename = attachment.getValue(); } } } } if (Strings.isNullOrEmpty(filename)) { String[] nameParts = url.split("/"); filename = nameParts[nameParts.length - 1]; } return Files.write(Paths.get(this.tmpDirectory, filename), EntityUtils.toByteArray(response.getEntity())); } catch (IOException e) { throw new RuntimeException("Error loading class from: " + url, e); } finally { if (null != response) { try { response.close(); } catch (IOException e) { LOGGER.error("Could not close connection to server: ", e); } } } }
From source file:com.grummages.app.rest.entity.service.ListingAddonRESTFacade.java
@POST @Consumes({ "application/json" }) @Transactional/*from w ww . j a va 2s . co m*/ public Response create(ListingAddon entity) { entityManager.persist(entity); return Response.created(URI.create(Double.parseDouble(entity.getListingAddonPK().getListingId()) + "," + Double.parseDouble(entity.getListingAddonPK().getAddonId()).toString())).build(); }
From source file:com.gopivotal.cloudfoundry.test.support.operations.RestOperationsTestOperationsTest.java
@Test public void dataSourceUrl() throws Exception { when(this.restOperations.getForObject("http://{host}/datasource/url", String.class, "test-host")) .thenReturn("http://test.url"); URI value = this.testOperations.dataSourceUrl(); assertEquals(URI.create("http://test.url"), value); }
From source file:io.gravitee.management.rest.resource.UsersResource.java
/** * Create a new user./*from w w w .j a va 2s . c o m*/ * @param newUserEntity * @return */ @POST @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response createUser(@Valid NewUserEntity newUserEntity) { // encode password if (passwordEncoder == null) { passwordEncoder = NoOpPasswordEncoder.getInstance(); } newUserEntity.setPassword(passwordEncoder.encode(newUserEntity.getPassword())); UserEntity newUser = userService.create(newUserEntity); if (newUser != null) { return Response.created(URI.create("/users/" + newUser.getUsername())).entity(newUser).build(); } return Response.serverError().build(); }
From source file:com.msopentech.odatajclient.engine.data.impl.JSONPropertyDeserializer.java
@Override protected JSONProperty doDeserialize(final JsonParser parser, final DeserializationContext ctxt) throws IOException, JsonProcessingException { final ObjectNode tree = (ObjectNode) parser.getCodec().readTree(parser); final JSONProperty property = new JSONProperty(); if (tree.hasNonNull(ODataConstants.JSON_METADATA)) { property.setMetadata(URI.create(tree.get(ODataConstants.JSON_METADATA).textValue())); tree.remove(ODataConstants.JSON_METADATA); }//from w w w . j a v a 2 s . c om try { final DocumentBuilder builder = XMLUtils.DOC_BUILDER_FACTORY.newDocumentBuilder(); final Document document = builder.newDocument(); Element content = document.createElement(ODataConstants.ELEM_PROPERTY); if (property.getMetadata() != null) { final String metadataURI = property.getMetadata().toASCIIString(); final int dashIdx = metadataURI.lastIndexOf('#'); if (dashIdx != -1) { content.setAttribute(ODataConstants.ATTR_M_TYPE, metadataURI.substring(dashIdx + 1)); } } JsonNode subtree = null; if (tree.has(ODataConstants.JSON_VALUE)) { if (tree.has(ODataConstants.JSON_TYPE) && StringUtils.isBlank(content.getAttribute(ODataConstants.ATTR_M_TYPE))) { content.setAttribute(ODataConstants.ATTR_M_TYPE, tree.get(ODataConstants.JSON_TYPE).asText()); } final JsonNode value = tree.get(ODataConstants.JSON_VALUE); if (value.isValueNode()) { content.appendChild(document.createTextNode(value.asText())); } else if (EdmSimpleType.isGeospatial(content.getAttribute(ODataConstants.ATTR_M_TYPE))) { subtree = tree.objectNode(); ((ObjectNode) subtree).put(ODataConstants.JSON_VALUE, tree.get(ODataConstants.JSON_VALUE)); if (StringUtils.isNotBlank(content.getAttribute(ODataConstants.ATTR_M_TYPE))) { ((ObjectNode) subtree).put(ODataConstants.JSON_VALUE + "@" + ODataConstants.JSON_TYPE, content.getAttribute(ODataConstants.ATTR_M_TYPE)); } } else { subtree = tree.get(ODataConstants.JSON_VALUE); } } else { subtree = tree; } if (subtree != null) { JSONDOMTreeUtils.buildSubtree(client, content, subtree); } final List<Node> children = XMLUtils.getChildNodes(content, Node.ELEMENT_NODE); if (children.size() == 1) { final Element value = (Element) children.iterator().next(); if (ODataConstants.JSON_VALUE.equals(XMLUtils.getSimpleName(value))) { if (StringUtils.isNotBlank(content.getAttribute(ODataConstants.ATTR_M_TYPE))) { value.setAttribute(ODataConstants.ATTR_M_TYPE, content.getAttribute(ODataConstants.ATTR_M_TYPE)); } content = value; } } property.setContent(content); } catch (ParserConfigurationException e) { throw new JsonParseException("Cannot build property", parser.getCurrentLocation(), e); } return property; }
From source file:org.springframework.cloud.netflix.ribbon.apache.RibbonApacheHttpResponseTests.java
@Test public void testNotNullEntity() throws Exception { StatusLine statusLine = mock(StatusLine.class); given(statusLine.getStatusCode()).willReturn(204); HttpResponse response = mock(HttpResponse.class); given(response.getStatusLine()).willReturn(statusLine); BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(new ByteArrayInputStream(new byte[0])); given(response.getEntity()).willReturn(entity); RibbonApacheHttpResponse httpResponse = new RibbonApacheHttpResponse(response, URI.create("http://example.com")); assertThat(httpResponse.isSuccess(), is(true)); assertThat(httpResponse.hasPayload(), is(true)); assertThat(httpResponse.getPayload(), is(notNullValue())); assertThat(httpResponse.getInputStream(), is(notNullValue())); }
From source file:org.apache.openejb.arquillian.tests.jaxrs.JaxrsTest.java
protected URI uri(String path) { return URI.create(String.format("%s%s", url.toExternalForm(), path)); }
From source file:io.coala.eve3.EveUtil.java
/** * @param agentID/* w ww. j av a2s .c o m*/ * @return */ public static URI getAddress(final AgentID agentID) { // FIXME create/employ global lookup service/agent return URI.create("local:" + toEveAgentId(agentID)); }
From source file:com.amazonaws.http.DelegatingDnsResolverTest.java
@Test public void testDelegateIsCalledWhenRequestIsMade() { // The ExecutionContext should collect the expected RequestCount ExecutionContext context = new ExecutionContext(true); String randomHost = UUID.randomUUID().toString(); final Request<String> request = new DefaultRequest<String>("bob") { };/* www .j ava 2 s. c o m*/ request.setEndpoint(URI.create("http://" + randomHost + "/")); request.setHttpMethod(HttpMethodName.GET); try { testedClient.execute(request, null, null, context); Assert.fail("AmazonClientException is expected."); } catch (AmazonClientException ace) { } assertTrue("dnsResolver should have been called at least once", dnsResolutionCounter.get() > 0); assertTrue("An attempt to resolve host " + randomHost + " should have been made", requestedHosts.contains(randomHost)); }
From source file:org.zodiark.publisher.PublisherTest.java
@BeforeClass public void startZodiark() { server = new ZodiarkServer().listen(URI.create("http://127.0.0.1:" + port)).on(); }