List of usage examples for javax.servlet.http HttpServletResponse SC_BAD_REQUEST
int SC_BAD_REQUEST
To view the source code for javax.servlet.http HttpServletResponse SC_BAD_REQUEST.
Click Source Link
From source file:com.haulmont.cuba.core.controllers.FileDownloadController.java
protected UserSession getSession(HttpServletRequest request, HttpServletResponse response) throws IOException { UUID sessionId;/*from w w w .jav a 2 s. c om*/ try { sessionId = UUID.fromString(request.getParameter("s")); } catch (Exception e) { log.error("Error parsing sessionId from URL param", e); response.sendError(HttpServletResponse.SC_BAD_REQUEST); return null; } UserSession session = userSessions.getAndRefresh(sessionId); if (session == null) response.sendError(HttpServletResponse.SC_FORBIDDEN); return session; }
From source file:com.stormpath.sdk.servlet.mvc.ChangePasswordController.java
@Override protected ViewModel doGet(HttpServletRequest request, HttpServletResponse response) throws Exception { String sptoken = Strings.clean(request.getParameter("sptoken")); if (isJsonPreferred(request, response)) { Map<String, Object> model = new HashMap<String, Object>(1); if (sptoken == null) { model.put("status", HttpServletResponse.SC_BAD_REQUEST); model.put("message", i18n(request, "stormpath.web.changePassword.form.errors.no_token")); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } else {/* ww w . j a v a 2 s . c om*/ try { Application application = (Application) request.getAttribute(Application.class.getName()); application.verifyPasswordResetToken(sptoken); response.setContentType(MediaType.APPLICATION_JSON_VALUE); return null; } catch (Exception e) { model = errorModelFactory.toError(request, e).toMap(); response.setStatus(errorModelFactory.toError(request, e).getStatus()); } } return new DefaultViewModel(View.STORMPATH_JSON_VIEW_NAME, model); } if (sptoken == null) { return new DefaultViewModel(forgotPasswordUri).setRedirect(true); } else { try { Application application = (Application) request.getAttribute(Application.class.getName()); application.verifyPasswordResetToken(sptoken); } catch (ResourceException re) { return new DefaultViewModel(errorUri).setRedirect(true); } return super.doGet(request, response); } }
From source file:org.energyos.espi.datacustodian.web.api.BatchRESTController.java
/** * Supports the upload (or import) of Green Button DMD files. Simply send * the DMD file within the POST data./* w ww . jav a 2 s . c o m*/ * * Requires Authorization: Bearer [{data_custodian_access_token} | * {upload_access_token}] * * @param response * HTTP Servlet Response * @param retailCustomerId * The locally unique identifier of a Retail Customer - NOTE PII * @param params * HTTP Query Parameters * @param stream * An input stream * @throws IOException * @throws FeedException * * @usage POST * /espi/1_1/resource/Batch/RetailCustomer/{retailCustomerId}/UsagePoint */ @RequestMapping(value = Routes.BATCH_UPLOAD_MY_DATA, method = RequestMethod.POST, consumes = "application/xml", produces = "application/atom+xml") @ResponseBody public void upload(HttpServletResponse response, @PathVariable Long retailCustomerId, @RequestParam Map<String, String> params, InputStream stream) throws IOException, FeedException { try { RetailCustomer retailCustomer = retailCustomerService.findById(retailCustomerId); importService.importData(stream, retailCustomerId); // do any notifications notificationService.notify(retailCustomer, importService.getMinUpdated(), importService.getMaxUpdated()); } catch (Exception e) { System.out.printf("**** Batch Import Error: %s\n", e.toString()); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } }
From source file:cz.muni.fi.pa165.deliverysystemweb.CourierActionBean.java
public Resolution delete() { String id = getContext().getRequest().getParameter("id"); Long l_id;//from www .j a v a 2s. c o m try { l_id = Long.valueOf(id); } catch (NumberFormatException ex) { return new ErrorResolution(HttpServletResponse.SC_BAD_REQUEST); } try { courierDTO = courierService.findCourier(l_id); } catch (DataAccessException ex) { return new ErrorResolution(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } if (courierDTO == null) { return new ErrorResolution(HttpServletResponse.SC_NOT_FOUND); } try { courierService.deleteCourier(courierDTO); } catch (DataAccessException ex) { return new ErrorResolution(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } return new RedirectResolution(this.getClass(), "list"); }
From source file:org.energyos.espi.datacustodian.web.api.ElectricPowerUsageSummaryRESTController.java
@RequestMapping(value = Routes.ROOT_ELECTRIC_POWER_USAGE_SUMMARY_MEMBER, method = RequestMethod.GET, produces = "application/atom+xml") @ResponseBody/*from www. j a v a 2 s . c o m*/ public void show(HttpServletRequest request, HttpServletResponse response, @PathVariable Long electricPowerUsageSummaryId, @RequestParam Map<String, String> params) throws IOException, FeedException { Long subscriptionId = getSubscriptionId(request); response.setContentType(MediaType.APPLICATION_ATOM_XML_VALUE); try { exportService.exportElectricPowerUsageSummary_Root(subscriptionId, electricPowerUsageSummaryId, response.getOutputStream(), new ExportFilter(params)); } catch (Exception e) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } }
From source file:org.energyos.espi.datacustodian.web.api.TimeConfigurationRESTController.java
@RequestMapping(value = Routes.ROOT_TIME_CONFIGURATION_COLLECTION, method = RequestMethod.POST, consumes = "application/atom+xml", produces = "application/atom+xml") @ResponseBody// w ww . jav a 2 s. c o m public void create(HttpServletResponse response, @RequestParam Map<String, String> params, InputStream stream) throws IOException { response.setContentType(MediaType.APPLICATION_ATOM_XML_VALUE); try { TimeConfiguration timeConfiguration = this.timeConfigurationService.importResource(stream); exportService.exportTimeConfiguration(timeConfiguration.getId(), response.getOutputStream(), new ExportFilter(new HashMap<String, String>())); } catch (Exception e) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } }
From source file:gr.cti.android.experimentation.controller.PluginController.java
/** * Register a new plugin to the backend. * * @param response the HTTP response object. * @param plugin the plugin object to register. *//* w w w. jav a2 s . c om*/ @ResponseBody @RequestMapping(value = "/plugin", method = RequestMethod.POST, produces = "application/json") public Object addPlugin(HttpServletRequest request, HttpServletResponse response, @ModelAttribute final Plugin plugin) throws IOException { LOGGER.info(request.getRemoteAddr()); final ApiResponse apiResponse = new ApiResponse(); final String contextType = plugin.getContextType(); if (contextType == null || plugin.getName() == null || plugin.getImageUrl() == null || plugin.getFilename() == null || plugin.getInstallUrl() == null || plugin.getDescription() == null || plugin.getRuntimeFactoryClass() == null || plugin.getUserId() == null) { LOGGER.info("wrong data: " + plugin); String errorMessage = "error"; if (contextType == null) { errorMessage = "contextType cannot be null"; } else if (plugin.getName() == null) { errorMessage = "name cannot be null"; } else if (plugin.getImageUrl() == null) { errorMessage = "imageUrl cannot be null"; } else if (plugin.getFilename() == null) { errorMessage = "filename cannot be null"; } else if (plugin.getInstallUrl() == null) { errorMessage = "url cannot be null"; } else if (plugin.getDescription() == null) { errorMessage = "description cannot be null"; } else if (plugin.getRuntimeFactoryClass() == null) { errorMessage = "runtimeFactoryClass cannot be null"; } else if (plugin.getUserId() == null) { errorMessage = "userId cannot be null"; } response.sendError(HttpServletResponse.SC_BAD_REQUEST, errorMessage); } else { final Set<Plugin> existingPlugins = pluginRepository.findByContextType(contextType); if (existingPlugins.isEmpty()) { LOGGER.info("addPlugin: " + plugin); pluginRepository.save(plugin); apiResponse.setStatus(HttpServletResponse.SC_OK); apiResponse.setMessage("ok"); apiResponse.setValue(plugin); return apiResponse; } else { LOGGER.info("plugin exists: " + plugin); response.sendError(HttpServletResponse.SC_CONFLICT, "a plugin with this contextType already exists"); } } return null; }
From source file:com.thinkberg.moxo.dav.PropPatchHandler.java
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { FileObject object = getResourceManager().getFileObject(request.getPathInfo()); try {// ww w . j a v a2 s .c om LockManager.getInstance().checkCondition(object, getIf(request)); } catch (LockException e) { if (e.getLocks() != null) { response.sendError(SC_LOCKED); } else { response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); } return; } SAXReader saxReader = new SAXReader(); try { Document propDoc = saxReader.read(request.getInputStream()); // log(propDoc); response.setContentType("text/xml"); response.setCharacterEncoding("UTF-8"); response.setStatus(SC_MULTI_STATUS); if (object.exists()) { Document resultDoc = DocumentHelper.createDocument(); Element multiStatusResponse = resultDoc.addElement("multistatus", "DAV:"); Element responseEl = multiStatusResponse.addElement("response"); try { URL url = new URL(getBaseUrl(request), URLEncoder.encode(object.getName().getPath(), "UTF-8")); log("!! " + url); responseEl.addElement("href").addText(url.toExternalForm()); } catch (Exception e) { e.printStackTrace(); } Element propstatEl = responseEl.addElement("propstat"); Element propEl = propstatEl.addElement("prop"); Element propertyUpdateEl = propDoc.getRootElement(); for (Object elObject : propertyUpdateEl.elements()) { Element el = (Element) elObject; if ("set".equals(el.getName())) { for (Object propObject : el.elements()) { setProperty(propEl, object, (Element) propObject); } } else if ("remove".equals(el.getName())) { for (Object propObject : el.elements()) { removeProperty(propEl, object, (Element) propObject); } } } propstatEl.addElement("status").addText(DavResource.STATUS_403); // log(resultDoc); // write the actual response XMLWriter writer = new XMLWriter(response.getWriter(), OutputFormat.createCompactFormat()); writer.write(resultDoc); writer.flush(); writer.close(); } else { log("!! " + object.getName().getPath() + " NOT FOUND"); response.sendError(HttpServletResponse.SC_NOT_FOUND); } } catch (DocumentException e) { log("!! inavlid request: " + e.getMessage()); response.sendError(HttpServletResponse.SC_BAD_REQUEST); } }
From source file:com.jaspersoft.jasperserver.rest.services.RESTJob.java
@Override protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServiceException { try {// ww w.j av a 2 s . c om StringWriter sw = new StringWriter(); Job job = restUtils.unmarshal(Job.class, req.getInputStream()); if (SecurityContextHolder.getContext().getAuthentication().getPrincipal() instanceof UserDetails) { UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication() .getPrincipal(); job.setUsername(userDetails.getUsername()); } try { job = reportSchedulerService.scheduleJob(job); } catch (AxisFault axisFault) { throw new ServiceException(HttpServletResponse.SC_BAD_REQUEST, "could not schedule job to report: " + job.getReportUnitURI() + ". check job parameters\n" + axisFault.getMessage()); } restUtils.getMarshaller(Job.class).marshal(job, sw); restUtils.setStatusAndBody(HttpServletResponse.SC_CREATED, resp, sw.toString()); // job is a unique case where we return the descriptor } catch (AxisFault axisFault) { throw new ServiceException(HttpServletResponse.SC_NOT_FOUND, axisFault.getMessage()); } catch (IOException e) { throw new ServiceException(HttpServletResponse.SC_BAD_REQUEST, e.getMessage()); } catch (JAXBException e) { throw new ServiceException(HttpServletResponse.SC_BAD_REQUEST, "please check the request job descriptor"); } }