@Test void testResponseTyped() throws Exception { assertEquals(RedPenResource.MIME_TYPE_XML, RedPenResource.responseTyped("test", "xml").getMetadata().getFirst(HttpHeaders.CONTENT_TYPE).toString()); assertEquals(RedPenResource.MIME_TYPE_JSON, RedPenResource.responseTyped("test", "json").getMetadata().getFirst(HttpHeaders.CONTENT_TYPE).toString()); assertEquals(RedPenResource.MIME_TYPE_JSON, RedPenResource.responseTyped("test", "json2").getMetadata().getFirst(HttpHeaders.CONTENT_TYPE).toString()); assertEquals(RedPenResource.MIME_TYPE_PLAINTEXT, RedPenResource.responseTyped("test", "plain").getMetadata().getFirst(HttpHeaders.CONTENT_TYPE).toString()); try { RedPenResource.responseTyped("test", "foobarbaz"); fail(); } catch (final RedPenException success) { assertTrue(true); } }
static Response responseTyped(final String formatted, final String format) throws RedPenException { if (format.startsWith("xml")) { return Response.ok(formatted, RedPenResource.MIME_TYPE_XML).build(); } else if (format.startsWith("json")) { return Response.ok(formatted, RedPenResource.MIME_TYPE_JSON).build(); } else if (format.startsWith("plain")) { return Response.ok(formatted, RedPenResource.MIME_TYPE_PLAINTEXT).build(); } else { throw new RedPenException("MIME type unknown with format: " + format); } }
RedPenResource { static Response responseTyped(final String formatted, final String format) throws RedPenException { if (format.startsWith("xml")) { return Response.ok(formatted, RedPenResource.MIME_TYPE_XML).build(); } else if (format.startsWith("json")) { return Response.ok(formatted, RedPenResource.MIME_TYPE_JSON).build(); } else if (format.startsWith("plain")) { return Response.ok(formatted, RedPenResource.MIME_TYPE_PLAINTEXT).build(); } else { throw new RedPenException("MIME type unknown with format: " + format); } } }
RedPenResource { static Response responseTyped(final String formatted, final String format) throws RedPenException { if (format.startsWith("xml")) { return Response.ok(formatted, RedPenResource.MIME_TYPE_XML).build(); } else if (format.startsWith("json")) { return Response.ok(formatted, RedPenResource.MIME_TYPE_JSON).build(); } else if (format.startsWith("plain")) { return Response.ok(formatted, RedPenResource.MIME_TYPE_PLAINTEXT).build(); } else { throw new RedPenException("MIME type unknown with format: " + format); } }  }
RedPenResource { static Response responseTyped(final String formatted, final String format) throws RedPenException { if (format.startsWith("xml")) { return Response.ok(formatted, RedPenResource.MIME_TYPE_XML).build(); } else if (format.startsWith("json")) { return Response.ok(formatted, RedPenResource.MIME_TYPE_JSON).build(); } else if (format.startsWith("plain")) { return Response.ok(formatted, RedPenResource.MIME_TYPE_PLAINTEXT).build(); } else { throw new RedPenException("MIME type unknown with format: " + format); } }  @Path("/language") @POST @Produces(MediaType.APPLICATION_JSON) @WinkAPIDescriber.Description("Detect language of document") JSONObject detectLanguage(@FormParam("document") @DefaultValue("") String document); @Path("/validate") @POST @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN}) @WinkAPIDescriber.Description("Validate a document and return any redpen errors") Response validateDocument(@FormParam("document") @DefaultValue("") String document,
                                     @FormParam("documentParser") @DefaultValue(DEFAULT_DOCUMENT_PARSER) String documentParser,
                                     @FormParam("lang") @DefaultValue(DEFAULT_CONFIGURATION) String lang,
                                     @FormParam("format") @DefaultValue(DEFAULT_FORMAT) String format,
                                     @FormParam("config") String config); @Path("/validate/json") @POST @Consumes(MediaType.APPLICATION_JSON) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN}) @WinkAPIDescriber.Description("Process a redpen JSON validation request and returns any redpen errors") Response validateDocumentJSON(JSONObject requestJSON); @Path("/tokenize") @POST @Produces(MediaType.APPLICATION_JSON) @WinkAPIDescriber.Description("Tokenize a document") JSONObject tokenize(@FormParam("document") @DefaultValue("") String document,
                               @FormParam("lang") @DefaultValue(DEFAULT_CONFIGURATION) String lang); }
RedPenResource { static Response responseTyped(final String formatted, final String format) throws RedPenException { if (format.startsWith("xml")) { return Response.ok(formatted, RedPenResource.MIME_TYPE_XML).build(); } else if (format.startsWith("json")) { return Response.ok(formatted, RedPenResource.MIME_TYPE_JSON).build(); } else if (format.startsWith("plain")) { return Response.ok(formatted, RedPenResource.MIME_TYPE_PLAINTEXT).build(); } else { throw new RedPenException("MIME type unknown with format: " + format); } }  @Path("/language") @POST @Produces(MediaType.APPLICATION_JSON) @WinkAPIDescriber.Description("Detect language of document") JSONObject detectLanguage(@FormParam("document") @DefaultValue("") String document); @Path("/validate") @POST @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN}) @WinkAPIDescriber.Description("Validate a document and return any redpen errors") Response validateDocument(@FormParam("document") @DefaultValue("") String document,
                                     @FormParam("documentParser") @DefaultValue(DEFAULT_DOCUMENT_PARSER) String documentParser,
                                     @FormParam("lang") @DefaultValue(DEFAULT_CONFIGURATION) String lang,
                                     @FormParam("format") @DefaultValue(DEFAULT_FORMAT) String format,
                                     @FormParam("config") String config); @Path("/validate/json") @POST @Consumes(MediaType.APPLICATION_JSON) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN}) @WinkAPIDescriber.Description("Process a redpen JSON validation request and returns any redpen errors") Response validateDocumentJSON(JSONObject requestJSON); @Path("/tokenize") @POST @Produces(MediaType.APPLICATION_JSON) @WinkAPIDescriber.Description("Tokenize a document") JSONObject tokenize(@FormParam("document") @DefaultValue("") String document,
                               @FormParam("lang") @DefaultValue(DEFAULT_CONFIGURATION) String lang);  }