Search in sources :

Example 51 with WebClient

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());
}
Also used : Response(javax.ws.rs.core.Response) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) WebClient(org.apache.cxf.jaxrs.client.WebClient) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 52 with WebClient

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);
}
Also used : Response(javax.ws.rs.core.Response) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.testng.annotations.Test)

Example 53 with WebClient

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);
}
Also used : Response(javax.ws.rs.core.Response) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.testng.annotations.Test)

Example 54 with WebClient

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));
}
Also used : Response(javax.ws.rs.core.Response) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Metadata(org.apache.tika.metadata.Metadata) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Attachment(org.apache.cxf.jaxrs.ext.multipart.Attachment) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 55 with WebClient

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());
    }
}
Also used : Response(javax.ws.rs.core.Response) TikaException(org.apache.tika.exception.TikaException) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonParseException(com.fasterxml.jackson.core.JsonParseException) WebClient(org.apache.cxf.jaxrs.client.WebClient) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

WebClient (org.apache.cxf.jaxrs.client.WebClient)723 Test (org.junit.Test)400 Response (javax.ws.rs.core.Response)351 URL (java.net.URL)198 HashMap (java.util.HashMap)100 Book (org.apache.cxf.systest.jaxrs.security.Book)94 ArrayList (java.util.ArrayList)88 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)87 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)77 ClientAccessToken (org.apache.cxf.rs.security.oauth2.common.ClientAccessToken)60 Bus (org.apache.cxf.Bus)48 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)46 Test (org.testng.annotations.Test)46 Form (javax.ws.rs.core.Form)44 JwtToken (org.apache.cxf.rs.security.jose.jwt.JwtToken)42 JwtClaims (org.apache.cxf.rs.security.jose.jwt.JwtClaims)40 JwtAuthenticationClientFilter (org.apache.cxf.rs.security.jose.jaxrs.JwtAuthenticationClientFilter)32 InputStream (java.io.InputStream)28 ResponseProcessingException (javax.ws.rs.client.ResponseProcessingException)28 Document (org.w3c.dom.Document)27