Search in sources :

Example 1 with CommandMap

use of jakarta.activation.CommandMap 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 2 with CommandMap

use of jakarta.activation.CommandMap 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

CommandMap (jakarta.activation.CommandMap)2 MailcapCommandMap (jakarta.activation.MailcapCommandMap)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 WebServiceFeature (jakarta.xml.ws.WebServiceFeature)1 Image (java.awt.Image)1 URL (java.net.URL)1 Source (javax.xml.transform.Source)1 StreamSource (javax.xml.transform.stream.StreamSource)1