List of usage examples for org.apache.commons.httpclient HttpStatus SC_NOT_FOUND
int SC_NOT_FOUND
To view the source code for org.apache.commons.httpclient HttpStatus SC_NOT_FOUND.
Click Source Link
From source file:org.wso2.carbon.device.mgt.jaxrs.api.impl.DeviceImpl.java
/** * Fetch device details for a given device type and device Id. * * @return Device wrapped inside Response *//*from w w w .j a v a 2 s . c o m*/ @GET @Path("view") @Produces({ MediaType.APPLICATION_JSON }) public Response getDevice(@QueryParam("type") String type, @QueryParam("id") String id) { DeviceIdentifier deviceIdentifier = DeviceMgtAPIUtils.instantiateDeviceIdentifier(type, id); DeviceManagementProviderService deviceManagementProviderService = DeviceMgtAPIUtils .getDeviceManagementService(); org.wso2.carbon.device.mgt.common.Device device; try { device = deviceManagementProviderService.getDevice(deviceIdentifier); } catch (DeviceManagementException e) { String msg = "Error occurred while fetching the device information."; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } ResponsePayload responsePayload = new ResponsePayload(); if (device == null) { responsePayload.setStatusCode(HttpStatus.SC_NOT_FOUND); responsePayload.setMessageFromServer( "Requested device by type: " + type + " and id: " + id + " does not exist."); return Response.status(Response.Status.NOT_FOUND).entity(responsePayload).build(); } else { responsePayload.setStatusCode(HttpStatus.SC_OK); responsePayload .setMessageFromServer("Sending Requested device by type: " + type + " and id: " + id + "."); responsePayload.setResponseContent(device); return Response.status(Response.Status.OK).entity(responsePayload).build(); } }
From source file:org.wso2.carbon.device.mgt.jaxrs.api.impl.LicenseImpl.java
/** * This method returns the license text related to a given device type and language code. * * @param deviceType Device type, ex: android, ios * @param languageCode Language code, ex: en_US * @return Returns the license text// w ww. j av a 2s.c o m */ @GET @Path("{deviceType}/{languageCode}") @Produces({ MediaType.APPLICATION_JSON }) public Response getLicense(@PathParam("deviceType") String deviceType, @PathParam("languageCode") String languageCode) { org.wso2.carbon.device.mgt.common.license.mgt.License license; ResponsePayload responsePayload; try { license = DeviceMgtAPIUtils.getDeviceManagementService().getLicense(deviceType, languageCode); if (license == null) { return Response.status(HttpStatus.SC_NOT_FOUND).build(); } responsePayload = ResponsePayload.statusCode(HttpStatus.SC_OK) .messageFromServer("License for '" + deviceType + "' was retrieved successfully") .responseContent(license.getText()).build(); } catch (DeviceManagementException e) { String msg = "Error occurred while retrieving the license configured for '" + deviceType + "' device type"; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } return Response.status(Response.Status.OK).entity(responsePayload).build(); }
From source file:org.wso2.carbon.device.mgt.jaxrs.api.impl.PolicyImpl.java
@Override @GET// ww w . jav a 2 s .co m @Produces({ MediaType.APPLICATION_JSON }) @Path("{id}") public Response getPolicy(@PathParam("id") int policyId) { PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService(); final org.wso2.carbon.policy.mgt.common.Policy policy; try { PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP(); policy = policyAdministratorPoint.getPolicy(policyId); } catch (PolicyManagementException e) { String msg = "Policy Management related exception"; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } if (policy == null) { ResponsePayload responsePayload = new ResponsePayload(); responsePayload.setStatusCode(HttpStatus.SC_NOT_FOUND); responsePayload.setMessageFromServer("Policy for ID " + policyId + " not found."); return Response.status(Response.Status.NOT_FOUND).entity(responsePayload).build(); } ResponsePayload responsePayload = new ResponsePayload(); responsePayload.setStatusCode(HttpStatus.SC_OK); responsePayload.setMessageFromServer("Sending all retrieved device policies."); responsePayload.setResponseContent(policy); return Response.status(Response.Status.OK).entity(responsePayload).build(); }
From source file:org.wso2.carbon.integration.tests.integration.AccessNonExistentServiceTestCase.java
@Test(groups = { "carbon.core" }, description = "Test that ?wsdl on a non-existent service returns an HTTP 404. " + "See https://wso2.org/jira/browse/CARBON-11833") public void testAccessNonExistentServiceWsdl() throws IOException { String URL = contextUrls.getServiceUrl(); HttpResponse httpResponse = HttpRequestUtil.sendGetRequest(URL + "/XXXFoo", "wsdl"); assertEquals(httpResponse.getResponseCode(), HttpStatus.SC_NOT_FOUND); }
From source file:org.wso2.carbon.mdm.api.License.java
/** * This method returns the license text related to a given device type and language code. * * @param deviceType Device type, ex: android, ios * @param languageCode Language code, ex: en_US * @return Returns the license text/*ww w. ja v a 2 s . c o m*/ * @throws MDMAPIException If the device type or language code arguments are not available or invalid. */ @GET @Path("{deviceType}/{languageCode}") @Produces({ MediaType.APPLICATION_JSON }) public Response getLicense(@PathParam("deviceType") String deviceType, @PathParam("languageCode") String languageCode) throws MDMAPIException { org.wso2.carbon.device.mgt.common.license.mgt.License license; ResponsePayload responsePayload = new ResponsePayload(); try { license = MDMAPIUtils.getDeviceManagementService().getLicense(deviceType, languageCode); if (license == null) { return Response.status(HttpStatus.SC_NOT_FOUND).build(); } responsePayload = ResponsePayload.statusCode(HttpStatus.SC_OK) .messageFromServer("License for '" + deviceType + "' was retrieved successfully") .responseContent(license.getText()).build(); } catch (DeviceManagementException e) { String msg = "Error occurred while retrieving the license configured for '" + deviceType + "' device type"; log.error(msg, e); throw new MDMAPIException(msg, e); } return Response.status(HttpStatus.SC_OK).entity(responsePayload).build(); }
From source file:org.wso2.carbon.mdm.api.Policy.java
@GET @Produces({ MediaType.APPLICATION_JSON }) @Path("{id}") public Response getPolicy(@PathParam("id") int policyId) throws MDMAPIException { PolicyManagerService policyManagementService = MDMAPIUtils.getPolicyManagementService(); final org.wso2.carbon.policy.mgt.common.Policy policy; try {/* w w w .j av a2s . c o m*/ PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP(); policy = policyAdministratorPoint.getPolicy(policyId); } catch (PolicyManagementException e) { String error = "Policy Management related exception"; log.error(error, e); throw new MDMAPIException(error, e); } if (policy == null) { ResponsePayload responsePayload = new ResponsePayload(); responsePayload.setStatusCode(HttpStatus.SC_NOT_FOUND); responsePayload.setMessageFromServer("Policy for ID " + policyId + " not found."); return Response.status(HttpStatus.SC_OK).entity(responsePayload).build(); } ResponsePayload responsePayload = new ResponsePayload(); responsePayload.setStatusCode(HttpStatus.SC_OK); responsePayload.setMessageFromServer("Sending all retrieved device policies."); responsePayload.setResponseContent(policy); return Response.status(HttpStatus.SC_OK).entity(responsePayload).build(); }
From source file:org.wso2.carbon.mdm.api.User.java
/** * Method to get user information from emm-user-store. * * @param username User-name of the user * @return {Response} Status of the request wrapped inside Response object * @throws MDMAPIException/* ww w . jav a2 s .c om*/ */ @GET @Path("view") @Produces({ MediaType.APPLICATION_JSON }) public Response getUser(@QueryParam("username") String username) throws MDMAPIException { UserStoreManager userStoreManager = MDMAPIUtils.getUserStoreManager(); ResponsePayload responsePayload = new ResponsePayload(); try { if (userStoreManager.isExistingUser(username)) { UserWrapper user = new UserWrapper(); user.setUsername(username); user.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS)); user.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME)); user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME)); // Outputting debug message upon successful retrieval of user if (log.isDebugEnabled()) { log.debug("User by username: " + username + " was found."); } responsePayload.setStatusCode(HttpStatus.SC_OK); responsePayload.setMessageFromServer("User information was retrieved successfully."); responsePayload.setResponseContent(user); return Response.status(HttpStatus.SC_OK).entity(responsePayload).build(); } else { // Outputting debug message upon trying to remove non-existing user if (log.isDebugEnabled()) { log.debug("User by username: " + username + " does not exist."); } // returning response with bad request state responsePayload.setStatusCode(HttpStatus.SC_BAD_REQUEST); responsePayload.setMessageFromServer("User by username: " + username + " does not exist."); return Response.status(HttpStatus.SC_NOT_FOUND).entity(responsePayload).build(); } } catch (UserStoreException e) { String msg = "Exception in trying to retrieve user by username: " + username; log.error(msg, e); throw new MDMAPIException(msg, e); } }
From source file:org.wso2.carbon.mdm.services.android.Operation.java
@PUT public Message updateOperation() throws AndroidAgentException { String msg;/*from w ww . j ava 2 s. c om*/ DeviceManagementService dmService; Message responseMsg = new Message(); try { dmService = AndroidAPIUtils.getDeviceManagementService(); //TODO: need to complete updateOperation logic boolean result = dmService.getOperationManager("").addOperation(null, null); if (result) { Response.status(HttpStatus.SC_OK); responseMsg.setResponseMessage("Device has already enrolled"); } else { Response.status(HttpStatus.SC_NOT_FOUND); responseMsg.setResponseMessage("Operation not found"); } return responseMsg; } catch (DeviceManagementServiceException e) { msg = "Device management service error"; log.error(msg, e); throw new AndroidAgentException(msg, e); } catch (DeviceManagementException e) { msg = "Error occurred while fetching the operation manager for the device type."; log.error(msg, e); Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); throw new AndroidAgentException(msg, e); } catch (OperationManagementException e) { msg = "Error occurred while updating the operation status for the device."; log.error(msg, e); Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); throw new AndroidAgentException(msg, e); } }
From source file:org.wso2.carbon.mdm.services.android.OperationManager.java
@PUT public Message updateOperation() throws AndroidAgentException { String msg;/* ww w .j a va 2 s. c om*/ DeviceManagementService dmService; Message responseMsg = new Message(); try { dmService = AndroidAPIUtils.getDeviceManagementService(); //TODO: need to complete updateOperation logic boolean result = dmService.addOperation(null, null); if (result) { Response.status(HttpStatus.SC_OK); responseMsg.setResponseMessage("Device has already enrolled"); } else { Response.status(HttpStatus.SC_NOT_FOUND); responseMsg.setResponseMessage("Operation not found"); } return responseMsg; } catch (OperationManagementException e) { msg = "Error occurred while updating the operation status for the device."; log.error(msg, e); Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); throw new AndroidAgentException(msg, e); } }
From source file:org.wso2.cdmserver.mobileservices.android.Operation.java
@PUT public Message updateOperation() throws AndroidAgentException { String msg;//from w w w . j av a 2 s . c o m DeviceManagementService dmService; Message responseMsg = new Message(); try { dmService = AndroidAPIUtils.getDeviceManagementService(); boolean result = dmService.getOperationManager("").addOperation(null, null); if (result) { Response.status(HttpStatus.SC_OK); responseMsg.setResponseMessage("Device has already enrolled"); } else { Response.status(HttpStatus.SC_NOT_FOUND); responseMsg.setResponseMessage("Operation not found"); } return responseMsg; } catch (DeviceManagementServiceException deviceMgtServiceEx) { msg = "Device management service error"; log.error(msg, deviceMgtServiceEx); throw new AndroidAgentException(msg, deviceMgtServiceEx); } catch (DeviceManagementException e) { msg = "Error occurred while fetching the operation manager for the device type."; log.error(msg, e); Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); throw new AndroidAgentException(msg, e); } catch (OperationManagementException e) { msg = "Error occurred while updating the operation status for the device."; log.error(msg, e); Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR); throw new AndroidAgentException(msg, e); } }