List of usage examples for org.apache.commons.httpclient HttpStatus SC_EXPECTATION_FAILED
int SC_EXPECTATION_FAILED
To view the source code for org.apache.commons.httpclient HttpStatus SC_EXPECTATION_FAILED.
Click Source Link
From source file:com.microfocus.application.automation.tools.octane.actions.Webhooks.java
@RequirePOST public void doNotify(StaplerRequest req, StaplerResponse res) throws IOException { logger.info("Received POST from " + req.getRemoteHost()); // legal user, handle request JSONObject inputNotification = (JSONObject) JSONValue.parse(req.getInputStream()); Object properties = inputNotification.get("properties"); // without build context, could not send octane relevant data if (!req.getHeader(PROJECT_KEY_HEADER).isEmpty() && properties instanceof Map) { // get relevant parameters Map sonarAttachedProperties = (Map) properties; // filter notifications from sonar projects, who haven't configured listener parameters if (sonarAttachedProperties.containsKey(BUILD_NUMBER_PARAM_NAME) && sonarAttachedProperties.containsKey(JOB_NAME_PARAM_NAME)) { String buildId = (String) (sonarAttachedProperties.get(BUILD_NUMBER_PARAM_NAME)); String jobName = (String) sonarAttachedProperties.get(JOB_NAME_PARAM_NAME); // get sonar details from job configuration TopLevelItem jenkinsJob = Jenkins.getInstance().getItem(jobName); if (isValidJenkinsJob(jenkinsJob)) { AbstractProject jenkinsProject = ((AbstractProject) jenkinsJob); Integer buildNumber = Integer.valueOf(buildId, 10); if (isValidJenkinsBuildNumber(jenkinsProject, buildNumber)) { AbstractBuild build = getBuild(jenkinsProject, buildNumber); if (build != null && isBuildExpectingToGetWebhookCall(build) && !isBuildAlreadyGotWebhookCall(build)) { WebhookExpectationAction action = build.getAction(WebhookExpectationAction.class); ExtensionList<GlobalConfiguration> allConfigurations = GlobalConfiguration.all(); GlobalConfiguration sonarConfiguration = allConfigurations .getDynamic(SonarHelper.SONAR_GLOBAL_CONFIG); if (sonarConfiguration != null) { String sonarToken = SonarHelper.getSonarInstallationTokenByUrl(sonarConfiguration, action.getServerUrl()); HashMap project = (HashMap) inputNotification.get(PROJECT); String sonarProjectKey = (String) project.get(SONAR_PROJECT_KEY_NAME); // use SDK to fetch and push data OctaneSDK.getClients() .forEach(octaneClient -> octaneClient.getSonarService() .enqueueFetchAndPushSonarCoverage(jobName, buildId, sonarProjectKey, action.getServerUrl(), sonarToken)); markBuildAsRecievedWebhookCall(build); res.setStatus(HttpStatus.SC_OK); // sonar should get positive feedback for webhook }/* www . j av a 2 s.c o m*/ } else { logger.warn("Got request from sonarqube webhook listener for build ," + buildId + " which is not expecting to get sonarqube data"); res.setStatus(HttpStatus.SC_EXPECTATION_FAILED); } } else { logger.warn("Got request from sonarqube webhook listener, but build " + buildId + " context could not be resolved"); res.setStatus(HttpStatus.SC_NOT_ACCEPTABLE); } } } } }
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:/*from ww w . j av a 2 s .c om*/ return 1; } }
From source file:org.wso2.carbon.device.mgt.iot.firealarm.api.FireAlarmManagerService.java
@Path("/device/register") @PUT//from w w w. j a v a 2 s. c om public boolean register(@QueryParam("deviceId") String deviceId, @QueryParam("name") String name, @QueryParam("owner") String owner) { DeviceManagement deviceManagement = new DeviceManagement(); DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(deviceId); deviceIdentifier.setType(FireAlarmConstants.DEVICE_TYPE); try { if (deviceManagement.getDeviceManagementService().isEnrolled(deviceIdentifier)) { Response.status(HttpStatus.SC_CONFLICT).build(); return false; } Device device = new Device(); device.setDeviceIdentifier(deviceId); EnrolmentInfo enrolmentInfo = new EnrolmentInfo(); enrolmentInfo.setDateOfEnrolment(new Date().getTime()); enrolmentInfo.setDateOfLastUpdate(new Date().getTime()); enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE); enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD); device.setName(name); device.setType(FireAlarmConstants.DEVICE_TYPE); enrolmentInfo.setOwner(owner); device.setEnrolmentInfo(enrolmentInfo); boolean added = deviceManagement.getDeviceManagementService().enrollDevice(device); if (added) { Response.status(HttpStatus.SC_OK).build(); } else { Response.status(HttpStatus.SC_EXPECTATION_FAILED).build(); } return added; } catch (DeviceManagementException e) { log.error(e.getErrorMessage()); return false; } }
From source file:org.wso2.carbon.device.mgt.iot.firealarm.api.FireAlarmManagerService.java
@Path("/device/remove/{device_id}") @DELETE//from w ww . j a v a 2 s . co m public void removeDevice(@PathParam("device_id") String deviceId, @Context HttpServletResponse response) { DeviceManagement deviceManagement = new DeviceManagement(); DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(deviceId); deviceIdentifier.setType(FireAlarmConstants.DEVICE_TYPE); try { boolean removed = deviceManagement.getDeviceManagementService().disenrollDevice(deviceIdentifier); if (removed) { response.setStatus(HttpStatus.SC_OK); } else { response.setStatus(HttpStatus.SC_EXPECTATION_FAILED); } } catch (DeviceManagementException e) { log.error(e.getErrorMessage()); } }
From source file:org.wso2.carbon.device.mgt.iot.firealarm.api.FireAlarmManagerService.java
@Path("/device/update/{device_id}") @POST/* www . jav a 2 s.c om*/ public boolean updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name, @Context HttpServletResponse response) { DeviceManagement deviceManagement = new DeviceManagement(); DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(deviceId); deviceIdentifier.setType(FireAlarmConstants.DEVICE_TYPE); try { Device device = deviceManagement.getDeviceManagementService().getDevice(deviceIdentifier); device.setDeviceIdentifier(deviceId); // device.setDeviceTypeId(deviceTypeId); device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime()); device.setName(name); device.setType(FireAlarmConstants.DEVICE_TYPE); boolean updated = deviceManagement.getDeviceManagementService().modifyEnrollment(device); if (updated) { response.setStatus(HttpStatus.SC_OK); } else { response.setStatus(HttpStatus.SC_EXPECTATION_FAILED); } return updated; } catch (DeviceManagementException e) { log.error(e.getErrorMessage()); return false; } }
From source file:org.wso2.carbon.device.mgt.iot.sensebot.api.SensebotManagerService.java
@Path("/device/register") @PUT/*from w w w . jav a2 s .c om*/ public boolean register(@QueryParam("deviceId") String deviceId, @QueryParam("name") String name, @QueryParam("owner") String owner) { DeviceManagement deviceManagement = new DeviceManagement(); DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(deviceId); deviceIdentifier.setType(SensebotConstants.DEVICE_TYPE); try { if (deviceManagement.isExist(deviceIdentifier)) { Response.status(HttpStatus.SC_CONFLICT).build(); return false; } Device device = new Device(); device.setDeviceIdentifier(deviceId); device.setDateOfEnrolment(new Date().getTime()); device.setDateOfLastUpdate(new Date().getTime()); // device.setStatus(true); device.setName(name); device.setType(SensebotConstants.DEVICE_TYPE); device.setOwner(owner); boolean added = deviceManagement.addNewDevice(device); if (added) { Response.status(HttpStatus.SC_OK).build(); } else { Response.status(HttpStatus.SC_EXPECTATION_FAILED).build(); } return added; } catch (DeviceManagementException e) { log.error(e.getErrorMessage()); return false; } }
From source file:org.wso2.carbon.device.mgt.iot.sensebot.api.SensebotManagerService.java
@Path("/device/remove/{device_id}") @DELETE// ww w . j a v a 2 s . c o m public void removeDevice(@PathParam("device_id") String deviceId, @Context HttpServletResponse response) { DeviceManagement deviceManagement = new DeviceManagement(); DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(deviceId); deviceIdentifier.setType(SensebotConstants.DEVICE_TYPE); try { boolean removed = deviceManagement.removeDevice(deviceIdentifier); if (removed) { response.setStatus(HttpStatus.SC_OK); } else { response.setStatus(HttpStatus.SC_EXPECTATION_FAILED); } } catch (DeviceManagementException e) { log.error(e.getErrorMessage()); } }
From source file:org.wso2.carbon.device.mgt.iot.sensebot.api.SensebotManagerService.java
@Path("/device/update/{device_id}") @POST//from ww w .ja va 2 s .c o m public boolean updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name, @Context HttpServletResponse response) { DeviceManagement deviceManagement = new DeviceManagement(); DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(deviceId); deviceIdentifier.setType(SensebotConstants.DEVICE_TYPE); try { Device device = deviceManagement.getDevice(deviceIdentifier); device.setDeviceIdentifier(deviceId); // device.setDeviceTypeId(deviceTypeId); device.setDateOfLastUpdate(new Date().getTime()); device.setName(name); device.setType(SensebotConstants.DEVICE_TYPE); boolean updated = deviceManagement.update(device); if (updated) { response.setStatus(HttpStatus.SC_OK); } else { response.setStatus(HttpStatus.SC_EXPECTATION_FAILED); } return updated; } catch (DeviceManagementException e) { log.error(e.getErrorMessage()); return false; } }