1.1 --- a/src/share/jaxws_classes/com/sun/xml/internal/ws/binding/BindingImpl.java Fri Dec 13 17:20:01 2013 -0800 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/binding/BindingImpl.java Sun Dec 15 23:35:45 2013 +0100 1.3 @@ -37,6 +37,9 @@ 1.4 import com.sun.xml.internal.ws.developer.MemberSubmissionAddressingFeature; 1.5 import com.sun.xml.internal.ws.developer.BindingTypeFeature; 1.6 1.7 +import javax.activation.CommandInfo; 1.8 +import javax.activation.CommandMap; 1.9 +import javax.activation.MailcapCommandMap; 1.10 import javax.xml.namespace.QName; 1.11 import javax.xml.ws.Service; 1.12 import javax.xml.ws.WebServiceFeature; 1.13 @@ -151,12 +154,61 @@ 1.14 return addressingVersion; 1.15 } 1.16 1.17 - public final 1.18 @NotNull 1.19 - Codec createCodec() { 1.20 + public final Codec createCodec() { 1.21 + 1.22 + // initialization from here should cover most of cases; 1.23 + // if not, it would be necessary to call 1.24 + // BindingImpl.initializeJavaActivationHandlers() 1.25 + // explicitly by programmer 1.26 + initializeJavaActivationHandlers(); 1.27 + 1.28 return bindingId.createEncoder(this); 1.29 } 1.30 1.31 + public static void initializeJavaActivationHandlers() { 1.32 + // DataHandler.writeTo() may search for DCH. So adding some default ones. 1.33 + try { 1.34 + CommandMap map = CommandMap.getDefaultCommandMap(); 1.35 + if (map instanceof MailcapCommandMap) { 1.36 + MailcapCommandMap mailMap = (MailcapCommandMap) map; 1.37 + 1.38 + // registering our DCH since javamail's DCH doesn't handle 1.39 + if (!cmdMapInitialized(mailMap)) { 1.40 + mailMap.addMailcap("text/xml;;x-java-content-handler=com.sun.xml.internal.ws.encoding.XmlDataContentHandler"); 1.41 + mailMap.addMailcap("application/xml;;x-java-content-handler=com.sun.xml.internal.ws.encoding.XmlDataContentHandler"); 1.42 + mailMap.addMailcap("image/*;;x-java-content-handler=com.sun.xml.internal.ws.encoding.ImageDataContentHandler"); 1.43 + mailMap.addMailcap("text/plain;;x-java-content-handler=com.sun.xml.internal.ws.encoding.StringDataContentHandler"); 1.44 + } 1.45 + } 1.46 + } catch (Throwable t) { 1.47 + // ignore the exception. 1.48 + } 1.49 + } 1.50 + 1.51 + private static boolean cmdMapInitialized(MailcapCommandMap mailMap) { 1.52 + CommandInfo[] commands = mailMap.getAllCommands("text/xml"); 1.53 + if (commands == null || commands.length == 0) { 1.54 + return false; 1.55 + } 1.56 + 1.57 + // SAAJ RI implements it's own DataHandlers which can be used for JAX-WS too; 1.58 + // see com.sun.xml.internal.messaging.saaj.soap.AttachmentPartImpl#initializeJavaActivationHandlers 1.59 + // so if found any of SAAJ or our own handler registered, we are ok; anyway using SAAJ directly here 1.60 + // is not good idea since we don't want standalone JAX-WS to depend on specific SAAJ impl. 1.61 + // This is also reason for duplication of Handler's code by JAX-WS 1.62 + String saajClassName = "com.sun.xml.internal.messaging.saaj.soap.XmlDataContentHandler"; 1.63 + String jaxwsClassName = "com.sun.xml.internal.ws.encoding.XmlDataContentHandler"; 1.64 + for (CommandInfo command : commands) { 1.65 + String commandClass = command.getCommandClass(); 1.66 + if (saajClassName.equals(commandClass) || 1.67 + jaxwsClassName.equals(commandClass)) { 1.68 + return true; 1.69 + } 1.70 + } 1.71 + return false; 1.72 + } 1.73 + 1.74 public static BindingImpl create(@NotNull BindingID bindingId) { 1.75 if (bindingId.equals(BindingID.XML_HTTP)) 1.76 return new HTTPBindingImpl();