change copy right text and refactor error handling

4.x.x
manoj 10 years ago
parent 0ba84713cd
commit 3eafd0fc45

@ -1,17 +1,19 @@
<!--
~ Copyright 2014 WSO2, Inc. (http://wso2.com)
~ Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ WSO2 Inc. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
@ -176,5 +178,4 @@
<cxf.version>2.6.1</cxf.version>
<junit.version>4.8.2</junit.version>
</properties>
</project>

@ -1,19 +1,20 @@
/*
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package cdm.api.android;
import cdm.api.android.common.AndroidAgentException;
@ -38,7 +39,7 @@ import java.util.List;
@Consumes({ "application/json", "application/xml" })
public class Device {
private static Log log = LogFactory.getLog(Device.class);
private static Log LOG = LogFactory.getLog(Device.class);
@GET
public List<org.wso2.carbon.device.mgt.common.Device> getAllDevices() throws AndroidAgentException {
@ -52,28 +53,27 @@ public class Device {
} catch (DeviceManagementServiceException deviceMgtServiceEx) {
String errorMsg = "Device management service error";
log.error(errorMsg, deviceMgtServiceEx);
throw new AndroidAgentException();
LOG.error(errorMsg, deviceMgtServiceEx);
throw new AndroidAgentException(errorMsg, deviceMgtServiceEx);
}
try {
devices = dmService.getAllDevices(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
Response.status(HttpStatus.SC_OK);
return devices;
} catch (DeviceManagementException e) {
msg = "Error occurred while fetching the device list.";
log.error(msg, e);
LOG.error(msg, e);
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
throw new AndroidAgentException(msg, e);
}
return devices;
}
@GET
@Path("{id}")
public org.wso2.carbon.device.mgt.common.Device getDevice(@PathParam("id") String id) throws AndroidAgentException {
String msg;
DeviceManagementService dmService;
org.wso2.carbon.device.mgt.common.Device device;
@ -83,21 +83,23 @@ public class Device {
} catch (DeviceManagementServiceException deviceMgtServiceEx) {
String errorMsg = "Device management service error";
log.error(errorMsg, deviceMgtServiceEx);
LOG.error(errorMsg, deviceMgtServiceEx);
throw new AndroidAgentException(errorMsg, deviceMgtServiceEx);
}
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
try {
device = dmService.getDevice(deviceIdentifier);
if (device == null) {
Response.status(HttpStatus.SC_NOT_FOUND);
}
return device;
} catch (DeviceManagementException deviceMgtEx) {
msg = "Error occurred while fetching the device information.";
log.error(msg, deviceMgtEx);
LOG.error(msg, deviceMgtEx);
throw new AndroidAgentException(msg, deviceMgtEx);
}
return device;
}
@PUT
@ -115,7 +117,7 @@ public class Device {
} catch (DeviceManagementServiceException deviceManagementServiceException) {
String errorMsg = "Device management service error";
log.error(errorMsg, deviceManagementServiceException);
LOG.error(errorMsg, deviceManagementServiceException);
}
try {
@ -133,9 +135,16 @@ public class Device {
} catch (DeviceManagementException deviceMgtEx) {
String msg = "Error occurred while modifying the device information.";
log.error(msg, deviceMgtEx);
LOG.error(msg, deviceMgtEx);
throw new AndroidAgentException(msg, deviceMgtEx);
}
}
@POST
@Path("/device/license")
@Produces ("text/plain")
public String getLicense() {
//TODO: need to implement fetch license from core
return "License Agreement";
}
}

@ -1,17 +1,19 @@
/*
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package cdm.api.android;
@ -40,14 +42,6 @@ public class Enrollment {
private static Log log = LogFactory.getLog(Enrollment.class);
/*
* Request Format : {"deviceIdentifier":"macid","description":"description","ownership":"BYOD",
* "properties":[{"name":"username","value":"harshan"},{"name":"device","value":"Harshan S5"},
* {"name":"imei","value":"356938035643809"},{"name":"imsi","value":"404685505601234"},{"name":"model","value":"Galaxy S5"},
* {"name":"regId","value":"02fab24b2242"},{"name":"vendor","value":"Samsung"},
* {"name":"osVersion","value":"5.0.0"}]}
*
**/
@POST
public Message enrollDevice(org.wso2.carbon.device.mgt.common.Device device) throws AndroidAgentException {
@ -75,7 +69,6 @@ public class Enrollment {
log.error(errorMsg, deviceMgtEx);
throw new AndroidAgentException(errorMsg, deviceMgtEx);
}
}
@GET
@ -106,25 +99,14 @@ public class Enrollment {
Response.status(HttpStatus.SC_NOT_FOUND);
responseMsg.setResponseMessage("Device not found");
}
return responseMsg;
} catch (DeviceManagementException deviceMgtEx) {
String errormsg = "Error occurred while enrollment of the device.";
log.error(errormsg, deviceMgtEx);
throw new AndroidAgentException(errormsg, deviceMgtEx);
}
}
/*
* Request Format : {"deviceIdentifier":"macid","description":"description","ownership":"BYOD",
* "properties":[{"name":"username","value":"harshan"},{"name":"device","value":"Harshan S5"},
* {"name":"imei","value":"356938035643809"},{"name":"imsi","value":"404685505601234"},{"name":"model","value":"Galaxy S5"},
* {"name":"regId","value":"02fab24b2242"},{"name":"vendor","value":"Samsung"},
* {"name":"osVersion","value":"5.0.0"}]}
*
**/
@PUT
@Path("{id}")
public Message modifyEnrollment(@PathParam("id") String id, org.wso2.carbon.device.mgt.common.Device device)
@ -157,19 +139,17 @@ public class Enrollment {
return responseMsg;
} catch (DeviceManagementException e) {
} catch (DeviceManagementException deviceMgtEx) {
String errorMsg = "Error occurred while modifying enrollment of the device";
log.error(errorMsg, e);
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
responseMsg.setResponseMessage(errorMsg);
return responseMsg;
log.error(errorMsg, deviceMgtEx);
throw new AndroidAgentException(errorMsg, deviceMgtEx);
}
}
@DELETE
@Path("{id}")
public Message disenrollDevice(@PathParam("id") String id) throws AndroidAgentException {
public Message disEnrollDevice(@PathParam("id") String id) throws AndroidAgentException {
DeviceManagementService dmService;
Message responseMsg = new Message();
@ -195,14 +175,12 @@ public class Enrollment {
responseMsg.setResponseMessage("Device not found");
Response.status(HttpStatus.SC_NOT_FOUND);
}
return responseMsg;
} catch (DeviceManagementException deviceMgtEx) {
String errorMsg = "Error occurred while dis enrolling the device";
log.error(errorMsg, deviceMgtEx);
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
responseMsg.setResponseMessage(errorMsg);
return responseMsg;
throw new AndroidAgentException(errorMsg, deviceMgtEx);
}
}
}

@ -11,7 +11,9 @@ import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.List;
/**
* This is a Test class
*/
@Produces({"application/json", "application/xml"})
@Consumes({"application/json", "application/xml"})
public class Test {

@ -15,10 +15,8 @@
* specific language governing permissions and limitations
* under the License.
*/
package cdm.api.android.common;
public class AndroidAgentException extends Exception{
private static final long serialVersionUID = 7950151650447893900L;

@ -15,7 +15,6 @@
* specific language governing permissions and limitations
* under the License.
*/
package cdm.api.android.common;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;

@ -15,7 +15,6 @@
* specific language governing permissions and limitations
* under the License.
*/
package cdm.api.android.common;

@ -1,19 +1,20 @@
/*
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package cdm.api.android.util;
import org.apache.commons.logging.Log;
@ -31,6 +32,7 @@ public class AndroidAPIUtils {
private static Log log = LogFactory.getLog(AndroidAPIUtils.class);
public static DeviceIdentifier convertToDeviceIdentifierObject(String deviceId) {
DeviceIdentifier identifier = new DeviceIdentifier();
identifier.setId(deviceId);
identifier.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
@ -41,7 +43,6 @@ public class AndroidAPIUtils {
public static DeviceManagementService getDeviceManagementService() throws DeviceManagementServiceException{
// until complete login this is use to load super tenant context
DeviceManagementService dmService;
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();

@ -1,19 +1,20 @@
/*
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package cdm.api.android.util;
/**

@ -15,7 +15,6 @@
* specific language governing permissions and limitations
* under the License.
*/
package cdm.api.android.util;
import javax.xml.bind.annotation.XmlElement;

@ -1,21 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2014 WSO2, Inc. (http://wso2.com)
~ Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ WSO2 Inc. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
@ -25,7 +25,7 @@
<jaxrs:server id="customerService" address="/register">
<jaxrs:serviceBeans>
<ref bean="serviceBean"/>
<ref bean="deviceMgtServiceBean"/>
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="jsonProvider"/>
@ -60,8 +60,6 @@
<ref bean="errorHandler"/>
</jaxrs:providers>
</jaxrs:server>
<bean id="serviceBean" class="cdm.api.android.Authentication"/>
<bean id="deviceMgtServiceBean" class="cdm.api.android.Device"/>
<bean id="enrollmentServiceBean" class="cdm.api.android.Enrollment"/>
<bean id="jsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>

@ -1,18 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2014 WSO2, Inc. (http://wso2.com)
~ Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ WSO2 Inc. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~1-2012
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<display-name>CDM-Android-API</display-name>

Loading…
Cancel
Save