Search in sources :

Example 11 with FormDataMultiPart

use of com.sun.jersey.multipart.FormDataMultiPart in project teammates by TEAMMATES.

the class MailgunService method sendEmailWithService.

@Override
protected void sendEmailWithService(EmailWrapper wrapper) {
    try (FormDataMultiPart email = parseToEmail(wrapper)) {
        Client client = Client.create();
        client.addFilter(new HTTPBasicAuthFilter("api", Config.MAILGUN_APIKEY));
        WebResource webResource = client.resource("https://api.mailgun.net/v3/" + Config.MAILGUN_DOMAINNAME + "/messages");
        ClientResponse response = webResource.type(MediaType.MULTIPART_FORM_DATA_TYPE).post(ClientResponse.class, email);
        if (isNotSuccessStatus(response.getStatus())) {
            log.severe("Email failed to send: " + response.getStatusInfo().getReasonPhrase());
        }
    } catch (IOException e) {
        log.warning("Could not clean up resources after sending email: " + TeammatesException.toStringWithStackTrace(e));
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) FormDataMultiPart(com.sun.jersey.multipart.FormDataMultiPart) WebResource(com.sun.jersey.api.client.WebResource) IOException(java.io.IOException) Client(com.sun.jersey.api.client.Client) HTTPBasicAuthFilter(com.sun.jersey.api.client.filter.HTTPBasicAuthFilter)

Example 12 with FormDataMultiPart

use of com.sun.jersey.multipart.FormDataMultiPart in project data-access by pentaho.

the class DataSourcePublishIT method testPublishDSW.

@Test
public void testPublishDSW() throws Exception {
    repositoryBase.login(singleTenantAdminUserName, defaultTenant, new String[] { repositoryBase.getTenantAdminRoleName(), AUTHENTICATED_ROLE_NAME });
    final String domainID = "test.xmi";
    final FileInputStream metadataFile = new FileInputStream("target/test-classes/test.xmi");
    final boolean overwrite = true;
    final RepositoryFileAclDto acl = generateACL(USERNAME_SUZY, RepositoryFileSid.Type.USER);
    MultiPart part = new FormDataMultiPart().field("domainId", domainID).field("overwrite", String.valueOf(overwrite)).field("acl", marshalACL(acl)).bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("metadataFile").fileName("test.xmi").size(metadataFile.available()).build(), metadataFile, MediaType.TEXT_XML_TYPE));
    WebResource webResource = resource();
    ClientResponse postAnalysis = webResource.path(DATA_ACCESS_API_DATASOURCE_DSW + "import").type(MediaType.MULTIPART_FORM_DATA_TYPE).put(ClientResponse.class, part);
    assertEquals(Response.Status.OK.getStatusCode(), postAnalysis.getStatus());
    final RepositoryFileAclDto savedACL = webResource.path(DATA_ACCESS_API_DATASOURCE_DSW + domainID + "/acl").get(ClientResponse.class).getEntity(RepositoryFileAclDto.class);
    assertNotNull(savedACL);
    repositoryBase.login(USERNAME_SUZY, defaultTenant, new String[] { AUTHENTICATED_ROLE_NAME });
    checkDSW(webResource, domainID, true);
    repositoryBase.login(USERNAME_TIFFANY, defaultTenant, new String[] { AUTHENTICATED_ROLE_NAME });
    checkDSW(webResource, domainID, false);
    repositoryBase.login(singleTenantAdminUserName, defaultTenant, new String[] { repositoryBase.getTenantAdminRoleName(), AUTHENTICATED_ROLE_NAME });
    final ClientResponse changeACL = webResource.path(DATA_ACCESS_API_DATASOURCE_DSW + domainID + "/acl").put(ClientResponse.class, generateACL(AUTHENTICATED_ROLE_NAME, RepositoryFileSid.Type.ROLE));
    assertEquals(Response.Status.OK.getStatusCode(), changeACL.getStatus());
    repositoryBase.login(USERNAME_TIFFANY, defaultTenant, new String[] { AUTHENTICATED_ROLE_NAME });
    checkDSW(webResource, domainID, true);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) MultiPart(com.sun.jersey.multipart.MultiPart) FormDataMultiPart(com.sun.jersey.multipart.FormDataMultiPart) FormDataBodyPart(com.sun.jersey.multipart.FormDataBodyPart) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) FormDataMultiPart(com.sun.jersey.multipart.FormDataMultiPart) WebResource(com.sun.jersey.api.client.WebResource) FileInputStream(java.io.FileInputStream) JerseyTest(com.sun.jersey.test.framework.JerseyTest) Test(org.junit.Test)

Example 13 with FormDataMultiPart

use of com.sun.jersey.multipart.FormDataMultiPart in project data-access by pentaho.

the class DataSourcePublishIT method testDSW_ACL.

@Test
public void testDSW_ACL() throws Exception {
    repositoryBase.login(singleTenantAdminUserName, defaultTenant, new String[] { repositoryBase.getTenantAdminRoleName(), AUTHENTICATED_ROLE_NAME });
    final String domainID = "test.xmi";
    final FileInputStream metadataFile = new FileInputStream("target/test-classes/test.xmi");
    final boolean overwrite = true;
    MultiPart part = new FormDataMultiPart().field("domainId", domainID).field("overwrite", String.valueOf(overwrite)).bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("metadataFile").fileName("test.xmi").size(metadataFile.available()).build(), metadataFile, MediaType.TEXT_XML_TYPE));
    WebResource webResource = resource();
    final ClientResponse noDSW = webResource.path(DATA_ACCESS_API_DATASOURCE_DSW + domainID + "/acl").get(ClientResponse.class);
    assertEquals(Response.Status.CONFLICT.getStatusCode(), noDSW.getStatus());
    ClientResponse postAnalysis = webResource.path(DATA_ACCESS_API_DATASOURCE_DSW + "import").type(MediaType.MULTIPART_FORM_DATA_TYPE).put(ClientResponse.class, part);
    assertEquals(Response.Status.OK.getStatusCode(), postAnalysis.getStatus());
    final ClientResponse noACL = webResource.path(DATA_ACCESS_API_DATASOURCE_DSW + domainID + "/acl").get(ClientResponse.class);
    assertEquals(Response.Status.NOT_FOUND.getStatusCode(), noACL.getStatus());
    repositoryBase.login(USERNAME_SUZY, defaultTenant, new String[] { AUTHENTICATED_ROLE_NAME });
    checkDSW(webResource, domainID, true);
    repositoryBase.login(singleTenantAdminUserName, defaultTenant, new String[] { repositoryBase.getTenantAdminRoleName(), AUTHENTICATED_ROLE_NAME });
    final ClientResponse setSuzyACL = webResource.path(DATA_ACCESS_API_DATASOURCE_DSW + domainID + "/acl").put(ClientResponse.class, generateACL(USERNAME_SUZY, RepositoryFileSid.Type.USER));
    assertEquals(Response.Status.OK.getStatusCode(), setSuzyACL.getStatus());
    repositoryBase.login(USERNAME_SUZY, defaultTenant, new String[] { AUTHENTICATED_ROLE_NAME });
    checkDSW(webResource, domainID, true);
    final ClientResponse noAccessACL = webResource.path(DATA_ACCESS_API_DATASOURCE_DSW + domainID + "/acl").get(ClientResponse.class);
    assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), noAccessACL.getStatus());
    final ClientResponse noAccessACLNoDS = webResource.path(DATA_ACCESS_API_DATASOURCE_DSW + domainID + "_not_exist/acl").get(ClientResponse.class);
    assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), noAccessACLNoDS.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) MultiPart(com.sun.jersey.multipart.MultiPart) FormDataMultiPart(com.sun.jersey.multipart.FormDataMultiPart) FormDataBodyPart(com.sun.jersey.multipart.FormDataBodyPart) FormDataMultiPart(com.sun.jersey.multipart.FormDataMultiPart) WebResource(com.sun.jersey.api.client.WebResource) FileInputStream(java.io.FileInputStream) JerseyTest(com.sun.jersey.test.framework.JerseyTest) Test(org.junit.Test)

Example 14 with FormDataMultiPart

use of com.sun.jersey.multipart.FormDataMultiPart in project data-access by pentaho.

the class DataSourcePublishIT method testPublishAnalysis.

@Test
public void testPublishAnalysis() throws Exception {
    repositoryBase.login(singleTenantAdminUserName, defaultTenant, new String[] { repositoryBase.getTenantAdminRoleName(), AUTHENTICATED_ROLE_NAME });
    final String catalogID = "FoodMart";
    final InputStream uploadAnalysis = new FileInputStream("target/test-classes/schema.xml");
    final boolean overwrite = true;
    final boolean xmlaEnabledFlag = false;
    final String parameters = "DataSource=" + catalogID + ";EnableXmla=" + xmlaEnabledFlag + ";overwrite=" + overwrite;
    final RepositoryFileAclDto acl = generateACL(USERNAME_SUZY, RepositoryFileSid.Type.USER);
    MultiPart part = new FormDataMultiPart().field("catalogName", catalogID).field("datasourceName", catalogID).field("overwrite", String.valueOf(overwrite)).field("xmlaEnabledFlag", String.valueOf(xmlaEnabledFlag)).field("acl", marshalACL(acl)).field("parameters", parameters).bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("uploadAnalysis").fileName("schema.xml").size(uploadAnalysis.available()).build(), uploadAnalysis, MediaType.TEXT_XML_TYPE));
    WebResource webResource = resource();
    ClientResponse postAnalysis = webResource.path("data-access/api/mondrian/postAnalysis").type(MediaType.MULTIPART_FORM_DATA_TYPE).post(ClientResponse.class, part);
    assertEquals(Response.Status.OK.getStatusCode(), postAnalysis.getStatus());
    final RepositoryFileAclDto savedACL = webResource.path("data-access/api/datasource/analysis/" + catalogID + "/acl").get(ClientResponse.class).getEntity(RepositoryFileAclDto.class);
    assertNotNull(savedACL);
    repositoryBase.login(USERNAME_SUZY, defaultTenant, new String[] { AUTHENTICATED_ROLE_NAME });
    checkAnalysis(webResource, catalogID, true);
    repositoryBase.login(USERNAME_TIFFANY, defaultTenant, new String[] { AUTHENTICATED_ROLE_NAME });
    checkAnalysis(webResource, catalogID, false);
    repositoryBase.login(singleTenantAdminUserName, defaultTenant, new String[] { repositoryBase.getTenantAdminRoleName(), AUTHENTICATED_ROLE_NAME });
    final ClientResponse changeACL = webResource.path("data-access/api/datasource/analysis/" + catalogID + "/acl").put(ClientResponse.class, generateACL(AUTHENTICATED_ROLE_NAME, RepositoryFileSid.Type.ROLE));
    assertEquals(Response.Status.OK.getStatusCode(), changeACL.getStatus());
    repositoryBase.login(USERNAME_TIFFANY, defaultTenant, new String[] { AUTHENTICATED_ROLE_NAME });
    checkAnalysis(webResource, catalogID, true);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) MultiPart(com.sun.jersey.multipart.MultiPart) FormDataMultiPart(com.sun.jersey.multipart.FormDataMultiPart) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FormDataBodyPart(com.sun.jersey.multipart.FormDataBodyPart) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) FormDataMultiPart(com.sun.jersey.multipart.FormDataMultiPart) WebResource(com.sun.jersey.api.client.WebResource) FileInputStream(java.io.FileInputStream) JerseyTest(com.sun.jersey.test.framework.JerseyTest) Test(org.junit.Test)

Example 15 with FormDataMultiPart

use of com.sun.jersey.multipart.FormDataMultiPart in project data-access by pentaho.

the class DataSourcePublishIT method testPublishMetadata.

@Test
public void testPublishMetadata() throws Exception {
    repositoryBase.login(singleTenantAdminUserName, defaultTenant, new String[] { repositoryBase.getTenantAdminRoleName(), AUTHENTICATED_ROLE_NAME });
    final String domainID = "domainID.xmi";
    final FileInputStream metadataFile = new FileInputStream("target/test-classes/Sample_SQL_Query.xmi");
    final String overwrite = "true";
    final RepositoryFileAclDto acl = generateACL(USERNAME_SUZY, RepositoryFileSid.Type.USER);
    MultiPart part = new FormDataMultiPart().field("domainId", domainID).field("overwrite", String.valueOf(overwrite)).field("acl", marshalACL(acl)).bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("metadataFile").fileName("Sample_SQL_Query.xmi").size(metadataFile.available()).build(), metadataFile, MediaType.TEXT_XML_TYPE));
    WebResource webResource = resource();
    ClientResponse postAnalysis = webResource.path("data-access/api/metadata/import").type(MediaType.MULTIPART_FORM_DATA_TYPE).put(ClientResponse.class, part);
    assertEquals(3, postAnalysis.getStatus());
    final RepositoryFileAclDto savedACL = webResource.path(DATA_ACCESS_API_DATASOURCE_METADATA + domainID + "/acl").get(ClientResponse.class).getEntity(RepositoryFileAclDto.class);
    assertNotNull(savedACL);
    repositoryBase.login(USERNAME_SUZY, defaultTenant, new String[] { AUTHENTICATED_ROLE_NAME });
    checkMetadata(webResource, domainID, true);
    repositoryBase.login(USERNAME_TIFFANY, defaultTenant, new String[] { AUTHENTICATED_ROLE_NAME });
    checkMetadata(webResource, domainID, false);
    repositoryBase.login(singleTenantAdminUserName, defaultTenant, new String[] { repositoryBase.getTenantAdminRoleName(), AUTHENTICATED_ROLE_NAME });
    final ClientResponse changeACL = webResource.path(DATA_ACCESS_API_DATASOURCE_METADATA + domainID + "/acl").put(ClientResponse.class, generateACL(AUTHENTICATED_ROLE_NAME, RepositoryFileSid.Type.ROLE));
    assertEquals(Response.Status.OK.getStatusCode(), changeACL.getStatus());
    repositoryBase.login(USERNAME_TIFFANY, defaultTenant, new String[] { AUTHENTICATED_ROLE_NAME });
    checkMetadata(webResource, domainID, true);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) MultiPart(com.sun.jersey.multipart.MultiPart) FormDataMultiPart(com.sun.jersey.multipart.FormDataMultiPart) FormDataBodyPart(com.sun.jersey.multipart.FormDataBodyPart) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) FormDataMultiPart(com.sun.jersey.multipart.FormDataMultiPart) WebResource(com.sun.jersey.api.client.WebResource) FileInputStream(java.io.FileInputStream) JerseyTest(com.sun.jersey.test.framework.JerseyTest) Test(org.junit.Test)

Aggregations

FormDataMultiPart (com.sun.jersey.multipart.FormDataMultiPart)23 ClientResponse (com.sun.jersey.api.client.ClientResponse)14 WebResource (com.sun.jersey.api.client.WebResource)14 FileInputStream (java.io.FileInputStream)10 MultiPart (com.sun.jersey.multipart.MultiPart)7 Test (org.junit.Test)7 FormDataBodyPart (com.sun.jersey.multipart.FormDataBodyPart)6 FileDataBodyPart (com.sun.jersey.multipart.file.FileDataBodyPart)6 JerseyTest (com.sun.jersey.test.framework.JerseyTest)6 File (java.io.File)6 InputStream (java.io.InputStream)5 Client (com.sun.jersey.api.client.Client)3 HTTPBasicAuthFilter (com.sun.jersey.api.client.filter.HTTPBasicAuthFilter)3 IOException (java.io.IOException)3 ZipInputStream (java.util.zip.ZipInputStream)3 RepositoryFileAclDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto)3 MalformedURLException (java.net.MalformedURLException)2 ParseException (org.apache.commons.cli.ParseException)2 StreamDataBodyPart (com.sun.jersey.multipart.file.StreamDataBodyPart)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1