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())));
}
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());
}
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);
}
}
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();
}
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();
}
Aggregations