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:cz.zcu.kiv.eegdatabase.webservices.rest.reservation.ReservationServiceController.java
/** * Exception handler for RestServiceException.class. * Writes exception message into HTTP response. * * @param ex exception body/* w w w . jav a2 s . c o m*/ * @param response HTTP response * @throws IOException error while writing error into response */ @ExceptionHandler(RestServiceException.class) public void handleRSException(RestServiceException ex, HttpServletResponse response) throws IOException { log.error(ex); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex.getMessage()); }
From source file:io.wcm.caravan.io.http.impl.CaravanHttpClientImplIntegrationTest.java
@Before public void setUp() { ArchaiusConfig.initialize();// ww w . j ava 2s .c o m ArchaiusConfig.getConfiguration() .setProperty(SERVICE_NAME + CaravanHttpServiceConfig.THROW_EXCEPTION_FOR_STATUS_500, true); wireMockHost = "localhost:" + wireMock.port(); context.registerInjectActivateService(new SimpleLoadBalancerFactory()); serviceConfig = context.registerInjectActivateService(new CaravanHttpServiceConfig(), getServiceConfigProperties(wireMockHost, "auto")); context.registerInjectActivateService(new CaravanHttpThreadPoolConfig(), ImmutableMap.of(CaravanHttpThreadPoolConfig.THREAD_POOL_NAME_PROPERTY, "default")); context.registerInjectActivateService(new LoadBalancerCommandFactory()); context.registerInjectActivateService(new HttpClientFactoryImpl()); context.registerInjectActivateService(new CaravanHttpClientConfig(), Collections.singletonMap(CaravanHttpClientConfig.SERVLET_CLIENT_ENABLED, true)); context.registerInjectActivateService(new ServletHttpClient()); context.registerInjectActivateService(new ApacheHttpClient()); context.registerInjectActivateService(new RibbonHttpClient()); client = context.registerInjectActivateService(new CaravanHttpClientImpl()); // setup wiremock wireMock.stubFor(get(urlEqualTo(HTTP_200_URI)).willReturn(aResponse() .withHeader("Content-Type", "text/plain;charset=" + CharEncoding.UTF_8).withBody(DUMMY_CONTENT))); wireMock.stubFor( get(urlEqualTo(HTTP_404_URI)).willReturn(aResponse().withStatus(HttpServletResponse.SC_NOT_FOUND))); wireMock.stubFor(get(urlEqualTo(HTTP_500_URI)) .willReturn(aResponse().withStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR))); wireMock.stubFor(get(urlEqualTo(CONNECT_TIMEOUT_URI)).willReturn(aResponse() .withHeader("Content-Type", "text/plain;charset=" + CharEncoding.UTF_8).withBody(DUMMY_CONTENT))); wireMock.stubFor(get(urlEqualTo(RESPONSE_TIMEOUT_URI)) .willReturn(aResponse().withHeader("Content-Type", "text/plain;charset=" + CharEncoding.UTF_8) .withBody(DUMMY_CONTENT).withFixedDelay(1000))); assertTrue(client.hasValidConfiguration(SERVICE_NAME)); }
From source file:eu.trentorise.smartcampus.profileservice.controllers.rest.ExtendedProfileController.java
/** * Creates a extended profile for a user given application and profileId * Valid only if userId is the authenticated user * // w w w. j ava 2s . co m * @param response * @param userId * @param profileId * @param content * @throws IOException * @throws ProfileServiceException */ @RequestMapping(method = RequestMethod.POST, value = "/extprofile/app/{userId}/{profileId:.*}") public void createExtendedProfile(HttpServletResponse response, @PathVariable("userId") String userId, @PathVariable("profileId") String profileId, @RequestBody Map<String, Object> content) throws IOException, ProfileServiceException { ExtendedProfile extProfile = new ExtendedProfile(); extProfile.setProfileId(profileId); extProfile.setUserId(userId); extProfile.setContent(content); extProfile.setUser(userId); extProfile.setUpdateTime(System.currentTimeMillis()); try { User user = getUserObject(userId); if (user == null) { throw new SmartCampusException("No user found for id " + userId); } profileManager.create(user, extProfile); } catch (AlreadyExistException e) { logger.error( String.format("Extended profile already exists userId:%s, profileId:%s", userId, profileId), e); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } catch (SmartCampusException e) { logger.error("General exception creating extended profile for user " + userId, e); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } }
From source file:it.geosolutions.geofence.gui.server.UploadServlet.java
@SuppressWarnings("unchecked") @Override/*from w w w. j a v a 2 s . co m*/ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // process only multipart requests if (ServletFileUpload.isMultipartContent(req)) { // Create a factory for disk-based file items FileItemFactory factory = new DiskFileItemFactory(); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); File uploadedFile = null; // Parse the request try { List<FileItem> items = upload.parseRequest(req); for (FileItem item : items) { // process only file upload - discard other form item types if (item.isFormField()) { continue; } String fileName = item.getName(); // get only the file name not whole path if (fileName != null) { fileName = FilenameUtils.getName(fileName); } uploadedFile = File.createTempFile(fileName, ""); // if (uploadedFile.createNewFile()) { item.write(uploadedFile); resp.setStatus(HttpServletResponse.SC_CREATED); resp.flushBuffer(); // uploadedFile.delete(); // } else // throw new IOException( // "The file already exists in repository."); } } catch (Exception e) { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "An error occurred while creating the file : " + e.getMessage()); } try { String wkt = calculateWKT(uploadedFile); resp.getWriter().print(wkt); } catch (Exception exc) { resp.getWriter().print("Error : " + exc.getMessage()); logger.error("ERROR ********** " + exc); } uploadedFile.delete(); } else { resp.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "Request contents type is not supported by the servlet."); } }
From source file:org.jetbrains.webdemo.sessions.MyHttpSession.java
public void handle(final HttpServletRequest request, final HttpServletResponse response) { try {/* w w w . ja v a 2s .c om*/ this.request = request; this.response = response; switch (request.getParameter("type")) { case ("loadHeaders"): sendExamplesList(); break; case ("loadExample"): sendExampleContent(); break; case ("loadExampleFile"): sendExampleFileContent(); break; case ("deleteProject"): sendDeleteProjectResult(request); break; case ("loadProject"): sendLoadProjectResult(); break; case ("loadProjectFile"): sendProjectFileContent(); break; case ("saveProject"): sendSaveProjectResult(); break; case ("saveFile"): sendSaveFileResult(); break; case ("addProject"): sendAddProjectResult(); break; case ("addAdventOfCodeProject"): sendAddAdventOfCodeProjectResult(); break; case ("addFile"): sendAddFileResult(); break; case ("deleteFile"): sendDeleteFileResult(); break; case ("checkFileExistence"): sendFileExistenceResult(); break; case ("renameFile"): sendRenameFileResult(); break; case ("renameProject"): sendRenameProjectResult(); break; case ("loadProjectName"): sendLoadProjectNameResult(); break; case ("checkIfProjectExists"): sendExistenceCheckResult(); break; case ("saveSolution"): sendSaveSolutionResult(); break; } } catch (Throwable e) { e.printStackTrace(); if (sessionInfo != null && sessionInfo.getType() != null && currentProject != null) { ErrorWriter.ERROR_WRITER.writeExceptionToExceptionAnalyzer(e, sessionInfo.getType(), sessionInfo.getOriginUrl(), JsonUtils.toJson(currentProject)); } else { ErrorWriter.ERROR_WRITER.writeExceptionToExceptionAnalyzer(e, "UNKNOWN", "unknown", "null"); } writeResponse(ResponseUtils.getErrorInJson("Internal server error"), HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } }
From source file:com.wso2telco.workflow.api.WorkflowHistoryAPI.java
@GET @Path("/operators") @Produces(MediaType.APPLICATION_JSON)/* w w w .j av a 2 s . co m*/ public Response getAllOperators() { String jsonPayload; try { List<String> operators = SbHostObjectUtils.getAllOperators(); jsonPayload = new Gson().toJson(operators); } catch (Exception e) { log.error(e); return Response.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).build(); } return Response.status(HttpServletResponse.SC_OK).entity(jsonPayload).build(); }
From source file:org.craftercms.search.controller.SearchRestController.java
@ExceptionHandler(Exception.class) public void handleException(Exception e, HttpServletRequest request, HttpServletResponse response) throws IOException { logger.error("RESTful request " + request.getRequestURI() + " failed", e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ExceptionUtils.getRootCauseMessage(e)); }
From source file:ch.admin.suis.msghandler.servlet.TriggerServlet.java
/** * Processes the incoming requests./*from w ww . ja va 2 s .com*/ * * @param request An HTTP Request. * @param response The Response * @throws ServletException Something went wront in the servlet ! * @throws IOException Classical IO problems. */ private void doProcess(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setStatus(HttpServletResponse.SC_OK); response.setContentType(TEXT); final String action = request.getParameter("action"); try { if (StringUtils.equalsIgnoreCase(action, "send")) { dispatchSendRequest(request, response); } else if (StringUtils.equalsIgnoreCase(action, "receive")) { handleReceive(response); } else if (StringUtils.equalsIgnoreCase(action, "poll")) { handlePoll(response); } else { String msg = "No valid parameter found. Valid parameter: action={send,receive,poll}"; LOG.warn(msg); response.getWriter().println(msg); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } } catch (SchedulerException ex) { String msg = "cannot trigger an immediate job"; LOG.fatal(msg, ex); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); throw new ServletException(msg, ex); } }
From source file:eu.trentorise.smartcampus.unidataservice.controller.rest.Esse3Controller.java
@RequestMapping(method = RequestMethod.GET, value = "/getfacolta") public @ResponseBody List<FacoltaData> getFacolta(HttpServletRequest request, HttpServletResponse response) throws InvocationException { try {// w w w . ja v a 2 s .co m Map<String, Object> params = new TreeMap<String, Object>(); return getFacolta(params); } catch (Exception e) { e.printStackTrace(); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } return null; }
From source file:ge.taxistgela.servlet.AdminServlet.java
private void toogleBan(SuperUserManager superUserManager, String sID, String password, HttpServletRequest request, HttpServletResponse response) { if (superUserManager == null) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } else {/*from w ww. j a va 2 s . c o m*/ Admin admin = (Admin) request.getSession().getAttribute(Admin.class.getName()); if (admin != null) { if (sID != null) { Integer id = null; try { id = Integer.parseInt(sID); } catch (Exception e) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } SuperDaoUser superUser = superUserManager.getByID(id); if (superUser != null) { superUser.setPassword(password); ErrorCode errorCode = superUserManager.update(superUser); if (errorCode.errorNotAccrued()) { response.setStatus(HttpServletResponse.SC_ACCEPTED); } else { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } } else { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } } } else { response.setStatus(HttpServletResponse.SC_FORBIDDEN); } } }