List of usage examples for javax.servlet.http HttpServletRequest getRequestURL
public StringBuffer getRequestURL();
From source file:io.personium.test.unit.core.jersey.filter.PersoniumCoreContainerFilterTest.java
/** * ???/???????./*from w ww. ja va2s . c o m*/ * X-FORWARDED-PROTO?X-FORWARDED-HOST?Uri, Base Uri?PROTO, HOST???????? * @throws URISyntaxException URISyntaxException */ @Test public void testFilterContainerRequest() throws URISyntaxException { // PersoniumCoreContainerFilter containerFilter = new PersoniumCoreContainerFilter(); // ContainerRequiest WebApplication wa = mock(WebApplication.class); InBoundHeaders headers = new InBoundHeaders(); // ? headers.add(PersoniumCoreUtils.HttpHeaders.X_HTTP_METHOD_OVERRIDE, HttpMethod.OPTIONS); // ? String authzValue = "Bearer tokenstring"; String acceptValue = "text/html"; String contentTypeValue = "application/xml"; headers.add(PersoniumCoreUtils.HttpHeaders.X_OVERRIDE, HttpHeaders.AUTHORIZATION + ": " + authzValue); headers.add(HttpHeaders.ACCEPT, contentTypeValue); headers.add(PersoniumCoreUtils.HttpHeaders.X_OVERRIDE, HttpHeaders.ACCEPT + ": " + acceptValue); headers.add(HttpHeaders.CONTENT_TYPE, contentTypeValue); // X-FORWARDED-* ? String scheme = "https"; String host = "example.org"; headers.add(PersoniumCoreUtils.HttpHeaders.X_FORWARDED_PROTO, scheme); headers.add(PersoniumCoreUtils.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()); }
From source file:nl.mok.mastersofcode.spectatorclient.controllers.IndexController.java
@RequestMapping(method = RequestMethod.GET) public ModelAndView showIndex(final HttpServletRequest request) { ModelAndView mav = new ModelAndView(); mav.addObject("page", new Object() { public String uri = "/spec/"; public String redirect = request.getRequestURL().toString(); });//from w w w. ja v a 2s . c om mav.addObject("competitions", DataController.getCompetitions()); mav.addObject("currentCompetition", DataController.getCurrentCompetition()); mav.addObject("currentRound", DataController.getCurrentRound()); mav.setViewName("index.twig"); return mav; }
From source file:org.shaf.server.controller.ExceptionHandlingController.java
/** * Handles the unexpected exception./*from www. j a v a 2s. c om*/ * * @param request * the server request. * @param exception * the occurred exception. * @return the view with exception dump and target IRL. */ @ExceptionHandler(Exception.class) public ModelAndView defaultErrorHandler(HttpServletRequest request, Exception exception) { LOG.debug("CALL: error handler"); exception.printStackTrace(); return ViewError.getErrorView().header("url", request.getRequestURL().toString()).addException(exception) .warn("Check the system log for more details."); }
From source file:org.shaf.server.controller.ExceptionHandlingController.java
@ExceptionHandler({ AuthenticationException.class }) @ResponseStatus(value = HttpStatus.UNAUTHORIZED) public ModelAndView handleAuthenticationException(HttpServletRequest request, Exception exception) { LOG.debug("CALL: error handler"); exception.printStackTrace();/*from ww w .j av a2s.co m*/ return ViewError.getErrorView().header("url", request.getRequestURL().toString()).addException(exception) .warn("Check the system log for more details."); }
From source file:cn.org.once.cstack.config.Http401EntryPoint.java
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException arg) throws IOException, ServletException { // Maybe change the log level... log.warn("Access Denied [ " + request.getRequestURL().toString() + "] : " + arg.getMessage()); response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Access unauthorized"); }
From source file:com.github.wnameless.spring.bulkapi.DefaultBulkApiService.java
private URI computeUri(HttpServletRequest servReq, BulkOperation op) { String rawUrl = servReq.getRequestURL().toString(); String rawUri = servReq.getRequestURI().toString(); if (op.getUrl() == null || isBulkPath(op.getUrl())) { throw new BulkApiException(UNPROCESSABLE_ENTITY, "Invalid URL(" + rawUri + ") exists in this bulk request"); }/*from w ww .j a va 2 s . c o m*/ URI uri; try { String servletPath = rawUrl.substring(0, rawUrl.indexOf(rawUri)); uri = new URI(servletPath + urlify(op.getUrl())); } catch (URISyntaxException e) { throw new BulkApiException(UNPROCESSABLE_ENTITY, "Invalid URL(" + urlify(op.getUrl()) + ") exists in this bulk request"); } if (!validator.validatePath(urlify(op.getUrl()), httpMethod(op.getMethod()))) { throw new BulkApiException(UNPROCESSABLE_ENTITY, "Invalid URL(" + urlify(op.getUrl()) + ") exists in this bulk request"); } return uri; }
From source file:com.education.lessons.ui.server.login.OpenIDLoginController.java
/** * Builds the current full URL.//from www .j a va 2 s. c o m */ private String getRequestURL(HttpServletRequest request, boolean qs) { StringBuffer requestURL = request.getRequestURL(); String queryString = request.getQueryString(); if (qs && queryString != null && !queryString.isEmpty()) { requestURL.append("?").append(queryString); } return requestURL.toString(); }
From source file:fr.univlille2.ecm.platform.ui.web.auth.cas2.AnonymousAuthenticatorForCAS2.java
@Override public Boolean handleLogout(HttpServletRequest httpRequest, HttpServletResponse httpResponse) { boolean isRedirectionToCas = false; log.debug(httpRequest.getRequestURL().toString()); Cookie[] cookies = httpRequest.getCookies(); for (Cookie cookie : cookies) { log.debug(String.format("ANONYMOUS_AUTH : cookie->%s:%s", cookie.getName(), cookie.getValue())); if (NXAuthConstants.SSO_INITIAL_URL_REQUEST_KEY.equals(cookie.getName())) { isRedirectionToCas = true;//from ww w . jav a2 s. c o m log.debug("isRedirectionToCAS"); break; } } if (isRedirectionToCas) { String authURL = getCas2Authenticator().getServiceURL(httpRequest, Cas2Authenticator.LOGIN_ACTION); String appURL = getCas2Authenticator().getAppURL(httpRequest); try { Map<String, String> urlParameters = new HashMap<String, String>(); urlParameters.put("service", URLEncoder.encode(appURL, "UTF-8")); String location = URIUtils.addParametersToURIQuery(authURL, urlParameters); httpResponse.sendRedirect(location); return true; } catch (IOException e) { log.error("Unable to redirect to CAS logout screen:", e); return false; } } return super.handleLogout(httpRequest, httpResponse); }
From source file:eionet.web.filter.ContentNegotiationFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { request.setCharacterEncoding("utf-8"); HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; String requestUrl = httpRequest.getRequestURL().toString(); if (!StringUtils.endsWithIgnoreCase(requestUrl, "/rdf")) { if (isRdfXmlPreferred(httpRequest)) { String redirectUrl = requestUrl + "/rdf"; httpResponse.sendRedirect(redirectUrl); return; }//from w w w. j av a2 s .c o m } chain.doFilter(request, response); }
From source file:it.smartcommunitylab.aac.controller.BasicProfileController.java
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) @ExceptionHandler(Exception.class) @ResponseBody//from w ww .j a v a2s. c o m ErrorInfo handleBadRequest(HttpServletRequest req, Exception ex) { StackTraceElement ste = ex.getStackTrace()[0]; return new ErrorInfo(req.getRequestURL().toString(), ex.getClass().getTypeName(), ste.getClassName(), ste.getLineNumber()); }