# HG changeset patch # User mkos # Date 1396888513 -3600 # Node ID d59994e61643564c655168c9bc919e96d9577583 # Parent 1906412d4965aaec2b685d3b3b080a8f2c55e1a0 8028388: 9 jaxws tests failed in nightly build with java.lang.ClassCastException Summary: test regression; fix also reviewed by Bill Shannon, Alexander Fomin Reviewed-by: mgrebac diff -r 1906412d4965 -r d59994e61643 drop_included/jaxws_src/src/com/sun/xml/internal/messaging/saaj/soap/AttachmentPartImpl.java --- a/drop_included/jaxws_src/src/com/sun/xml/internal/messaging/saaj/soap/AttachmentPartImpl.java Mon Apr 07 17:25:17 2014 +0100 +++ b/drop_included/jaxws_src/src/com/sun/xml/internal/messaging/saaj/soap/AttachmentPartImpl.java Mon Apr 07 17:35:13 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -69,67 +69,18 @@ Logger.getLogger(LogDomainConstants.SOAP_DOMAIN, "com.sun.xml.internal.messaging.saaj.soap.LocalStrings"); - static { - try { - CommandMap map = CommandMap.getDefaultCommandMap(); - if (map instanceof MailcapCommandMap) { - MailcapCommandMap mailMap = (MailcapCommandMap) map; - String hndlrStr = ";;x-java-content-handler="; - mailMap.addMailcap( - "text/xml" - + hndlrStr - + "com.sun.xml.internal.messaging.saaj.soap.XmlDataContentHandler"); - mailMap.addMailcap( - "application/xml" - + hndlrStr - + "com.sun.xml.internal.messaging.saaj.soap.XmlDataContentHandler"); - mailMap.addMailcap( - "application/fastinfoset" - + hndlrStr - + "com.sun.xml.internal.messaging.saaj.soap.FastInfosetDataContentHandler"); - /* Image DataContentHandler handles all image types - mailMap.addMailcap( - "image/jpeg" - + hndlrStr - + "com.sun.xml.internal.messaging.saaj.soap.JpegDataContentHandler"); - mailMap.addMailcap( - "image/gif" - + hndlrStr - + "com.sun.xml.internal.messaging.saaj.soap.GifDataContentHandler"); */ - /*mailMap.addMailcap( - "multipart/*" - + hndlrStr - + "com.sun.xml.internal.messaging.saaj.soap.MultipartDataContentHandler");*/ - mailMap.addMailcap( - "image/*" - + hndlrStr - + "com.sun.xml.internal.messaging.saaj.soap.ImageDataContentHandler"); - mailMap.addMailcap( - "text/plain" - + hndlrStr - + "com.sun.xml.internal.messaging.saaj.soap.StringDataContentHandler"); - } else { - throw new SOAPExceptionImpl("Default CommandMap is not a MailcapCommandMap"); - } - } catch (Throwable t) { - log.log( - Level.SEVERE, - "SAAJ0508.soap.cannot.register.handlers", - t); - if (t instanceof RuntimeException) { - throw (RuntimeException) t; - } else { - throw new RuntimeException(t.getLocalizedMessage()); - } - } - }; - private final MimeHeaders headers; private MimeBodyPart rawContent = null; private DataHandler dataHandler = null; public AttachmentPartImpl() { headers = new MimeHeaders(); + + // initialization from here should cover most of cases; + // if not, it would be necessary to call + // AttachmentPartImpl.initializeJavaActivationHandlers() + // explicitly by programmer + initializeJavaActivationHandlers(); } public int getSize() throws SOAPException { @@ -218,7 +169,7 @@ log.log( Level.FINE, "SAAJ0580.soap.set.Content-Type", - new String[] { dataHandler.getContentType()}); + new String[] { dataHandler.getContentType() }); setMimeHeader("Content-Type", dataHandler.getContentType()); } @@ -515,4 +466,43 @@ return headers; } + 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.internal.messaging.saaj.soap.XmlDataContentHandler"); + mailMap.addMailcap("application/xml;;x-java-content-handler=com.sun.xml.internal.messaging.saaj.soap.XmlDataContentHandler"); + mailMap.addMailcap("application/fastinfoset;;x-java-content-handler=com.sun.xml.internal.messaging.saaj.soap.FastInfosetDataContentHandler"); + mailMap.addMailcap("multipart/*;;x-java-content-handler=com.sun.xml.internal.messaging.saaj.soap.MultipartDataContentHandler"); + mailMap.addMailcap("image/*;;x-java-content-handler=com.sun.xml.internal.messaging.saaj.soap.ImageDataContentHandler"); + mailMap.addMailcap("text/plain;;x-java-content-handler=com.sun.xml.internal.messaging.saaj.soap.StringDataContentHandler"); + } + } + } catch (Throwable t) { + // ignore the exception. + } + } + + private static boolean cmdMapInitialized(MailcapCommandMap mailMap) { + + // checking fastinfoset handler, since this one is specific to SAAJ + CommandInfo[] commands = mailMap.getAllCommands("application/fastinfoset"); + if (commands == null || commands.length == 0) { + return false; + } + + String saajClassName = "com.sun.xml.internal.ws.binding.FastInfosetDataContentHandler"; + for (CommandInfo command : commands) { + String commandClass = command.getCommandClass(); + if (saajClassName.equals(commandClass)) { + return true; + } + } + return false; + } } diff -r 1906412d4965 -r d59994e61643 drop_included/jaxws_src/src/com/sun/xml/internal/ws/binding/BindingImpl.java --- a/drop_included/jaxws_src/src/com/sun/xml/internal/ws/binding/BindingImpl.java Mon Apr 07 17:25:17 2014 +0100 +++ b/drop_included/jaxws_src/src/com/sun/xml/internal/ws/binding/BindingImpl.java Mon Apr 07 17:35:13 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -36,6 +36,9 @@ import com.sun.xml.internal.ws.developer.MemberSubmissionAddressingFeature; import com.sun.xml.internal.ws.developer.BindingTypeFeature; +import javax.activation.CommandInfo; +import javax.activation.CommandMap; +import javax.activation.MailcapCommandMap; import javax.xml.ws.WebServiceFeature; import javax.xml.ws.soap.AddressingFeature; import javax.xml.ws.handler.Handler; @@ -121,9 +124,15 @@ return addressingVersion; } - public final @NotNull - Codec createCodec() { + public final Codec createCodec() { + + // initialization from here should cover most of cases; + // if not, it would be necessary to call + // BindingImpl.initializeJavaActivationHandlers() + // explicitly by programmer + initializeJavaActivationHandlers(); + return bindingId.createEncoder(this); } @@ -181,4 +190,48 @@ public void addFeature(@NotNull WebServiceFeature newFeature) { features.add(newFeature); } + + 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.internal.ws.encoding.XmlDataContentHandler"); + mailMap.addMailcap("application/xml;;x-java-content-handler=com.sun.xml.internal.ws.encoding.XmlDataContentHandler"); + mailMap.addMailcap("image/*;;x-java-content-handler=com.sun.xml.internal.ws.encoding.ImageDataContentHandler"); + mailMap.addMailcap("text/plain;;x-java-content-handler=com.sun.xml.internal.ws.encoding.StringDataContentHandler"); + } + } + } catch (Throwable t) { + // ignore the exception. + } + } + + private static boolean cmdMapInitialized(MailcapCommandMap mailMap) { + CommandInfo[] commands = mailMap.getAllCommands("text/xml"); + if (commands == null || commands.length == 0) { + return false; + } + + // SAAJ RI implements it's own DataHandlers which can be used for JAX-WS too; + // see com.sun.xml.internal.messaging.saaj.soap.AttachmentPartImpl#initializeJavaActivationHandlers + // so if found any of SAAJ or our own handler registered, we are ok; anyway using SAAJ directly here + // is not good idea since we don't want standalone JAX-WS to depend on specific SAAJ impl. + // This is also reason for duplication of Handler's code by JAX-WS + String saajClassName = "com.sun.xml.internal.messaging.saaj.soap.XmlDataContentHandler"; + String jaxwsClassName = "com.sun.xml.internal.ws.encoding.XmlDataContentHandler"; + for (CommandInfo command : commands) { + String commandClass = command.getCommandClass(); + if (saajClassName.equals(commandClass) || + jaxwsClassName.equals(commandClass)) { + return true; + } + } + return false; + } + } diff -r 1906412d4965 -r d59994e61643 drop_included/jaxws_src/src/com/sun/xml/internal/ws/encoding/MimeCodec.java --- a/drop_included/jaxws_src/src/com/sun/xml/internal/ws/encoding/MimeCodec.java Mon Apr 07 17:25:17 2014 +0100 +++ b/drop_included/jaxws_src/src/com/sun/xml/internal/ws/encoding/MimeCodec.java Mon Apr 07 17:35:13 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -61,27 +61,6 @@ */ abstract class MimeCodec implements Codec { - static { - // DataHandler.writeTo() may search for DCH. So adding some default ones. - try { - CommandMap map = CommandMap.getDefaultCommandMap(); - if (map instanceof MailcapCommandMap) { - MailcapCommandMap mailMap = (MailcapCommandMap) map; - String hndlrStr = ";;x-java-content-handler="; - mailMap.addMailcap( - "text/xml" + hndlrStr + XmlDataContentHandler.class.getName()); - mailMap.addMailcap( - "application/xml" + hndlrStr + XmlDataContentHandler.class.getName()); - mailMap.addMailcap( - "image/*" + hndlrStr + ImageDataContentHandler.class.getName()); - mailMap.addMailcap( - "text/plain" + hndlrStr + StringDataContentHandler.class.getName()); - } - } catch (Throwable t) { - // ignore the exception. - } - } - public static final String MULTIPART_RELATED_MIME_TYPE = "multipart/related"; private String boundary;