Search in sources :

Example 1 with MailcapCommandMap

use of jakarta.activation.MailcapCommandMap in project metro-jax-ws by eclipse-ee4j.

the class MimeTypeTest method checkApplicationXMLMime.

/**
 * Test mail message MIME type processing with provided MIME type.
 * @param mimeType MIME type to be tested.
 * @throws IOException {@code Cannot convert DataSource with content type "application/XML" to object in XmlDataContentHandler}
 *         when MIME type is not recognized.
 */
private void checkApplicationXMLMime(final String mimeType) throws MessagingException, IOException {
    MailcapCommandMap mailcapCommandMap = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
    mailcapCommandMap.addMailcap("application/XML;; x-java-content-handler=com.sun.xml.ws.encoding.XmlDataContentHandler");
    mailcapCommandMap.addMailcap("application/xml;; x-java-content-handler=com.sun.xml.ws.encoding.XmlDataContentHandler");
    MimeMessage message;
    MimeMultipart mimeMultipart;
    final byte[] bodyConent = "<test/>".getBytes();
    InternetHeaders headers = new InternetHeaders();
    headers.setHeader("Content-Transfer-Encoding", "binary");
    headers.setHeader("Content-Disposition", "attachment; filename=test.xml");
    message = new MimeMessage(Session.getDefaultInstance(new Properties()));
    mimeMultipart = new MimeMultipart();
    headers.setHeader("Content-Type", mimeType);
    mimeMultipart.addBodyPart(new MimeBodyPart(headers, bodyConent));
    message.setContent(mimeMultipart);
    message.saveChanges();
    try {
        ((MimeMultipart) message.getContent()).getBodyPart(0).getContent();
    } catch (IOException ex) {
        throw ex;
    }
}
Also used : InternetHeaders(jakarta.mail.internet.InternetHeaders) MimeMessage(jakarta.mail.internet.MimeMessage) MimeMultipart(jakarta.mail.internet.MimeMultipart) MailcapCommandMap(jakarta.activation.MailcapCommandMap) IOException(java.io.IOException) Properties(java.util.Properties) MimeBodyPart(jakarta.mail.internet.MimeBodyPart)

Example 2 with MailcapCommandMap

use of jakarta.activation.MailcapCommandMap in project metro-jax-ws by eclipse-ee4j.

the class BindingImpl method initializeJavaActivationHandlers.

public static void initializeJavaActivationHandlers() {
    // DataHandler.writeTo() may search for DCH. So adding some default ones.
    try {
        CommandMap map = CommandMap.getDefaultCommandMap();
        if (map instanceof MailcapCommandMap) {
            MailcapCommandMap mailMap = (MailcapCommandMap) map;
            // registering our DCH since javamail's DCH doesn't handle
            if (!cmdMapInitialized(mailMap)) {
                mailMap.addMailcap("text/xml;;x-java-content-handler=com.sun.xml.ws.encoding.XmlDataContentHandler");
                mailMap.addMailcap("application/xml;;x-java-content-handler=com.sun.xml.ws.encoding.XmlDataContentHandler");
                mailMap.addMailcap("image/*;;x-java-content-handler=com.sun.xml.ws.encoding.ImageDataContentHandler");
                mailMap.addMailcap("text/plain;;x-java-content-handler=com.sun.xml.ws.encoding.StringDataContentHandler");
            }
        }
    } catch (Throwable t) {
    // ignore the exception.
    }
}
Also used : MailcapCommandMap(jakarta.activation.MailcapCommandMap) MailcapCommandMap(jakarta.activation.MailcapCommandMap) CommandMap(jakarta.activation.CommandMap)

Example 3 with MailcapCommandMap

use of jakarta.activation.MailcapCommandMap in project metro-jax-ws by eclipse-ee4j.

the class SwaMimeAttachmentTest method testCTS_WsiDocLitSwaTest.

public void testCTS_WsiDocLitSwaTest() throws Exception {
    WSDLPort wsdlPort = getWSDLPort(getResource("WSW2JDLSwaTestService.wsdl"));
    Class endpointClass = SwaTestImpl1.class;
    Class proxySEIClass = SwaTest1.class;
    DatabindingConfig srvConfig = new DatabindingConfig();
    srvConfig.setEndpointClass(endpointClass);
    // srvConfig.setMetadataReader(new DummyAnnotations());
    WebServiceFeature[] f = { databindingMode() };
    srvConfig.setFeatures(f);
    srvConfig.setWsdlPort(wsdlPort);
    DatabindingConfig cliConfig = new DatabindingConfig();
    // cliConfig.setMetadataReader(new DummyAnnotations());
    cliConfig.setContractClass(proxySEIClass);
    cliConfig.setFeatures(f);
    cliConfig.setWsdlPort(wsdlPort);
    CommandMap map = CommandMap.getDefaultCommandMap();
    ((MailcapCommandMap) map).addMailcap("image/*;;x-java-content-handler=com.sun.xml.messaging.saaj.soap.ImageDataContentHandler");
    SwaTest1 port = createProxy(SwaTest1.class, srvConfig, cliConfig, false);
    {
        URL url1 = getResource("attach.text");
        URL url2 = getResource("attach.html");
        URL url3 = getResource("attach.xml");
        URL url4 = getResource("attach.jpeg1");
        URL url5 = getResource("attach.jpeg2");
        DataHandler dh1 = new DataHandler(url1);
        DataHandler dh2 = new DataHandler(url2);
        DataHandler dh3 = new DataHandler(url3);
        DataHandler dh4 = new DataHandler(url4);
        DataHandler dh5 = new DataHandler(url5);
        jakarta.xml.ws.Holder<jakarta.activation.DataHandler> attach1 = new jakarta.xml.ws.Holder<jakarta.activation.DataHandler>();
        attach1.value = dh1;
        jakarta.xml.ws.Holder<jakarta.activation.DataHandler> attach2 = new jakarta.xml.ws.Holder<jakarta.activation.DataHandler>();
        attach2.value = dh2;
        jakarta.xml.ws.Holder<javax.xml.transform.Source> attach3 = new jakarta.xml.ws.Holder<javax.xml.transform.Source>();
        attach3.value = new StreamSource(dh3.getInputStream());
        jakarta.xml.ws.Holder<java.awt.Image> attach4 = new jakarta.xml.ws.Holder<java.awt.Image>();
        jakarta.xml.ws.Holder<java.awt.Image> attach5 = new jakarta.xml.ws.Holder<java.awt.Image>();
        attach4.value = javax.imageio.ImageIO.read(url4);
        attach5.value = javax.imageio.ImageIO.read(url5);
        VoidRequest request = new VoidRequest();
        OutputResponseAll response = port.echoAllAttachmentTypes(request, attach1, attach2, attach3, attach4, attach5);
        assertTrue(ValidateRequestResponseAttachmentsEchoAllTestCase(request, response, attach1, attach2, attach3, attach4, attach5));
    }
    {
        InputRequestGet request = new InputRequestGet();
        URL url1 = getResource("attach.text");
        URL url2 = getResource("attach.html");
        request.setMimeType1("text/plain");
        request.setMimeType2("text/html");
        request.setUrl1(url1.toString());
        request.setUrl2(url2.toString());
        jakarta.xml.ws.Holder<DataHandler> attach1 = new jakarta.xml.ws.Holder<DataHandler>();
        jakarta.xml.ws.Holder<DataHandler> attach2 = new jakarta.xml.ws.Holder<DataHandler>();
        jakarta.xml.ws.Holder<OutputResponse> response = new jakarta.xml.ws.Holder<OutputResponse>();
        port.getMultipleAttachments(request, response, attach1, attach2);
        assertTrue(ValidateRequestResponseAttachmentsGetTestCase(request, response.value, attach1, attach2));
    }
    {
        jakarta.xml.ws.Holder<byte[]> data = new jakarta.xml.ws.Holder<byte[]>();
        // InputStream in = getSwaAttachmentURL("attach.jpeg1").openStream();
        // java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
        // byte[] bytes = new byte[4096];
        // int read = in.read(bytes);
        // while (read != -1) {
        // baos.write(bytes, 0, read);
        // read = in.read(bytes);
        // }
        java.awt.Image image = javax.imageio.ImageIO.read(getResource("attach.jpeg1"));
        java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
        javax.imageio.ImageIO.write((java.awt.image.RenderedImage) image, "jpeg", baos);
        data.value = baos.toByteArray();
        byte[] bytes = baos.toByteArray();
        port.echoData("EnableMIMEContent = false", data);
    // for ( int i = 0; i < data.value.length; i++ ) {
    // assertTrue(bytes[i] == data.value[i]);
    // }
    }
}
Also used : MailcapCommandMap(jakarta.activation.MailcapCommandMap) DataHandler(jakarta.activation.DataHandler) Image(java.awt.Image) URL(java.net.URL) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) WSDLPort(com.sun.xml.ws.api.model.wsdl.WSDLPort) StreamSource(javax.xml.transform.stream.StreamSource) DatabindingConfig(com.sun.xml.ws.api.databinding.DatabindingConfig) WebServiceFeature(jakarta.xml.ws.WebServiceFeature) MailcapCommandMap(jakarta.activation.MailcapCommandMap) CommandMap(jakarta.activation.CommandMap)

Aggregations

MailcapCommandMap (jakarta.activation.MailcapCommandMap)3 CommandMap (jakarta.activation.CommandMap)2 DatabindingConfig (com.sun.xml.ws.api.databinding.DatabindingConfig)1 WSDLPort (com.sun.xml.ws.api.model.wsdl.WSDLPort)1 DataHandler (jakarta.activation.DataHandler)1 InternetHeaders (jakarta.mail.internet.InternetHeaders)1 MimeBodyPart (jakarta.mail.internet.MimeBodyPart)1 MimeMessage (jakarta.mail.internet.MimeMessage)1 MimeMultipart (jakarta.mail.internet.MimeMultipart)1 WebServiceFeature (jakarta.xml.ws.WebServiceFeature)1 Image (java.awt.Image)1 IOException (java.io.IOException)1 URL (java.net.URL)1 Properties (java.util.Properties)1 Source (javax.xml.transform.Source)1 StreamSource (javax.xml.transform.stream.StreamSource)1