jaxws/src/share/jaxws_classes/com/sun/xml/internal/ws/binding/BindingImpl.java
changeset 23959 f37ffa18553c
parent 16791 fe5141eabb0e
equal deleted inserted replaced
23816:b47e02119575 23959:f37ffa18553c
    35 import com.sun.xml.internal.ws.api.pipe.Codec;
    35 import com.sun.xml.internal.ws.api.pipe.Codec;
    36 import com.sun.xml.internal.ws.client.HandlerConfiguration;
    36 import com.sun.xml.internal.ws.client.HandlerConfiguration;
    37 import com.sun.xml.internal.ws.developer.MemberSubmissionAddressingFeature;
    37 import com.sun.xml.internal.ws.developer.MemberSubmissionAddressingFeature;
    38 import com.sun.xml.internal.ws.developer.BindingTypeFeature;
    38 import com.sun.xml.internal.ws.developer.BindingTypeFeature;
    39 
    39 
       
    40 import javax.activation.CommandInfo;
       
    41 import javax.activation.CommandMap;
       
    42 import javax.activation.MailcapCommandMap;
    40 import javax.xml.namespace.QName;
    43 import javax.xml.namespace.QName;
    41 import javax.xml.ws.Service;
    44 import javax.xml.ws.Service;
    42 import javax.xml.ws.WebServiceFeature;
    45 import javax.xml.ws.WebServiceFeature;
    43 import javax.xml.ws.soap.AddressingFeature;
    46 import javax.xml.ws.soap.AddressingFeature;
    44 import javax.xml.ws.handler.Handler;
    47 import javax.xml.ws.handler.Handler;
   149         else
   152         else
   150             addressingVersion = null;
   153             addressingVersion = null;
   151         return addressingVersion;
   154         return addressingVersion;
   152     }
   155     }
   153 
   156 
   154     public final
       
   155     @NotNull
   157     @NotNull
   156     Codec createCodec() {
   158     public final Codec createCodec() {
       
   159 
       
   160         // initialization from here should cover most of cases;
       
   161         // if not, it would be necessary to call
       
   162         //   BindingImpl.initializeJavaActivationHandlers()
       
   163         // explicitly by programmer
       
   164         initializeJavaActivationHandlers();
       
   165 
   157         return bindingId.createEncoder(this);
   166         return bindingId.createEncoder(this);
       
   167     }
       
   168 
       
   169     public static void initializeJavaActivationHandlers() {
       
   170         // DataHandler.writeTo() may search for DCH. So adding some default ones.
       
   171         try {
       
   172             CommandMap map = CommandMap.getDefaultCommandMap();
       
   173             if (map instanceof MailcapCommandMap) {
       
   174                 MailcapCommandMap mailMap = (MailcapCommandMap) map;
       
   175 
       
   176                 // registering our DCH since javamail's DCH doesn't handle
       
   177                 if (!cmdMapInitialized(mailMap)) {
       
   178                     mailMap.addMailcap("text/xml;;x-java-content-handler=com.sun.xml.internal.ws.encoding.XmlDataContentHandler");
       
   179                     mailMap.addMailcap("application/xml;;x-java-content-handler=com.sun.xml.internal.ws.encoding.XmlDataContentHandler");
       
   180                     mailMap.addMailcap("image/*;;x-java-content-handler=com.sun.xml.internal.ws.encoding.ImageDataContentHandler");
       
   181                     mailMap.addMailcap("text/plain;;x-java-content-handler=com.sun.xml.internal.ws.encoding.StringDataContentHandler");
       
   182                 }
       
   183             }
       
   184         } catch (Throwable t) {
       
   185             // ignore the exception.
       
   186         }
       
   187     }
       
   188 
       
   189     private static boolean cmdMapInitialized(MailcapCommandMap mailMap) {
       
   190         CommandInfo[] commands = mailMap.getAllCommands("text/xml");
       
   191         if (commands == null || commands.length == 0) {
       
   192             return false;
       
   193         }
       
   194 
       
   195         // SAAJ RI implements it's own DataHandlers which can be used for JAX-WS too;
       
   196         // see com.sun.xml.internal.messaging.saaj.soap.AttachmentPartImpl#initializeJavaActivationHandlers
       
   197         // so if found any of SAAJ or our own handler registered, we are ok; anyway using SAAJ directly here
       
   198         // is not good idea since we don't want standalone JAX-WS to depend on specific SAAJ impl.
       
   199         // This is also reason for duplication of Handler's code by JAX-WS
       
   200         String saajClassName = "com.sun.xml.internal.messaging.saaj.soap.XmlDataContentHandler";
       
   201         String jaxwsClassName = "com.sun.xml.internal.ws.encoding.XmlDataContentHandler";
       
   202         for (CommandInfo command : commands) {
       
   203             String commandClass = command.getCommandClass();
       
   204             if (saajClassName.equals(commandClass) ||
       
   205                     jaxwsClassName.equals(commandClass)) {
       
   206                 return true;
       
   207             }
       
   208         }
       
   209         return false;
   158     }
   210     }
   159 
   211 
   160     public static BindingImpl create(@NotNull BindingID bindingId) {
   212     public static BindingImpl create(@NotNull BindingID bindingId) {
   161         if (bindingId.equals(BindingID.XML_HTTP))
   213         if (bindingId.equals(BindingID.XML_HTTP))
   162             return new HTTPBindingImpl();
   214             return new HTTPBindingImpl();