List of usage examples for javax.servlet.http HttpServletRequest getRequestURL
public StringBuffer getRequestURL();
From source file:br.com.semanticwot.cd.controllers.GatewayController.java
@ExceptionHandler({ GatewayWotNotCreated.class }) public ModelAndView handleError(HttpServletRequest req, Exception exception) { LOGGER.log(Level.WARNING, "Request: {0} raised {1}", new Object[] { req.getRequestURL(), exception }); ModelAndView mav = new ModelAndView(); mav.addObject("info", exception.getMessage()); mav.addObject("gateway", new GatewayForm()); mav.addObject("url", req.getRequestURL()); mav.setViewName("gateway/form"); return mav;// w ww. ja v a2 s . c o m }
From source file:com.devicehive.application.filter.SwaggerFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { URL requestUrl = new URL(request.getRequestURL().toString()); logger.debug("Swagger filter triggered by '{}: {}'. Request will be redirected to swagger page", request.getMethod(), requestUrl); String swaggerJsonUrl = String.format("%s://%s:%s%s%s/swagger.json", requestUrl.getProtocol(), requestUrl.getHost(),//w ww . j av a 2 s . c o m requestUrl.getPort() == -1 ? requestUrl.getDefaultPort() : requestUrl.getPort(), request.getContextPath(), JerseyConfig.REST_PATH); String url = request.getContextPath() + "/swagger.html?url=" + swaggerJsonUrl; logger.debug("Request is being redirected to '{}'", url); response.sendRedirect(url); }
From source file:org.smigo.config.RequestLogFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletResponse resp = (HttpServletResponse) response; HttpServletRequest req = (HttpServletRequest) request; resp.addHeader("SmigoUser", req.getRemoteUser()); log.info("Incoming request:" + req.getMethod() + req.getRequestURL().toString()); request.setAttribute(REQUEST_TIMER, System.nanoTime()); chain.doFilter(request, response);/*from w ww . java 2 s. co m*/ logHandler.log(req, resp); }
From source file:io.kamax.mxisd.controller.DefaultExceptionHandler.java
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) @ExceptionHandler(RuntimeException.class) public String handle(HttpServletRequest req, RuntimeException e) { log.error("Unknown error when handling {}", req.getRequestURL(), e); return handle(req, "M_UNKNOWN", StringUtils.defaultIfBlank(e.getMessage(), "An internal server error occurred. If this error persists, please contact support with reference #" + Instant.now().toEpochMilli())); }
From source file:net.big_oh.common.web.listener.request.ObservedHttpServletRequest.java
public ObservedHttpServletRequest(HttpServletRequest request) { super(request); httpMethod = request.getMethod();//from w w w . ja v a 2s. c om resourceRequested = request.getRequestURL().toString(); queryString = request.getQueryString(); contextName = request.getContextPath(); containerUserName = request.getRemoteUser(); HttpSession session = request.getSession(false); jSessionId = (session == null) ? null : session.getId(); }
From source file:com.artivisi.belajar.restful.ui.controller.UserController.java
@RequestMapping(value = "/user", method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED)//ww w . j ava 2 s .c o m public void create(@RequestBody @Valid User 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.idega.block.oauth2.client.servlet.GoogleAuthorizationCodeServlet.java
@Override protected String getRedirectUri(HttpServletRequest req) throws ServletException, IOException { GenericUrl url = new GenericUrl(req.getRequestURL().toString()); url.setRawPath(GoogleLoginService.BEAN_NAME); return url.build(); }
From source file:org.osiam.resources.controller.GroupController.java
private void setLocationUriWithNewId(HttpServletRequest request, HttpServletResponse response, String id) { String requestUrl = request.getRequestURL().toString(); URI uri = new UriTemplate("{requestUrl}{internalId}").expand(requestUrl + "/", id); response.setHeader("Location", uri.toASCIIString()); }
From source file:eu.freme.common.exception.ExceptionHandlerService.java
public ResponseEntity<String> handleError(HttpServletRequest req, Throwable exception) { logger.error("Request: " + req.getRequestURL() + " raised ", exception); HttpStatus statusCode = null;/*w ww . java2 s . c om*/ if (exception instanceof MissingServletRequestParameterException) { // create response for spring exceptions statusCode = HttpStatus.BAD_REQUEST; } else if (exception instanceof FREMEHttpException && ((FREMEHttpException) exception).getHttpStatusCode() != null) { // get response code from FREMEHttpException statusCode = ((FREMEHttpException) exception).getHttpStatusCode(); } else if (exception instanceof AccessDeniedException) { statusCode = HttpStatus.UNAUTHORIZED; } else if (exception instanceof HttpMessageNotReadableException) { statusCode = HttpStatus.BAD_REQUEST; } else { // get status code from exception class annotation Annotation responseStatusAnnotation = exception.getClass().getAnnotation(ResponseStatus.class); if (responseStatusAnnotation instanceof ResponseStatus) { statusCode = ((ResponseStatus) responseStatusAnnotation).value(); } else { // set default status code 500 statusCode = HttpStatus.INTERNAL_SERVER_ERROR; } } JSONObject json = new JSONObject(); json.put("status", statusCode.value()); json.put("message", exception.getMessage()); json.put("error", statusCode.getReasonPhrase()); json.put("timestamp", new Date().getTime()); json.put("exception", exception.getClass().getName()); json.put("path", req.getRequestURI()); if (exception instanceof AdditionalFieldsException) { Map<String, JSONObject> additionalFields = ((AdditionalFieldsException) exception) .getAdditionalFields(); for (String key : additionalFields.keySet()) { json.put(key, additionalFields.get(key)); } } HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.add("Content-Type", "application/json"); return new ResponseEntity<String>(json.toString(2), responseHeaders, statusCode); }
From source file:com.artivisi.belajar.restful.ui.controller.RoleController.java
@RequestMapping(value = "/role", method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED)//from w ww .ja va2s .com public void create(@RequestBody @Valid Role 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()); }