X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=esr-mgr%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faai%2Fesr%2Futil%2FRestResponseUtil.java;fp=esr-mgr%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faai%2Fesr%2Futil%2FRestResponseUtil.java;h=3c27178c438570690c695d8cb5e9f98b9789489b;hb=fa6dd60a45a093205ae55065f6de044c91493e60;hp=0000000000000000000000000000000000000000;hpb=03cb28b3dfabbf7c49c645dde29a74fd5e60bbf8;p=aai%2Fesr-server.git diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/util/RestResponseUtil.java b/esr-mgr/src/main/java/org/onap/aai/esr/util/RestResponseUtil.java new file mode 100644 index 0000000..3c27178 --- /dev/null +++ b/esr-mgr/src/main/java/org/onap/aai/esr/util/RestResponseUtil.java @@ -0,0 +1,49 @@ +/** + * Copyright 2016-2017 ZTE Corporation. + * + * Licensed 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 org.onap.aai.esr.util; + +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; + +public class RestResponseUtil { + + /** + * get http success entity. + */ + public static Response getSuccessResponse(Object obj) { + if (obj != null) { + return Response.ok(obj).build(); + } else { + return Response.ok().build(); + } + } + + public static Response getCreateSussceeResponse(Object obj) { + return Response.status(Status.CREATED).entity(obj).build(); + } + + /** + * get http error entity. + */ + public static Response getErrorResponse(Object obj) { + if (obj != null) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(obj).build(); + } else { + return Response.serverError().build(); + } + + } +}