The wsimport tool converts a byte of type DataHandler [] into the generated client code

I have a simple WebService developed using JAXWS. I need to upload / download some files. I created a FileItem class with the DataHandler property. The service is working fine.

But when I generated client stubs using the wsimport tool, the FileItem class has a property of type byte [] instead of the DataHandler type.

How can I customize this behavior so that the generated code also has the same DataHandler type in the generated client code?

+3
source share
2 answers

Short answer

xmime:expectedContentTypes -, : image/gif, image/jpeg, text/xml application/xml, DataHandler.


H.2.1.1 JAXB 2.2 , mime Java.

MIME Type              Java Type
---------              -------------
image/gif              java.awt.Image
image/jpeg             java.awt.Image
text/xml               javax.xml.transform.Source
application/xml        javax.xml.transform.Source
any other mime type    javax.activation.DataHandler

XML

XML- base64Binary, xmime:expectedContentTypes, .

<?xml version="1.0"?>
<xsd:schema
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xmime="http://www.w3.org/2005/05/xmlmime"
    xmlns="http://www.example.com"
    targetNamespace="http://www.example.com">
    <xsd:element name="root">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element minOccurs="0" name="default" type="xsd:base64Binary"/>
                <xsd:element minOccurs="0" name="imageGif" type="xsd:base64Binary" xmime:expectedContentTypes="image/gif"/>
                <xsd:element minOccurs="0" name="imageJpeg" type="xsd:base64Binary" xmime:expectedContentTypes="image/jpeg"/>
                <xsd:element minOccurs="0" name="textXml" type="xsd:base64Binary" xmime:expectedContentTypes="text/xml"/>
                <xsd:element minOccurs="0" name="applicationXml" type="xsd:base64Binary" xmime:expectedContentTypes="application/xml"/>
                <xsd:element minOccurs="0" name="anythingElse" type="xsd:base64Binary" xmime:expectedContentTypes="anything/else"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

( )

. : byte[], Image, Source DataHandler.

package com.example;

import java.awt.Image;
import javax.activation.DataHandler;
import javax.xml.bind.annotation.*;
import javax.xml.transform.Source;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "_default",
    "imageGif",
    "imageJpeg",
    "textXml",
    "applicationXml",
    "anythingElse"
})
@XmlRootElement(name = "root")
public class Root {

    @XmlElement(name = "default")
    protected byte[] _default;
    @XmlMimeType("image/gif")
    protected Image imageGif;
    @XmlMimeType("image/jpeg")
    protected Image imageJpeg;
    @XmlMimeType("text/xml")
    protected Source textXml;
    @XmlMimeType("application/xml")
    protected Source applicationXml;
    @XmlMimeType("anything/else")
    protected DataHandler anythingElse;


    ...
}
+6

, wsimport , DataHandler , , . jaxb DataHandler XML.

0

All Articles