Skip to content

Commit 3341a46

Browse files
committed
Json output
1 parent faf7e84 commit 3341a46

File tree

7 files changed

+83
-22
lines changed

7 files changed

+83
-22
lines changed

src/main/java/com/authlete/jaxrs/server/api/vci/BatchCredentialEndpoint.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,14 @@ private Response credentialIssue(final AuthleteApi api,
122122
return ResponseUtil.unauthorized(accessToken, content);
123123

124124
case FORBIDDEN:
125-
return ResponseUtil.forbidden(content);
125+
return ResponseUtil.forbiddenJson(content);
126126

127127
case OK:
128-
return ResponseUtil.ok(content);
128+
return ResponseUtil.okJson(content);
129129

130130
case INTERNAL_SERVER_ERROR:
131131
default:
132-
throw ExceptionUtil.internalServerErrorException(content);
132+
throw ExceptionUtil.internalServerErrorExceptionJson(content);
133133
}
134134
}
135135
}

src/main/java/com/authlete/jaxrs/server/api/vci/CredentialEndpoint.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,17 @@ private Response credentialIssue(final AuthleteApi api,
122122
return ResponseUtil.unauthorized(accessToken, content);
123123

124124
case FORBIDDEN:
125-
return ResponseUtil.forbidden(content);
125+
return ResponseUtil.forbiddenJson(content);
126126

127127
case OK:
128-
return ResponseUtil.ok(content);
128+
return ResponseUtil.okJson(content);
129129

130130
case ACCEPTED:
131-
return ResponseUtil.accepted(content);
131+
return ResponseUtil.acceptedJson(content);
132132

133133
case INTERNAL_SERVER_ERROR:
134134
default:
135-
throw ExceptionUtil.internalServerErrorException(content);
135+
throw ExceptionUtil.internalServerErrorExceptionJson(content);
136136
}
137137
}
138138
}

src/main/java/com/authlete/jaxrs/server/api/vci/CredentialMetadataEndpoint.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ private Response metadata(final AuthleteApi api)
6868
switch (response.getAction())
6969
{
7070
case NOT_FOUND:
71-
return ResponseUtil.notFound(content);
71+
return ResponseUtil.notFoundJson(content);
7272

7373
case OK:
74-
return ResponseUtil.ok(response.getResponseContent());
74+
return ResponseUtil.okJson(response.getResponseContent());
7575

7676
case INTERNAL_SERVER_ERROR:
7777
default:
78-
throw ExceptionUtil.internalServerErrorException(content);
78+
throw ExceptionUtil.internalServerErrorExceptionJson(content);
7979
}
8080
}
8181
}

src/main/java/com/authlete/jaxrs/server/api/vci/DeferredCredentialEndpoint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ private Response credentialIssue(final AuthleteApi api,
122122
return ResponseUtil.badRequest(content);
123123

124124
case FORBIDDEN:
125-
return ResponseUtil.forbidden(content);
125+
return ResponseUtil.forbiddenJson(content);
126126

127127
case OK:
128128
return ResponseUtil.ok(content);

src/main/java/com/authlete/jaxrs/server/api/vci/JWKSetMetadataEndpoint.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ private Response metadata(final AuthleteApi api)
5555
switch (response.getAction())
5656
{
5757
case NOT_FOUND:
58-
return ResponseUtil.notFound(content);
58+
return ResponseUtil.notFoundJson(content);
5959

6060
case OK:
61-
return ResponseUtil.ok(response.getResponseContent());
61+
return ResponseUtil.okJson(response.getResponseContent());
6262

6363
case INTERNAL_SERVER_ERROR:
6464
default:
65-
throw ExceptionUtil.internalServerErrorException(content);
65+
throw ExceptionUtil.internalServerErrorExceptionJson(content);
6666
}
6767
}
6868
}

src/main/java/com/authlete/jaxrs/server/util/ExceptionUtil.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919

2020
import static com.authlete.jaxrs.server.util.ResponseUtil.badRequest;
21-
import static com.authlete.jaxrs.server.util.ResponseUtil.forbidden;
21+
import static com.authlete.jaxrs.server.util.ResponseUtil.forbiddenJson;
22+
import static com.authlete.jaxrs.server.util.ResponseUtil.internalServerErrorJson;
2223
import static com.authlete.jaxrs.server.util.ResponseUtil.unauthorized;
2324
import static com.authlete.jaxrs.server.util.ResponseUtil.notFound;
2425
import static com.authlete.jaxrs.server.util.ResponseUtil.internalServerError;
@@ -111,7 +112,7 @@ public static WebApplicationException unauthorizedException(Viewable entity, Str
111112
*/
112113
public static WebApplicationException forbiddenException(final String entity)
113114
{
114-
return new WebApplicationException(entity, forbidden(entity));
115+
return new WebApplicationException(entity, forbiddenJson(entity));
115116
}
116117

117118

@@ -160,6 +161,21 @@ public static WebApplicationException internalServerErrorException(String entity
160161
}
161162

162163

164+
/**
165+
* Create an exception indicating "500 Internal Server Error" in application/json format.
166+
*
167+
* @param entity
168+
* An entity to contain in the response of the exception.
169+
*
170+
* @return
171+
* An exception indicating "500 Internal Server Error".
172+
*/
173+
public static WebApplicationException internalServerErrorExceptionJson(String entity)
174+
{
175+
return new WebApplicationException(entity, internalServerErrorJson(entity));
176+
}
177+
178+
163179
/**
164180
* Create an exception indicating "500 Internal Server Error".
165181
*

src/main/java/com/authlete/jaxrs/server/util/ResponseUtil.java

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,21 @@ public static Response ok(String entity)
6767
}
6868

6969

70+
/**
71+
* Build an "application/json" response of "200 OK".
72+
*
73+
* @param entity
74+
* A string entity to contain in the response.
75+
*
76+
* @return
77+
* An "application/json" response of "200 OK".
78+
*/
79+
public static Response okJson(String entity)
80+
{
81+
return builderForJson(Status.OK, entity).build();
82+
}
83+
84+
7085
/**
7186
* Build a "text/html" response of "200 OK".
7287
*
@@ -83,15 +98,15 @@ public static Response ok(Viewable entity)
8398

8499

85100
/**
86-
* Build a "text/plain" response of "202 ACCEPTED".
101+
* Build an "application/json" response of "202 ACCEPTED".
87102
*
88103
* @param entity
89104
* A string entity to contain in the response.
90105
*
91106
* @return
92-
* A "text/plain" response of "202 ACCEPTED".
107+
* An "application/json" response of "202 ACCEPTED".
93108
*/
94-
public static Response accepted(String entity)
109+
public static Response acceptedJson(String entity)
95110
{
96111
return builderForJson(Status.ACCEPTED, entity).build();
97112
}
@@ -180,15 +195,15 @@ public static Response unauthorized(Viewable entity, String challenge)
180195

181196

182197
/**
183-
* Build a "text/plain" response of "403 Forbidden".
198+
* Build an "application/json" response of "403 Forbidden".
184199
*
185200
* @param entity
186201
* A string entity to contain in the response.
187202
*
188203
* @return
189-
* A "text/plain" response of "403 Forbidde".
204+
* An "application/json" response of "403 Forbidde".
190205
*/
191-
public static Response forbidden(final String entity)
206+
public static Response forbiddenJson(final String entity)
192207
{
193208
return builderForJson(Status.FORBIDDEN, entity).build();
194209
}
@@ -209,6 +224,21 @@ public static Response notFound(String entity)
209224
}
210225

211226

227+
/**
228+
* Build an "application/json" response of "404 Not Found".
229+
*
230+
* @param entity
231+
* A string entity to contain in the response.
232+
*
233+
* @return
234+
* An "application/json" response of "404 Not Found".
235+
*/
236+
public static Response notFoundJson(String entity)
237+
{
238+
return builderForJson(Status.NOT_FOUND, entity).build();
239+
}
240+
241+
212242
/**
213243
* Build a "text/html" response of "404 Not Found".
214244
*
@@ -239,6 +269,21 @@ public static Response internalServerError(String entity)
239269
}
240270

241271

272+
/**
273+
* Build a "text/plain" response of "500 Internal Server Error".
274+
*
275+
* @param entity
276+
* A string entity to contain in the response.
277+
*
278+
* @return
279+
* A "text/plain" response of "500 Internal Server Error".
280+
*/
281+
public static Response internalServerErrorJson(String entity)
282+
{
283+
return builderForTextPlain(Status.INTERNAL_SERVER_ERROR, entity).build();
284+
}
285+
286+
242287
/**
243288
* Build a "text/html" response of "500 Internal Server Error".
244289
*

0 commit comments

Comments
 (0)