List of usage examples for org.springframework.http HttpHeaders LOCATION
String LOCATION
To view the source code for org.springframework.http HttpHeaders LOCATION.
Click Source Link
From source file:org.moserp.product.rest.ProductRestTest.java
@Test public void retrieveProduct() { Response post = given().contentType(ContentType.JSON).body(new Product("My Product")).when() .post("/products"); String productUri = post.header(HttpHeaders.LOCATION); Product product = restTemplate.getForEntity(productUri, Product.class).getBody(); assertNotNull("productInstance", product); }
From source file:org.openwms.tms.CreateTODocumentation.java
public @Test void testCreateTO() throws Exception { MvcResult res = postTOAndValidate(createTO(), "to-create"); assertThat(res.getResponse().getHeaderValue(HttpHeaders.LOCATION)).isNotNull(); }
From source file:org.openwms.common.location.LocationGroupController.java
@PatchMapping(value = CommonConstants.API_LOCATIONGROUPS + "/{id}") public void save(@PathVariable String id, @RequestParam(name = "statein", required = false) LocationGroupState stateIn, @RequestParam(name = "stateout", required = false) LocationGroupState stateOut, HttpServletRequest req, HttpServletResponse res) {/* ww w . j a v a 2s . c om*/ locationGroupService.changeGroupState(id, stateIn, stateOut); res.addHeader(HttpHeaders.LOCATION, getLocationForCreatedResource(req, id)); }
From source file:org.openwms.tms.CreateTODocumentation.java
public @Test void testCreateTOAndGet() throws Exception { CreateTransportOrderVO vo = createTO(); MvcResult res = postTOAndValidate(vo, NOTLOGGED); String toLocation = (String) res.getResponse().getHeaderValue(HttpHeaders.LOCATION); mockMvc.perform(get(toLocation)).andExpect(status().isOk()) .andExpect(jsonPath("state", is(TransportOrderState.STARTED.toString()))) .andExpect(jsonPath("sourceLocation", is(INIT_LOC_STRING))) .andExpect(jsonPath("targetLocation", is(ERR_LOC_STRING))).andDo(document("to-create-and-get")); }
From source file:org.mitre.uma.view.ResourceSetEntityView.java
@Override protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) {/*from w w w .j av a 2 s .co m*/ response.setContentType("application/json"); HttpStatus code = (HttpStatus) model.get("code"); if (code == null) { code = HttpStatus.OK; // default to 200 } response.setStatus(code.value()); String location = (String) model.get("location"); if (!Strings.isNullOrEmpty(location)) { response.setHeader(HttpHeaders.LOCATION, location); } try { Writer out = response.getWriter(); ResourceSet rs = (ResourceSet) model.get("entity"); JsonObject o = new JsonObject(); o.addProperty("_id", rs.getId().toString()); // send the id as a string o.addProperty("user_access_policy_uri", config.getIssuer() + "manage/resource/" + rs.getId()); o.addProperty("name", rs.getName()); o.addProperty("uri", rs.getUri()); o.addProperty("type", rs.getType()); o.add("scopes", JsonUtils.getAsArray(rs.getScopes())); o.addProperty("icon_uri", rs.getIconUri()); gson.toJson(o, out); } catch (IOException e) { logger.error("IOException in ResourceSetEntityView.java: ", e); } }
From source file:org.openwms.tms.api.TransportationController.java
@PostMapping @ResponseStatus(HttpStatus.CREATED)/*from w ww . j a v a 2 s. c o m*/ public void createTO(@RequestBody CreateTransportOrderVO vo, HttpServletRequest req, HttpServletResponse resp) { validatePriority(vo); TransportOrder to = service.create(vo.getBarcode(), vo.getTarget(), PriorityLevel.valueOf(vo.getPriority())); resp.addHeader(HttpHeaders.LOCATION, getCreatedResourceURI(req, to.getPersistentKey())); }
From source file:org.mitre.uma.view.ResourceSetEntityAbbreviatedView.java
@Override protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) {/* w w w. j a v a2 s .c o m*/ response.setContentType("application/json"); HttpStatus code = (HttpStatus) model.get(HttpCodeView.CODE); if (code == null) { code = HttpStatus.OK; // default to 200 } response.setStatus(code.value()); String location = (String) model.get(LOCATION); if (!Strings.isNullOrEmpty(location)) { response.setHeader(HttpHeaders.LOCATION, location); } try { Writer out = response.getWriter(); ResourceSet rs = (ResourceSet) model.get(JsonEntityView.ENTITY); JsonObject o = new JsonObject(); o.addProperty("_id", rs.getId().toString()); // set the ID to a string o.addProperty("user_access_policy_uri", config.getIssuer() + "manage/user/policy/" + rs.getId()); gson.toJson(o, out); } catch (IOException e) { logger.error("IOException in ResourceSetEntityView.java: ", e); } }
From source file:org.openwms.core.uaa.api.RolesController.java
/** * Documented here: https://openwms.atlassian.net/wiki/x/BIAWAQ * * @param role The {@link Role} instance to be created * @return An {@link Response} object to encapsulate the result of the creation operation * @status Reviewed [scherrer]//from w ww .j ava2 s .com */ @PostMapping @ResponseBody public ResponseEntity<Response<RoleVO>> create(@RequestBody @Valid @NotNull RoleVO role, HttpServletRequest req, HttpServletResponse resp) { RoleVO createdRole = m.map(service.save(m.map(role, Role.class)), RoleVO.class); resp.addHeader(HttpHeaders.LOCATION, getLocationForCreatedResource(req, createdRole.getId().toString())); return buildResponse(HttpStatus.CREATED, translate(Messages.CREATED), Messages.CREATED); }
From source file:org.awesomeagile.testing.google.FakeGoogleController.java
@ResponseBody @RequestMapping(method = RequestMethod.GET, path = "/oauth2/auth") public ResponseEntity<?> authenticate(@RequestParam("client_id") String clientId, @RequestParam(value = "client_secret", required = false) String clientSecret, @RequestParam("response_type") String responseType, @RequestParam("redirect_uri") String redirectUri, @RequestParam("scope") String scope) { // Validate client_id and client_secret if (!this.clientId.equals(clientId) || (clientSecret != null && !this.clientSecret.equals(clientSecret))) { return ResponseEntity.<String>badRequest().body("Wrong client_id or client_secret!"); }/*www . java 2 s. com*/ if (!prefixMatches(redirectUri)) { return wrongRedirectUriResponse(); } String code = RandomStringUtils.randomAlphanumeric(64); String token = RandomStringUtils.randomAlphanumeric(64); codeToToken.put(code, new AccessToken(token, scope, "", System.currentTimeMillis() + EXPIRATION_MILLIS)); UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(redirectUri).queryParam(CODE, code); return ResponseEntity.status(HttpStatus.FOUND).header(HttpHeaders.LOCATION, builder.build().toUriString()) .build(); }
From source file:org.openwms.tms.CreateTODocumentation.java
public @Test void testCreateTOTargetNotAvailable() throws Exception { CreateTransportOrderVO vo = createTO(); vo.setTarget(ERR_LOC_STRING);//from w w w .ja v a 2 s . c o m Location loc = new Location(ERR_LOC_STRING); loc.setIncomingActive(false); given(commonGateway.getLocation(vo.getTarget())).willReturn(Optional.of(loc)); MvcResult res = mockMvc.perform(post(TMSConstants.ROOT_ENTITIES).contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(vo))).andExpect(status().isCreated()).andReturn(); String toLocation = (String) res.getResponse().getHeaderValue(HttpHeaders.LOCATION); mockMvc.perform(get(toLocation)).andExpect(status().isOk()) .andExpect(jsonPath("state", is(TransportOrderState.INITIALIZED.toString()))) .andExpect(jsonPath("sourceLocation", is(INIT_LOC_STRING))) .andExpect(jsonPath("targetLocation", is(ERR_LOC_STRING))) .andDo(document("to-create-and-get-target-na")); }