Java Code Examples for org.springframework.http.HttpStatus#FOUND

The following examples show how to use org.springframework.http.HttpStatus#FOUND . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AddressController.java    From resilient-transport-service with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "validate", method = RequestMethod.POST)
@ResponseBody
public ResponseEntity<AddressDTO> validateAdress(@RequestBody AddressDTO addressDTO, HttpServletRequest request) {

    Address address;
    try {
        appendSpan("not-found");
        address = addressService.validateAddress(addressDTO);
    } catch (Exception e) {
        appendSpan("not-found");
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }

    if (address == null) {
        appendSpan("not-found");
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }

    AddressDTO adressDTO = mapToAdressDTO(address);

    appendSpan(address.getCity());

    return new ResponseEntity<>(adressDTO, HttpStatus.FOUND);

}
 
Example 2
Source File: CustomerController.java    From resilient-transport-service with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "search/id")
@ResponseBody
public ResponseEntity<CustomerDTO> searchById(@RequestParam("customerId") Long customerId, HttpServletRequest request) {

    Customer customer;
    try {
        customer = customerService.findCustomerById(customerId);
    } catch (CustomerNotFoundException e) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }

    CustomerDTO customerDTO = mapToCustomerDTO(customer);

    appendSpan(customerDTO.getCustomerName(), "customer-name");
    appendSpan(String.valueOf(customerDTO.getCustomerId()), "customer-id");

    return new ResponseEntity<>(customerDTO, HttpStatus.FOUND);

}
 
Example 3
Source File: CustomerController.java    From resilient-transport-service with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "search/name")
@ResponseBody
public ResponseEntity<CustomerDTO> searchByName(@RequestParam("name") String name, HttpServletRequest request) {

    Customer customer;
    try {
        customer = customerService.findByName(name);

    } catch (CustomerNotFoundException e) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }

    CustomerDTO customerDTO = mapToCustomerDTO(customer);

    appendSpan(customerDTO.getCustomerName(), "customer-name");
    appendSpan(String.valueOf(customerDTO.getCustomerId()), "customer-id");

    return new ResponseEntity<>(customerDTO, HttpStatus.FOUND);

}
 
Example 4
Source File: BaseTests.java    From enhanced-pet-clinic with Apache License 2.0 6 votes vote down vote up
protected ResponseEntity<String> executeLogin(String username, String password) throws Exception {
	String url = "http://localhost:" + this.port + "/login";

	ResponseEntity<String> page = sendRequest(url, HttpMethod.GET);
	saveCSRFAndCookieValues(page);

	if (page.getStatusCode() == HttpStatus.FOUND) {
		page = sendRequest(page.getHeaders().getLocation(), HttpMethod.POST);
	}
	String body = page.getBody();
	assertNotNull("Body was null", body);

	httpHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);

	MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
	form.set("username", username);
	form.set("password", password);
	form.set("_csrf", csrfValue);

	page = sendRequest("http://localhost:" + this.port + "/login", HttpMethod.POST, form);

	assertEquals(HttpStatus.FOUND, page.getStatusCode());
	assertTrue("Login redirected to error page.", !page.getHeaders().getLocation().toString().contains("error"));

	return page;
}
 
Example 5
Source File: SampleWebUiApplicationTests.java    From enhanced-pet-clinic with Apache License 2.0 6 votes vote down vote up
@After
public void cleanSession() throws Exception {
	ResponseEntity<String> page = sendRequest("http://localhost:" + this.port, HttpMethod.GET);

	MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
	form.set("_csrf", csrfValue);
	httpHeaders.set("X-CSRF-TOKEN", csrfValue);

	page = sendRequest("http://localhost:" + this.port + "/logout", HttpMethod.GET, form);

	assertEquals(HttpStatus.FOUND, page.getStatusCode());

	if (page.getStatusCode() == HttpStatus.FOUND) {
		page = sendRequest(page.getHeaders().getLocation(), HttpMethod.GET);
	}

	httpHeaders = null;
	csrfValue = null;
}
 
Example 6
Source File: RedirectViewTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void customStatusCode() {
	String url = "https://url.somewhere.com";
	RedirectView view = new RedirectView(url, HttpStatus.FOUND);
	view.render(new HashMap<>(), MediaType.TEXT_HTML, this.exchange).block();
	assertEquals(HttpStatus.FOUND, this.exchange.getResponse().getStatusCode());
	assertEquals(URI.create(url), this.exchange.getResponse().getHeaders().getLocation());
}
 
Example 7
Source File: RedirectViewTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void customStatusCode() {
	String url = "http://url.somewhere.com";
	RedirectView view = new RedirectView(url, HttpStatus.FOUND);
	view.render(new HashMap<>(), MediaType.TEXT_HTML, this.exchange).block();
	assertEquals(HttpStatus.FOUND, this.exchange.getResponse().getStatusCode());
	assertEquals(URI.create(url), this.exchange.getResponse().getHeaders().getLocation());
}
 
Example 8
Source File: ResultVo.java    From MicroCommunity with Apache License 2.0 5 votes vote down vote up
/**
 * 页面跳转
 *
 * @param url
 * @return
 */
public static ResponseEntity<String> redirectPage(String url) {
    HttpHeaders headers = new HttpHeaders();
    headers.add(HttpHeaders.LOCATION, url);
    ResponseEntity<String> responseEntity = new ResponseEntity<String>("", headers, HttpStatus.FOUND);
    return responseEntity;
}
 
Example 9
Source File: RequestMonitor.java    From curl with The Unlicense 5 votes vote down vote up
@RequestMapping (value = "/private/login", produces = MediaType.TEXT_PLAIN_VALUE)
@ResponseStatus (code = HttpStatus.FOUND)
@ResponseBody
public String login (final HttpServletRequest request, final HttpServletResponse response, @RequestBody (required = false) final String body, final Authentication auth) {
    response.setHeader ("Location", this.serverLocation (request) + "/private/logged");
    this.logRequest (request, body);
    return "";
}
 
Example 10
Source File: RequestMonitor.java    From curl with The Unlicense 5 votes vote down vote up
@RequestMapping (value = "/public/redirection", produces = MediaType.TEXT_PLAIN_VALUE)
@ResponseStatus (code = HttpStatus.FOUND)
@ResponseBody
public String redirection (final HttpServletRequest request, final HttpServletResponse response, @RequestBody (required = false) final String body) {
    response.setHeader ("Location", this.serverLocation (request) + "/public/redirectedThere");
    this.logRequest (request, body);
    return "";
}
 
Example 11
Source File: DocumentAttachmentsRestController.java    From metasfresh-webui-api-legacy with GNU General Public License v3.0 5 votes vote down vote up
private static ResponseEntity<byte[]> extractResponseEntryFromURL(@NonNull final IDocumentAttachmentEntry entry)
{
	final HttpHeaders headers = new HttpHeaders();
	headers.setLocation(entry.getUrl()); // forward to attachment entry's URL
	final ResponseEntity<byte[]> response = new ResponseEntity<>(new byte[] {}, headers, HttpStatus.FOUND);
	return response;
}
 
Example 12
Source File: ControllerUtils.java    From wallride with Apache License 2.0 5 votes vote down vote up
public static ResponseEntity<?> createRedirectResponseEntity(
		HttpServletRequest nativeRequest,
		HttpServletResponse nativeResponse,
		String path) {
	UrlPathHelper pathHelper = new UrlPathHelper();
	String url = pathHelper.getContextPath(nativeRequest) + path;
	String encodedUrl = nativeResponse.encodeRedirectURL(url);
	
	HttpHeaders headers = new HttpHeaders();
	headers.setLocation(URI.create(encodedUrl));
	
	ResponseEntity<?> response = new ResponseEntity<>(null, headers, HttpStatus.FOUND);
	return response;
}
 
Example 13
Source File: ResponseUtils.java    From XS2A-Sandbox with Apache License 2.0 4 votes vote down vote up
public <T extends OnlineBankingResponse> ResponseEntity<T> redirect(String locationURI, HttpServletResponse httpResp) {
	HttpHeaders headers = new HttpHeaders();
	headers.add(LOCATION_HEADER_NAME, locationURI);
	removeCookies(httpResp);
	return new ResponseEntity<>(headers, HttpStatus.FOUND);
}
 
Example 14
Source File: SampleWebUiApplicationTests.java    From enhanced-pet-clinic with Apache License 2.0 4 votes vote down vote up
@Test
public void testCreateUserAndLogin() throws Exception {
	ResponseEntity<String> page = getPage("http://localhost:" + this.port + "/users");

	assertTrue("Client or server error.",
			!page.getStatusCode().is4xxClientError() && !page.getStatusCode().is5xxServerError());

	if (page.getStatusCode() == HttpStatus.FOUND) {
		page = getPage(page.getHeaders().getLocation());
	}

	String body = page.getBody();
	assertNotNull("Body was null", body);

	String username = "newuser";
	String password = "password";
	String formAction = getFormAction(page);

	MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
	form.set("username", username);
	form.set("email", "[email protected]");
	form.set("name", "New User");
	form.set("uiPassword", password);
	form.set("verifyPassword", password);
	form.set("_eventId_saveUser", "Create User");
	form.set("_csrf", csrfValue);

	httpHeaders.set("X-CSRF-TOKEN", csrfValue);

	page = postPage(formAction, form);

	if (page.getStatusCode() == HttpStatus.FOUND) {
		page = getPage(page.getHeaders().getLocation());
	}

	assertEquals(HttpStatus.OK, page.getStatusCode());
	body = page.getBody();
	assertNotNull("Body was null", body);
	assertTrue("User not created:\n" + body, body.contains("User " + username + " saved"));

	executeLogin(username, password);
}