List of usage examples for org.springframework.web.util UriComponentsBuilder fromUriString
public static UriComponentsBuilder fromUriString(String uri)
From source file:org.cateproject.test.functional.mockmvc.HtmlUnitRequestBuilder.java
private UriComponents uriComponents() { URL url = webRequest.getUrl(); UriComponentsBuilder uriBldr = UriComponentsBuilder.fromUriString(url.toExternalForm()); return uriBldr.build(); }
From source file:org.zalando.boot.etcd.EtcdClient.java
/** * Atomically deletes a key-value pair in etcd. * /*from www. j a v a 2 s . c om*/ * @param key * the key * @param prevIndex * the modified index of the key * @return the response from etcd with the node * @throws EtcdException * in case etcd returned an error */ public EtcdResponse compareAndDelete(final String key, int prevIndex) throws EtcdException { UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(KEYSPACE); builder.pathSegment(key); builder.queryParam("prevIndex", prevIndex); return execute(builder, HttpMethod.DELETE, null, EtcdResponse.class); }
From source file:org.zalando.boot.etcd.EtcdClient.java
/** * Atomically deletes a key-value pair in etcd. * // www .j av a2 s . co m * @param key * the key * @param prevValue * the previous value of the key * @return the response from etcd with the node * @throws EtcdException * in case etcd returned an error */ public EtcdResponse compareAndDelete(final String key, String prevValue) throws EtcdException { UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(KEYSPACE); builder.pathSegment(key); builder.queryParam("prevValue", prevValue); return execute(builder, HttpMethod.DELETE, null, EtcdResponse.class); }
From source file:io.pivotal.github.GithubClient.java
private ResponseEntity<ImportGithubIssueResponse> importIssue(ImportGithubIssue importIssue) { URI uri = UriComponentsBuilder.fromUriString(getRepositoryUrl()).pathSegment("import", "issues").build() .toUri();/*from w ww . j a v a 2 s . co m*/ BodyBuilder request = RequestEntity.post(uri) .accept(new MediaType("application", "vnd.github.golden-comet-preview+json")) .header("Authorization", "token " + getAccessToken()); ResponseEntity<ImportGithubIssueResponse> result = rest.exchange(request.body(importIssue), ImportGithubIssueResponse.class); result.getBody().setImportIssue(importIssue); return result; }
From source file:org.springframework.data.rest.webmvc.jpa.JpaWebTests.java
/** * Checks, that the server only returns the properties contained in the projection requested. * //from ww w . j a v a 2 s .co m * @see OrderSummary * @see DATAREST-221 */ @Test public void returnsProjectionIfRequested() throws Exception { Link orders = client.discoverUnique("orders"); MockHttpServletResponse response = client.request(orders); Link orderLink = assertContentLinkWithRel("self", response, true).expand(); UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(orderLink.getHref()); String uri = builder.queryParam("projection", "summary").build().toUriString(); response = mvc.perform(get(uri)). // andExpect(status().isOk()). // andExpect(jsonPath("$.price", is(2.5))).// andReturn().getResponse(); assertJsonPathDoesntExist("$.lineItems", response); }
From source file:org.zalando.boot.etcd.EtcdClient.java
/** * Creates a directory node in etcd.//from w w w.j av a2 s.c o m * * @param key * the key * @return the response from etcd with the node * @throws EtcdException * in case etcd returned an error */ public EtcdResponse putDir(final String key) throws EtcdException { UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(KEYSPACE); builder.pathSegment(key); MultiValueMap<String, String> payload = new LinkedMultiValueMap<>(1); payload.set("dir", "true"); return execute(builder, HttpMethod.PUT, payload, EtcdResponse.class); }
From source file:com.github.hateoas.forms.spring.AffordanceBuilder.java
@Override public URI toUri() { PartialUriTemplate partialUriTemplate = new PartialUriTemplate(partialUriTemplateComponents.toString()); final String actionLink = partialUriTemplate.stripOptionalVariables(actionDescriptors).toString(); if (actionLink == null || actionLink.contains("{")) { throw new IllegalStateException("cannot convert template to URI"); }/*from w w w. jav a 2s. c om*/ return UriComponentsBuilder.fromUriString(actionLink).build().toUri(); }
From source file:org.zalando.boot.etcd.EtcdClient.java
/** * Creates a directory node in etcd./*w ww. ja v a 2 s .c om*/ * * @param key * the key * @param ttl * the time-to-live * @return the response from etcd with the node * @throws EtcdException * in case etcd returned an error */ public EtcdResponse putDir(String key, int ttl) throws EtcdException { UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(KEYSPACE); builder.pathSegment(key); MultiValueMap<String, String> payload = new LinkedMultiValueMap<>(1); payload.set("dir", "true"); payload.set("ttl", ttl == -1 ? "" : String.valueOf(ttl)); return execute(builder, HttpMethod.PUT, payload, EtcdResponse.class); }
From source file:org.zalando.boot.etcd.EtcdClient.java
public EtcdResponse deleteDir(String key) throws EtcdException { UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(KEYSPACE); builder.pathSegment(key);//from w w w .j a va 2s .co m builder.queryParam("dir", "true"); return execute(builder, HttpMethod.DELETE, null, EtcdResponse.class); }
From source file:net.slkdev.swagger.confluence.service.impl.XHtmlToConfluenceServiceImpl.java
private void addExistingPageData(final ConfluencePage confluencePage) { final SwaggerConfluenceConfig swaggerConfluenceConfig = SWAGGER_CONFLUENCE_CONFIG.get(); final HttpHeaders httpHeaders = buildHttpHeaders(swaggerConfluenceConfig.getAuthentication()); final HttpEntity<String> requestEntity = new HttpEntity<>(httpHeaders); final URI targetUrl = UriComponentsBuilder.fromUriString(swaggerConfluenceConfig.getConfluenceRestApiUrl()) .path("/content").queryParam(SPACE_KEY, swaggerConfluenceConfig.getSpaceKey()) .queryParam(TITLE, confluencePage.getConfluenceTitle()) .queryParam(EXPAND, "body.storage,version,ancestors").build().toUri(); final ResponseEntity<String> responseEntity = restTemplate.exchange(targetUrl, HttpMethod.GET, requestEntity, String.class); final String jsonBody = responseEntity.getBody(); try {/*from ww w.j a v a 2s . c o m*/ LOG.debug("GET RESPONSE: {}", jsonBody); final String id = JsonPath.read(jsonBody, "$.results[0].id"); final Integer version = JsonPath.read(jsonBody, "$.results[0].version.number"); final JSONArray ancestors = JsonPath.read(jsonBody, "$.results[0].ancestors"); if (!ancestors.isEmpty()) { final Map<String, Object> lastAncestor = (Map<String, Object>) ancestors.get(ancestors.size() - 1); final Integer ancestorId = Integer.valueOf((String) lastAncestor.get(ID)); LOG.debug("ANCESTORS: {} : {}, CHOSE -> {}", ancestors.getClass().getName(), ancestors, ancestorId); confluencePage.setAncestorId(ancestorId); } confluencePage.setId(id); confluencePage.setVersion(version); confluencePage.setExists(true); LOG.info("Page <{} : {}> Already Exists, Performing an Update!", confluencePage.getId(), confluencePage.getConfluenceTitle()); } catch (final PathNotFoundException e) { confluencePage.setExists(false); LOG.info("Page <{}> Does Not Exist, Creating a New Page!", confluencePage.getConfluenceTitle()); // Prevent New Pages from Being Orphaned if there was no ancestor id // specified by querying for the id of the space root. Confluence // does not do this automatically, and thus you would otherwise not be // able to navigate to the page unless you manually knew the URL if (confluencePage.getAncestorId() == null) { final ConfluencePage spaceRootPage = ConfluencePageBuilder.aConfluencePage() .withConfluenceTitle(swaggerConfluenceConfig.getSpaceKey()) .withOriginalTitle(swaggerConfluenceConfig.getSpaceKey()).build(); addExistingPageData(spaceRootPage); final Integer spaceRootAncestorId = Integer.valueOf(spaceRootPage.getId()); LOG.info("ORPHAN PREVENTION FAIL SAFE: Using Space Root Ancestor Id {}", spaceRootAncestorId); confluencePage.setAncestorId(spaceRootAncestorId); } } }