use of org.apache.cxf.jaxrs.client.WebClient in project midpoint by Evolveum.
the class TestAbstractRestService method test130DarthAdderDisableHimself.
@Test
public void test130DarthAdderDisableHimself() throws Exception {
final String TEST_NAME = "test130DarthAdderDisableHimself";
displayTestTile(this, TEST_NAME);
WebClient client = prepareClient(USER_DARTHADDER_USERNAME, USER_DARTHADDER_PASSWORD);
client.path("/users/" + USER_DARTHADDER_OID);
getDummyAuditService().clear();
TestUtil.displayWhen(TEST_NAME);
Response response = client.post(MiscUtil.readFile(getRequestFile(MODIFICATION_DISABLE)));
TestUtil.displayThen(TEST_NAME);
displayResponse(response);
assertStatus(response, 204);
IntegrationTestTools.display("Audit", getDummyAuditService());
getDummyAuditService().assertRecords(4);
getDummyAuditService().assertLoginLogout(SchemaConstants.CHANNEL_REST_URI);
getDummyAuditService().assertHasDelta(1, ChangeType.MODIFY, UserType.class);
OperationResult result = new OperationResult("test");
PrismObject<UserType> user = getRepositoryService().getObject(UserType.class, USER_DARTHADDER_OID, null, result);
assertEquals("Wrong administrativeStatus", ActivationStatusType.DISABLED, user.asObjectable().getActivation().getAdministrativeStatus());
}
use of org.apache.cxf.jaxrs.client.WebClient in project midpoint by Evolveum.
the class TestAbstractRestService method test501generateValue.
@Test
public void test501generateValue() throws Exception {
final String TEST_NAME = "test501generateValue";
displayTestTile(this, TEST_NAME);
WebClient client = prepareClient();
client.path("/users/" + USER_DARTHADDER_OID + "/generate");
getDummyAuditService().clear();
TestUtil.displayWhen(TEST_NAME);
Response response = client.post(getRepoFile(POLICY_ITEM_DEFINITION_GENERATE));
TestUtil.displayThen(TEST_NAME);
displayResponse(response);
traceResponse(response);
assertEquals("Expected 200 but got " + response.getStatus(), 200, response.getStatus());
IntegrationTestTools.display("Audit", getDummyAuditService());
getDummyAuditService().assertRecords(2);
getDummyAuditService().assertLoginLogout(SchemaConstants.CHANNEL_REST_URI);
}
use of org.apache.cxf.jaxrs.client.WebClient in project midpoint by Evolveum.
the class TestAbstractRestService method test007GetAuthNoPassword.
@Test
public void test007GetAuthNoPassword() {
final String TEST_NAME = "test007GetAuthNoPassword";
displayTestTile(this, TEST_NAME);
WebClient client = prepareClient(USER_ADMINISTRATOR_USERNAME, null);
client.path("/users/" + SystemObjectsType.USER_ADMINISTRATOR.value());
getDummyAuditService().clear();
TestUtil.displayWhen(TEST_NAME);
Response response = client.get();
TestUtil.displayThen(TEST_NAME);
assertStatus(response, 401);
IntegrationTestTools.display("Audit", getDummyAuditService());
getDummyAuditService().assertRecords(1);
getDummyAuditService().assertFailedLogin(SchemaConstants.CHANNEL_REST_URI);
}
use of org.apache.cxf.jaxrs.client.WebClient in project tika by apache.
the class RecursiveMetadataResourceTest method testHandlerTypeInMultipartXML.
@Test
public void testHandlerTypeInMultipartXML() throws Exception {
//default unspecified
Attachment attachmentPart = new Attachment("myworddocx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", ClassLoader.getSystemResourceAsStream(TEST_RECURSIVE_DOC));
WebClient webClient = WebClient.create(endPoint + META_PATH + FORM_PATH);
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);
assertEquals(12, metadataList.size());
String content = metadataList.get(6).get(RecursiveParserWrapper.TIKA_CONTENT).trim();
assertTrue(content.startsWith("<html xmlns=\"http://www.w3.org/1999/xhtml\">"));
//unparseable
attachmentPart = new Attachment("myworddocx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", ClassLoader.getSystemResourceAsStream(TEST_RECURSIVE_DOC));
webClient = WebClient.create(endPoint + META_PATH + FORM_PATH + UNPARSEABLE_PATH);
response = webClient.type("multipart/form-data").accept("application/json").post(attachmentPart);
reader = new InputStreamReader((InputStream) response.getEntity(), UTF_8);
metadataList = JsonMetadataList.fromJson(reader);
assertEquals(12, metadataList.size());
content = metadataList.get(6).get(RecursiveParserWrapper.TIKA_CONTENT).trim();
assertTrue(content.startsWith("<html xmlns=\"http://www.w3.org/1999/xhtml\">"));
//xml
attachmentPart = new Attachment("myworddocx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", ClassLoader.getSystemResourceAsStream(TEST_RECURSIVE_DOC));
webClient = WebClient.create(endPoint + META_PATH + FORM_PATH + XML_PATH);
response = webClient.type("multipart/form-data").accept("application/json").post(attachmentPart);
reader = new InputStreamReader((InputStream) response.getEntity(), UTF_8);
metadataList = JsonMetadataList.fromJson(reader);
assertEquals(12, metadataList.size());
content = metadataList.get(6).get(RecursiveParserWrapper.TIKA_CONTENT).trim();
assertTrue(content.startsWith("<html xmlns=\"http://www.w3.org/1999/xhtml\">"));
//text
attachmentPart = new Attachment("myworddocx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", ClassLoader.getSystemResourceAsStream(TEST_RECURSIVE_DOC));
webClient = WebClient.create(endPoint + META_PATH + FORM_PATH + TEXT_PATH);
response = webClient.type("multipart/form-data").accept("application/json").post(attachmentPart);
reader = new InputStreamReader((InputStream) response.getEntity(), UTF_8);
metadataList = JsonMetadataList.fromJson(reader);
assertEquals(12, metadataList.size());
content = metadataList.get(6).get(RecursiveParserWrapper.TIKA_CONTENT).trim();
assertTrue(content.startsWith("embed_3"));
//ignore -- no content
attachmentPart = new Attachment("myworddocx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", ClassLoader.getSystemResourceAsStream(TEST_RECURSIVE_DOC));
webClient = WebClient.create(endPoint + META_PATH + FORM_PATH + IGNORE_PATH);
response = webClient.type("multipart/form-data").accept("application/json").query("handler", "ignore").post(attachmentPart);
reader = new InputStreamReader((InputStream) response.getEntity(), UTF_8);
metadataList = JsonMetadataList.fromJson(reader);
assertEquals(12, metadataList.size());
assertNull(metadataList.get(6).get(RecursiveParserWrapper.TIKA_CONTENT));
}
use of org.apache.cxf.jaxrs.client.WebClient in project tika by apache.
the class YandexTranslator method translate.
@Override
public String translate(String text, String sourceLanguage, String targetLanguage) throws TikaException, IOException {
if (!this.isAvailable()) {
return text;
}
WebClient client = WebClient.create(YANDEX_TRANSLATE_URL_BASE);
String langCode;
if (sourceLanguage == null) {
//Translate Service will identify source language
langCode = targetLanguage;
} else {
//Source language is well known
langCode = sourceLanguage + '-' + targetLanguage;
}
//TODO Add support for text over 10k characters
Response response = client.accept(MediaType.APPLICATION_JSON).query("key", this.apiKey).query("lang", langCode).query("text", text).get();
BufferedReader reader = new BufferedReader(new InputStreamReader((InputStream) response.getEntity(), UTF_8));
String line = null;
StringBuffer responseText = new StringBuffer();
while ((line = reader.readLine()) != null) {
responseText.append(line);
}
try {
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonResp = mapper.readTree(responseText.toString());
if (!jsonResp.findValuesAsText("code").isEmpty()) {
String code = jsonResp.findValuesAsText("code").get(0);
if (code.equals("200")) {
return jsonResp.findValue("text").get(0).asText();
} else {
throw new TikaException(jsonResp.findValue("message").get(0).asText());
}
} else {
throw new TikaException("Return message not recognized: " + responseText.toString().substring(0, Math.min(responseText.length(), 100)));
}
} catch (JsonParseException e) {
throw new TikaException("Error requesting translation from '" + sourceLanguage + "' to '" + targetLanguage + "', JSON response from Lingo24 is not well formatted: " + responseText.toString());
}
}
Aggregations