List of usage examples for javax.servlet.http HttpServletResponse getStatus
public int getStatus();
From source file:org.bessle.neo4j.proxy.HttpRequestLoggingFilter.java
protected void enhanceTrace(Map<String, Object> trace, HttpServletResponse response) { Map<String, String> headers = new LinkedHashMap<String, String>(); for (String header : response.getHeaderNames()) { String value = response.getHeader(header); headers.put(header, value);//w ww . ja va 2s .co m } headers.put("status", "" + response.getStatus()); @SuppressWarnings("unchecked") Map<String, Object> allHeaders = (Map<String, Object>) trace.get("headers"); allHeaders.put("response", headers); }
From source file:servlets.Tickets.java
/** * Handles the HTTP <code>GET</code> method. * * @param request servlet request//from w ww. j a v a 2s. co m * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); Map<String, String[]> paramMap = request.getParameterMap(); if (paramMap.isEmpty()) { try (PrintWriter out = response.getWriter()) { SelectTicketListTemplate ticketList = new SelectTicketListTemplate(response.getStatus(), DataHelper.getInstance().getTicketIds()); ObjectMapper mapper = new ObjectMapper(); mapper.writeValue(out, ticketList); } catch (Exception e) { } //? ID ? Issue } }
From source file:com.ge.predix.acs.commons.web.RestErrorHandlerTest.java
@Test public void testRestApiException() { RestErrorHandler errorHandler = new RestErrorHandler(); HttpServletRequest request = new MockHttpServletRequest(); HttpServletResponse response = new MockHttpServletResponse(); Exception e = new RestApiException(HttpStatus.NOT_ACCEPTABLE, "NOT_ACCEPTABLE", "Not acceptable Error Message"); ModelAndView errorResponse = errorHandler.createApiErrorResponse(e, request, response); // Custom error status code 406 Assert.assertEquals(response.getStatus(), HttpStatus.NOT_ACCEPTABLE.value()); Assert.assertNotNull(errorResponse); Assert.assertNotNull(errorResponse.getModel().get("ErrorDetails")); // Response payload with customer error code and message assertRestApiErrorResponse(errorResponse, "NOT_ACCEPTABLE", "Not acceptable Error Message"); }
From source file:com.thorpora.module.core.error.ErrorLogger.java
public void logServletError(Logger logger, HttpServletRequest request, HttpServletResponse response) { String requestFullpath = request.getRequestURI(); if (request.getQueryString() != null) { requestFullpath += "?" + request.getQueryString(); }/*from w ww .ja va 2 s . c o m*/ String msg = String.format("Servlet error [%s] : %s (will forward to /error)", response.getStatus(), requestFullpath); if (response.getStatus() >= 500) { logger.error(msg); } else { logger.info(msg); } }
From source file:org.wso2.carbon.analytics.message.tracer.MessageTracerFilter.java
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { if (servletRequest instanceof HttpServletRequest) { HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest; MultiReadHttpServletRequest bufferedRequest = new MultiReadHttpServletRequest(httpServletRequest); Message message = new Message(); message.setHost(bufferedRequest.getLocalAddr()); message.setResourceUrl(bufferedRequest.getRequestURI()); if (isDumpMessageBody) { message.setPayload(bufferedRequest.getRequestBody()); }// ww w. ja va 2s . c o m String activityId = bufferedRequest.getHeader(MessageTracerConstants.ACTIVITY_ID_KEY); if (activityId == null || activityId.isEmpty()) { activityId = String.valueOf(System.nanoTime()) + Math.round(Math.random() * 123456789); } message.setActivityId(activityId); message.setType(MESSAGE_TYPE); message.setRequestMethod(bufferedRequest.getMethod()); Map<String, String> additionalValues = getAdditionalDetails(bufferedRequest); message.setAdditionalValues(additionalValues); message.setTimestamp(System.currentTimeMillis()); if (servletResponse instanceof HttpServletResponse) { HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse; int status = httpServletResponse.getStatus(); if (status == 200 || status == 202) { message.setStatus(SUCCESS); } else { message.setStatus(FAULT); } } eventPublisher.publish(message); filterChain.doFilter(bufferedRequest, servletResponse); } else { filterChain.doFilter(servletRequest, servletResponse); } }
From source file:org.springframework.boot.actuate.trace.WebRequestTraceFilter.java
private Map<String, String> getResponseHeaders(HttpServletResponse response) { Map<String, String> headers = new LinkedHashMap<String, String>(); for (String header : response.getHeaderNames()) { String value = response.getHeader(header); headers.put(header, value);/*from w w w. j a v a 2s .c o m*/ } headers.put("status", "" + response.getStatus()); return headers; }
From source file:com.hp.autonomy.frontend.find.core.web.CustomErrorController.java
@RequestMapping(DispatcherServletConfiguration.SERVER_ERROR_PATH) public ModelAndView serverErrorPage(final HttpServletRequest request, final HttpServletResponse response) { final Exception exception = (Exception) request.getAttribute(RequestDispatcher.ERROR_EXCEPTION); return controllerUtils.buildErrorModelAndView(new ErrorModelAndViewInfo.Builder().setRequest(request) .setMainMessageCode(MESSAGE_CODE_INTERNAL_SERVER_ERROR_MAIN) .setSubMessageCode(MESSAGE_CODE_INTERNAL_SERVER_ERROR_SUB).setSubMessageArguments(null) .setStatusCode(response.getStatus()).setContactSupport(true).setButtonHref(getErrorUrl(request)) .setException(exception).build()); }
From source file:com.ibm.jaggr.core.test.TestUtils.java
public static HttpServletResponse createMockResponse(final Map<String, String> responseAttributes) { HttpServletResponse mockResponse = EasyMock.createNiceMock(HttpServletResponse.class); mockResponse.setContentLength(EasyMock.anyInt()); EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() { public Object answer() throws Throwable { if (responseAttributes != null) { responseAttributes.put("Content-Length", ((Integer) EasyMock.getCurrentArguments()[0]).toString()); }//from ww w . ja va 2s .c o m return null; } }).anyTimes(); mockResponse.setStatus(EasyMock.anyInt()); EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() { public Object answer() throws Throwable { if (responseAttributes != null) { responseAttributes.put("Status", ((Integer) EasyMock.getCurrentArguments()[0]).toString()); } return null; } }).anyTimes(); EasyMock.expect(mockResponse.getStatus()).andAnswer(new IAnswer<Integer>() { @Override public Integer answer() throws Throwable { int result = 0; if (responseAttributes != null) { result = Integer.parseInt(responseAttributes.get("Status")); } return result; } }).anyTimes(); return mockResponse; }
From source file:com.netflix.spinnaker.kork.web.interceptors.MetricsInterceptor.java
@Override public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { if (handler instanceof HandlerMethod) { HandlerMethod handlerMethod = (HandlerMethod) handler; String controller = handlerMethod.getMethod().getDeclaringClass().getSimpleName(); if (controllersToExclude.contains(controller)) { return; }// w ww . ja v a2 s. com Integer status = response.getStatus(); if (ex != null) { // propagated exceptions should get tracked as '500' regardless of response status status = 500; } Id id = registry.createId(metricName).withTag("controller", controller) .withTag("method", handlerMethod.getMethod().getName()) .withTag("status", status.toString().charAt(0) + "xx").withTag("statusCode", status.toString()); Map variables = (Map) request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE); for (String pathVariable : pathVariablesToTag) { if (variables.containsKey(pathVariable)) { id = id.withTag(pathVariable, variables.get(pathVariable).toString()); } } if (ex != null) { id = id.withTag("success", "false").withTag("cause", ex.getClass().getSimpleName()); } else { id = id.withTag("success", "true"); } registry.timer(id).record(getNanoTime() - ((Long) request.getAttribute(TIMER_ATTRIBUTE)), TimeUnit.NANOSECONDS); } }
From source file:nl.dtls.fairdatapoint.api.config.ApplicationFilter.java
@Override public void doFilter(ServletRequest sr, ServletResponse sr1, FilterChain fc) throws IOException, ServletException { HttpServletResponse response = (HttpServletResponse) sr1; HttpServletRequest request = (HttpServletRequest) sr; response.setHeader(HttpHeaders.SERVER, "FAIR data point (JAVA)"); response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "*"); response.setHeader(HttpHeaders.ALLOW, (RequestMethod.GET.name())); response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, (HttpHeaders.ACCEPT)); ThreadContext.put("ipAddress", request.getRemoteAddr()); ThreadContext.put("responseStatus", String.valueOf(response.getStatus())); fc.doFilter(sr, sr1);/*from ww w . ja v a2s . com*/ ThreadContext.clearAll(); }