Skip to content

Commit

Permalink
Support response exception construction with strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
noboomu committed Jul 18, 2018
1 parent 2f59835 commit c8ac7ad
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/main/java/io/sinistral/proteus/server/MediaType.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

public class MediaType {

private static final Map<String, MediaType> FILE_EXTENSISONS = new LinkedHashMap<>();
private static final Map<String, MediaType> FILE_EXTENSIONS = new LinkedHashMap<>();
private static final String[] NO_ATTR = new String[0];
private static final String[] UTF8_ATTR = {"charset=utf-8"};

Expand Down Expand Up @@ -1178,7 +1178,7 @@ public static synchronized MediaType create(String type, String[] attributes, St
MediaType mt = new MediaType(type, attributes);

for (String ext : fileExtensisons) {
FILE_EXTENSISONS.put(ext, mt);
FILE_EXTENSIONS.put(ext, mt);
}

return mt;
Expand All @@ -1189,7 +1189,7 @@ public static synchronized MediaType createUTF8(String type, String... fileExten
}

public static synchronized MediaType getByFileExtension(String fileExtension) {
return FILE_EXTENSISONS.get(fileExtension);
return FILE_EXTENSIONS.get(fileExtension);
}

public static synchronized MediaType getByFileName(String filename) {
Expand Down
41 changes: 40 additions & 1 deletion src/main/java/io/sinistral/proteus/server/ServerResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,18 @@ public ServerResponse<T> contentType(String contentType)
this.setContentType(contentType);
return this;
}

public ServerResponse<T> contentType(javax.ws.rs.core.MediaType mediaType)
{
this.setContentType(mediaType.toString());
return this;
}

public ServerResponse<T> contentType(MediaType mediaType)
{
this.setContentType(mediaType.contentType());
return this;
}

public ServerResponse<T> applicationJson()
{
Expand Down Expand Up @@ -272,7 +284,11 @@ public ServerResponse<T> badRequest(Throwable t)
this.throwable = t;
return this;
}

public ServerResponse<T> badRequest(String message)
{
return this.badRequest(new Throwable(message));
}

public ServerResponse<T> internalServerError()
{
this.status = StatusCodes.INTERNAL_SERVER_ERROR;
Expand All @@ -285,6 +301,11 @@ public ServerResponse<T> internalServerError(Throwable t)
this.throwable = t;
return this;
}

public ServerResponse<T> internalServerError(String message)
{
return this.internalServerError(new Throwable(message));
}

public ServerResponse<T> created()
{
Expand All @@ -304,6 +325,12 @@ public ServerResponse<T> notFound(Throwable t)
this.throwable = t;
return this;
}

public ServerResponse<T> notFound(String message)
{
return this.notFound(new Throwable(message));
}


public ServerResponse<T> forbidden()
{
Expand All @@ -317,6 +344,12 @@ public ServerResponse<T> forbidden(Throwable t)
this.throwable = t;
return this;
}

public ServerResponse<T> forbidden(String message)
{
return this.forbidden(new Throwable(message));
}


public ServerResponse<T> found()
{
Expand All @@ -337,6 +370,12 @@ public ServerResponse<T> noContent(Throwable t)
return this;
}


public ServerResponse<T> noContent(String message)
{
return this.noContent(new Throwable(message));
}

public ServerResponse<T> withIoCallback(IoCallback ioCallback)
{
this.ioCallback = ioCallback;
Expand Down

0 comments on commit c8ac7ad

Please sign in to comment.