@Test public void testGetField_Author_XMP_Partial_Found() throws Exception { InputStream stream = ClassLoader.getSystemResourceAsStream(TikaResourceTest.TEST_DOC); Response response = WebClient.create(endPoint + META_PATH + "/dc:creator").type("application/msword") .accept("application/rdf+xml").put(copy(stream, 12000)); Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); String s = IOUtils.readStringFromStream((InputStream) response.getEntity()); assertContains("<rdf:li>Maxim Valyanskiy</rdf:li>", s); }
@Test public void testXMP() throws Exception { Response response = WebClient .create(endPoint + META_PATH) .type("application/msword") .accept("application/rdf+xml") .put(ClassLoader .getSystemResourceAsStream(TikaResourceTest.TEST_DOC)); String result = IOUtils.readStringFromStream((InputStream) response.getEntity()); assertContains("<rdf:li>Maxim Valyanskiy</rdf:li>", result); }
@Test public void testGetField_Author_TEXT_Partial_Found() throws Exception { InputStream stream = ClassLoader.getSystemResourceAsStream(TikaResourceTest.TEST_DOC); Response response = WebClient.create(endPoint + META_PATH + "/"+TikaCoreProperties.CREATOR.getName()) .type("application/msword") .accept(MediaType.TEXT_PLAIN).put(copy(stream, 12000)); Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); String s = IOUtils.readStringFromStream((InputStream) response.getEntity()); assertEquals("Maxim Valyanskiy", s); }
public static UserApplication getUserApplicationFromStream(InputStream is, ParseConfiguration cfg) throws IOException { return getUserApplicationFromJson(IOUtils.readStringFromStream(is), cfg); } public static UserApplication getUserApplicationFromJson(String json) {
public List<String> readFrom(Class<List<String>> arg0, Type arg1, Annotation[] arg2, MediaType arg3, MultivaluedMap<String, String> arg4, InputStream arg5) throws IOException, WebApplicationException { return Collections.singletonList(IOUtils.readStringFromStream(arg5)); }
@Override public Object readFrom(Class<Object> arg0, Type arg1, Annotation[] arg2, MediaType arg3, MultivaluedMap<String, String> arg4, InputStream is) throws IOException, WebApplicationException { return Boolean.valueOf(IOUtils.readStringFromStream(is)); }
@Override public Object readFrom(Class<Object> arg0, Type arg1, Annotation[] arg2, MediaType arg3, MultivaluedMap<String, String> arg4, InputStream is) throws IOException, WebApplicationException { return Boolean.valueOf(IOUtils.readStringFromStream(is)); }
public int[] readFrom(Class<int[]> arg0, Type arg1, Annotation[] arg2, MediaType arg3, MultivaluedMap<String, String> arg4, InputStream arg5) throws IOException, WebApplicationException { String[] stringArr = IOUtils.readStringFromStream(arg5).split(","); int[] intArr = new int[stringArr.length]; for (int i = 0; i < stringArr.length; i++) { intArr[i] = Integer.valueOf(stringArr[i]); } return intArr; }
public Object readFrom(Class<Object> arg0, Type arg1, Annotation[] arg2, MediaType arg3, MultivaluedMap<String, String> arg4, InputStream arg5) throws IOException, WebApplicationException { String[] stringArr = IOUtils.readStringFromStream(arg5).split(","); double[] intArr = new double[stringArr.length]; for (int i = 0; i < stringArr.length; i++) { intArr[i] = Double.valueOf(stringArr[i]); } return intArr; }
private static String getExpectedValue(String name, Object... args) throws IOException { return String.format(IOUtils.readStringFromStream( AbstractSwagger2ServiceDescriptionTest.class.getResourceAsStream(name)), args); } }
@POST @Path("/bookform") @Consumes("application/xml") @Produces("application/xml") public String echoBookFormXml(@Context HttpServletRequest req) throws IOException { InputStream is = req.getInputStream(); return IOUtils.readStringFromStream(is); }
@POST @Path("/books/istream2") @Produces("text/xml") public Book addBookFromInputStreamReadItself(InputStream is) throws Exception { String body = IOUtils.readStringFromStream(is); if (!body.trim().startsWith("--")) { throw new RuntimeException(); } return new Book("432", 432L); }
public static JsonWebKey decryptJwkKey(InputStream is, JweDecryptionProvider jwe) throws IOException { return new JwkReaderWriter().jsonToJwk( jwe.decrypt(IOUtils.readStringFromStream(is)).getContentText()); } public static JsonWebKeys loadPublicJwkSet(Message m, Properties props) {
public static JsonWebKeys decryptJwkSet(InputStream is, JweDecryptionProvider jwe) throws IOException { return new JwkReaderWriter().jsonToJwkSet( jwe.decrypt(IOUtils.readStringFromStream(is)).getContentText()); } public static String encryptJwkKey(JsonWebKey jwkKey, char[] password) {
private void verifyResponse(Response response, String actualBookName, String actualHeaderName) throws Exception { List<Object> customHeaders = response.getMetadata().get("CustomHeader"); assertEquals(customHeaders.size(), 1); assertEquals(actualHeaderName, customHeaders.get(0).toString()); String responseValue = IOUtils.readStringFromStream((InputStream)response.getEntity()); assertEquals(actualBookName, responseValue); } }
@Test public void testGetAllBooksIs() throws Exception { final Response response = createWebClient("/bookstore/is", MediaType.TEXT_PLAIN).get(); try { assertEquals(200, response.getStatus()); assertThat(response.readEntity(String.class), equalTo(IOUtils.readStringFromStream( getClass().getResourceAsStream("/files/books.txt")))); } finally { response.close(); } }
@Test public void testGetAllBooks() throws Exception { final Response response = createWebClient("/bookstore", MediaType.TEXT_PLAIN).get(); try { assertEquals(200, response.getStatus()); assertThat(response.readEntity(String.class), equalTo(IOUtils.readStringFromStream( getClass().getResourceAsStream("/files/books.txt")))); } finally { response.close(); } }
private void doInvoke(String actualBookName, String actualHeaderName) throws Exception { Response response = client.post(actualBookName); assertEquals(actualHeaderName, response.getMetadata().getFirst("CustomHeader").toString()); String responseValue = IOUtils.readStringFromStream((InputStream)response.getEntity()); assertEquals(actualBookName, responseValue); } }
@Test public void testNullableParamsPrimitive() throws Exception { String address = "http://localhost:" + PORT + "/bookstore/books/testnullpartprimitive"; WebClient client = WebClient.create(address); client.type("multipart/form-data").accept("text/plain"); List<Attachment> atts = new LinkedList<>(); atts.add(new Attachment("somepart", "text/plain", "hello there")); Response r = client.postCollection(atts, Attachment.class); assertEquals(Response.Status.OK.getStatusCode(), r.getStatus()); assertEquals((Integer)0, Integer.valueOf(IOUtils.readStringFromStream((InputStream)r.getEntity()))); }
@Test public void testGetBookWithoutJsonpCallback() throws Exception { String url = "http://localhost:" + PORT + "/the/jsonp/books/123"; WebClient client = WebClient.create(url); client.accept("application/json, application/x-javascript"); WebClient.getConfig(client).getHttpConduit().getClient().setReceiveTimeout(1000000L); Response r = client.get(); assertEquals("application/json", r.getMetadata().getFirst("Content-Type")); assertEquals("{\"Book\":{\"id\":123,\"name\":\"CXF in Action\"}}", IOUtils.readStringFromStream((InputStream)r.getEntity())); }