List of usage examples for javax.servlet.http HttpServletResponse SC_INTERNAL_SERVER_ERROR
int SC_INTERNAL_SERVER_ERROR
To view the source code for javax.servlet.http HttpServletResponse SC_INTERNAL_SERVER_ERROR.
Click Source Link
From source file:com.linuxbox.enkive.web.GetPermissionsServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { PermissionService permService = getPermissionService(); try {// w ww.j a va 2 s. c om Collection<String> userAuthorities = permService.getCurrentUserAuthorities(); JSONObject jsonResponse = new JSONObject(); jsonResponse.put(USER_AUTHORITIES, userAuthorities); String jsonResultString = jsonResponse.toString(); try { resp.getWriter().write(jsonResultString); } catch (IOException e) { LOGGER.error("Could not write JSON response"); } } catch (JSONException e) { respondError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, null, resp); LOGGER.error("Could not serialize JSON", e); } catch (CannotGetPermissionsException e) { respondError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, null, resp); LOGGER.error("Could not get user permissions", e); } }
From source file:ee.ria.xroad.proxy.testsuite.testcases.ServiceReturnsFault.java
@Override public AbstractHandler getServiceHandler() { return new AbstractHandler() { @Override//from www.j av a2 s. c o m public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { response.setContentType(MimeTypes.TEXT_XML); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); try (FileInputStream in = new FileInputStream(QUERIES_DIR + "/fault.query")) { IOUtils.copy(in, response.getOutputStream()); } baseRequest.setHandled(true); } }; }
From source file:com.sixt.service.framework.json.JsonRpcResponse.java
public static JsonRpcResponse fromString(String rawResponse) { JsonParser parser = new JsonParser(); JsonObject response = parser.parse(rawResponse).getAsJsonObject(); JsonElement id = response.get("id"); JsonElement errorElement = response.get("error"); int responseStatus = HttpServletResponse.SC_OK; String error;/*from w w w .ja v a 2 s .co m*/ if (!(errorElement instanceof JsonNull)) { if (errorElement instanceof JsonObject) { error = errorElement.toString(); // try parsing it into RpcCallException to get the HttpStatus from there RpcCallException rpcEx = RpcCallException.fromJson(error); if (rpcEx != null) { responseStatus = rpcEx.getCategory().getHttpStatus(); JsonElement resultElement = response.get("result"); return new JsonRpcResponse(id, resultElement == null ? JsonNull.INSTANCE : resultElement, errorElement, responseStatus); } } error = errorElement.getAsString(); if (StringUtils.isNotBlank(error)) { responseStatus = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; } } JsonElement resultElement = response.get("result"); return new JsonRpcResponse(id, resultElement == null ? JsonNull.INSTANCE : resultElement, errorElement, responseStatus); }
From source file:net.zcarioca.jmx.servlet.handlers.RestRequestHandler.java
public void respond(HttpServletRequest request, HttpServletResponse response) throws IOException { try {/*from ww w. j av a 2 s.c om*/ Object value = getResponse(request); if (value != null) { response.setContentType(MediaType.APPLICATION_JSON); response.setCharacterEncoding("UTF-8"); BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream()); ObjectMapper mapper = new ObjectMapper(); mapper.writeValue(out, value); out.flush(); out.close(); } else { response.sendError(HttpServletResponse.SC_NOT_FOUND); } } catch (InvalidObjectException exc) { response.sendError(HttpServletResponse.SC_BAD_REQUEST); } catch (IOException exc) { throw exc; } catch (Exception exc) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } }
From source file:me.chester.myretweetedtweets.RetrieveTweetsServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String path = request.getPathInfo(); String callback = request.getParameter("callback"); PrintWriter out = response.getWriter(); if (path != null && path.length() > 1) { try {//from w w w . j a v a2 s . c o m long id = Long.parseLong(path.substring(1)); String json = getJsonWithCache(id, callback); response.setContentType("application/json"); out.write(json); return; } catch (NumberFormatException e) { // Invalid id, will be treated as 404-not-found below } catch (EntityNotFoundException e) { // Invalid id, will be treated as 404-not-found below } catch (TwitterException e) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); out.write("Error retrieving tweets. Maybe you should re-authorize?"); } catch (CacheException e) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); out.write("Error with Memcache. We are all doomed."); } } response.setStatus(HttpServletResponse.SC_NOT_FOUND); out.write("Invalid URL. Try authorizing again to get a valid one"); }
From source file:com.nabla.wapp.server.basic.general.ExportService.java
@Override public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException { final String id = request.getParameter("id"); if (id == null || id.isEmpty()) { if (log.isTraceEnabled()) log.trace("missing file ID"); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return;//from www . java 2 s . com } final UserSession userSession = UserSession.load(request); if (userSession == null) { if (log.isTraceEnabled()) log.trace("missing user session"); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } try { if (exportFile(id, userSession, response)) { // response.setStatus(HttpServletResponse.SC_OK); } else response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } catch (final SQLException e) { if (log.isErrorEnabled()) log.error("SQL error " + e.getErrorCode() + "-" + e.getSQLState(), e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } catch (final Throwable e) { if (log.isErrorEnabled()) log.error("unexpected error", e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } }
From source file:fr.epsi.controllers.rest.OrderController.java
/** * Methode pour les commandes/* w ww. j av a2 s.c om*/ * @param reference la reference du produit * @param quantity la quantite voulue * @param guid l'identifiant de l'utilisateur * @return Un message selon le statut de la commande */ @RequestMapping(value = "/order", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody Product order(@RequestParam("reference") String reference, @RequestParam("quantity") int quantity, @RequestParam("token") String token, HttpServletResponse resp) { Users userModel = Users.getInstance(); //Recupere l'instance de user try { // Si on trouve un user correspondant au guid if (userModel.findByGUID(token) != null) { Products productModel = Products.getInstance(); // On recupere le produit par reference Product product = productModel.findByRef(reference); if (product == null || quantity <= 0 || product.getQuantity() == 0 || product.getQuantity() < quantity) { resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); } else { //On decremente la quantite du produit product.setQuantity(product.getQuantity() - quantity); return new Product(product.getReference(), product.getName(), quantity); } } else { resp.setStatus(HttpServletResponse.SC_FORBIDDEN); } return null; } catch (Exception e) { resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return null; } }
From source file:de.tub.av.pe.xcapsrv.XCAPResultFactory.java
public static XCAPResult newResultForConflict(int index, String reason) { XCAPResult result;//from w w w . j a v a2 s .c o m switch (index) { case XDMSConstants.CANNOT_DELETE_INDEX: result = conflictDelete(); break; case XDMSConstants.CANNOT_INSERT_INDEX: result = conflictInsert(); break; case XDMSConstants.CONSTRAINT_FAILURE_INDEX: result = conflictConstraintFailure(); break; case XDMSConstants.EXTENSION_INDEX: result = conflictExtension(); break; case XDMSConstants.NO_PARENT_INDEX: result = conflictNoParent(); break; case XDMSConstants.NO_WELL_FORMED_INDEX: result = conflictNoWellFormed(); break; case XDMSConstants.NOT_XML_ATT_VALUE_INDEX: result = conflictNOTXmlAttValue(); break; case XDMSConstants.NOT_XML_FRAG_INDEX: result = conflictNOTXmlFrag(); break; case XDMSConstants.SCHEMA_VALIDATION_ERROR_INDEX: result = conflictSchemaValidation(reason); break; case XDMSConstants.UNIQUENESS_FAILURE_INDEX: result = conflictUniquenessFailure(); break; case XDMSConstants.NOT_UTF_8_INDEX: result = conflictNOTUTF8(); break; default: log.debug("because of a not correct index, reply with internal server error"); result = new XCAPResult(); result.setStatusCode(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); break; } return result; }
From source file:de.highbyte_le.weberknecht.request.error.DefaultErrorHandler.java
@Override public boolean handleException(Exception exception, HttpServletRequest request, RoutingTarget routingTarget) { if (exception instanceof ActionNotFoundException) { log.warn(/*w w w .j a va2 s. co m*/ "action not found: " + exception.getMessage() + "; request URI was " + request.getRequestURI()); this.statusCode = HttpServletResponse.SC_NOT_FOUND; //throw 404, if action doesn't exist } else if (exception instanceof ContentProcessingException) { log.error("doGet() - " + exception.getClass().getSimpleName() + ": " + exception.getMessage(), //$NON-NLS-1$ exception); this.statusCode = ((ContentProcessingException) exception).getHttpStatusCode(); //TODO error page with error message or set request attribute to be able to write it on standard error pages } else if (exception instanceof ActionInstantiationException) { log.warn("action could not be instantiated: " + exception.getMessage(), exception); this.statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; //throw 500, if action could not instantiated } else if (exception instanceof ProcessingException) { log.error("doGet() - PreProcessingException: " + exception.getMessage(), exception); //$NON-NLS-1$ this.statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; //throw 500 } else if (exception instanceof DBConnectionException) { log.error("doGet() - DBConnectionException: " + exception.getMessage(), exception); //$NON-NLS-1$ this.statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; //throw 500 } else if (exception instanceof ActionExecutionException) { log.error("doGet() - ActionExecutionException: " + exception.getMessage(), exception); //$NON-NLS-1$ this.statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; //throw 500 } else { log.error("doGet() - " + exception.getClass().getSimpleName() + ": " + exception.getMessage(), //$NON-NLS-1$ exception); this.statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; //throw 500 } return true; }
From source file:nl.surfnet.mujina.saml.SingleSignOnService.java
@SuppressWarnings("rawtypes") @Override//w w w .ja v a2 s. c om public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { SAMLMessageContext messageContext = null; try { messageContext = adapter.extractSAMLMessageContext(request); } catch (MessageDecodingException mde) { logger.error("Exception decoding SAML message", mde); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } catch (SecurityException se) { logger.error("Exception decoding SAML message", se); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } AuthnRequest authnRequest = (AuthnRequest) messageContext.getInboundSAMLMessage(); try { validatorSuite.validate(authnRequest); } catch (ValidationException ve) { logger.warn("AuthnRequest Message failed Validation", ve); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } AuthnRequestInfo info = new AuthnRequestInfo(authnRequest.getAssertionConsumerServiceURL(), authnRequest.getID(), authnRequest.getIssuer().getValue()); logger.debug("AuthnRequest {} verified. Forwarding to SSOSuccessAuthnResponder", info); request.getSession().setAttribute(AuthnRequestInfo.class.getName(), info); logger.debug("request.getSession().getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION) is {}", request.getSession().getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION)); logger.debug("forwarding to authnResponderURI: {}", authnResponderURI); request.getRequestDispatcher(authnResponderURI).forward(request, response); }