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)
\r
44 .type(MediaType.APPLICATION_JSON)
\r
49 public static Response badRequestWithMessage(String msg) {
\r
50 return Response.status(400)
\r
51 .type(MediaType.APPLICATION_JSON)
\r
52 .entity(new OTFApiResponse(400, msg))
\r
56 public static Response internalServerError() {
\r
57 return Response.status(500).build();
\r
60 public static Response internalServerErrorWithMessage(String msg) {
\r
61 return Response.status(500)
\r
62 .type(MediaType.APPLICATION_JSON)
\r
63 .entity(new OTFApiResponse(500, msg))
\r
67 public static Response unauthorized() {
\r
68 return Response.status(401).build();
\r
71 public static Response unauthorizedWithMessage(String msg) {
\r
72 return Response.status(401)
\r
73 .type(MediaType.APPLICATION_JSON)
\r
74 .entity(new OTFApiResponse(401, msg))
\r
78 public static Response notFound() {
\r
79 return Response.status(404).build();
\r
82 public static Response notFoundWithMessage(String msg) {
\r
83 return Response.status(404)
\r
84 .type(MediaType.APPLICATION_JSON)
\r
85 .entity(new OTFApiResponse(404, msg))
\r
89 public static Response genericWithCode(int code) {
\r
90 return Response.status(code).build();
\r
93 public static Response genericWithMessage(int code, String msg) {
\r
94 return Response.status(code)
\r
95 .type(MediaType.APPLICATION_JSON)
\r
96 .entity(new OTFApiResponse(code, msg))
\r
100 public static Response genericWithObject(int code, Object obj) {
\r
101 return Response.status(code)
\r
102 .type(MediaType.APPLICATION_JSON)
\r