Redirecting to swagger-ui from JAX-RS, v2

public class SwaggerResource {

    public Response readJson() throws IOException {
        try (InputStream resource
                = getClass().getResourceAsStream("/swagger.json");
             final JsonReader reader = Json.createReader(resource)) {
            final JsonObject object = reader.readObject();
            final JsonObjectBuilder builder = Json.createObjectBuilder();
                    .filter(e -> !e.getKey().equals("host")
                                 && !e.getKey().equals("basePath")
                                 && !e.getKey().equals("schemes"))
                    .forEach(e -> builder.add(e.getKey(), e.getValue()));
            builder.add("host", uriInfo.getBaseUri().getAuthority());
            builder.add("basePath", servletContext.getContextPath()
                                    + Application_.APPLICATION_PATH);
            builder.add("schemes", Json.createArrayBuilder()
            return Response.ok((StreamingOutput) output -> {
                try (JsonWriter writer = Json.createWriter(output)) {

    public Response readUi() throws IOException {
        final URI json
                = uriInfo.getBaseUriBuilder()
        final URI swaggerUi
                = UriBuilder.fromUri(servletContext.getContextPath())
                .queryParam("url", json).build();
        return Response.seeOther(swaggerUi).build();

    private UriInfo uriInfo;

    private ServletContext servletContext;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s