From 6836bb1d9b9e11197a1b0772c4b212cf4feacfc3 Mon Sep 17 00:00:00 2001 From: manoj Date: Tue, 16 Dec 2014 15:14:02 +0530 Subject: [PATCH] JAX-RS Refractor --- .../src/main/java/cdm/api/android/Test.java | 34 +++++++++++++ .../cdm/api/android/common/ErrorHandler.java | 32 ++++++++++++ .../java/cdm/api/android/util/Message.java | 49 +++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Test.java create mode 100644 product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/common/ErrorHandler.java create mode 100644 product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/util/Message.java diff --git a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Test.java b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Test.java new file mode 100644 index 0000000000..2c7e6fd25c --- /dev/null +++ b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Test.java @@ -0,0 +1,34 @@ +package cdm.api.android; + +import org.wso2.carbon.device.mgt.common.*; +import org.wso2.carbon.device.mgt.common.Device; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.List; + + +@Produces({"application/json", "application/xml"}) +@Consumes({"application/json", "application/xml"}) +public class Test { + + @GET + public List getAllDevices() { + + Device dev = new Device(); + dev.setName("test1"); + dev.setDateOfEnrolment(11111111L); + dev.setDateOfLastUpdate(992093209L); + dev.setDescription("sassasaas"); + + ArrayList listdevices = new ArrayList(); + listdevices.add(dev); + + return listdevices; + } + +} diff --git a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/common/ErrorHandler.java b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/common/ErrorHandler.java new file mode 100644 index 0000000000..b252cf1b1b --- /dev/null +++ b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/common/ErrorHandler.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * 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. + */ + +package cdm.api.android.common; + +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.ExceptionMapper; + +public class ErrorHandler implements ExceptionMapper { + + @Override public Response toResponse(Throwable throwable) { + Response.Status status; + status = Response.Status.INTERNAL_SERVER_ERROR; + + return Response.status(status).header("exception", exception.getMessage()).build(); + } +} diff --git a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/util/Message.java b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/util/Message.java new file mode 100644 index 0000000000..f5e34cf7ec --- /dev/null +++ b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/util/Message.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * 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. + */ + +package cdm.api.android.util; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +public class Message { + + private String responseCode; + private String responseMessage; + + @XmlElement + public String getResponseMessage() { + return responseMessage; + } + + public void setResponseMessage(String responseMessage) { + this.responseMessage = responseMessage; + } + + + @XmlElement + public String getResponseCode() { + return responseCode; + } + + public void setResponseCode(String responseCode) { + this.responseCode = responseCode; + } + +}