Search in sources :

Example 1 with ByteArrayDataSource

use of jakarta.mail.util.ByteArrayDataSource in project resteasy by resteasy.

the class SignedTest method testPythonSigned.

/**
 * @tpTestDetails Test for python sign format
 * @tpSince RESTEasy 3.0.16
 */
@Test
public void testPythonSigned() throws Exception {
    final InputStream pythonIs = new FileInputStream(pythonPath);
    ByteArrayDataSource ds = new ByteArrayDataSource(pythonIs, "multipart/signed");
    MimeMultipart mm = new MimeMultipart(ds);
    logger.info(mm.getContentType());
    logger.info("Multipart.count(): " + mm.getCount());
    MimeBodyPart mbp = (MimeBodyPart) mm.getBodyPart(0);
    output(mbp);
    SMIMESigned signed = new SMIMESigned(mm);
    SignerInformationStore signers = signed.getSignerInfos();
    Assert.assertEquals("Wrong count of signers", 1, signers.size());
    SignerInformation signer = signers.getSigners().iterator().next();
    Assert.assertTrue("Unsuccessful verification of signer", signer.verify(new JcaSimpleSignerInfoVerifierBuilder().setProvider("BC").build(cert.getPublicKey())));
}
Also used : SMIMESigned(org.bouncycastle.mail.smime.SMIMESigned) MimeMultipart(jakarta.mail.internet.MimeMultipart) SignerInformationStore(org.bouncycastle.cms.SignerInformationStore) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) SignerInformation(org.bouncycastle.cms.SignerInformation) JcaSimpleSignerInfoVerifierBuilder(org.bouncycastle.cms.jcajce.JcaSimpleSignerInfoVerifierBuilder) MimeBodyPart(jakarta.mail.internet.MimeBodyPart) ByteArrayDataSource(jakarta.mail.util.ByteArrayDataSource) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 2 with ByteArrayDataSource

use of jakarta.mail.util.ByteArrayDataSource in project resteasy by resteasy.

the class SignedTest method testMultipart.

/**
 * @tpTestDetails Multipart test
 * @tpSince RESTEasy 3.0.16
 */
@Test
public void testMultipart() throws Exception {
    MimeMultipart mp = new MimeMultipart();
    InternetHeaders ih = new InternetHeaders();
    ih.addHeader("Content-Type", "text/xml");
    MimeBodyPart bp = new MimeBodyPart(ih, "<customer/>".getBytes());
    mp.addBodyPart(bp);
    bp = new MimeBodyPart(ih, "<product/>".getBytes());
    mp.addBodyPart(bp);
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    mp.writeTo(os);
    String s = new String(os.toByteArray());
    logger.info(s);
    logger.info("************");
    String contentType = mp.getContentType();
    contentType = contentType.replace("\r\n", "").replace("\t", " ");
    logger.info("Content-Type: " + contentType);
    mp = new MimeMultipart(new ByteArrayDataSource(s.getBytes(), "multipart/signed"));
    logger.info("count: " + mp.getCount());
}
Also used : InternetHeaders(jakarta.mail.internet.InternetHeaders) MimeMultipart(jakarta.mail.internet.MimeMultipart) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MimeBodyPart(jakarta.mail.internet.MimeBodyPart) ByteArrayDataSource(jakarta.mail.util.ByteArrayDataSource) Test(org.junit.Test)

Example 3 with ByteArrayDataSource

use of jakarta.mail.util.ByteArrayDataSource in project resteasy by resteasy.

the class MultipartSignedReader method readFrom.

public SignedInput readFrom(Class<SignedInput> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> headers, InputStream entityStream) throws IOException, WebApplicationException {
    Class<?> baseType = null;
    Type baseGenericType = null;
    if (genericType != null && genericType instanceof ParameterizedType) {
        ParameterizedType param = (ParameterizedType) genericType;
        baseGenericType = param.getActualTypeArguments()[0];
        baseType = Types.getRawType(baseGenericType);
    }
    try {
        ByteArrayDataSource ds = new ByteArrayDataSource(entityStream, mediaType.toString());
        MimeMultipart mm = new MimeMultipart(ds);
        MultipartSignedInputImpl input = new MultipartSignedInputImpl();
        input.setType(baseType);
        input.setGenericType(baseGenericType);
        input.setAnnotations(annotations);
        input.setBody(mm);
        Providers providers = ResteasyContext.getContextData(Providers.class);
        input.setProviders(providers);
        return input;
    } catch (MessagingException e) {
        throw new ReaderException(e);
    }
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) MediaType(jakarta.ws.rs.core.MediaType) Type(java.lang.reflect.Type) MimeMultipart(jakarta.mail.internet.MimeMultipart) MessagingException(jakarta.mail.MessagingException) Providers(jakarta.ws.rs.ext.Providers) ByteArrayDataSource(jakarta.mail.util.ByteArrayDataSource) ReaderException(org.jboss.resteasy.spi.ReaderException)

Example 4 with ByteArrayDataSource

use of jakarta.mail.util.ByteArrayDataSource in project resteasy by resteasy.

the class HeaderFlushedOutputStreamTest method testPostForm.

/**
 * @tpTestDetails Test post method
 * @tpSince RESTEasy 3.0.16
 */
@Test
public void testPostForm() throws Exception {
    // prepare file
    File file = new File(testFilePath);
    Assert.assertTrue("File " + testFilePath + " doesn't exists", file.exists());
    // test logic
    MultipartFormDataOutput mpfdo = new MultipartFormDataOutput();
    mpfdo.addFormData("part1", "This is Value 1", MediaType.TEXT_PLAIN_TYPE);
    mpfdo.addFormData("part2", "This is Value 2", MediaType.TEXT_PLAIN_TYPE);
    mpfdo.addFormData("data.txt", file, MediaType.TEXT_PLAIN_TYPE);
    Response response = client.target(TEST_URI).request().post(Entity.entity(mpfdo, MediaType.MULTIPART_FORM_DATA_TYPE));
    BufferedInputStream in = new BufferedInputStream(response.readEntity(InputStream.class));
    String contentType = response.getHeaderString("content-type");
    ByteArrayDataSource ds = new ByteArrayDataSource(in, contentType);
    MimeMultipart mimeMultipart = new MimeMultipart(ds);
    Assert.assertEquals("Wrong count of parts of response", mimeMultipart.getCount(), 3);
    response.close();
}
Also used : Response(jakarta.ws.rs.core.Response) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) BufferedInputStream(java.io.BufferedInputStream) MimeMultipart(jakarta.mail.internet.MimeMultipart) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) File(java.io.File) ByteArrayDataSource(jakarta.mail.util.ByteArrayDataSource) MultipartFormDataOutput(org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataOutput) Test(org.junit.Test)

Example 5 with ByteArrayDataSource

use of jakarta.mail.util.ByteArrayDataSource in project resteasy by resteasy.

the class MimeMultipartProviderTest method testGet.

/**
 * @tpTestDetails Client sends get request for InputStream from the server
 * @tpSince RESTEasy 3.0.16
 */
@Test
public void testGet() throws Exception {
    Response response = client.target(TEST_URI).request().get();
    Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus());
    BufferedInputStream in = new BufferedInputStream(response.readEntity(InputStream.class));
    String contentType = response.getStringHeaders().getFirst("content-type");
    ByteArrayDataSource ds = new ByteArrayDataSource(in, contentType);
    MimeMultipart mimeMultipart = new MimeMultipart(ds);
    Assert.assertEquals(ERR_NUMBER, mimeMultipart.getCount(), 2);
    response.close();
}
Also used : Response(jakarta.ws.rs.core.Response) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) BufferedInputStream(java.io.BufferedInputStream) MimeMultipart(jakarta.mail.internet.MimeMultipart) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) ByteArrayDataSource(jakarta.mail.util.ByteArrayDataSource) Test(org.junit.Test)

Aggregations

ByteArrayDataSource (jakarta.mail.util.ByteArrayDataSource)35 Test (org.junit.Test)16 MimeMultipart (jakarta.mail.internet.MimeMultipart)11 DataHandler (jakarta.activation.DataHandler)8 InputStream (java.io.InputStream)7 MimeMessage (jakarta.mail.internet.MimeMessage)6 DataSource (jakarta.activation.DataSource)5 MimeBodyPart (jakarta.mail.internet.MimeBodyPart)5 BufferedInputStream (java.io.BufferedInputStream)5 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)4 Response (jakarta.ws.rs.core.Response)4 Email (org.simplejavamail.api.email.Email)4 MessagingException (jakarta.mail.MessagingException)3 File (java.io.File)3 IOException (java.io.IOException)3 NamedDataSource (org.simplejavamail.internal.util.NamedDataSource)3 BodyPart (jakarta.mail.BodyPart)2 Multipart (jakarta.mail.Multipart)2 InternetAddress (jakarta.mail.internet.InternetAddress)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2