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:io.lavagna.web.security.login.PersonaLoginTest.java
@Test public void verifierUserNotEnabled() throws IOException { prepareSuccessfulPreconditions();// www . jav a 2 s .c om VerifierResponse verifier = new VerifierResponse(); verifier.setStatus("okay"); verifier.setAudience("audience"); verifier.setEmail("email"); when(restTemplate.postForObject(any(String.class), any(), eq(VerifierResponse.class))).thenReturn(verifier); when(userRepository.userExistsAndEnabled(PersonaLogin.USER_PROVIDER, "email")).thenReturn(false); Assert.assertTrue(personaLogin.doAction(req, resp)); verify(resp).setStatus(HttpServletResponse.SC_BAD_REQUEST); }
From source file:com.oneops.transistor.ws.rest.TransistorRestController.java
@ExceptionHandler(DesignExportException.class) @ResponseBody//from ww w. j ava 2s .c om public void handleExceptions(DesignExportException e, HttpServletResponse response) throws IOException { logger.error(e); sendError(response, HttpServletResponse.SC_BAD_REQUEST, e); }
From source file:com.haulmont.cuba.core.controllers.FileDownloadController.java
protected FileDescriptor getFileDescriptor(HttpServletRequest request, HttpServletResponse response) throws IOException { UUID fileId;/*w w w . j a v a 2s . co m*/ try { fileId = UUID.fromString(request.getParameter("f")); } catch (Exception e) { log.error("Error parsing fileId from URL param", e); response.sendError(HttpServletResponse.SC_BAD_REQUEST); return null; } FileDescriptor fileDescriptor = dataService.load(new LoadContext<>(FileDescriptor.class).setId(fileId)); if (fileDescriptor == null) response.sendError(HttpServletResponse.SC_NOT_FOUND); return fileDescriptor; }
From source file:edu.emory.cci.aiw.cvrg.eureka.servlet.JobSubmitServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Principal principal = request.getUserPrincipal(); if (principal == null) { throw new ServletException("Spreadsheet upload attempt: no user associated with the request"); }// w w w. j av a2 s . co m SubmitJobResponse jobResponse = new SubmitJobResponse(); String value; try { Long jobId = submitJob(request, principal); jobResponse.setJobId(jobId); } catch (ParseException ex) { jobResponse.setMessage("The date range you specified is invalid."); jobResponse.setStatusCode(HttpServletResponse.SC_BAD_REQUEST); jobResponse.setErrorThrown("Bad request"); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } catch (ClientException | FileUploadException | IOException ex) { String msg = "Upload failed due to an internal error"; jobResponse.setMessage(msg); jobResponse.setStatusCode(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); jobResponse.setErrorThrown("Internal server error"); log("Upload failed for user " + principal.getName(), ex); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } value = MAPPER.writeValueAsString(jobResponse); response.setContentLength(value.length()); response.setContentType("application/json"); PrintWriter out = response.getWriter(); out.println(value); }
From source file:com.baidu.jprotobuf.rpc.server.HttpRequestHandlerServlet.java
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String context = request.getPathInfo(); if (context == null) { LOGGER.warn("invalid request path."); response.setStatus(HttpServletResponse.SC_NOT_FOUND); return;// w w w .j a v a 2 s .co m } else { if (context.startsWith("/")) { context = context.substring(1); } if (!serviceMap.containsKey(context)) { LOGGER.warn("invalid request path service name[" + context + "] not found."); response.setStatus(HttpServletResponse.SC_NOT_FOUND); return; } } try { ServiceExporter idlServiceExporter = serviceMap.get(context); //to check if a get idl request if (request.getParameter(ServiceExporter.INPUT_IDL_PARAMETER) != null) { String inputIDL = idlServiceExporter.getInputIDL(); if (inputIDL != null) { response.setContentLength(inputIDL.length()); response.getOutputStream().write(inputIDL.getBytes()); return; } } else if (request.getParameter(ServiceExporter.OUTPUT_IDL_PARAMETER) != null) { String outputIDL = idlServiceExporter.getOutputIDL(); if (outputIDL != null) { response.setContentLength(outputIDL.length()); response.getOutputStream().write(outputIDL.getBytes()); return; } } IDLProxyObject inputIDLProxyObject = idlServiceExporter.getInputProxyObject(); IDLProxyObject input = null; if (inputIDLProxyObject != null && request.getContentLength() > 0) { byte[] bytes = readStream(request.getInputStream(), request.getContentLength()); input = inputIDLProxyObject.decode(bytes); } IDLProxyObject result = idlServiceExporter.execute(input); if (result != null) { byte[] bytes = result.encode(); response.setContentLength(bytes.length); response.getOutputStream().write(bytes); } } catch (Exception ex) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, ex.getMessage()); } finally { response.getOutputStream().flush(); response.getOutputStream().close(); } }
From source file:com.aipo.container.protocol.AipoDataServiceServlet.java
@Override protected void doPut(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { try {/*from w w w. j a va 2 s . c o m*/ checkContentTypes(ALLOWED_CONTENT_TYPES, servletRequest.getContentType()); executeRequest(servletRequest, servletResponse); } catch (ContentTypes.InvalidContentTypeException icte) { sendError(servletResponse, new ResponseItem(HttpServletResponse.SC_BAD_REQUEST, icte.getMessage(), AipoErrorCode.BAD_REQUEST.responseJSON())); } }
From source file:com.devicehive.util.ServerResponsesFactory.java
private static DeviceEquipmentVO constructDeviceEquipmentObject(JsonObject jsonEquipmentObject, DeviceVO device) {/*w w w . j av a2 s.co m*/ DeviceEquipmentVO result = new DeviceEquipmentVO(); final JsonElement jsonElement = jsonEquipmentObject.get(Constants.EQUIPMENT); if (jsonElement == null) { throw new HiveException(Messages.NO_EQUIPMENT_IN_JSON, HttpServletResponse.SC_BAD_REQUEST); } String deviceEquipmentCode = jsonElement.getAsString(); result.setCode(deviceEquipmentCode); jsonEquipmentObject.remove(Constants.EQUIPMENT); result.setParameters(new JsonStringWrapper(jsonEquipmentObject.toString())); return result; }
From source file:net.sourceforge.fenixedu.presentationTier.Action.publico.ExecutionCourseDA.java
@Override public ActionForward execute(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception { final String executionCourseIDString = request.getParameter("executionCourseID"); ExecutionCourse executionCourse = null; if (executionCourseIDString != null) { final DomainObject object = FenixFramework.getDomainObject(executionCourseIDString); if (object instanceof ExecutionCourse) { executionCourse = (ExecutionCourse) object; } else {/*from w w w. ja v a 2s.c om*/ response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.getWriter().write(HttpStatus.getStatusText(HttpStatus.SC_BAD_REQUEST)); response.getWriter().close(); return null; } } else { ExecutionCourseSite site = SiteMapper.getSite(request); executionCourse = site.getSiteExecutionCourse(); } OldCmsSemanticURLHandler.selectSite(request, executionCourse.getSite()); request.setAttribute("executionCourse", executionCourse); request.setAttribute("executionCourseID", executionCourse.getExternalId()); return super.execute(mapping, actionForm, request, response); }
From source file:org.bjason.oauth2.TokenResource.java
@POST @Produces("application/json") public Response authorize(@Context HttpServletRequest request) throws OAuthSystemException { try {/*from w w w . j a v a 2 s. co m*/ OAuthTokenRequest oauthRequest = new OAuthTokenRequest(request); OAuthIssuer oauthIssuerImpl = new OAuthIssuerImpl(new MD5Generator()); if (Common.checkClientIdandSecret(oauthRequest) == false) { return Common.unauthorisedResponse(); } if (oauthRequest.getParam(OAuth.OAUTH_GRANT_TYPE).equals(GrantType.AUTHORIZATION_CODE.toString())) { TOKEN_STATE ts = checkAuthCode(oauthRequest.getParam(OAuth.OAUTH_CODE)); if (ts == TOKEN_STATE.BAD) { return buildBadAuthCodeResponse("invalid authorization code"); } if (ts == TOKEN_STATE.EXPIRED) { return buildBadAuthCodeResponse("expired authorization code"); } } else if (oauthRequest.getParam(OAuth.OAUTH_GRANT_TYPE).equals(GrantType.PASSWORD.toString())) { if (!checkUserPass(oauthRequest.getUsername(), oauthRequest.getPassword())) { return buildInvalidUserPassResponse(); } } else if (oauthRequest.getParam(OAuth.OAUTH_GRANT_TYPE).equals(GrantType.REFRESH_TOKEN.toString())) { buildInvalidUserPassResponse(); } final String accessToken = oauthIssuerImpl.accessToken(); GenerictokenData authCodeFromUser = database.getTokenCode(oauthRequest.getParam(OAuth.OAUTH_CODE)); GenerictokenData newAccessToken = new GenerictokenData(accessToken, Common.THIRTY_SECONDS); Set<String> requestedScopes = oauthRequest.getScopes(); // check if we are limiting scope to access token if (requestedScopes != null && requestedScopes.size() > 0) { LinkedHashSet<String> permToGrant = new LinkedHashSet<String>(); for (String what : requestedScopes) { if (authCodeFromUser.allowedTo(what) == false) { return buildBadAuthCodeResponse("invalid scope"); } permToGrant.add(what + "true"); } newAccessToken.copyPermission(permToGrant); } else { newAccessToken.copyPermission(authCodeFromUser); } database.addAccessToken(newAccessToken); OAuthResponse response = OAuthASResponse.tokenResponse(HttpServletResponse.SC_OK) .setAccessToken(accessToken).setExpiresIn("" + newAccessToken.getExpires()).buildJSONMessage(); return Response.status(response.getResponseStatus()).entity(response.getBody()).build(); } catch (OAuthProblemException e) { OAuthResponse res = OAuthASResponse.errorResponse(HttpServletResponse.SC_BAD_REQUEST).error(e) .buildJSONMessage(); return Response.status(res.getResponseStatus()).entity(res.getBody()).build(); } }
From source file:com.kdab.daytona.Logger.java
@Override public void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (m_error) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); PrintWriter out = response.getWriter(); out.println("Daytona not operational. See server log for details."); out.flush();/*from www .j a v a 2 s . c om*/ out.close(); return; } String format = request.getParameter("format"); if (format == null) format = "xml"; if (!m_queuesByFormat.containsKey(format)) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); PrintWriter out = response.getWriter(); out.println(String.format("Unknown format \'%s\'.", format)); out.flush(); out.close(); return; } byte[] ba = IOUtils.toByteArray(request.getInputStream()); try { m_queuesByFormat.get(format).put(ba); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } PrintWriter out = response.getWriter(); out.println("Message received."); out.flush(); out.close(); }