List of usage examples for org.apache.commons.httpclient HttpStatus SC_BAD_REQUEST
int SC_BAD_REQUEST
To view the source code for org.apache.commons.httpclient HttpStatus SC_BAD_REQUEST.
Click Source Link
From source file:org.openo.gso.roa.impl.DrivermgrRoaModuleImplTest.java
/** * test query gso network service progress<br> * fail2: response status is 400, bad request * @since GSO 0.5//from w w w . j a v a2 s . com */ @Test public void testQueryGSONsProgressFail2() { String jobId = "1"; // get data ServiceSegmentOperation segOper = new ServiceSegmentOperation(); segOper.setOperationType(CommonConstant.OperationType.CREATE); segOper.setServiceSegmentId("seg1"); ServiceSegmentModel segment = new ServiceSegmentModel(); segment.setDomainHost("10.100.1.1:80"); new MockUp<ServiceSegmentDaoImpl>() { @Mock public ServiceSegmentOperation querySegmentOperByJobIdAndType(String jobId, String segmentType) { return segOper; } @Mock public ServiceSegmentModel queryServiceSegmentByIdAndType(String segmentId, String segmentType) { return segment; } @Mock public void updateSegmentOper(ServiceSegmentOperation svcSegmentOper) { // do nothing } }; // get response RestfulResponse restRsp = new RestfulResponse(); restRsp.setStatus(HttpStatus.SC_BAD_REQUEST); restRsp.setResponseJson(getJsonString(FILE_PATH + "queryGsoNsRsp.json")); mockGetRestfulRsp(restRsp); try { Response rsp = impl.queryGsoJobStatus(jobId); } catch (ApplicationException e) { Assert.assertNotNull(e); } }
From source file:org.opens.tanaguru.util.http.HttpRequestHandler.java
private int computeStatus(int status) { switch (status) { case HttpStatus.SC_FORBIDDEN: case HttpStatus.SC_METHOD_NOT_ALLOWED: case HttpStatus.SC_BAD_REQUEST: case HttpStatus.SC_UNAUTHORIZED: case HttpStatus.SC_PAYMENT_REQUIRED: case HttpStatus.SC_NOT_FOUND: case HttpStatus.SC_NOT_ACCEPTABLE: case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED: case HttpStatus.SC_REQUEST_TIMEOUT: case HttpStatus.SC_CONFLICT: case HttpStatus.SC_GONE: case HttpStatus.SC_LENGTH_REQUIRED: case HttpStatus.SC_PRECONDITION_FAILED: case HttpStatus.SC_REQUEST_TOO_LONG: case HttpStatus.SC_REQUEST_URI_TOO_LONG: case HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE: case HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE: case HttpStatus.SC_EXPECTATION_FAILED: case HttpStatus.SC_INSUFFICIENT_SPACE_ON_RESOURCE: case HttpStatus.SC_METHOD_FAILURE: case HttpStatus.SC_UNPROCESSABLE_ENTITY: case HttpStatus.SC_LOCKED: case HttpStatus.SC_FAILED_DEPENDENCY: case HttpStatus.SC_INTERNAL_SERVER_ERROR: case HttpStatus.SC_NOT_IMPLEMENTED: case HttpStatus.SC_BAD_GATEWAY: case HttpStatus.SC_SERVICE_UNAVAILABLE: case HttpStatus.SC_GATEWAY_TIMEOUT: case HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED: case HttpStatus.SC_INSUFFICIENT_STORAGE: return 0; case HttpStatus.SC_CONTINUE: case HttpStatus.SC_SWITCHING_PROTOCOLS: case HttpStatus.SC_PROCESSING: case HttpStatus.SC_OK: case HttpStatus.SC_CREATED: case HttpStatus.SC_ACCEPTED: case HttpStatus.SC_NON_AUTHORITATIVE_INFORMATION: case HttpStatus.SC_NO_CONTENT: case HttpStatus.SC_RESET_CONTENT: case HttpStatus.SC_PARTIAL_CONTENT: case HttpStatus.SC_MULTI_STATUS: case HttpStatus.SC_MULTIPLE_CHOICES: case HttpStatus.SC_MOVED_PERMANENTLY: case HttpStatus.SC_MOVED_TEMPORARILY: case HttpStatus.SC_SEE_OTHER: case HttpStatus.SC_NOT_MODIFIED: case HttpStatus.SC_USE_PROXY: case HttpStatus.SC_TEMPORARY_REDIRECT: return 1; default:/*ww w. jav a 2s .c om*/ return 1; } }
From source file:org.oryxeditor.server.BPMN2XPDLServlet.java
protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/xml"); String data = req.getParameter("data"); String action = req.getParameter("action"); if ("Export".equals(action)) { BPMN2XPDLConverter converter = new BPMN2XPDLConverter(); try {//from w w w .ja v a 2 s . com res.getWriter().print(converter.exportXPDL(data)); } catch (Exception e) { res.setStatus(HttpStatus.SC_BAD_REQUEST); } } else if ("Import".equals(action)) { BPMN2XPDLConverter converter = new BPMN2XPDLConverter(); res.getWriter().print(converter.importXPDL(data)); } else { res.setStatus(HttpStatus.SC_BAD_REQUEST); } }
From source file:org.phenotips.recordLocking.script.RecordLockingService.java
/** * Locks the patient record.//from ww w .j a va 2 s . c o m * * @param patient The patient to be locked * @return A {@link HttpStatus} indicating the status of the request. */ public int lockPatient(Patient patient) { if (patient == null) { return HttpStatus.SC_BAD_REQUEST; } return this.lockManager.lockPatientRecord(this.pr.get(patient.getDocumentReference())) ? HttpStatus.SC_OK : HttpStatus.SC_BAD_REQUEST; }
From source file:org.phenotips.recordLocking.script.RecordLockingService.java
/** * Unlocks the patient record./* ww w .j a v a2 s.c o m*/ * * @param patient The patient to be unlocked * @return A {@link HttpStatus} indicating the status of the request. */ public int unlockPatient(Patient patient) { if (patient == null) { return HttpStatus.SC_BAD_REQUEST; } return this.lockManager.unlockPatientRecord(this.pr.get(patient.getDocumentReference())) ? HttpStatus.SC_OK : HttpStatus.SC_BAD_REQUEST; }
From source file:org.phenotips.recordLocking.script.RecordLockingService.java
/** * Locks the patient record./*w ww .j a v a2 s. c om*/ * * @param patientID The id of the patient to be locked * @return A {@link HttpStatus} indicating the status of the request. */ public int lockPatient(String patientID) { Patient patient = this.pr.get(patientID); return patient == null ? HttpStatus.SC_BAD_REQUEST : this.lockPatient(patient); }
From source file:org.phenotips.recordLocking.script.RecordLockingService.java
/** * Unlocks the patient record./* w w w .j a v a2 s.c om*/ * * @param patientID The id of the patient to be unlocked * @return A {@link HttpStatus} indicating the status of the request. */ public int unlockPatient(String patientID) { Patient patient = this.pr.get(patientID); return patient == null ? HttpStatus.SC_BAD_REQUEST : this.unlockPatient(patient); }
From source file:org.projectforge.business.teamcal.servlet.CalendarAboServlet.java
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { if (ProjectForgeApp.getInstance().isUpAndRunning() == false) { log.error(//ww w.j ava 2 s . c o m "System isn't up and running, CalendarFeed call denied. The system is may-be in start-up phase or in maintenance mode."); resp.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); return; } PFUserDO user = null; String logMessage = null; try { MDC.put("ip", (Object) req.getRemoteAddr()); MDC.put("session", (Object) req.getSession().getId()); if (StringUtils.isBlank(req.getParameter("user")) || StringUtils.isBlank(req.getParameter("q"))) { resp.sendError(HttpStatus.SC_BAD_REQUEST); log.error("Bad request, parameters user and q not given. Query string is: " + req.getQueryString()); return; } final String encryptedParams = req.getParameter("q"); final Integer userId = NumberHelper.parseInteger(req.getParameter("user")); if (userId == null) { log.error("Bad request, parameter user is not an integer: " + req.getQueryString()); return; } user = TenantRegistryMap.getInstance().getTenantRegistry().getUserGroupCache().getUser(userId); if (user == null) { log.error("Bad request, user not found: " + req.getQueryString()); return; } ThreadLocalUserContext.setUser(getUserGroupCache(), user); MDC.put("user", (Object) user.getUsername()); final String decryptedParams = userService.decrypt(userId, encryptedParams); if (decryptedParams == null) { log.error( "Bad request, can't decrypt parameter q (may-be the user's authentication token was changed): " + req.getQueryString()); return; } final Map<String, String> params = StringHelper.getKeyValues(decryptedParams, "&"); final Calendar calendar = createCal(params, userId, params.get("token"), params.get(CalendarFeedConst.PARAM_NAME_TIMESHEET_USER)); final StringBuffer buf = new StringBuffer(); boolean first = true; for (final Map.Entry<String, String> entry : params.entrySet()) { if ("token".equals(entry.getKey()) == true) { continue; } first = StringHelper.append(buf, first, entry.getKey(), ", "); buf.append("=").append(entry.getValue()); } logMessage = buf.toString(); log.info("Getting calendar entries for: " + logMessage); if (calendar == null) { resp.sendError(HttpStatus.SC_BAD_REQUEST); log.error("Bad request, can't find calendar."); return; } resp.setContentType("text/calendar"); final CalendarOutputter output = new CalendarOutputter(false); try { output.output(calendar, resp.getOutputStream()); } catch (final ValidationException ex) { ex.printStackTrace(); } } finally { log.info("Finished request: " + logMessage); ThreadLocalUserContext.setUser(getUserGroupCache(), null); MDC.remove("ip"); MDC.remove("session"); if (user != null) { MDC.remove("user"); } } }
From source file:org.projectforge.business.teamcal.servlet.TeamCalResponseServlet.java
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { if (StringUtils.isBlank(req.getQueryString())) { resp.sendError(HttpStatus.SC_BAD_REQUEST); log.error("Bad request, no query string given."); return;/*from w ww. j a v a 2 s . c o m*/ } Map<String, String> decryptedParameters = cryptService.decryptParameterMessage(req.getQueryString()); //Getting request status final String reqStatus = decryptedParameters.get("status"); if (StringUtils.isBlank(reqStatus) == true) { log.warn("Bad request, request parameter 'status' not given."); resp.sendError(HttpStatus.SC_BAD_REQUEST); return; } TeamEventAttendeeStatus status = null; try { status = TeamEventAttendeeStatus.valueOf(reqStatus.toUpperCase()); } catch (IllegalArgumentException e) { log.warn("Bad request, request parameter 'status' not valid: " + reqStatus); resp.sendError(HttpStatus.SC_BAD_REQUEST); return; } final TeamEventAttendeeStatus statusFinal = status; //Getting request event final String reqEventUid = decryptedParameters.get("uid"); if (StringUtils.isBlank(reqEventUid) == true) { log.warn("Bad request, request parameter 'uid' not given."); resp.sendError(HttpStatus.SC_BAD_REQUEST); return; } TeamEventDO event = teamEventService.findByUid(reqEventUid); if (event == null) { log.warn("Bad request, request parameter 'uid' not valid: " + reqEventUid); resp.sendError(HttpStatus.SC_BAD_REQUEST); return; } //Getting request attendee final String reqEventAttendee = decryptedParameters.get("attendee"); if (StringUtils.isBlank(reqEventAttendee) == true) { log.warn("Bad request, request parameter 'attendee' not given."); resp.sendError(HttpStatus.SC_BAD_REQUEST); return; } Integer attendeeId = null; try { attendeeId = Integer.parseInt(reqEventAttendee); } catch (NumberFormatException e) { log.warn("Bad request, request parameter 'attendee' not valid: " + reqEventAttendee); resp.sendError(HttpStatus.SC_BAD_REQUEST); return; } final TeamEventAttendeeDO eventAttendee = teamEventService.findByAttendeeId(attendeeId, false); if (eventAttendee != null) { event.getAttendees().stream().forEach(attendee -> { if (attendee.equals(eventAttendee) == true) { attendee.setStatus(statusFinal); } }); try { teamEventService.update(event, false); } catch (Exception e) { log.error("Bad request, exception while updating event: " + e.getMessage()); resp.sendError(HttpStatus.SC_BAD_REQUEST); return; } } else { log.warn("Bad request, request parameter 'attendee' not valid: " + reqEventAttendee); resp.sendError(HttpStatus.SC_BAD_REQUEST); return; } resp.getOutputStream().print("SUCCESSFULLY RESPONDED: " + status); }
From source file:org.projectforge.web.address.PhoneLookUpServlet.java
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { final String number = req.getParameter("nr"); if (StringUtils.isBlank(number) == true || StringUtils.containsOnly(number, "+1234567890 -/") == false) { log.warn(//w w w . jav a 2 s .c om "Bad request, request parameter nr not given or contains invalid characters (only +0123456789 -/ are allowed): " + number); resp.sendError(HttpStatus.SC_BAD_REQUEST); return; } final String key = req.getParameter("key"); final String expectedKey = ConfigXml.getInstance().getPhoneLookupKey(); if (StringUtils.isBlank(expectedKey) == true) { log.warn( "Servlet call for receiving phonelookups ignored because phoneLookupKey is not given in config.xml file."); resp.sendError(HttpStatus.SC_BAD_REQUEST); return; } if (expectedKey.equals(key) == false) { log.warn("Servlet call for phonelookups ignored because phoneLookupKey does not match given key: " + key); resp.sendError(HttpStatus.SC_FORBIDDEN); return; } final String searchNumber = NumberHelper.extractPhonenumber(number); final AddressDao addressDao = (AddressDao) Registry.instance().getDao(AddressDao.class); final BaseSearchFilter filter = new BaseSearchFilter(); filter.setSearchString("*" + searchNumber); final QueryFilter queryFilter = new QueryFilter(filter); final StringBuffer buf = new StringBuffer(); // Use internal get list method for avoiding access checking (no user is logged-in): final List<AddressDO> list = addressDao.internalGetList(queryFilter); if (list != null && list.size() >= 1) { AddressDO result = list.get(0); if (list.size() > 1) { // More than one result, therefore find the newest one: buf.append("+"); // Mark that more than one entry does exist. for (final AddressDO matchingUser : list) { if (matchingUser.getLastUpdate().after(result.getLastUpdate()) == true) { result = matchingUser; } } } resp.setContentType("text/plain"); final String fullname = result.getFullName(); final String organization = result.getOrganization(); StringHelper.listToString(buf, "; ", fullname, organization); resp.getOutputStream().print(buf.toString()); } else { /* mit Thomas abgesprochen. */ resp.getOutputStream().print(0); } }