List of usage examples for javax.servlet.http HttpServletRequest getRequestURL
public StringBuffer getRequestURL();
From source file:net.sourceforge.subsonic.backend.controller.RedirectionController.java
private String getRedirectFrom(HttpServletRequest request) throws MalformedURLException { URL url = new URL(request.getRequestURL().toString()); String host = url.getHost();/*from w ww . jav a 2 s .c om*/ String redirectFrom; if (host.contains(".")) { redirectFrom = StringUtils.substringBefore(host, "."); } else { // For testing. redirectFrom = request.getParameter("redirectFrom"); } return StringUtils.lowerCase(redirectFrom); }
From source file:things.view.rest.ThingRestExceptionHandler.java
@ExceptionHandler(Error.class) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) @ResponseBody/*from w w w. j a va 2s .c om*/ public ErrorInfo error(final HttpServletRequest req, final Error ex) { myLogger.debug("Exception: " + ex.getLocalizedMessage(), ex); return new ErrorInfo(req.getRequestURL().toString(), ex); }
From source file:com.artivisi.belajar.restful.ui.controller.ProdukController.java
@RequestMapping(value = "/produk", method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED)//from w ww .j av a 2 s .co m public void create(@RequestBody @Valid Produk x, HttpServletRequest request, HttpServletResponse response) { belajarRestfulService.save(x); String requestUrl = request.getRequestURL().toString(); URI uri = new UriTemplate("{requestUrl}/{id}").expand(requestUrl, x.getId()); response.setHeader("Location", uri.toASCIIString()); }
From source file:com.artivisi.belajar.restful.ui.controller.SaleController.java
@RequestMapping(value = "/sale", method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED)/*w w w .ja v a2 s . c o m*/ public void create(@RequestBody @Valid Sale x, HttpServletRequest request, HttpServletResponse response) { belajarRestfulService.save(x); String requestUrl = request.getRequestURL().toString(); URI uri = new UriTemplate("{requestUrl}/{idjual}").expand(requestUrl, x.getIdJual()); response.setHeader("Location", uri.toASCIIString()); }
From source file:cec.easyshop.storefront.controllers.integration.BaseIntegrationController.java
protected void initializeSiteFromRequest(final HttpServletRequest httpRequest) { final String queryString = httpRequest.getQueryString(); final String currentRequestURL = httpRequest.getRequestURL().toString(); final String absoluteURL = StringUtils.removeEnd(currentRequestURL, "/") + (StringUtils.isBlank(queryString) ? "" : "?" + queryString); try {// ww w . jav a2s. c o m final URL currentURL = new URL(absoluteURL); final CMSSiteModel cmsSiteModel = cmsSiteService.getSiteForURL(currentURL); if (cmsSiteModel != null) { baseSiteService.setCurrentBaseSite(cmsSiteModel, true); } } catch (final MalformedURLException e) { if (LOG.isDebugEnabled()) { LOG.debug("Cannot find CMSSite associated with current URL ( " + absoluteURL + " - check whether this is correct URL) !"); } } catch (final CMSItemNotFoundException e) { LOG.warn("Cannot find CMSSite associated with current URL (" + absoluteURL + ")!"); if (LOG.isDebugEnabled()) { LOG.debug(e); } } }
From source file:nl.dtls.fairdatapoint.api.controller.DataAccessorController.java
@ApiOperation(value = "Dataset distribution metadata") @RequestMapping(produces = { "text/turtle", "application/ld+json", "application/rdf+xml", "text/n3" }, method = RequestMethod.GET) public String getDatasetDistribution(@PathVariable final String catalogID, @PathVariable final String datasetID, @PathVariable final String distributionID, HttpServletRequest request, HttpServletResponse response) { LOGGER.info("Request to get dataset's distribution {}", distributionID); LOGGER.info("GET : " + request.getRequestURL()); String responseBody = null;//from w w w. j av a 2s .c o m String acceptHeader = request.getHeader(HttpHeaders.ACCEPT); RDFFormat requesetedContentType = HttpHeadersUtils.getRequestedAcceptHeader(acceptHeader); try { responseBody = dataAccessorService.retrieveDatasetDistribution(catalogID, datasetID, distributionID, requesetedContentType); HttpHeadersUtils.set200ResponseHeaders(responseBody, response, requesetedContentType); } catch (DataAccessorServiceException ex) { HttpHeadersUtils.set500ResponseHeaders(response, ex); } LoggerUtils.logRequest(LOGGER, request, response); return responseBody; }
From source file:com.lennonjesus.auth.security.Http401UnauthorizedEntryPoint.java
/** * Always returns a 401 error code to the client. *//*from www. j av a 2s .co m*/ public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException arg2) throws IOException, ServletException { log.debug("Pre-authenticated entry point called. Rejecting access:" + request.getRequestURL()); response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Access Denied"); }
From source file:things.view.rest.ThingRestExceptionHandler.java
@ExceptionHandler(Exception.class) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) @ResponseBody//from www.j a v a 2 s .c om public ErrorInfo exception(final HttpServletRequest req, final Exception ex) { myLogger.debug("Exception: " + ex.getLocalizedMessage(), ex); return new ErrorInfo(req.getRequestURL().toString(), ex); }
From source file:com.sv.udb.utils.CustomComponent.java
private String getServerName(FacesContext context) { HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest(); String url = request.getRequestURL().toString(); String baseURL = url.substring(0, url.length() - request.getRequestURI().length()); return baseURL; }
From source file:com.fujitsu.dc.test.unit.core.jersey.filter.DcCoreContainerFilterTest.java
/** * ???/???????.//from w w w . j a v a 2s. c o m * X-FORWARDED-PROTO?X-FORWARDED-HOST?Uri, Base Uri?PROTO, HOST???????? * @throws URISyntaxException URISyntaxException */ @Test public void testFilterContainerRequest() throws URISyntaxException { // DcCoreContainerFilter containerFilter = new DcCoreContainerFilter(); // ContainerRequiest WebApplication wa = mock(WebApplication.class); InBoundHeaders headers = new InBoundHeaders(); // ? headers.add(DcCoreUtils.HttpHeaders.X_HTTP_METHOD_OVERRIDE, HttpMethod.OPTIONS); // ? String authzValue = "Bearer tokenstring"; String acceptValue = "text/html"; String contentTypeValue = "application/xml"; headers.add(DcCoreUtils.HttpHeaders.X_OVERRIDE, HttpHeaders.AUTHORIZATION + ": " + authzValue); headers.add(HttpHeaders.ACCEPT, contentTypeValue); headers.add(DcCoreUtils.HttpHeaders.X_OVERRIDE, HttpHeaders.ACCEPT + ": " + acceptValue); headers.add(HttpHeaders.CONTENT_TYPE, contentTypeValue); // X-FORWARDED-* ? String scheme = "https"; String host = "example.org"; headers.add(DcCoreUtils.HttpHeaders.X_FORWARDED_PROTO, scheme); headers.add(DcCoreUtils.HttpHeaders.X_FORWARDED_HOST, host); ContainerRequest request = new ContainerRequest(wa, HttpMethod.POST, new URI("http://dc1.example.com/hoge"), new URI("http://dc1.example.com/hoge/hoho"), headers, null); // HttpServletRequest?mock HttpServletRequest mockServletRequest = mock(HttpServletRequest.class); when(mockServletRequest.getRequestURL()).thenReturn(new StringBuffer("http://dc1.example.com")); ServletContext mockServletContext = mock(ServletContext.class); when(mockServletContext.getContextPath()).thenReturn(""); when(mockServletRequest.getServletContext()).thenReturn(mockServletContext); containerFilter.setHttpServletRequest(mockServletRequest); // ?? ContainerRequest filteredRequest = containerFilter.filter(request); // ?? Assert.assertEquals(HttpMethod.OPTIONS, filteredRequest.getMethod()); Assert.assertEquals(authzValue, filteredRequest.getHeaderValue(HttpHeaders.AUTHORIZATION)); Assert.assertEquals(acceptValue, filteredRequest.getHeaderValue(HttpHeaders.ACCEPT)); Assert.assertEquals(contentTypeValue, filteredRequest.getHeaderValue(HttpHeaders.CONTENT_TYPE)); Assert.assertEquals(scheme, filteredRequest.getRequestUri().getScheme()); Assert.assertEquals(host, filteredRequest.getRequestUri().getHost()); }