/** * recognises names of entities in the text * @param text text which possibly contains names * @return map of entity type -> set of names */ public Map<String, Set<String>> recognise(String text) { Map<String, Set<String>> entities = new HashMap<>(); try { String url = restHostUrlStr + "/nltk"; Response response = WebClient.create(url).accept(MediaType.TEXT_HTML).post(text); int responseCode = response.getStatus(); if (responseCode == 200) { String result = response.readEntity(String.class); JSONParser parser = new JSONParser(); JSONObject j = (JSONObject) parser.parse(result); Iterator<?> keys = j.keySet().iterator(); while( keys.hasNext() ) { String key = (String)keys.next(); if ( !key.equals("result") ) { ENTITY_TYPES.add(key); entities.put(key.toUpperCase(Locale.ENGLISH), new HashSet((Collection) j.get(key))); } } } } catch (Exception e) { LOG.debug(e.getMessage(), e); } return entities; }
public void parse(String filePath, ContentHandler handler, Metadata metadata, ParseContext context) throws FileNotFoundException { File pdfFile = new File(filePath); ContentDisposition cd = new ContentDisposition( "form-data; name=\"input\"; filename=\"" + pdfFile.getName() + "\""); Attachment att = new Attachment("input", new FileInputStream(pdfFile), cd); MultipartBody body = new MultipartBody(att); Response response = WebClient .create(restHostUrlStr + GROBID_PROCESSHEADER_PATH) .accept(MediaType.APPLICATION_XML).type(MediaType.MULTIPART_FORM_DATA) .post(body); try { String resp = response.readEntity(String.class); Metadata teiMet = new TEIDOMParser().parse(resp, context); for (String key : teiMet.names()) { metadata.add("grobid:header_" + key, teiMet.get(key)); } } catch (Exception e) { LOG.warn("Couldn't read response", e); } }
providers.add(jacksonJsonProvider); client = WebClient.create(networkURI, providers); jsonNode.put("inputText", inputText); Response response = client.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).post(jsonNode); BufferedReader reader = new BufferedReader(new InputStreamReader( (InputStream) response.getEntity(), UTF_8));
@Test public void testTextMainMultipart() throws Exception { //boilerpipe Attachment attachmentPart = new Attachment("myhtml", "text/html", ClassLoader.getSystemResourceAsStream("testHTML.html")); Response response = WebClient.create(endPoint + TIKA_PATH+"/form/main") .type("multipart/form-data") .accept("text/plain") .post(attachmentPart); String responseMsg = getStringFromInputStream((InputStream) response .getEntity()); assertTrue(responseMsg.contains("Title : Test Indexation Html")); assertFalse(responseMsg.contains("Indexation du fichier")); }
@Test public void testThatResponseValidationForAllBooksFails() { Response r = createWebClient("/bookstore/books").post(new Form().param("id", "1234")); assertEquals(Status.CREATED.getStatusCode(), r.getStatus()); r = createWebClient("/bookstore/books").get(); assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), r.getStatus()); }
@Test public void testSimpleWordMultipartXML() throws Exception { ClassLoader.getSystemResourceAsStream(TEST_DOC); Attachment attachmentPart = new Attachment("myworddoc", "application/msword", ClassLoader.getSystemResourceAsStream(TEST_DOC)); WebClient webClient = WebClient.create(endPoint + TIKA_PATH + "/form"); Response response = webClient.type("multipart/form-data") .accept("text/xml") .post(attachmentPart); String responseMsg = getStringFromInputStream((InputStream) response .getEntity()); assertTrue(responseMsg.contains("test")); assertContains("<meta name=\"X-TIKA:digest:MD5\" content=\"f8be45c34e8919eedba48cc8d207fbf0\"/>", responseMsg); }
@Test public void testThatResponseValidationForOneResponseBookFails() { Response r = createWebClient("/bookstore/booksResponse/1234").get(); assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), r.getStatus()); r = createWebClient("/bookstore/books").post(new Form().param("id", "1234")); assertEquals(Status.CREATED.getStatusCode(), r.getStatus()); r = createWebClient("/bookstore/booksResponse/1234").get(); assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), r.getStatus()); }
@Test public void testExtractTextAcceptPlainText() throws Exception { //TIKA-2384 Attachment attachmentPart = new Attachment( "my-docx-file", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", ClassLoader.getSystemResourceAsStream("2pic.docx") ); Response response = WebClient.create(endPoint + TIKA_PATH + "/form") .type("multipart/form-data") .accept("text/plain") .post(attachmentPart); String responseMsg = getStringFromInputStream((InputStream) response.getEntity()); assertTrue(responseMsg.contains("P1040893.JPG")); assertNotFound( STREAM_CLOSED_FAULT, responseMsg ); }
Response response = webClient.type("multipart/form-data") .accept("application/json") .post(attachmentPart); Reader reader = new InputStreamReader((InputStream) response.getEntity(), UTF_8); List<Metadata> metadataList = JsonMetadataList.fromJson(reader); response = webClient.type("multipart/form-data") .accept("application/json") .post(attachmentPart); reader = new InputStreamReader((InputStream) response.getEntity(), UTF_8); metadataList = JsonMetadataList.fromJson(reader); response = webClient.type("multipart/form-data") .accept("application/json") .post(attachmentPart); reader = new InputStreamReader((InputStream) response.getEntity(), UTF_8); metadataList = JsonMetadataList.fromJson(reader); .post(attachmentPart); reader = new InputStreamReader((InputStream) response.getEntity(), UTF_8); metadataList = JsonMetadataList.fromJson(reader); .post(attachmentPart); reader = new InputStreamReader((InputStream) response.getEntity(), UTF_8); metadataList = JsonMetadataList.fromJson(reader);
@Test public void testNoHttpSignature() throws Exception { URL busFile = JAXRSHTTPSignatureTest.class.getResource("client.xml"); String address = "https://localhost:" + PORT + "/httpsig/bookstore/books"; WebClient client = WebClient.create(address, busFile.toString()); client.type("application/xml").accept("application/xml"); Response response = client.post(new Book("CXF", 126L)); assertEquals(response.getStatus(), 400); }
@Test public void testEchoBookName202() throws Exception { WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/booksecho202"); wc.type("text/plain").accept("text/plain"); Response r = wc.post("book"); assertEquals(202, r.getStatus()); assertEquals("book", r.readEntity(String.class)); }
@Test public void testBookDepthExceededJettison() throws Exception { String endpointAddress = "http://localhost:" + PORT + "/the/thebooks10/depth"; WebClient wc = WebClient.create(endpointAddress); wc.accept("application/json").type("application/json"); Response r = wc.post(new Book("CXF", 123L)); assertEquals(413, r.getStatus()); }
@org.junit.Test public void testRegisterClientNoInitialAccessToken() throws Exception { URL busFile = OIDCDynamicRegistrationTest.class.getResource("client.xml"); String address = "https://localhost:" + PORT + "/services/dynamic/register"; WebClient wc = WebClient.create(address, Collections.singletonList(new JsonMapObjectProvider()), busFile.toString()); wc.accept("application/json").type("application/json"); assertEquals(401, wc.post(newClientRegistrationCodeGrant()).getStatus()); }