Permalink
Browse files

merged 14_02 changeset (JDK-8026188-EnvelopeFactory)

  • Loading branch information...
mirank committed May 13, 2014
2 parents 8bb251e + 0de363a commit 98a18741024fe520d28d735f98f17372baf02775
View
@@ -5,4 +5,8 @@
/saaj-ri/src/test/mime/data/message.txt
/saaj-ri/src/test/mime/data/custom_type_sent.ctp
/saaj-ri/src/test/mime/data/java_logo_sent.jpg
/saaj-ri/src/test/mime/data/saving.cnt
/saaj-ri/src/test/mime/data/saving.cnt
*.iml
*.ipr
.idea
.DS_Store
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 1997-2013 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997-2014 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
@@ -77,61 +77,6 @@
Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
"com.sun.xml.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.messaging.saaj.soap.XmlDataContentHandler");
mailMap.addMailcap(
"application/xml"
+ hndlrStr
+ "com.sun.xml.messaging.saaj.soap.XmlDataContentHandler");
mailMap.addMailcap(
"application/fastinfoset"
+ hndlrStr
+ "com.sun.xml.messaging.saaj.soap.FastInfosetDataContentHandler");
/* Image DataContentHandler handles all image types
mailMap.addMailcap(
"image/jpeg"
+ hndlrStr
+ "com.sun.xml.messaging.saaj.soap.JpegDataContentHandler");
mailMap.addMailcap(
"image/gif"
+ hndlrStr
+ "com.sun.xml.messaging.saaj.soap.GifDataContentHandler"); */
/*mailMap.addMailcap(
"multipart/*"
+ hndlrStr
+ "com.sun.xml.messaging.saaj.soap.MultipartDataContentHandler");*/
mailMap.addMailcap(
"image/*"
+ hndlrStr
+ "com.sun.xml.messaging.saaj.soap.ImageDataContentHandler");
mailMap.addMailcap(
"text/plain"
+ hndlrStr
+ "com.sun.xml.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;
@@ -141,6 +86,12 @@
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 AttachmentPartImpl(MIMEPart part) {
@@ -422,7 +373,7 @@ public void setBase64Content(InputStream content, String contentType)
bos.close();
try {
if (decoded != null)
decoded.close();
decoded.close();
} catch (IOException ex) {
throw new SOAPException(ex);
}
@@ -634,5 +585,43 @@ public MimeHeaders getMimeHeaders() {
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;
}
}
@@ -0,0 +1,101 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* http://glassfish.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.xml.messaging.saaj.soap;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.text.MessageFormat;
import java.util.ResourceBundle;
import java.util.WeakHashMap;
/**
* Simple utility ensuring that the value is cached only in case it is non-internal implementation
*/
abstract class ContextClassloaderLocal<V> {
private static final String FAILED_TO_CREATE_NEW_INSTANCE = "FAILED_TO_CREATE_NEW_INSTANCE";
private WeakHashMap<ClassLoader, V> CACHE = new WeakHashMap<ClassLoader, V>();
public V get() throws Error {
ClassLoader tccl = getContextClassLoader();
V instance = CACHE.get(tccl);
if (instance == null) {
instance = createNewInstance();
CACHE.put(tccl, instance);
}
return instance;
}
public void set(V instance) {
CACHE.put(getContextClassLoader(), instance);
}
protected abstract V initialValue() throws Exception;
private V createNewInstance() {
try {
return initialValue();
} catch (Exception e) {
throw new Error(format(FAILED_TO_CREATE_NEW_INSTANCE, getClass().getName()), e);
}
}
private static String format(String property, Object... args) {
String text = ResourceBundle.getBundle(ContextClassloaderLocal.class.getName()).getString(property);
return MessageFormat.format(text, args);
}
private static ClassLoader getContextClassLoader() {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader cl = null;
try {
cl = Thread.currentThread().getContextClassLoader();
} catch (SecurityException ex) {
}
return cl;
}
});
}
}
@@ -0,0 +1,40 @@
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#
# Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
#
# The contents of this file are subject to the terms of either the GNU
# General Public License Version 2 only ("GPL") or the Common Development
# and Distribution License("CDDL") (collectively, the "License"). You
# may not use this file except in compliance with the License. You can
# obtain a copy of the License at
# http://glassfish.java.net/public/CDDL+GPL_1_1.html
# or packager/legal/LICENSE.txt. See the License for the specific
# language governing permissions and limitations under the License.
#
# When distributing the software, include this License Header Notice in each
# file and include the License file at packager/legal/LICENSE.txt.
#
# GPL Classpath Exception:
# Oracle designates this particular file as subject to the "Classpath"
# exception as provided by Oracle in the GPL Version 2 section of the License
# file that accompanied this code.
#
# Modifications:
# If applicable, add the following below the License Header, with the fields
# enclosed by brackets [] replaced by your own identifying information:
# "Portions Copyright [year] [name of copyright owner]"
#
# Contributor(s):
# If you wish your version of this file to be governed by only the CDDL or
# only the GPL Version 2, indicate your decision by adding "[Contributor]
# elects to include this software in this distribution under the [CDDL or GPL
# Version 2] license." If you don't indicate a single choice of license, a
# recipient has the option to distribute your version of this file under
# either the CDDL, the GPL Version 2 or to extend the choice of license to
# its licensees as provided above. However, if you add GPL Version 2 code
# and therefore, elected the GPL Version 2 license, then the option applies
# only if the new code is made subject to such option by the copyright
# holder.
# Error messages for ContextClassloaderLocal utility class
FAILED_TO_CREATE_NEW_INSTANCE=Failed to create new instance of {0}
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 1997-2013 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997-2014 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
@@ -40,7 +40,15 @@
package com.sun.xml.messaging.saaj.soap;
import java.util.logging.Logger;
import com.sun.xml.messaging.saaj.LazyEnvelopeSource;
import com.sun.xml.messaging.saaj.SOAPExceptionImpl;
import com.sun.xml.messaging.saaj.util.JAXMStreamSource;
import com.sun.xml.messaging.saaj.util.LogDomainConstants;
import com.sun.xml.messaging.saaj.util.ParserPool;
import com.sun.xml.messaging.saaj.util.RejectDoctypeSaxFilter;
import com.sun.xml.messaging.saaj.util.transform.EfficientStreamingTransformer;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import javax.xml.parsers.SAXParser;
import javax.xml.soap.SOAPException;
@@ -53,14 +61,7 @@
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stax.StAXSource;
import javax.xml.transform.stream.StreamSource;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import com.sun.xml.messaging.saaj.LazyEnvelopeSource;
import com.sun.xml.messaging.saaj.SOAPExceptionImpl;
import com.sun.xml.messaging.saaj.util.*;
import com.sun.xml.messaging.saaj.util.transform.EfficientStreamingTransformer;
import java.util.logging.Logger;
/**
* EnvelopeFactory creates SOAP Envelope objects using different
@@ -72,21 +73,27 @@
log = Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
"com.sun.xml.messaging.saaj.soap.LocalStrings");
private static ParserPool parserPool = new ParserPool(5);
private static ContextClassloaderLocal<ParserPool> parserPool =
new ContextClassloaderLocal<ParserPool>() {
@Override
protected ParserPool initialValue() throws Exception {
return new ParserPool(5);
}
};
public static Envelope createEnvelope(Source src, SOAPPartImpl soapPart)
throws SOAPException
{
if (src instanceof JAXMStreamSource) {
try {
if (!SOAPPartImpl.lazyContentLength) {
((JAXMStreamSource) src).reset();
if (src instanceof JAXMStreamSource) {
try {
if (!SOAPPartImpl.lazyContentLength) {
((JAXMStreamSource) src).reset();
}
} catch (java.io.IOException ioe) {
log.severe("SAAJ0515.source.reset.exception");
throw new SOAPExceptionImpl(ioe);
}
} catch (java.io.IOException ioe) {
log.severe("SAAJ0515.source.reset.exception");
throw new SOAPExceptionImpl(ioe);
}
}
if (src instanceof LazyEnvelopeSource) {
return lazy((LazyEnvelopeSource)src, soapPart);
}
@@ -98,7 +105,7 @@ public static Envelope createEnvelope(Source src, SOAPPartImpl soapPart)
}
private static Envelope lazy(LazyEnvelopeSource src, SOAPPartImpl soapPart) throws SOAPException {
try {
try {
StaxBridge staxBridge = new StaxLazySourceBridge(src, soapPart);
staxBridge.bridgeEnvelopeAndHeaders();
Envelope env = (Envelope) soapPart.getEnvelope();
@@ -145,7 +152,7 @@ private static Envelope parseEnvelopeSax(Source src, SOAPPartImpl soapPart)
SAXParser saxParser = null;
if (src instanceof StreamSource) {
try {
saxParser = parserPool.get();
saxParser = parserPool.get().get();
} catch (Exception e) {
log.severe("SAAJ0601.util.newSAXParser.exception");
throw new SOAPExceptionImpl(
@@ -186,7 +193,7 @@ private static Envelope parseEnvelopeSax(Source src, SOAPPartImpl soapPart)
ex);
} finally {
if (saxParser != null) {
parserPool.returnParser(saxParser);
parserPool.get().returnParser(saxParser);
}
}
}

0 comments on commit 98a1874

Please sign in to comment.