本文整理了Java中javax.mail.internet.MimeMultipart.getContentType()
方法的一些代码示例,展示了MimeMultipart.getContentType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MimeMultipart.getContentType()
方法的具体详情如下:
包路径:javax.mail.internet.MimeMultipart
类名称:MimeMultipart
方法名:getContentType
暂无
代码示例来源:origin: geoserver/geoserver
public void testMultiPartFormUploadWithBodyField() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setContextPath("/geoserver");
request.setRequestURI("/geoserver/hello");
request.setMethod("post");
String xml = "<Hello service='hello' message='Hello world!' version='1.0.0' />";
MimeMultipart body = new MimeMultipart();
request.setContentType(body.getContentType());
InternetHeaders headers = new InternetHeaders();
headers.setHeader("Content-Disposition", "form-data; name=\"body\";");
headers.setHeader("Content-Type", "application/xml");
body.addBodyPart(new MimeBodyPart(headers, xml.getBytes()));
ByteArrayOutputStream bout = new ByteArrayOutputStream();
body.writeTo(bout);
request.setContent(bout.toByteArray());
MockHttpServletResponse response = new MockHttpServletResponse();
URL url = getClass().getResource("applicationContext.xml");
FileSystemXmlApplicationContext context =
new FileSystemXmlApplicationContext(url.toString());
Dispatcher dispatcher = (Dispatcher) context.getBean("dispatcher");
dispatcher.handleRequestInternal(request, response);
assertEquals("Hello world!", response.getContentAsString());
}
代码示例来源:origin: geoserver/geoserver
public void testMultiPartFormUpload() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setContextPath("/geoserver");
request.setRequestURI("/geoserver/hello");
request.setMethod("post");
String xml = "<Hello service='hello' message='Hello world!' version='1.0.0' />";
MimeMultipart body = new MimeMultipart();
request.setContentType(body.getContentType());
InternetHeaders headers = new InternetHeaders();
headers.setHeader(
"Content-Disposition", "form-data; name=\"upload\"; filename=\"request.xml\"");
headers.setHeader("Content-Type", "application/xml");
body.addBodyPart(new MimeBodyPart(headers, xml.getBytes()));
ByteArrayOutputStream bout = new ByteArrayOutputStream();
body.writeTo(bout);
request.setContent(bout.toByteArray());
MockHttpServletResponse response = new MockHttpServletResponse();
URL url = getClass().getResource("applicationContext.xml");
FileSystemXmlApplicationContext context =
new FileSystemXmlApplicationContext(url.toString());
Dispatcher dispatcher = (Dispatcher) context.getBean("dispatcher");
dispatcher.handleRequestInternal(request, response);
assertEquals("Hello world!", response.getContentAsString());
}
代码示例来源:origin: oblac/jodd
@Test
void testTextHtml() throws MessagingException, IOException {
final Email email = Email.create()
.from(FROM_EXAMPLE_COM)
.to(TO_EXAMPLE_COM)
.subject(SUB)
.textMessage(HELLO)
.htmlMessage("<html><body><h1>Hey!</h1></body></html>");
final Message message = createMessage(email);
assertEquals(1, message.getFrom().length);
assertEquals(FROM_EXAMPLE_COM, message.getFrom()[0].toString());
assertEquals(1, message.getRecipients(RecipientType.TO).length);
assertEquals(TO_EXAMPLE_COM, message.getRecipients(RecipientType.TO)[0].toString());
assertEquals(SUB, message.getSubject());
// wrapper
final MimeMultipart multipart = (MimeMultipart) message.getContent();
assertEquals(1, multipart.getCount());
assertTrue(multipart.getContentType().contains("multipart/mixed"));
// inner content
final MimeBodyPart mimeBodyPart = (MimeBodyPart) multipart.getBodyPart(0);
final MimeMultipart mimeMultipart = (MimeMultipart) mimeBodyPart.getContent();
assertEquals(2, mimeMultipart.getCount());
assertTrue(mimeMultipart.getContentType().contains("multipart/alternative"));
MimeBodyPart bodyPart = (MimeBodyPart) mimeMultipart.getBodyPart(0);
assertEquals(HELLO, bodyPart.getContent());
assertTrue(bodyPart.getDataHandler().getContentType().contains(MimeTypes.MIME_TEXT_PLAIN));
bodyPart = (MimeBodyPart) mimeMultipart.getBodyPart(1);
assertEquals("<html><body><h1>Hey!</h1></body></html>", bodyPart.getContent());
assertTrue(bodyPart.getDataHandler().getContentType().contains(MimeTypes.MIME_TEXT_HTML));
}
代码示例来源:origin: oblac/jodd
assertTrue(htmlMessage.getContentType().contains("multipart/related"));
assertEquals(2, htmlMessage.getCount());
代码示例来源:origin: resteasy/Resteasy
httpHeaders.putSingle("Content-Type", MediaType.valueOf(mimeMultipart.getContentType()));
mimeMultipart.writeTo(entityStream);
代码示例来源:origin: resteasy/Resteasy
@Override
public void writeTo(SignedOutput out, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException, WebApplicationException
{
try
{
SMIMESignedGenerator gen = new SMIMESignedGenerator();
SignerInfoGenerator signer = new JcaSimpleSignerInfoGeneratorBuilder().setProvider("BC").build("SHA1WITHRSA", out.getPrivateKey(), out.getCertificate());
gen.addSignerInfoGenerator(signer);
MimeMultipart mp = gen.generate(EnvelopedWriter.createBodyPart(providers, out));
String contentType = mp.getContentType();
contentType = contentType.replace("\r\n", "").replace("\t", " ");
headers.putSingle("Content-Type", contentType);
mp.writeTo(os);
}
catch (Exception e)
{
throw new WriterException(e);
}
}
}
代码示例来源:origin: org.jboss.ws.native/jbossws-native-core
/**
* Returns the new content type of this encoder. This value must be specified
* in the mime Content-type header in what ever way that the transport
* requires it.
*
* @return the content type
*/
public String getContentType()
{
String contentType = multipart.getContentType();
return contentType;
}
代码示例来源:origin: org.geoserver/wcs1_1
@Override
public String getMimeType(Object value, Operation operation) throws ServiceException {
// javamail outputs multipart/mixed, but in our case we're producing multipart/related
return multipart.getContentType().replace("mixed", "related");
}
代码示例来源:origin: org.geoserver/gs-wcs1_1
@Override
public String getMimeType(Object value, Operation operation) throws ServiceException {
// javamail outputs multipart/mixed, but in our case we're producing multipart/related
return multipart
.getContentType()
.replace("mixed", "related")
.replace("\n", "")
.replace("\r", "");
}
代码示例来源:origin: axis/axis
public MimeMultipartDataSource(String name, MimeMultipart data) {
this.name = name;
this.contentType = data == null ? CONTENT_TYPE : data.getContentType();
os = new ByteArrayOutputStream();
try {
if (data != null) {
data.writeTo(os);
}
}
catch (Exception e) {
// Is this sufficient?
}
} // ctor
代码示例来源:origin: OpenAS2/OpenAs2App
public static MimeBodyPart createMimeBodyPart(MimeMultipart multipart)
throws MessagingException {
MimeBodyPart part = new MimeBodyPart();
part.setContent(multipart);
part.setHeader("Content-Type", multipart.getContentType());
return part;
}
代码示例来源:origin: org.jboss.ws.native/jbossws-native-core
/**
* Resolve the mime type for an object.
* Default to <code>application/octet-stream</code>
* if no mapping could be found.
*/
public static String resolveMimeType(Object obj) {
String mimeType = (obj instanceof MimeMultipart) ?
((MimeMultipart)obj).getContentType() :
resolveMimeType(obj.getClass());
return mimeType;
}
代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.core
public String stringFromMultipart(MimeMultipart multipart, QName schemaTypeQName, CoreAbstractSession session) {
DataHandler handler = new DataHandler(multipart, multipart.getContentType());
return stringFromDataHandler(handler, schemaTypeQName, session);
}
代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence
public String stringFromMultipart(MimeMultipart multipart, QName schemaTypeQName, AbstractSession session) {
DataHandler handler = new DataHandler(multipart, multipart.getContentType());
return stringFromDataHandler(handler, schemaTypeQName, session);
}
代码示例来源:origin: org.apache.axis/com.springsource.org.apache.axis
public MimeMultipartDataSource(String name, MimeMultipart data) {
this.name = name;
this.contentType = data == null ? CONTENT_TYPE : data.getContentType();
os = new ByteArrayOutputStream();
try {
if (data != null) {
data.writeTo(os);
}
}
catch (Exception e) {
// Is this sufficient?
}
} // ctor
代码示例来源:origin: org.apache.axis/axis
public MimeMultipartDataSource(String name, MimeMultipart data) {
this.name = name;
this.contentType = data == null ? CONTENT_TYPE : data.getContentType();
os = new ByteArrayOutputStream();
try {
if (data != null) {
data.writeTo(os);
}
}
catch (Exception e) {
// Is this sufficient?
}
} // ctor
代码示例来源:origin: org.codehaus.xfire/xfire-core
public String getContentType()
{
return getMimeMultipart().getContentType();
}
代码示例来源:origin: stackoverflow.com
SMIMESignedGenerator gen = new SMIMESignedGenerator();
SignerInfoGenerator sigGen = new JcaSimpleSignerInfoGeneratorBuilder()
.setProvider(BC)
.build("SHA1withRSA", senderKey, senderCert);
gen.addSignerInfoGenerator(sigGen);
MimeMultipart smime = gen.generate(part);
MimeBodyPart tmpBody = new MimeBodyPart();
tmpBody.setContent(smime);
tmpBody.setHeader("Content-Type", smime.getContentType());
return tmpBody;
代码示例来源:origin: org.mule.services/mule-service-http
@Test
public void createMultipartRelatedContentWithoutStartParameter() throws Exception {
MimeMultipart mimeMultipart =
toMimeMultipart(httpEntity, "multipart/related; boundary=\"MIMEBoundary\"; type=\"text/plain\";");
verifyBodyPart(mimeMultipart.getBodyPart(0), FIRST_PART_CONTENT, "firstPart");
verifyBodyPart(mimeMultipart.getBodyPart(1), SECOND_PART_CONTENT, "secondPart");
verifyBodyPart(mimeMultipart.getBodyPart(2), THIRD_PART_CONTENT, "thirdPart");
assertThat(mimeMultipart.getContentType(), containsString("type=\"text/plain\""));
}
代码示例来源:origin: org.mule.services/mule-service-http
@Test
public void createMultipartRelatedContentWithStartParameter() throws Exception {
MimeMultipart mimeMultipart =
toMimeMultipart(httpEntity, "multipart/related; boundary= \"MIMEBoundary\"; type=\"text/plain\"; start=thirdPart");
verifyBodyPart(mimeMultipart.getBodyPart(0), THIRD_PART_CONTENT, "thirdPart");
verifyBodyPart(mimeMultipart.getBodyPart(1), FIRST_PART_CONTENT, "firstPart");
verifyBodyPart(mimeMultipart.getBodyPart(2), SECOND_PART_CONTENT, "secondPart");
assertThat(mimeMultipart.getContentType(), containsString("type=\"text/plain\""));
}
内容来源于网络,如有侵权,请联系作者删除!