1 /* Copyright (c) 2019 AT&T Intellectual Property. #
\r
3 # Licensed under the Apache License, Version 2.0 (the "License"); #
\r
4 # you may not use this file except in compliance with the License. #
\r
5 # You may obtain a copy of the License at #
\r
7 # http://www.apache.org/licenses/LICENSE-2.0 #
\r
9 # Unless required by applicable law or agreed to in writing, software #
\r
10 # distributed under the License is distributed on an "AS IS" BASIS, #
\r
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
\r
12 # See the License for the specific language governing permissions and #
\r
13 # limitations under the License. #
\r
14 ##############################################################################*/
\r
17 package org.oran.otf.common.utility.http;
\r
19 import org.oran.otf.common.model.local.OTFApiResponse;
\r
20 import javax.ws.rs.core.MediaType;
\r
21 import javax.ws.rs.core.Response;
\r
23 public class ResponseUtility {
\r
25 public static class Build {
\r
27 public static Response okRequest() {
\r
28 return Response.ok().build();
\r
31 public static Response badRequest() {
\r
32 return Response.status(400).build();
\r
35 public static Response okRequestWithMessage(String msg) {
\r
36 return Response.status(200)
\r
37 .type(MediaType.APPLICATION_JSON)
\r
38 .entity(new OTFApiResponse(200, msg))
\r
42 public static Response okRequestWithObject(Object obj) {
\r
43 return Response.status(200).type(MediaType.APPLICATION_JSON).entity(obj).build();
\r
46 public static Response badRequestWithMessage(String msg) {
\r
47 return Response.status(400)
\r
48 .type(MediaType.APPLICATION_JSON)
\r
49 .entity(new OTFApiResponse(400, msg))
\r
53 public static Response internalServerError() {
\r
54 return Response.status(500).build();
\r
57 public static Response internalServerErrorWithMessage(String msg) {
\r
58 return Response.status(500)
\r
59 .type(MediaType.APPLICATION_JSON)
\r
60 .entity(new OTFApiResponse(500, msg))
\r
64 public static Response unauthorized() {
\r
65 return Response.status(401).build();
\r
67 public static Response unauthorizedWithMessage(String msg) {
\r
68 return Response.status(401)
\r
69 .type(MediaType.APPLICATION_JSON)
\r
70 .entity(new OTFApiResponse(401, msg))
\r
74 public static Response notFoundWithMessage(String msg) {
\r
75 return Response.status(404)
\r
76 .type(MediaType.APPLICATION_JSON)
\r
77 .entity(new OTFApiResponse(404, msg))
\r
81 public static Response serviceUnavailableWithMessage(String msg) {
\r
82 return Response.status(503)
\r
83 .type(MediaType.APPLICATION_JSON)
\r
84 .entity(new OTFApiResponse(503, msg))
\r
88 public static Response serviceUnavailable() {
\r
89 return Response.status(503).build();
\r
92 public static Response genericWithCode(int code) {
\r
93 return Response.status(code).build();
\r
96 public static Response genericWithMessage(int code, String msg) {
\r
97 return Response.status(code)
\r
98 .type(MediaType.APPLICATION_JSON)
\r
99 .entity(new OTFApiResponse(code, msg))
\r
103 public static Response genericWithObject(int code, Object obj) {
\r
104 return Response.status(code).type(MediaType.APPLICATION_JSON).entity(obj).build();
\r