feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import javax.xml.soap.SOAPException;
|
||||
|
||||
/**
|
||||
* An exception that signals that a SOAP exception has occurred. A
|
||||
* <code>SOAPExceptionImpl</code> object may contain a <code>String</code>
|
||||
* that gives the reason for the exception, an embedded
|
||||
* <code>Throwable</code> object, or both. This class provides methods
|
||||
* for retrieving reason messages and for retrieving the embedded
|
||||
* <code>Throwable</code> object.
|
||||
*
|
||||
* <P> Typical reasons for throwing a <code>SOAPExceptionImpl</code>
|
||||
* object are problems such as difficulty setting a header, not being
|
||||
* able to send a message, and not being able to get a connection with
|
||||
* the provider. Reasons for embedding a <code>Throwable</code>
|
||||
* object include problems such as input/output errors or a parsing
|
||||
* problem, such as an error in parsing a header.
|
||||
*/
|
||||
public class SOAPExceptionImpl extends SOAPException {
|
||||
private Throwable cause;
|
||||
|
||||
/**
|
||||
* Constructs a <code>SOAPExceptionImpl</code> object with no
|
||||
* reason or embedded <code>Throwable</code> object.
|
||||
*/
|
||||
public SOAPExceptionImpl() {
|
||||
super();
|
||||
this.cause = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>SOAPExceptionImpl</code> object with the given
|
||||
* <code>String</code> as the reason for the exception being thrown.
|
||||
*
|
||||
* @param reason a description of what caused the exception
|
||||
*/
|
||||
public SOAPExceptionImpl(String reason) {
|
||||
super(reason);
|
||||
this.cause = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>SOAPExceptionImpl</code> object with the given
|
||||
* <code>String</code> as the reason for the exception being thrown
|
||||
* and the given <code>Throwable</code> object as an embedded
|
||||
* exception.
|
||||
*
|
||||
* @param reason a description of what caused the exception
|
||||
* @param cause a <code>Throwable</code> object that is to
|
||||
* be embedded in this <code>SOAPExceptionImpl</code> object
|
||||
*/
|
||||
public SOAPExceptionImpl(String reason, Throwable cause) {
|
||||
super (reason);
|
||||
initCause(cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>SOAPExceptionImpl</code> object initialized
|
||||
* with the given <code>Throwable</code> object.
|
||||
*/
|
||||
public SOAPExceptionImpl(Throwable cause) {
|
||||
super (cause.toString());
|
||||
initCause(cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the detail message for this <code>SOAPExceptionImpl</code>
|
||||
* object.
|
||||
* <P>
|
||||
* If there is an embedded <code>Throwable</code> object, and if the
|
||||
* <code>SOAPExceptionImpl</code> object has no detail message of its
|
||||
* own, this method will return the detail message from the embedded
|
||||
* <code>Throwable</code> object.
|
||||
*
|
||||
* @return the error or warning message for this
|
||||
* <code>SOAPExceptionImpl</code> or, if it has none, the
|
||||
* message of the embedded <code>Throwable</code> object,
|
||||
* if there is one
|
||||
*/
|
||||
public String getMessage() {
|
||||
String message = super.getMessage ();
|
||||
if (message == null && cause != null) {
|
||||
return cause.getMessage();
|
||||
} else {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <code>Throwable</code> object embedded in this
|
||||
* <code>SOAPExceptionImpl</code> if there is one. Otherwise, this method
|
||||
* returns <code>null</code>.
|
||||
*
|
||||
* @return the embedded <code>Throwable</code> object or <code>null</code>
|
||||
* if there is none
|
||||
*/
|
||||
|
||||
public Throwable getCause() {
|
||||
return cause;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>cause</code> field of this <code>SOAPExceptionImpl</code>
|
||||
* object with the given <code>Throwable</code> object.
|
||||
* <P>
|
||||
* This method can be called at most once. It is generally called from
|
||||
* within the constructor or immediately after the constructor has
|
||||
* returned a new <code>SOAPExceptionImpl</code> object.
|
||||
* If this <code>SOAPExceptionImpl</code> object was created with the
|
||||
* constructor {@link #SOAPExceptionImpl(Throwable)} or
|
||||
* {@link #SOAPExceptionImpl(String,Throwable)}, meaning that its
|
||||
* <code>cause</code> field already has a value, this method cannot be
|
||||
* called even once.
|
||||
*
|
||||
* @param cause the <code>Throwable</code> object that caused this
|
||||
* <code>SOAPExceptionImpl</code> object to be thrown. The value of this
|
||||
* parameter is saved for later retrieval by the
|
||||
* {@link #getCause()} method. A <tt>null</tt> value is
|
||||
* permitted and indicates that the cause is nonexistent or
|
||||
* unknown.
|
||||
* @return a reference to this <code>SOAPExceptionImpl</code> instance
|
||||
* @throws IllegalArgumentException if <code>cause</code> is this
|
||||
* <code>Throwable</code> object. (A <code>Throwable</code> object
|
||||
* cannot be its own cause.)
|
||||
* @throws IllegalStateException if this <code>SOAPExceptionImpl</code> object
|
||||
* was created with {@link #SOAPExceptionImpl(Throwable)} or
|
||||
* {@link #SOAPExceptionImpl(String,Throwable)}, or this
|
||||
* method has already been called on this <code>SOAPExceptionImpl</code>
|
||||
* object
|
||||
*/
|
||||
public synchronized Throwable initCause(Throwable cause)
|
||||
{
|
||||
if(this.cause != null) {
|
||||
throw new IllegalStateException("Can't override cause");
|
||||
}
|
||||
if(cause == this) {
|
||||
throw new IllegalArgumentException("Self-causation not permitted");
|
||||
}
|
||||
this.cause = cause;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public void printStackTrace() {
|
||||
super.printStackTrace();
|
||||
if (cause != null) {
|
||||
System.err.println("\nCAUSE:\n");
|
||||
cause.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void printStackTrace(PrintStream s) {
|
||||
super.printStackTrace(s);
|
||||
if (cause != null) {
|
||||
s.println("\nCAUSE:\n");
|
||||
cause.printStackTrace(s);
|
||||
}
|
||||
}
|
||||
|
||||
public void printStackTrace(PrintWriter s) {
|
||||
super.printStackTrace(s);
|
||||
if (cause != null) {
|
||||
s.println("\nCAUSE:\n");
|
||||
cause.printStackTrace(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,656 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.client.p2p;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.*;
|
||||
import java.security.*;
|
||||
import java.util.Iterator;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.xml.soap.*;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.util.*;
|
||||
|
||||
/**
|
||||
* This represents a "connection" to the simple HTTP-based provider.
|
||||
*
|
||||
* @author Anil Vijendran (akv@eng.sun.com)
|
||||
* @author Rajiv Mordani (rajiv.mordani@sun.com)
|
||||
* @author Manveen Kaur (manveen.kaur@sun.com)
|
||||
*
|
||||
*/
|
||||
class HttpSOAPConnection extends SOAPConnection {
|
||||
|
||||
public static final String vmVendor = SAAJUtil.getSystemProperty("java.vendor.url");
|
||||
private static final String sunVmVendor = "http://java.sun.com/";
|
||||
private static final String ibmVmVendor = "http://www.ibm.com/";
|
||||
private static final boolean isSunVM = sunVmVendor.equals(vmVendor) ? true: false;
|
||||
private static final boolean isIBMVM = ibmVmVendor.equals(vmVendor) ? true : false;
|
||||
private static final String JAXM_URLENDPOINT="javax.xml.messaging.URLEndpoint";
|
||||
|
||||
protected static final Logger log =
|
||||
Logger.getLogger(LogDomainConstants.HTTP_CONN_DOMAIN,
|
||||
"com.sun.xml.internal.messaging.saaj.client.p2p.LocalStrings");
|
||||
|
||||
|
||||
MessageFactory messageFactory = null;
|
||||
|
||||
boolean closed = false;
|
||||
|
||||
public HttpSOAPConnection() throws SOAPException {
|
||||
|
||||
try {
|
||||
messageFactory = MessageFactory.newInstance(SOAPConstants.DYNAMIC_SOAP_PROTOCOL);
|
||||
} catch (NoSuchMethodError ex) {
|
||||
//fallback to default SOAP 1.1 in this case for backward compatibility
|
||||
messageFactory = MessageFactory.newInstance();
|
||||
} catch (Exception ex) {
|
||||
log.log(Level.SEVERE, "SAAJ0001.p2p.cannot.create.msg.factory", ex);
|
||||
throw new SOAPExceptionImpl("Unable to create message factory", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void close() throws SOAPException {
|
||||
if (closed) {
|
||||
log.severe("SAAJ0002.p2p.close.already.closed.conn");
|
||||
throw new SOAPExceptionImpl("Connection already closed");
|
||||
}
|
||||
|
||||
messageFactory = null;
|
||||
closed = true;
|
||||
}
|
||||
|
||||
public SOAPMessage call(SOAPMessage message, Object endPoint)
|
||||
throws SOAPException {
|
||||
if (closed) {
|
||||
log.severe("SAAJ0003.p2p.call.already.closed.conn");
|
||||
throw new SOAPExceptionImpl("Connection is closed");
|
||||
}
|
||||
|
||||
Class urlEndpointClass = null;
|
||||
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||
try {
|
||||
if (loader != null) {
|
||||
urlEndpointClass = loader.loadClass(JAXM_URLENDPOINT);
|
||||
} else {
|
||||
urlEndpointClass = Class.forName(JAXM_URLENDPOINT);
|
||||
}
|
||||
} catch (ClassNotFoundException ex) {
|
||||
//Do nothing. URLEndpoint is available only when JAXM is there.
|
||||
if (log.isLoggable(Level.FINEST))
|
||||
log.finest("SAAJ0090.p2p.endpoint.available.only.for.JAXM");
|
||||
}
|
||||
|
||||
if (urlEndpointClass != null) {
|
||||
if (urlEndpointClass.isInstance(endPoint)) {
|
||||
String url = null;
|
||||
|
||||
try {
|
||||
Method m = urlEndpointClass.getMethod("getURL", (Class[])null);
|
||||
url = (String) m.invoke(endPoint, (Object[])null);
|
||||
} catch (Exception ex) {
|
||||
// TBD -- exception chaining
|
||||
log.log(Level.SEVERE,"SAAJ0004.p2p.internal.err",ex);
|
||||
throw new SOAPExceptionImpl(
|
||||
"Internal error: " + ex.getMessage());
|
||||
}
|
||||
try {
|
||||
endPoint = new URL(url);
|
||||
} catch (MalformedURLException mex) {
|
||||
log.log(Level.SEVERE,"SAAJ0005.p2p.", mex);
|
||||
throw new SOAPExceptionImpl("Bad URL: " + mex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (endPoint instanceof java.lang.String) {
|
||||
try {
|
||||
endPoint = new URL((String) endPoint);
|
||||
} catch (MalformedURLException mex) {
|
||||
log.log(Level.SEVERE, "SAAJ0006.p2p.bad.URL", mex);
|
||||
throw new SOAPExceptionImpl("Bad URL: " + mex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if (endPoint instanceof URL)
|
||||
try {
|
||||
SOAPMessage response = post(message, (URL)endPoint);
|
||||
return response;
|
||||
} catch (Exception ex) {
|
||||
// TBD -- chaining?
|
||||
throw new SOAPExceptionImpl(ex);
|
||||
} else {
|
||||
log.severe("SAAJ0007.p2p.bad.endPoint.type");
|
||||
throw new SOAPExceptionImpl("Bad endPoint type " + endPoint);
|
||||
}
|
||||
}
|
||||
|
||||
SOAPMessage post(SOAPMessage message, URL endPoint) throws SOAPException, IOException {
|
||||
boolean isFailure = false;
|
||||
|
||||
URL url = null;
|
||||
HttpURLConnection httpConnection = null;
|
||||
|
||||
int responseCode = 0;
|
||||
try {
|
||||
if (endPoint.getProtocol().equals("https"))
|
||||
//if(!setHttps)
|
||||
initHttps();
|
||||
// Process the URL
|
||||
URI uri = new URI(endPoint.toString());
|
||||
String userInfo = uri.getRawUserInfo();
|
||||
|
||||
url = endPoint;
|
||||
|
||||
if (dL > 0)
|
||||
d("uri: " + userInfo + " " + url + " " + uri);
|
||||
|
||||
// TBD
|
||||
// Will deal with https later.
|
||||
if (!url.getProtocol().equalsIgnoreCase("http")
|
||||
&& !url.getProtocol().equalsIgnoreCase("https")) {
|
||||
log.severe("SAAJ0052.p2p.protocol.mustbe.http.or.https");
|
||||
throw new IllegalArgumentException(
|
||||
"Protocol "
|
||||
+ url.getProtocol()
|
||||
+ " not supported in URL "
|
||||
+ url);
|
||||
}
|
||||
httpConnection = (HttpURLConnection) createConnection(url);
|
||||
|
||||
httpConnection.setRequestMethod("POST");
|
||||
|
||||
httpConnection.setDoOutput(true);
|
||||
httpConnection.setDoInput(true);
|
||||
httpConnection.setUseCaches(false);
|
||||
httpConnection.setInstanceFollowRedirects(true);
|
||||
|
||||
if (message.saveRequired())
|
||||
message.saveChanges();
|
||||
|
||||
MimeHeaders headers = message.getMimeHeaders();
|
||||
|
||||
Iterator it = headers.getAllHeaders();
|
||||
boolean hasAuth = false; // true if we find explicit Auth header
|
||||
while (it.hasNext()) {
|
||||
MimeHeader header = (MimeHeader) it.next();
|
||||
|
||||
String[] values = headers.getHeader(header.getName());
|
||||
if (values.length == 1)
|
||||
httpConnection.setRequestProperty(
|
||||
header.getName(),
|
||||
header.getValue());
|
||||
else {
|
||||
StringBuffer concat = new StringBuffer();
|
||||
int i = 0;
|
||||
while (i < values.length) {
|
||||
if (i != 0)
|
||||
concat.append(',');
|
||||
concat.append(values[i]);
|
||||
i++;
|
||||
}
|
||||
|
||||
httpConnection.setRequestProperty(
|
||||
header.getName(),
|
||||
concat.toString());
|
||||
}
|
||||
|
||||
if ("Authorization".equals(header.getName())) {
|
||||
hasAuth = true;
|
||||
if (log.isLoggable(Level.FINE))
|
||||
log.fine("SAAJ0091.p2p.https.auth.in.POST.true");
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasAuth && userInfo != null) {
|
||||
initAuthUserInfo(httpConnection, userInfo);
|
||||
}
|
||||
|
||||
OutputStream out = httpConnection.getOutputStream();
|
||||
try {
|
||||
message.writeTo(out);
|
||||
out.flush();
|
||||
} finally {
|
||||
out.close();
|
||||
}
|
||||
|
||||
httpConnection.connect();
|
||||
|
||||
try {
|
||||
|
||||
responseCode = httpConnection.getResponseCode();
|
||||
|
||||
// let HTTP_INTERNAL_ERROR (500) through because it is used for SOAP faults
|
||||
if (responseCode == HttpURLConnection.HTTP_INTERNAL_ERROR) {
|
||||
isFailure = true;
|
||||
}
|
||||
//else if (responseCode != HttpURLConnection.HTTP_OK)
|
||||
//else if (!(responseCode >= HttpURLConnection.HTTP_OK && responseCode < 207))
|
||||
else if ((responseCode / 100) != 2) {
|
||||
log.log(Level.SEVERE,
|
||||
"SAAJ0008.p2p.bad.response",
|
||||
new String[] {httpConnection.getResponseMessage()});
|
||||
throw new SOAPExceptionImpl(
|
||||
"Bad response: ("
|
||||
+ responseCode
|
||||
+ httpConnection.getResponseMessage());
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// on JDK1.3.1_01, we end up here, but then getResponseCode() succeeds!
|
||||
responseCode = httpConnection.getResponseCode();
|
||||
if (responseCode == HttpURLConnection.HTTP_INTERNAL_ERROR) {
|
||||
isFailure = true;
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (SOAPException ex) {
|
||||
throw ex;
|
||||
} catch (Exception ex) {
|
||||
log.severe("SAAJ0009.p2p.msg.send.failed");
|
||||
throw new SOAPExceptionImpl("Message send failed", ex);
|
||||
}
|
||||
|
||||
SOAPMessage response = null;
|
||||
InputStream httpIn = null;
|
||||
if (responseCode == HttpURLConnection.HTTP_OK || isFailure) {
|
||||
try {
|
||||
MimeHeaders headers = new MimeHeaders();
|
||||
|
||||
String key, value;
|
||||
|
||||
// Header field 0 is the status line so we skip it.
|
||||
|
||||
int i = 1;
|
||||
|
||||
while (true) {
|
||||
key = httpConnection.getHeaderFieldKey(i);
|
||||
value = httpConnection.getHeaderField(i);
|
||||
|
||||
if (key == null && value == null)
|
||||
break;
|
||||
|
||||
if (key != null) {
|
||||
StringTokenizer values =
|
||||
new StringTokenizer(value, ",");
|
||||
while (values.hasMoreTokens())
|
||||
headers.addHeader(key, values.nextToken().trim());
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
httpIn =
|
||||
(isFailure
|
||||
? httpConnection.getErrorStream()
|
||||
: httpConnection.getInputStream());
|
||||
|
||||
byte[] bytes = readFully(httpIn);
|
||||
|
||||
int length =
|
||||
httpConnection.getContentLength() == -1
|
||||
? bytes.length
|
||||
: httpConnection.getContentLength();
|
||||
|
||||
// If no reply message is returned,
|
||||
// content-Length header field value is expected to be zero.
|
||||
if (length == 0) {
|
||||
response = null;
|
||||
log.warning("SAAJ0014.p2p.content.zero");
|
||||
} else {
|
||||
ByteInputStream in = new ByteInputStream(bytes, length);
|
||||
response = messageFactory.createMessage(headers, in);
|
||||
}
|
||||
|
||||
} catch (SOAPException ex) {
|
||||
throw ex;
|
||||
} catch (Exception ex) {
|
||||
log.log(Level.SEVERE,"SAAJ0010.p2p.cannot.read.resp", ex);
|
||||
throw new SOAPExceptionImpl(
|
||||
"Unable to read response: " + ex.getMessage());
|
||||
} finally {
|
||||
if (httpIn != null)
|
||||
httpIn.close();
|
||||
httpConnection.disconnect();
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
// Object identifies where the request should be sent.
|
||||
// It is required to support objects of type String and java.net.URL.
|
||||
|
||||
public SOAPMessage get(Object endPoint) throws SOAPException {
|
||||
if (closed) {
|
||||
log.severe("SAAJ0011.p2p.get.already.closed.conn");
|
||||
throw new SOAPExceptionImpl("Connection is closed");
|
||||
}
|
||||
Class urlEndpointClass = null;
|
||||
|
||||
try {
|
||||
urlEndpointClass = Class.forName("javax.xml.messaging.URLEndpoint");
|
||||
} catch (Exception ex) {
|
||||
//Do nothing. URLEndpoint is available only when JAXM is there.
|
||||
}
|
||||
|
||||
if (urlEndpointClass != null) {
|
||||
if (urlEndpointClass.isInstance(endPoint)) {
|
||||
String url = null;
|
||||
|
||||
try {
|
||||
Method m = urlEndpointClass.getMethod("getURL", (Class[])null);
|
||||
url = (String) m.invoke(endPoint, (Object[])null);
|
||||
} catch (Exception ex) {
|
||||
log.severe("SAAJ0004.p2p.internal.err");
|
||||
throw new SOAPExceptionImpl(
|
||||
"Internal error: " + ex.getMessage());
|
||||
}
|
||||
try {
|
||||
endPoint = new URL(url);
|
||||
} catch (MalformedURLException mex) {
|
||||
log.severe("SAAJ0005.p2p.");
|
||||
throw new SOAPExceptionImpl("Bad URL: " + mex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (endPoint instanceof java.lang.String) {
|
||||
try {
|
||||
endPoint = new URL((String) endPoint);
|
||||
} catch (MalformedURLException mex) {
|
||||
log.severe("SAAJ0006.p2p.bad.URL");
|
||||
throw new SOAPExceptionImpl("Bad URL: " + mex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if (endPoint instanceof URL)
|
||||
try {
|
||||
SOAPMessage response = doGet((URL)endPoint);
|
||||
return response;
|
||||
} catch (Exception ex) {
|
||||
throw new SOAPExceptionImpl(ex);
|
||||
} else
|
||||
throw new SOAPExceptionImpl("Bad endPoint type " + endPoint);
|
||||
}
|
||||
|
||||
SOAPMessage doGet(URL endPoint) throws SOAPException, IOException {
|
||||
boolean isFailure = false;
|
||||
|
||||
URL url = null;
|
||||
HttpURLConnection httpConnection = null;
|
||||
|
||||
int responseCode = 0;
|
||||
try {
|
||||
/// Is https GET allowed??
|
||||
if (endPoint.getProtocol().equals("https"))
|
||||
initHttps();
|
||||
// Process the URL
|
||||
URI uri = new URI(endPoint.toString());
|
||||
String userInfo = uri.getRawUserInfo();
|
||||
|
||||
url = endPoint;
|
||||
|
||||
if (dL > 0)
|
||||
d("uri: " + userInfo + " " + url + " " + uri);
|
||||
|
||||
// TBD
|
||||
// Will deal with https later.
|
||||
if (!url.getProtocol().equalsIgnoreCase("http")
|
||||
&& !url.getProtocol().equalsIgnoreCase("https")) {
|
||||
log.severe("SAAJ0052.p2p.protocol.mustbe.http.or.https");
|
||||
throw new IllegalArgumentException(
|
||||
"Protocol "
|
||||
+ url.getProtocol()
|
||||
+ " not supported in URL "
|
||||
+ url);
|
||||
}
|
||||
httpConnection = (HttpURLConnection) createConnection(url);
|
||||
|
||||
httpConnection.setRequestMethod("GET");
|
||||
|
||||
httpConnection.setDoOutput(true);
|
||||
httpConnection.setDoInput(true);
|
||||
httpConnection.setUseCaches(false);
|
||||
httpConnection.setFollowRedirects(true);
|
||||
|
||||
httpConnection.connect();
|
||||
|
||||
try {
|
||||
|
||||
responseCode = httpConnection.getResponseCode();
|
||||
|
||||
// let HTTP_INTERNAL_ERROR (500) through because it is used for SOAP faults
|
||||
if (responseCode == HttpURLConnection.HTTP_INTERNAL_ERROR) {
|
||||
isFailure = true;
|
||||
} else if ((responseCode / 100) != 2) {
|
||||
log.log(Level.SEVERE,
|
||||
"SAAJ0008.p2p.bad.response",
|
||||
new String[] { httpConnection.getResponseMessage()});
|
||||
throw new SOAPExceptionImpl(
|
||||
"Bad response: ("
|
||||
+ responseCode
|
||||
+ httpConnection.getResponseMessage());
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// on JDK1.3.1_01, we end up here, but then getResponseCode() succeeds!
|
||||
responseCode = httpConnection.getResponseCode();
|
||||
if (responseCode == HttpURLConnection.HTTP_INTERNAL_ERROR) {
|
||||
isFailure = true;
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (SOAPException ex) {
|
||||
throw ex;
|
||||
} catch (Exception ex) {
|
||||
log.severe("SAAJ0012.p2p.get.failed");
|
||||
throw new SOAPExceptionImpl("Get failed", ex);
|
||||
}
|
||||
|
||||
SOAPMessage response = null;
|
||||
InputStream httpIn = null;
|
||||
if (responseCode == HttpURLConnection.HTTP_OK || isFailure) {
|
||||
try {
|
||||
MimeHeaders headers = new MimeHeaders();
|
||||
|
||||
String key, value;
|
||||
|
||||
// Header field 0 is the status line so we skip it.
|
||||
|
||||
int i = 1;
|
||||
|
||||
while (true) {
|
||||
key = httpConnection.getHeaderFieldKey(i);
|
||||
value = httpConnection.getHeaderField(i);
|
||||
|
||||
if (key == null && value == null)
|
||||
break;
|
||||
|
||||
if (key != null) {
|
||||
StringTokenizer values =
|
||||
new StringTokenizer(value, ",");
|
||||
while (values.hasMoreTokens())
|
||||
headers.addHeader(key, values.nextToken().trim());
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
httpIn =
|
||||
(isFailure
|
||||
? httpConnection.getErrorStream()
|
||||
: httpConnection.getInputStream());
|
||||
// If no reply message is returned,
|
||||
// content-Length header field value is expected to be zero.
|
||||
// java SE 6 documentation says :
|
||||
// available() : an estimate of the number of bytes that can be read
|
||||
//(or skipped over) from this input stream without blocking
|
||||
//or 0 when it reaches the end of the input stream.
|
||||
if ((httpIn == null )
|
||||
|| (httpConnection.getContentLength() == 0)
|
||||
|| (httpIn.available() == 0)) {
|
||||
response = null;
|
||||
log.warning("SAAJ0014.p2p.content.zero");
|
||||
} else {
|
||||
response = messageFactory.createMessage(headers, httpIn);
|
||||
}
|
||||
|
||||
} catch (SOAPException ex) {
|
||||
throw ex;
|
||||
} catch (Exception ex) {
|
||||
log.log(Level.SEVERE,
|
||||
"SAAJ0010.p2p.cannot.read.resp",
|
||||
ex);
|
||||
throw new SOAPExceptionImpl(
|
||||
"Unable to read response: " + ex.getMessage());
|
||||
} finally {
|
||||
if (httpIn != null)
|
||||
httpIn.close();
|
||||
httpConnection.disconnect();
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
private byte[] readFully(InputStream istream) throws IOException {
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
byte[] buf = new byte[1024];
|
||||
int num = 0;
|
||||
|
||||
while ((num = istream.read(buf)) != -1) {
|
||||
bout.write(buf, 0, num);
|
||||
}
|
||||
|
||||
byte[] ret = bout.toByteArray();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//private static String SSL_PKG = "com.sun.net.ssl.internal.www.protocol";
|
||||
//private static String SSL_PROVIDER =
|
||||
// "com.sun.net.ssl.internal.ssl.Provider";
|
||||
private static final String SSL_PKG;
|
||||
private static final String SSL_PROVIDER;
|
||||
|
||||
static {
|
||||
if (isIBMVM) {
|
||||
SSL_PKG ="com.ibm.net.ssl.internal.www.protocol";
|
||||
SSL_PROVIDER ="com.ibm.net.ssl.internal.ssl.Provider";
|
||||
} else {
|
||||
//if not IBM VM default to Sun.
|
||||
SSL_PKG = "com.sun.net.ssl.internal.www.protocol";
|
||||
SSL_PROVIDER ="com.sun.net.ssl.internal.ssl.Provider";
|
||||
}
|
||||
}
|
||||
|
||||
private void initHttps() {
|
||||
//if(!setHttps) {
|
||||
String pkgs = SAAJUtil.getSystemProperty("java.protocol.handler.pkgs");
|
||||
if (log.isLoggable(Level.FINE))
|
||||
log.log(Level.FINE, "SAAJ0053.p2p.providers", new String[] { pkgs });
|
||||
|
||||
if (pkgs == null || pkgs.indexOf(SSL_PKG) < 0) {
|
||||
if (pkgs == null)
|
||||
pkgs = SSL_PKG;
|
||||
else
|
||||
pkgs = pkgs + "|" + SSL_PKG;
|
||||
System.setProperty("java.protocol.handler.pkgs", pkgs);
|
||||
if (log.isLoggable(Level.FINE))
|
||||
log.log(Level.FINE, "SAAJ0054.p2p.set.providers",
|
||||
new String[] { pkgs });
|
||||
try {
|
||||
Class c = Class.forName(SSL_PROVIDER);
|
||||
Provider p = (Provider) c.newInstance();
|
||||
Security.addProvider(p);
|
||||
if (log.isLoggable(Level.FINE))
|
||||
log.log(Level.FINE, "SAAJ0055.p2p.added.ssl.provider",
|
||||
new String[] { SSL_PROVIDER });
|
||||
//System.out.println("Added SSL_PROVIDER " + SSL_PROVIDER);
|
||||
//setHttps = true;
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
private void initAuthUserInfo(HttpURLConnection conn, String userInfo) {
|
||||
String user;
|
||||
String password;
|
||||
if (userInfo != null) { // get the user and password
|
||||
//System.out.println("UserInfo= " + userInfo );
|
||||
int delimiter = userInfo.indexOf(':');
|
||||
if (delimiter == -1) {
|
||||
user = ParseUtil.decode(userInfo);
|
||||
password = null;
|
||||
} else {
|
||||
user = ParseUtil.decode(userInfo.substring(0, delimiter++));
|
||||
password = ParseUtil.decode(userInfo.substring(delimiter));
|
||||
}
|
||||
|
||||
String plain = user + ":";
|
||||
byte[] nameBytes = plain.getBytes();
|
||||
byte[] passwdBytes = password.getBytes();
|
||||
|
||||
// concatenate user name and password bytes and encode them
|
||||
byte[] concat = new byte[nameBytes.length + passwdBytes.length];
|
||||
|
||||
System.arraycopy(nameBytes, 0, concat, 0, nameBytes.length);
|
||||
System.arraycopy(
|
||||
passwdBytes,
|
||||
0,
|
||||
concat,
|
||||
nameBytes.length,
|
||||
passwdBytes.length);
|
||||
String auth = "Basic " + new String(Base64.encode(concat));
|
||||
conn.setRequestProperty("Authorization", auth);
|
||||
if (dL > 0)
|
||||
d("Adding auth " + auth);
|
||||
}
|
||||
}
|
||||
|
||||
private static final int dL = 0;
|
||||
private void d(String s) {
|
||||
log.log(Level.SEVERE,
|
||||
"SAAJ0013.p2p.HttpSOAPConnection",
|
||||
new String[] { s });
|
||||
System.err.println("HttpSOAPConnection: " + s);
|
||||
}
|
||||
|
||||
private java.net.HttpURLConnection createConnection(URL endpoint)
|
||||
throws IOException {
|
||||
return (HttpURLConnection) endpoint.openConnection();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.client.p2p;
|
||||
|
||||
import javax.xml.soap.*;
|
||||
|
||||
/**
|
||||
* Implementation of the SOAPConnectionFactory
|
||||
*
|
||||
* @author Anil Vijendran (anil@sun.com)
|
||||
*/
|
||||
public class HttpSOAPConnectionFactory extends SOAPConnectionFactory {
|
||||
|
||||
public SOAPConnection createConnection()
|
||||
throws SOAPException
|
||||
{
|
||||
return new HttpSOAPConnection();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)Header.java 1.3 02/03/27
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.packaging.mime;
|
||||
|
||||
|
||||
/**
|
||||
* The Header class stores a name/value pair to represent headers.
|
||||
*
|
||||
* @author John Mani
|
||||
*/
|
||||
|
||||
public interface Header {
|
||||
|
||||
/**
|
||||
* Returns the name of this header.
|
||||
*
|
||||
* @return name of the header
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Returns the value of this header.
|
||||
*
|
||||
* @return value of the header
|
||||
*/
|
||||
String getValue();
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)MessagingException.java 1.10 02/06/13
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.packaging.mime;
|
||||
|
||||
|
||||
/**
|
||||
* The base class for all exceptions thrown by the Messaging classes
|
||||
*
|
||||
* @author John Mani
|
||||
* @author Bill Shannon
|
||||
*/
|
||||
|
||||
public class MessagingException extends Exception {
|
||||
|
||||
/**
|
||||
* The next exception in the chain.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private Exception next;
|
||||
|
||||
/**
|
||||
* Constructs a MessagingException with no detail message.
|
||||
*/
|
||||
public MessagingException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a MessagingException with the specified detail message.
|
||||
* @param s the detail message
|
||||
*/
|
||||
public MessagingException(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a MessagingException with the specified
|
||||
* Exception and detail message. The specified exception is chained
|
||||
* to this exception.
|
||||
* @param s the detail message
|
||||
* @param e the embedded exception
|
||||
* @see #getNextException
|
||||
* @see #setNextException
|
||||
*/
|
||||
public MessagingException(String s, Exception e) {
|
||||
super(s);
|
||||
next = e;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next exception chained to this one. If the
|
||||
* next exception is a MessagingException, the chain
|
||||
* may extend further.
|
||||
*
|
||||
* @return next Exception, null if none.
|
||||
*/
|
||||
public Exception getNextException() {
|
||||
return next;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an exception to the end of the chain. If the end
|
||||
* is <strong>not</strong> a MessagingException, this
|
||||
* exception cannot be added to the end.
|
||||
*
|
||||
* @param ex the new end of the Exception chain
|
||||
* @return <code>true</code> if the this Exception
|
||||
* was added, <code>false</code> otherwise.
|
||||
*/
|
||||
public synchronized boolean setNextException(Exception ex) {
|
||||
Exception theEnd = this;
|
||||
while (theEnd instanceof MessagingException &&
|
||||
((MessagingException)theEnd).next != null) {
|
||||
theEnd = ((MessagingException)theEnd).next;
|
||||
}
|
||||
// If the end is a MessagingException, we can add this
|
||||
// exception to the chain.
|
||||
if (theEnd instanceof MessagingException) {
|
||||
((MessagingException)theEnd).next = ex;
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Produce the message, include the message from the nested
|
||||
* exception if there is one.
|
||||
*/
|
||||
public String getMessage() {
|
||||
if (next == null)
|
||||
return super.getMessage();
|
||||
Exception n = next;
|
||||
String s = super.getMessage();
|
||||
StringBuffer sb = new StringBuffer(s == null ? "" : s);
|
||||
while (n != null) {
|
||||
sb.append(";\n nested exception is:\n\t");
|
||||
if (n instanceof MessagingException) {
|
||||
MessagingException mex = (MessagingException)n;
|
||||
sb.append(n.getClass().toString());
|
||||
String msg = mex.getSuperMessage();
|
||||
if (msg != null) {
|
||||
sb.append(": ");
|
||||
sb.append(msg);
|
||||
}
|
||||
n = mex.next;
|
||||
} else {
|
||||
sb.append(n.toString());
|
||||
n = null;
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String getSuperMessage() {
|
||||
return super.getMessage();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)MultipartDataSource.java 1.6 02/03/27
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.packaging.mime;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.MimeBodyPart;
|
||||
|
||||
import javax.activation.DataSource;
|
||||
|
||||
/**
|
||||
* MultipartDataSource is a <code>DataSource</code> that contains body
|
||||
* parts. This allows "mail aware" <code>DataContentHandlers</code> to
|
||||
* be implemented more efficiently by being aware of such
|
||||
* <code>DataSources</code> and using the appropriate methods to access
|
||||
* <code>BodyParts</code>. <p>
|
||||
*
|
||||
* Note that the data of a MultipartDataSource is also available as
|
||||
* an input stream. <p>
|
||||
*
|
||||
* This interface will typically be implemented by providers that
|
||||
* preparse multipart bodies, for example an IMAP provider.
|
||||
*
|
||||
* @version 1.6, 02/03/27
|
||||
* @author John Mani
|
||||
* @see javax.activation.DataSource
|
||||
*/
|
||||
|
||||
public interface MultipartDataSource extends DataSource {
|
||||
|
||||
/**
|
||||
* Return the number of enclosed MimeBodyPart objects.
|
||||
*
|
||||
* @return number of parts
|
||||
*/
|
||||
public int getCount();
|
||||
|
||||
/**
|
||||
* Get the specified MimeBodyPart. Parts are numbered starting at 0.
|
||||
*
|
||||
* @param index the index of the desired MimeBodyPart
|
||||
* @return the MimeBodyPart
|
||||
* @exception IndexOutOfBoundsException if the given index
|
||||
* is out of range.
|
||||
* @exception MessagingException
|
||||
*/
|
||||
public MimeBodyPart getBodyPart(int index) throws MessagingException;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,762 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)MimeMultipart.java 1.31 03/01/29
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.packaging.mime.internet;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.BitSet;
|
||||
|
||||
import javax.activation.DataSource;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.packaging.mime.*;
|
||||
import com.sun.xml.internal.messaging.saaj.packaging.mime.util.*;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream;
|
||||
import com.sun.xml.internal.messaging.saaj.util.FinalArrayList;
|
||||
|
||||
/**
|
||||
* The MimeMultipart class is an implementation of the abstract Multipart
|
||||
* class that uses MIME conventions for the multipart data. <p>
|
||||
*
|
||||
* A MimeMultipart is obtained from a MimePart whose primary type
|
||||
* is "multipart" (by invoking the part's <code>getContent()</code> method)
|
||||
* or it can be created by a client as part of creating a new MimeMessage. <p>
|
||||
*
|
||||
* The default multipart subtype is "mixed". The other multipart
|
||||
* subtypes, such as "alternative", "related", and so on, can be
|
||||
* implemented as subclasses of MimeMultipart with additional methods
|
||||
* to implement the additional semantics of that type of multipart
|
||||
* content. The intent is that service providers, mail JavaBean writers
|
||||
* and mail clients will write many such subclasses and their Command
|
||||
* Beans, and will install them into the JavaBeans Activation
|
||||
* Framework, so that any JavaMail implementation and its clients can
|
||||
* transparently find and use these classes. Thus, a MIME multipart
|
||||
* handler is treated just like any other type handler, thereby
|
||||
* decoupling the process of providing multipart handlers from the
|
||||
* JavaMail API. Lacking these additional MimeMultipart subclasses,
|
||||
* all subtypes of MIME multipart data appear as MimeMultipart objects. <p>
|
||||
*
|
||||
* An application can directly construct a MIME multipart object of any
|
||||
* subtype by using the <code>MimeMultipart(String subtype)</code>
|
||||
* constructor. For example, to create a "multipart/alternative" object,
|
||||
* use <code>new MimeMultipart("alternative")</code>.
|
||||
*
|
||||
*/
|
||||
|
||||
//TODO: cleanup the SharedInputStream handling
|
||||
public class BMMimeMultipart extends MimeMultipart {
|
||||
|
||||
/*
|
||||
* When true it indicates parsing hasnt been done at all
|
||||
*/
|
||||
private boolean begining = true;
|
||||
|
||||
int[] bcs = new int[256];
|
||||
int[] gss = null;
|
||||
private static final int BUFFER_SIZE = 4096;
|
||||
private byte[] buffer = new byte[BUFFER_SIZE];
|
||||
private byte[] prevBuffer = new byte[BUFFER_SIZE];
|
||||
private BitSet lastPartFound = new BitSet(1);
|
||||
|
||||
// cached inputstream which is possibly partially consumed
|
||||
private InputStream in = null;
|
||||
private String boundary = null;
|
||||
// current stream position, set to -1 on EOF
|
||||
int b = 0;
|
||||
|
||||
// property to indicate if lazyAttachments is ON
|
||||
private boolean lazyAttachments = false;
|
||||
|
||||
/**
|
||||
* Default constructor. An empty MimeMultipart object
|
||||
* is created. Its content type is set to "multipart/mixed".
|
||||
* A unique boundary string is generated and this string is
|
||||
* setup as the "boundary" parameter for the
|
||||
* <code>contentType</code> field. <p>
|
||||
*
|
||||
* MimeBodyParts may be added later.
|
||||
*/
|
||||
public BMMimeMultipart() {
|
||||
super();
|
||||
//this("mixed");
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a MimeMultipart object of the given subtype.
|
||||
* A unique boundary string is generated and this string is
|
||||
* setup as the "boundary" parameter for the
|
||||
* <code>contentType</code> field. <p>
|
||||
*
|
||||
* MimeBodyParts may be added later.
|
||||
*/
|
||||
public BMMimeMultipart(String subtype) {
|
||||
super(subtype);
|
||||
/*
|
||||
* Compute a boundary string.
|
||||
String boundary = UniqueValue.getUniqueBoundaryValue();
|
||||
ContentType cType = new ContentType("multipart", subtype, null);
|
||||
contentType.setParameter("boundary", boundary);
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a MimeMultipart object and its bodyparts from the
|
||||
* given DataSource. <p>
|
||||
*
|
||||
* This constructor handles as a special case the situation where the
|
||||
* given DataSource is a MultipartDataSource object. In this case, this
|
||||
* method just invokes the superclass (i.e., Multipart) constructor
|
||||
* that takes a MultipartDataSource object. <p>
|
||||
*
|
||||
* Otherwise, the DataSource is assumed to provide a MIME multipart
|
||||
* byte stream. The <code>parsed</code> flag is set to false. When
|
||||
* the data for the body parts are needed, the parser extracts the
|
||||
* "boundary" parameter from the content type of this DataSource,
|
||||
* skips the 'preamble' and reads bytes till the terminating
|
||||
* boundary and creates MimeBodyParts for each part of the stream.
|
||||
*
|
||||
* @param ds DataSource, can be a MultipartDataSource
|
||||
*/
|
||||
public BMMimeMultipart(DataSource ds, ContentType ct)
|
||||
throws MessagingException {
|
||||
super(ds,ct);
|
||||
boundary = ct.getParameter("boundary");
|
||||
/*
|
||||
if (ds instanceof MultipartDataSource) {
|
||||
// ask super to do this for us.
|
||||
setMultipartDataSource((MultipartDataSource)ds);
|
||||
return;
|
||||
}
|
||||
|
||||
// 'ds' was not a MultipartDataSource, we have
|
||||
// to parse this ourself.
|
||||
parsed = false;
|
||||
this.ds = ds;
|
||||
if (ct==null)
|
||||
contentType = new ContentType(ds.getContentType());
|
||||
else
|
||||
contentType = ct;
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
public InputStream initStream() throws MessagingException {
|
||||
|
||||
if (in == null) {
|
||||
try {
|
||||
in = ds.getInputStream();
|
||||
if (!(in instanceof ByteArrayInputStream) &&
|
||||
!(in instanceof BufferedInputStream) &&
|
||||
!(in instanceof SharedInputStream))
|
||||
in = new BufferedInputStream(in);
|
||||
} catch (Exception ex) {
|
||||
throw new MessagingException("No inputstream from datasource");
|
||||
}
|
||||
|
||||
if (!in.markSupported()) {
|
||||
throw new MessagingException(
|
||||
"InputStream does not support Marking");
|
||||
}
|
||||
}
|
||||
return in;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the InputStream from our DataSource, constructing the
|
||||
* appropriate MimeBodyParts. The <code>parsed</code> flag is
|
||||
* set to true, and if true on entry nothing is done. This
|
||||
* method is called by all other methods that need data for
|
||||
* the body parts, to make sure the data has been parsed.
|
||||
*
|
||||
* @since JavaMail 1.2
|
||||
*/
|
||||
protected void parse() throws MessagingException {
|
||||
if (parsed)
|
||||
return;
|
||||
|
||||
initStream();
|
||||
|
||||
SharedInputStream sin = null;
|
||||
if (in instanceof SharedInputStream) {
|
||||
sin = (SharedInputStream)in;
|
||||
}
|
||||
|
||||
String bnd = "--" + boundary;
|
||||
byte[] bndbytes = ASCIIUtility.getBytes(bnd);
|
||||
try {
|
||||
parse(in, bndbytes, sin);
|
||||
} catch (IOException ioex) {
|
||||
throw new MessagingException("IO Error", ioex);
|
||||
} catch (Exception ex) {
|
||||
throw new MessagingException("Error", ex);
|
||||
}
|
||||
|
||||
parsed = true;
|
||||
}
|
||||
|
||||
public boolean lastBodyPartFound() {
|
||||
return lastPartFound.get(0);
|
||||
}
|
||||
|
||||
public MimeBodyPart getNextPart(
|
||||
InputStream stream, byte[] pattern, SharedInputStream sin)
|
||||
throws Exception {
|
||||
|
||||
if (!stream.markSupported()) {
|
||||
throw new Exception("InputStream does not support Marking");
|
||||
}
|
||||
|
||||
if (begining) {
|
||||
compile(pattern);
|
||||
if (!skipPreamble(stream, pattern, sin)) {
|
||||
throw new Exception(
|
||||
"Missing Start Boundary, or boundary does not start on a new line");
|
||||
}
|
||||
begining = false;
|
||||
}
|
||||
|
||||
if (lastBodyPartFound()) {
|
||||
throw new Exception("No parts found in Multipart InputStream");
|
||||
}
|
||||
|
||||
if (sin != null) {
|
||||
long start = sin.getPosition();
|
||||
b = readHeaders(stream);
|
||||
if (b == -1) {
|
||||
throw new Exception(
|
||||
"End of Stream encountered while reading part headers");
|
||||
}
|
||||
long[] v = new long[1];
|
||||
v[0] = -1; // just to ensure the code later sets it correctly
|
||||
b = readBody(stream, pattern, v, null, sin);
|
||||
// looks like this check has to be disabled
|
||||
// it is allowed to have Mime Package without closing boundary
|
||||
if (!ignoreMissingEndBoundary) {
|
||||
if ((b == -1) && !lastBodyPartFound()) {
|
||||
throw new MessagingException("Missing End Boundary for Mime Package : EOF while skipping headers");
|
||||
}
|
||||
}
|
||||
long end = v[0];
|
||||
MimeBodyPart mbp = createMimeBodyPart(sin.newStream(start, end));
|
||||
addBodyPart(mbp);
|
||||
return mbp;
|
||||
|
||||
} else {
|
||||
InternetHeaders headers = createInternetHeaders(stream);
|
||||
ByteOutputStream baos = new ByteOutputStream();
|
||||
b = readBody(stream, pattern, null,baos, null);
|
||||
// looks like this check has to be disabled
|
||||
// in the old impl it is allowed to have Mime Package
|
||||
// without closing boundary
|
||||
if (!ignoreMissingEndBoundary) {
|
||||
if ((b == -1) && !lastBodyPartFound()) {
|
||||
throw new MessagingException("Missing End Boundary for Mime Package : EOF while skipping headers");
|
||||
}
|
||||
}
|
||||
MimeBodyPart mbp = createMimeBodyPart(
|
||||
headers, baos.getBytes(), baos.getCount());
|
||||
addBodyPart(mbp);
|
||||
return mbp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean parse(
|
||||
InputStream stream, byte[] pattern, SharedInputStream sin)
|
||||
throws Exception {
|
||||
|
||||
while (!lastPartFound.get(0) && (b != -1)) {
|
||||
getNextPart(stream, pattern, sin);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private int readHeaders(InputStream is) throws Exception {
|
||||
// if the headers are to end properly then there has to be CRLF
|
||||
// actually we just need to mark the start and end positions
|
||||
int b = is.read();
|
||||
while(b != -1) {
|
||||
// when it is a shared input stream no need to copy
|
||||
if (b == '\r') {
|
||||
b = is.read();
|
||||
if (b == '\n') {
|
||||
b = is.read();
|
||||
if (b == '\r') {
|
||||
b = is.read();
|
||||
if (b == '\n') {
|
||||
return b;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
b = is.read();
|
||||
}
|
||||
if (b == -1) {
|
||||
throw new Exception(
|
||||
"End of inputstream while reading Mime-Part Headers");
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
private int readBody(
|
||||
InputStream is, byte[] pattern, long[] posVector,
|
||||
ByteOutputStream baos, SharedInputStream sin)
|
||||
throws Exception {
|
||||
if (!find(is, pattern, posVector, baos, sin)) {
|
||||
throw new Exception(
|
||||
"Missing boundary delimitier while reading Body Part");
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
private boolean skipPreamble(
|
||||
InputStream is, byte[] pattern, SharedInputStream sin)
|
||||
throws Exception {
|
||||
if (!find(is, pattern, sin)) {
|
||||
return false;
|
||||
}
|
||||
if (lastPartFound.get(0)) {
|
||||
throw new Exception(
|
||||
"Found closing boundary delimiter while trying to skip preamble");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public int readNext(InputStream is, byte[] buff, int patternLength,
|
||||
BitSet eof, long[] posVector, SharedInputStream sin)
|
||||
throws Exception {
|
||||
|
||||
int bufferLength = is.read(buffer, 0, patternLength);
|
||||
if (bufferLength == -1) {
|
||||
eof.flip(0);
|
||||
} else if (bufferLength < patternLength) {
|
||||
//repeatedly read patternLength - bufferLength
|
||||
int temp = 0;
|
||||
long pos = 0;
|
||||
int i = bufferLength;
|
||||
for (; i < patternLength; i++) {
|
||||
if (sin != null) {
|
||||
pos = sin.getPosition();
|
||||
}
|
||||
temp = is.read();
|
||||
if (temp == -1) {
|
||||
eof.flip(0);
|
||||
if (sin != null) {
|
||||
posVector[0] = pos;
|
||||
}
|
||||
break;
|
||||
}
|
||||
buffer[i] = (byte)temp;
|
||||
}
|
||||
bufferLength=i;
|
||||
}
|
||||
return bufferLength;
|
||||
}
|
||||
|
||||
public boolean find(InputStream is, byte[] pattern, SharedInputStream sin)
|
||||
throws Exception {
|
||||
int i;
|
||||
int l = pattern.length;
|
||||
int lx = l -1;
|
||||
int bufferLength = 0;
|
||||
BitSet eof = new BitSet(1);
|
||||
long[] posVector = new long[1];
|
||||
|
||||
while (true) {
|
||||
is.mark(l);
|
||||
bufferLength = readNext(is, buffer, l, eof, posVector, sin);
|
||||
if (eof.get(0)) {
|
||||
// End of stream
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
if (bufferLength < l) {
|
||||
//is.reset();
|
||||
return false;
|
||||
}*/
|
||||
|
||||
for(i = lx; i >= 0; i--) {
|
||||
if (buffer[i] != pattern[i]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i < 0) {
|
||||
// found the boundary, skip *LWSP-char and CRLF
|
||||
if (!skipLWSPAndCRLF(is)) {
|
||||
throw new Exception("Boundary does not terminate with CRLF");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int s = Math.max(i + 1 - bcs[buffer[i] & 0x7f], gss[i]);
|
||||
is.reset();
|
||||
is.skip(s);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean find(
|
||||
InputStream is, byte[] pattern, long[] posVector,
|
||||
ByteOutputStream out, SharedInputStream sin) throws Exception {
|
||||
int i;
|
||||
int l = pattern.length;
|
||||
int lx = l -1;
|
||||
int bufferLength = 0;
|
||||
int s = 0;
|
||||
long endPos = -1;
|
||||
byte[] tmp = null;
|
||||
|
||||
boolean first = true;
|
||||
BitSet eof = new BitSet(1);
|
||||
|
||||
while (true) {
|
||||
is.mark(l);
|
||||
if (!first) {
|
||||
tmp = prevBuffer;
|
||||
prevBuffer = buffer;
|
||||
buffer = tmp;
|
||||
}
|
||||
if (sin != null) {
|
||||
endPos = sin.getPosition();
|
||||
}
|
||||
|
||||
bufferLength = readNext(is, buffer, l, eof, posVector, sin);
|
||||
|
||||
if (bufferLength == -1) {
|
||||
// End of stream
|
||||
// looks like it is allowed to not have a closing boundary
|
||||
//return false;
|
||||
//if (sin != null) {
|
||||
// posVector[0] = endPos;
|
||||
//}
|
||||
b = -1;
|
||||
if ((s == l) && (sin == null)) {
|
||||
out.write(prevBuffer, 0, s);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (bufferLength < l) {
|
||||
if (sin != null) {
|
||||
//endPos = sin.getPosition();
|
||||
//posVector[0] = endPos;
|
||||
} else {
|
||||
// looks like it is allowed to not have a closing boundary
|
||||
// in the old implementation
|
||||
out.write(buffer, 0, bufferLength);
|
||||
}
|
||||
// looks like it is allowed to not have a closing boundary
|
||||
// in the old implementation
|
||||
//return false;
|
||||
b = -1;
|
||||
return true;
|
||||
}
|
||||
|
||||
for(i = lx; i >= 0; i--) {
|
||||
if (buffer[i] != pattern[i]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i < 0) {
|
||||
if (s > 0) {
|
||||
//looks like the earlier impl allowed just an LF
|
||||
// so if s == 1 : it must be an LF
|
||||
// if s == 2 : it must be a CR LF
|
||||
if (s <= 2) {
|
||||
//it could be "some-char\n" so write some-char
|
||||
if (s == 2) {
|
||||
if (prevBuffer[1] == '\n') {
|
||||
if (prevBuffer[0] != '\r' && prevBuffer[0] != '\n') {
|
||||
out.write(prevBuffer,0,1);
|
||||
}
|
||||
if (sin != null) {
|
||||
posVector[0] = endPos;
|
||||
}
|
||||
|
||||
} else {
|
||||
throw new Exception(
|
||||
"Boundary characters encountered in part Body " +
|
||||
"without a preceeding CRLF");
|
||||
}
|
||||
|
||||
} else if (s==1) {
|
||||
if (prevBuffer[0] != '\n') {
|
||||
throw new Exception(
|
||||
"Boundary characters encountered in part Body " +
|
||||
"without a preceeding CRLF");
|
||||
}else {
|
||||
if (sin != null) {
|
||||
posVector[0] = endPos;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else if (s > 2) {
|
||||
if ((prevBuffer[s-2] == '\r') && (prevBuffer[s-1] == '\n')) {
|
||||
if (sin != null) {
|
||||
posVector[0] = endPos - 2;
|
||||
} else {
|
||||
out.write(prevBuffer, 0, s - 2);
|
||||
}
|
||||
} else if (prevBuffer[s-1] == '\n') {
|
||||
//old impl allowed just a \n
|
||||
if (sin != null) {
|
||||
posVector[0] = endPos - 1;
|
||||
} else {
|
||||
out.write(prevBuffer, 0, s - 1);
|
||||
}
|
||||
} else {
|
||||
throw new Exception(
|
||||
"Boundary characters encountered in part Body " +
|
||||
"without a preceeding CRLF");
|
||||
}
|
||||
}
|
||||
}
|
||||
// found the boundary, skip *LWSP-char and CRLF
|
||||
if (!skipLWSPAndCRLF(is)) {
|
||||
//throw new Exception(
|
||||
// "Boundary does not terminate with CRLF");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((s > 0) && (sin == null)) {
|
||||
if (prevBuffer[s-1] == (byte)13) {
|
||||
// if buffer[0] == (byte)10
|
||||
if (buffer[0] == (byte)10) {
|
||||
int j=lx-1;
|
||||
for(j = lx-1; j > 0; j--) {
|
||||
if (buffer[j+1] != pattern[j]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j == 0) {
|
||||
// matched the pattern excluding the last char of the pattern
|
||||
// so dont write the CR into stream
|
||||
out.write(prevBuffer,0,s-1);
|
||||
} else {
|
||||
out.write(prevBuffer,0,s);
|
||||
}
|
||||
} else {
|
||||
out.write(prevBuffer, 0, s);
|
||||
}
|
||||
} else {
|
||||
out.write(prevBuffer, 0, s);
|
||||
}
|
||||
}
|
||||
|
||||
s = Math.max(i + 1 - bcs[buffer[i] & 0x7f], gss[i]);
|
||||
is.reset();
|
||||
is.skip(s);
|
||||
if (first) {
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean skipLWSPAndCRLF(InputStream is) throws Exception {
|
||||
|
||||
b = is.read();
|
||||
//looks like old impl allowed just a \n as well
|
||||
if (b == '\n') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (b == '\r') {
|
||||
b = is.read();
|
||||
//skip any multiple '\r' "\r\n" --> "\r\r\n" on Win2k
|
||||
if (b == '\r') {
|
||||
b = is.read();
|
||||
}
|
||||
if (b == '\n') {
|
||||
return true;
|
||||
} else {
|
||||
throw new Exception(
|
||||
"transport padding after a Mime Boundary should end in a CRLF, found CR only");
|
||||
}
|
||||
}
|
||||
|
||||
if (b == '-') {
|
||||
b = is.read();
|
||||
if (b != '-') {
|
||||
throw new Exception(
|
||||
"Unexpected singular '-' character after Mime Boundary");
|
||||
} else {
|
||||
//System.out.println("Last Part Found");
|
||||
lastPartFound.flip(0);
|
||||
// read the next char
|
||||
b = is.read();
|
||||
}
|
||||
}
|
||||
|
||||
while ((b != -1) && ((b == ' ') || (b == '\t'))) {
|
||||
b = is.read();
|
||||
if (b == '\n') {
|
||||
return true;
|
||||
}
|
||||
if (b == '\r') {
|
||||
b = is.read();
|
||||
//skip any multiple '\r': "\r\n" --> "\r\r\n" on Win2k
|
||||
if (b == '\r') {
|
||||
b = is.read();
|
||||
}
|
||||
if (b == '\n') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (b == -1) {
|
||||
// the last boundary need not have CRLF
|
||||
if (!lastPartFound.get(0)) {
|
||||
throw new Exception(
|
||||
"End of Multipart Stream before encountering closing boundary delimiter");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void compile(byte[] pattern) {
|
||||
int l = pattern.length;
|
||||
|
||||
int i;
|
||||
int j;
|
||||
|
||||
// Copied from J2SE 1.4 regex code
|
||||
// java.util.regex.Pattern.java
|
||||
|
||||
// Initialise Bad Character Shift table
|
||||
for (i = 0; i < l; i++) {
|
||||
bcs[pattern[i]] = i + 1;
|
||||
}
|
||||
|
||||
// Initialise Good Suffix Shift table
|
||||
gss = new int[l];
|
||||
NEXT: for (i = l; i > 0; i--) {
|
||||
// j is the beginning index of suffix being considered
|
||||
for (j = l - 1; j >= i; j--) {
|
||||
// Testing for good suffix
|
||||
if (pattern[j] == pattern[j - i]) {
|
||||
// pattern[j..len] is a good suffix
|
||||
gss[j - 1] = i;
|
||||
} else {
|
||||
// No match. The array has already been
|
||||
// filled up with correct values before.
|
||||
continue NEXT;
|
||||
}
|
||||
}
|
||||
while (j > 0) {
|
||||
gss[--j] = i;
|
||||
}
|
||||
}
|
||||
gss[l - 1] = 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Iterates through all the parts and outputs each Mime part
|
||||
* separated by a boundary.
|
||||
*/
|
||||
byte[] buf = new byte[1024];
|
||||
|
||||
public void writeTo(OutputStream os)
|
||||
throws IOException, MessagingException {
|
||||
|
||||
// inputStream was not null
|
||||
if (in != null) {
|
||||
contentType.setParameter("boundary", this.boundary);
|
||||
}
|
||||
|
||||
String bnd = "--" + contentType.getParameter("boundary");
|
||||
for (int i = 0; i < parts.size(); i++) {
|
||||
OutputUtil.writeln(bnd, os); // put out boundary
|
||||
((MimeBodyPart)parts.get(i)).writeTo(os);
|
||||
OutputUtil.writeln(os); // put out empty line
|
||||
}
|
||||
|
||||
if (in != null) {
|
||||
OutputUtil.writeln(bnd, os); // put out boundary
|
||||
if ((os instanceof ByteOutputStream) && lazyAttachments) {
|
||||
((ByteOutputStream)os).write(in);
|
||||
} else {
|
||||
ByteOutputStream baos = new ByteOutputStream(in.available());
|
||||
baos.write(in);
|
||||
baos.writeTo(os);
|
||||
// reset the inputstream so that we can support a
|
||||
//getAttachment later
|
||||
in = baos.newInputStream();
|
||||
}
|
||||
|
||||
// this will endup writing the end boundary
|
||||
} else {
|
||||
// put out last boundary
|
||||
OutputUtil.writeAsAscii(bnd, os);
|
||||
OutputUtil.writeAsAscii("--", os);
|
||||
}
|
||||
}
|
||||
|
||||
public void setInputStream(InputStream is) {
|
||||
this.in = is;
|
||||
}
|
||||
|
||||
public InputStream getInputStream() {
|
||||
return this.in;
|
||||
}
|
||||
|
||||
public void setBoundary(String bnd) {
|
||||
this.boundary = bnd;
|
||||
if (this.contentType != null) {
|
||||
this.contentType.setParameter("boundary", bnd);
|
||||
}
|
||||
}
|
||||
public String getBoundary() {
|
||||
return this.boundary;
|
||||
}
|
||||
|
||||
public boolean isEndOfStream() {
|
||||
return (b == -1);
|
||||
}
|
||||
|
||||
public void setLazyAttachments(boolean flag) {
|
||||
lazyAttachments = flag;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)ContentDisposition.java 1.6 02/03/27
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.packaging.mime.internet;
|
||||
|
||||
|
||||
/**
|
||||
* This class represents a MIME ContentDisposition value. It provides
|
||||
* methods to parse a ContentDisposition string into individual components
|
||||
* and to generate a MIME style ContentDisposition string.
|
||||
*
|
||||
* @version 1.6, 02/03/27
|
||||
* @author John Mani
|
||||
*/
|
||||
|
||||
public class ContentDisposition {
|
||||
|
||||
private String disposition; // disposition
|
||||
private ParameterList list; // parameter list
|
||||
|
||||
/**
|
||||
* No-arg Constructor.
|
||||
*/
|
||||
public ContentDisposition() { }
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param disposition disposition
|
||||
* @param list ParameterList
|
||||
* @since JavaMail 1.2
|
||||
*/
|
||||
public ContentDisposition(String disposition, ParameterList list) {
|
||||
this.disposition = disposition;
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor that takes a ContentDisposition string. The String
|
||||
* is parsed into its constituents: dispostion and parameters.
|
||||
* A ParseException is thrown if the parse fails.
|
||||
*
|
||||
* @param s the ContentDisposition string.
|
||||
* @exception ParseException if the parse fails.
|
||||
* @since JavaMail 1.2
|
||||
*/
|
||||
public ContentDisposition(String s) throws ParseException {
|
||||
HeaderTokenizer h = new HeaderTokenizer(s, HeaderTokenizer.MIME);
|
||||
HeaderTokenizer.Token tk;
|
||||
|
||||
// First "disposition" ..
|
||||
tk = h.next();
|
||||
if (tk.getType() != HeaderTokenizer.Token.ATOM)
|
||||
throw new ParseException();
|
||||
disposition = tk.getValue();
|
||||
|
||||
// Then parameters ..
|
||||
String rem = h.getRemainder();
|
||||
if (rem != null)
|
||||
list = new ParameterList(rem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the disposition value.
|
||||
* @return the disposition
|
||||
* @since JavaMail 1.2
|
||||
*/
|
||||
public String getDisposition() {
|
||||
return disposition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the specified parameter value. Returns <code>null</code>
|
||||
* if this parameter is absent.
|
||||
* @return parameter value
|
||||
* @since JavaMail 1.2
|
||||
*/
|
||||
public String getParameter(String name) {
|
||||
if (list == null)
|
||||
return null;
|
||||
|
||||
return list.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a ParameterList object that holds all the available
|
||||
* parameters. Returns null if no parameters are available.
|
||||
*
|
||||
* @return ParameterList
|
||||
* @since JavaMail 1.2
|
||||
*/
|
||||
public ParameterList getParameterList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the primary type. Overrides existing primary type.
|
||||
* @param primaryType primary type
|
||||
* @since JavaMail 1.2
|
||||
*/
|
||||
public void setDisposition(String disposition) {
|
||||
this.disposition = disposition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the specified parameter. If this parameter already exists,
|
||||
* it is replaced by this new value.
|
||||
*
|
||||
* @param name parameter name
|
||||
* @param value parameter value
|
||||
* @since JavaMail 1.2
|
||||
*/
|
||||
public void setParameter(String name, String value) {
|
||||
if (list == null)
|
||||
list = new ParameterList();
|
||||
|
||||
list.set(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a new ParameterList.
|
||||
* @param list ParameterList
|
||||
* @since JavaMail 1.2
|
||||
*/
|
||||
public void setParameterList(ParameterList list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a RFC2045 style string representation of
|
||||
* this ContentDisposition. Returns <code>null</code> if
|
||||
* the conversion failed.
|
||||
*
|
||||
* @return RFC2045 style string
|
||||
* @since JavaMail 1.2
|
||||
*/
|
||||
public String toString() {
|
||||
if (disposition == null)
|
||||
return null;
|
||||
|
||||
if (list == null)
|
||||
return disposition;
|
||||
|
||||
StringBuffer sb = new StringBuffer(disposition);
|
||||
|
||||
// append the parameter list
|
||||
// use the length of the string buffer + the length of
|
||||
// the header name formatted as follows "Content-Disposition: "
|
||||
sb.append(list.toString(sb.length() + 21));
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)ContentType.java 1.7 02/03/27
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.packaging.mime.internet;
|
||||
|
||||
|
||||
/**
|
||||
* This class represents a MIME ContentType value. It provides
|
||||
* methods to parse a ContentType string into individual components
|
||||
* and to generate a MIME style ContentType string.
|
||||
*
|
||||
* @version 1.7, 02/03/27
|
||||
* @author John Mani
|
||||
*/
|
||||
public final class ContentType {
|
||||
|
||||
private String primaryType; // primary type
|
||||
private String subType; // subtype
|
||||
private ParameterList list; // parameter list
|
||||
|
||||
/**
|
||||
* No-arg Constructor.
|
||||
*/
|
||||
public ContentType() { }
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param primaryType primary type
|
||||
* @param subType subType
|
||||
* @param list ParameterList
|
||||
*/
|
||||
public ContentType(String primaryType, String subType,
|
||||
ParameterList list) {
|
||||
this.primaryType = primaryType;
|
||||
this.subType = subType;
|
||||
if (list == null)
|
||||
list = new ParameterList();
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor that takes a Content-Type string. The String
|
||||
* is parsed into its constituents: primaryType, subType
|
||||
* and parameters. A ParseException is thrown if the parse fails.
|
||||
*
|
||||
* @param s the Content-Type string.
|
||||
* @exception ParseException if the parse fails.
|
||||
*/
|
||||
public ContentType(String s) throws ParseException {
|
||||
HeaderTokenizer h = new HeaderTokenizer(s, HeaderTokenizer.MIME);
|
||||
HeaderTokenizer.Token tk;
|
||||
|
||||
// First "type" ..
|
||||
tk = h.next();
|
||||
if (tk.getType() != HeaderTokenizer.Token.ATOM)
|
||||
throw new ParseException();
|
||||
primaryType = tk.getValue();
|
||||
|
||||
// The '/' separator ..
|
||||
tk = h.next();
|
||||
if ((char)tk.getType() != '/')
|
||||
throw new ParseException();
|
||||
|
||||
// Then "subType" ..
|
||||
tk = h.next();
|
||||
if (tk.getType() != HeaderTokenizer.Token.ATOM)
|
||||
throw new ParseException();
|
||||
subType = tk.getValue();
|
||||
|
||||
// Finally parameters ..
|
||||
String rem = h.getRemainder();
|
||||
if (rem != null)
|
||||
list = new ParameterList(rem);
|
||||
}
|
||||
|
||||
public ContentType copy() {
|
||||
return new ContentType(primaryType,subType,list.copy());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the primary type.
|
||||
* @return the primary type
|
||||
*/
|
||||
public String getPrimaryType() {
|
||||
return primaryType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the subType.
|
||||
* @return the subType
|
||||
*/
|
||||
public String getSubType() {
|
||||
return subType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the MIME type string, without the parameters.
|
||||
* The returned value is basically the concatenation of
|
||||
* the primaryType, the '/' character and the secondaryType.
|
||||
*
|
||||
* @return the type
|
||||
*/
|
||||
public String getBaseType() {
|
||||
return primaryType + '/' + subType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the specified parameter value. Returns <code>null</code>
|
||||
* if this parameter is absent.
|
||||
* @return parameter value
|
||||
*/
|
||||
public String getParameter(String name) {
|
||||
if (list == null)
|
||||
return null;
|
||||
|
||||
return list.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a ParameterList object that holds all the available
|
||||
* parameters. Returns null if no parameters are available.
|
||||
*
|
||||
* @return ParameterList
|
||||
*/
|
||||
public ParameterList getParameterList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the primary type. Overrides existing primary type.
|
||||
* @param primaryType primary type
|
||||
*/
|
||||
public void setPrimaryType(String primaryType) {
|
||||
this.primaryType = primaryType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the subType. Overrides existing subType
|
||||
* @param subType subType
|
||||
*/
|
||||
public void setSubType(String subType) {
|
||||
this.subType = subType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the specified parameter. If this parameter already exists,
|
||||
* it is replaced by this new value.
|
||||
*
|
||||
* @param name parameter name
|
||||
* @param value parameter value
|
||||
*/
|
||||
public void setParameter(String name, String value) {
|
||||
if (list == null)
|
||||
list = new ParameterList();
|
||||
|
||||
list.set(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a new ParameterList.
|
||||
* @param list ParameterList
|
||||
*/
|
||||
public void setParameterList(ParameterList list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a RFC2045 style string representation of
|
||||
* this Content-Type. Returns <code>null</code> if
|
||||
* the conversion failed.
|
||||
*
|
||||
* @return RFC2045 style string
|
||||
*/
|
||||
public String toString() {
|
||||
if (primaryType == null || subType == null) // need both
|
||||
return null;
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(primaryType).append('/').append(subType);
|
||||
if (list != null)
|
||||
// Http Binding section of the "SOAP with attachments" specification says,
|
||||
// "SOAP message senders should send Content-Type headers on a single long line."
|
||||
// (http://www.w3.org/TR/SOAP-attachments#HTTPBinding)
|
||||
sb.append(list.toString());
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Match with the specified ContentType object. This method
|
||||
* compares <strong>only the <code>primaryType</code> and
|
||||
* <code>subType</code> </strong>. The parameters of both operands
|
||||
* are ignored. <p>
|
||||
*
|
||||
* For example, this method will return <code>true</code> when
|
||||
* comparing the ContentTypes for <strong>"text/plain"</strong>
|
||||
* and <strong>"text/plain; charset=foobar"</strong>.
|
||||
*
|
||||
* If the <code>subType</code> of either operand is the special
|
||||
* character '*', then the subtype is ignored during the match.
|
||||
* For example, this method will return <code>true</code> when
|
||||
* comparing the ContentTypes for <strong>"text/plain"</strong>
|
||||
* and <strong>"text/*" </strong>
|
||||
*
|
||||
* @param cType to compare this against
|
||||
*/
|
||||
public boolean match(ContentType cType) {
|
||||
// Match primaryType
|
||||
if (!primaryType.equalsIgnoreCase(cType.getPrimaryType()))
|
||||
return false;
|
||||
|
||||
String sType = cType.getSubType();
|
||||
|
||||
// If either one of the subTypes is wildcarded, return true
|
||||
if ((subType.charAt(0) == '*') || (sType.charAt(0) == '*'))
|
||||
return true;
|
||||
|
||||
// Match subType
|
||||
if (!subType.equalsIgnoreCase(sType))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Match with the specified content-type string. This method
|
||||
* compares <strong>only the <code>primaryType</code> and
|
||||
* <code>subType</code> </strong>.
|
||||
* The parameters of both operands are ignored. <p>
|
||||
*
|
||||
* For example, this method will return <code>true</code> when
|
||||
* comparing the ContentType for <strong>"text/plain"</strong>
|
||||
* with <strong>"text/plain; charset=foobar"</strong>.
|
||||
*
|
||||
* If the <code>subType</code> of either operand is the special
|
||||
* character '*', then the subtype is ignored during the match.
|
||||
* For example, this method will return <code>true</code> when
|
||||
* comparing the ContentType for <strong>"text/plain"</strong>
|
||||
* with <strong>"text/*" </strong>
|
||||
*/
|
||||
public boolean match(String s) {
|
||||
try {
|
||||
return match(new ContentType(s));
|
||||
} catch (ParseException pex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,382 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)HeaderTokenizer.java 1.9 02/03/27
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.packaging.mime.internet;
|
||||
|
||||
|
||||
/**
|
||||
* This class tokenizes RFC822 and MIME headers into the basic
|
||||
* symbols specified by RFC822 and MIME. <p>
|
||||
*
|
||||
* This class handles folded headers (ie headers with embedded
|
||||
* CRLF SPACE sequences). The folds are removed in the returned
|
||||
* tokens.
|
||||
*
|
||||
* @version 1.9, 02/03/27
|
||||
* @author John Mani
|
||||
*/
|
||||
|
||||
public class HeaderTokenizer {
|
||||
|
||||
/**
|
||||
* The Token class represents tokens returned by the
|
||||
* HeaderTokenizer.
|
||||
*/
|
||||
public static class Token {
|
||||
|
||||
private int type;
|
||||
private String value;
|
||||
|
||||
/**
|
||||
* Token type indicating an ATOM.
|
||||
*/
|
||||
public static final int ATOM = -1;
|
||||
|
||||
/**
|
||||
* Token type indicating a quoted string. The value
|
||||
* field contains the string without the quotes.
|
||||
*/
|
||||
public static final int QUOTEDSTRING = -2;
|
||||
|
||||
/**
|
||||
* Token type indicating a comment. The value field
|
||||
* contains the comment string without the comment
|
||||
* start and end symbols.
|
||||
*/
|
||||
public static final int COMMENT = -3;
|
||||
|
||||
/**
|
||||
* Token type indicating end of input.
|
||||
*/
|
||||
public static final int EOF = -4;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param type Token type
|
||||
* @param value Token value
|
||||
*/
|
||||
public Token(int type, String value) {
|
||||
this.type = type;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type of the token. If the token represents a
|
||||
* delimiter or a control character, the type is that character
|
||||
* itself, converted to an integer. Otherwise, it's value is
|
||||
* one of the following:
|
||||
* <ul>
|
||||
* <li><code>ATOM</code> A sequence of ASCII characters
|
||||
* delimited by either SPACE, CTL, "(", <"> or the
|
||||
* specified SPECIALS
|
||||
* <li><code>QUOTEDSTRING</code> A sequence of ASCII characters
|
||||
* within quotes
|
||||
* <li><code>COMMENT</code> A sequence of ASCII characters
|
||||
* within "(" and ")".
|
||||
* <li><code>EOF</code> End of header
|
||||
* </ul>
|
||||
*/
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the token just read. When the current
|
||||
* token is a quoted string, this field contains the body of the
|
||||
* string, without the quotes. When the current token is a comment,
|
||||
* this field contains the body of the comment.
|
||||
*
|
||||
* @return token value
|
||||
*/
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
private String string; // the string to be tokenized
|
||||
private boolean skipComments; // should comments be skipped ?
|
||||
private String delimiters; // delimiter string
|
||||
private int currentPos; // current parse position
|
||||
private int maxPos; // string length
|
||||
private int nextPos; // track start of next Token for next()
|
||||
private int peekPos; // track start of next Token for peek()
|
||||
|
||||
/**
|
||||
* RFC822 specials
|
||||
*/
|
||||
public final static String RFC822 = "()<>@,;:\\\"\t .[]";
|
||||
|
||||
/**
|
||||
* MIME specials
|
||||
*/
|
||||
public final static String MIME = "()<>@,;:\\\"\t []/?=";
|
||||
|
||||
// The EOF Token
|
||||
private final static Token EOFToken = new Token(Token.EOF, null);
|
||||
|
||||
/**
|
||||
* Constructor that takes a rfc822 style header.
|
||||
*
|
||||
* @param header The rfc822 header to be tokenized
|
||||
* @param delimiters Set of delimiter characters
|
||||
* to be used to delimit ATOMS. These
|
||||
* are usually <code>RFC822</code> or
|
||||
* <code>MIME</code>
|
||||
* @param skipComments If true, comments are skipped and
|
||||
* not returned as tokens
|
||||
*/
|
||||
public HeaderTokenizer(String header, String delimiters,
|
||||
boolean skipComments) {
|
||||
string = (header == null) ? "" : header; // paranoia ?!
|
||||
this.skipComments = skipComments;
|
||||
this.delimiters = delimiters;
|
||||
currentPos = nextPos = peekPos = 0;
|
||||
maxPos = string.length();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor. Comments are ignored and not returned as tokens
|
||||
*
|
||||
* @param header The header that is tokenized
|
||||
* @param delimiters The delimiters to be used
|
||||
*/
|
||||
public HeaderTokenizer(String header, String delimiters) {
|
||||
this(header, delimiters, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor. The RFC822 defined delimiters - RFC822 - are
|
||||
* used to delimit ATOMS. Also comments are skipped and not
|
||||
* returned as tokens
|
||||
*/
|
||||
public HeaderTokenizer(String header) {
|
||||
this(header, RFC822);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the next token from this String. <p>
|
||||
*
|
||||
* Clients sit in a loop calling next() to parse successive
|
||||
* tokens until an EOF Token is returned.
|
||||
*
|
||||
* @return the next Token
|
||||
* @exception ParseException if the parse fails
|
||||
*/
|
||||
public Token next() throws ParseException {
|
||||
Token tk;
|
||||
|
||||
currentPos = nextPos; // setup currentPos
|
||||
tk = getNext();
|
||||
nextPos = peekPos = currentPos; // update currentPos and peekPos
|
||||
return tk;
|
||||
}
|
||||
|
||||
/**
|
||||
* Peek at the next token, without actually removing the token
|
||||
* from the parse stream. Invoking this method multiple times
|
||||
* will return successive tokens, until <code>next()</code> is
|
||||
* called. <p>
|
||||
*
|
||||
* @return the next Token
|
||||
* @exception ParseException if the parse fails
|
||||
*/
|
||||
public Token peek() throws ParseException {
|
||||
Token tk;
|
||||
|
||||
currentPos = peekPos; // setup currentPos
|
||||
tk = getNext();
|
||||
peekPos = currentPos; // update peekPos
|
||||
return tk;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the rest of the Header.
|
||||
*
|
||||
* @return String rest of header. null is returned if we are
|
||||
* already at end of header
|
||||
*/
|
||||
public String getRemainder() {
|
||||
return string.substring(nextPos);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the next token starting from 'currentPos'. After the
|
||||
* parse, 'currentPos' is updated to point to the start of the
|
||||
* next token.
|
||||
*/
|
||||
private Token getNext() throws ParseException {
|
||||
// If we're already at end of string, return EOF
|
||||
if (currentPos >= maxPos)
|
||||
return EOFToken;
|
||||
|
||||
// Skip white-space, position currentPos beyond the space
|
||||
if (skipWhiteSpace() == Token.EOF)
|
||||
return EOFToken;
|
||||
|
||||
char c;
|
||||
int start;
|
||||
boolean filter = false;
|
||||
|
||||
c = string.charAt(currentPos);
|
||||
|
||||
// Check or Skip comments and position currentPos
|
||||
// beyond the comment
|
||||
while (c == '(') {
|
||||
// Parsing comment ..
|
||||
int nesting;
|
||||
for (start = ++currentPos, nesting = 1;
|
||||
nesting > 0 && currentPos < maxPos;
|
||||
currentPos++) {
|
||||
c = string.charAt(currentPos);
|
||||
if (c == '\\') { // Escape sequence
|
||||
currentPos++; // skip the escaped character
|
||||
filter = true;
|
||||
} else if (c == '\r')
|
||||
filter = true;
|
||||
else if (c == '(')
|
||||
nesting++;
|
||||
else if (c == ')')
|
||||
nesting--;
|
||||
}
|
||||
if (nesting != 0)
|
||||
throw new ParseException("Unbalanced comments");
|
||||
|
||||
if (!skipComments) {
|
||||
// Return the comment, if we are asked to.
|
||||
// Note that the comment start & end markers are ignored.
|
||||
String s;
|
||||
if (filter) // need to go thru the token again.
|
||||
s = filterToken(string, start, currentPos-1);
|
||||
else
|
||||
s = string.substring(start,currentPos-1);
|
||||
|
||||
return new Token(Token.COMMENT, s);
|
||||
}
|
||||
|
||||
// Skip any whitespace after the comment.
|
||||
if (skipWhiteSpace() == Token.EOF)
|
||||
return EOFToken;
|
||||
c = string.charAt(currentPos);
|
||||
}
|
||||
|
||||
// Check for quoted-string and position currentPos
|
||||
// beyond the terminating quote
|
||||
if (c == '"') {
|
||||
for (start = ++currentPos; currentPos < maxPos; currentPos++) {
|
||||
c = string.charAt(currentPos);
|
||||
if (c == '\\') { // Escape sequence
|
||||
currentPos++;
|
||||
filter = true;
|
||||
} else if (c == '\r')
|
||||
filter = true;
|
||||
else if (c == '"') {
|
||||
currentPos++;
|
||||
String s;
|
||||
|
||||
if (filter)
|
||||
s = filterToken(string, start, currentPos-1);
|
||||
else
|
||||
s = string.substring(start,currentPos-1);
|
||||
|
||||
return new Token(Token.QUOTEDSTRING, s);
|
||||
}
|
||||
}
|
||||
throw new ParseException("Unbalanced quoted string");
|
||||
}
|
||||
|
||||
// Check for SPECIAL or CTL
|
||||
if (c < 040 || c >= 0177 || delimiters.indexOf(c) >= 0) {
|
||||
currentPos++; // re-position currentPos
|
||||
char ch[] = new char[1];
|
||||
ch[0] = c;
|
||||
return new Token((int)c, new String(ch));
|
||||
}
|
||||
|
||||
// Check for ATOM
|
||||
for (start = currentPos; currentPos < maxPos; currentPos++) {
|
||||
c = string.charAt(currentPos);
|
||||
// ATOM is delimited by either SPACE, CTL, "(", <">
|
||||
// or the specified SPECIALS
|
||||
if (c < 040 || c >= 0177 || c == '(' || c == ' ' ||
|
||||
c == '"' || delimiters.indexOf(c) >= 0)
|
||||
break;
|
||||
}
|
||||
return new Token(Token.ATOM, string.substring(start, currentPos));
|
||||
}
|
||||
|
||||
// Skip SPACE, HT, CR and NL
|
||||
private int skipWhiteSpace() {
|
||||
char c;
|
||||
for (; currentPos < maxPos; currentPos++)
|
||||
if (((c = string.charAt(currentPos)) != ' ') &&
|
||||
(c != '\t') && (c != '\r') && (c != '\n'))
|
||||
return currentPos;
|
||||
return Token.EOF;
|
||||
}
|
||||
|
||||
/* Process escape sequences and embedded LWSPs from a comment or
|
||||
* quoted string.
|
||||
*/
|
||||
private static String filterToken(String s, int start, int end) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
char c;
|
||||
boolean gotEscape = false;
|
||||
boolean gotCR = false;
|
||||
|
||||
for (int i = start; i < end; i++) {
|
||||
c = s.charAt(i);
|
||||
if (c == '\n' && gotCR) {
|
||||
// This LF is part of an unescaped
|
||||
// CRLF sequence (i.e, LWSP). Skip it.
|
||||
gotCR = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
gotCR = false;
|
||||
if (!gotEscape) {
|
||||
// Previous character was NOT '\'
|
||||
if (c == '\\') // skip this character
|
||||
gotEscape = true;
|
||||
else if (c == '\r') // skip this character
|
||||
gotCR = true;
|
||||
else // append this character
|
||||
sb.append(c);
|
||||
} else {
|
||||
// Previous character was '\'. So no need to
|
||||
// bother with any special processing, just
|
||||
// append this character
|
||||
sb.append(c);
|
||||
gotEscape = false;
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,402 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)InternetHeaders.java 1.16 02/08/08
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.packaging.mime.internet;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.packaging.mime.Header;
|
||||
import com.sun.xml.internal.messaging.saaj.packaging.mime.MessagingException;
|
||||
import com.sun.xml.internal.messaging.saaj.packaging.mime.util.LineInputStream;
|
||||
import com.sun.xml.internal.messaging.saaj.util.FinalArrayList;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.AbstractList;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
* InternetHeaders is a utility class that manages RFC822 style
|
||||
* headers. Given an RFC822 format message stream, it reads lines
|
||||
* until the blank line that indicates end of header. The input stream
|
||||
* is positioned at the start of the body. The lines are stored
|
||||
* within the object and can be extracted as either Strings or
|
||||
* {@link Header} objects. <p>
|
||||
* <p/>
|
||||
* This class is mostly intended for service providers. MimeMessage
|
||||
* and MimeBody use this class for holding their headers. <p>
|
||||
* <p/>
|
||||
* <hr> <strong>A note on RFC822 and MIME headers</strong><p>
|
||||
* <p/>
|
||||
* RFC822 and MIME header fields <strong>must</strong> contain only
|
||||
* US-ASCII characters. If a header contains non US-ASCII characters,
|
||||
* it must be encoded as per the rules in RFC 2047. The MimeUtility
|
||||
* class provided in this package can be used to to achieve this.
|
||||
* Callers of the <code>setHeader</code>, <code>addHeader</code>, and
|
||||
* <code>addHeaderLine</code> methods are responsible for enforcing
|
||||
* the MIME requirements for the specified headers. In addition, these
|
||||
* header fields must be folded (wrapped) before being sent if they
|
||||
* exceed the line length limitation for the transport (1000 bytes for
|
||||
* SMTP). Received headers may have been folded. The application is
|
||||
* responsible for folding and unfolding headers as appropriate. <p>
|
||||
*
|
||||
* @author John Mani
|
||||
* @author Bill Shannon
|
||||
* @see MimeUtility
|
||||
*/
|
||||
public final class InternetHeaders {
|
||||
|
||||
private final FinalArrayList headers = new FinalArrayList();
|
||||
|
||||
/**
|
||||
* Lazily cerated view of header lines (Strings).
|
||||
*/
|
||||
private List headerValueView;
|
||||
|
||||
/**
|
||||
* Create an empty InternetHeaders object.
|
||||
*/
|
||||
public InternetHeaders() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Read and parse the given RFC822 message stream till the
|
||||
* blank line separating the header from the body. The input
|
||||
* stream is left positioned at the start of the body. The
|
||||
* header lines are stored internally. <p>
|
||||
* <p/>
|
||||
* For efficiency, wrap a BufferedInputStream around the actual
|
||||
* input stream and pass it as the parameter.
|
||||
*
|
||||
* @param is RFC822 input stream
|
||||
*/
|
||||
public InternetHeaders(InputStream is) throws MessagingException {
|
||||
load(is);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read and parse the given RFC822 message stream till the
|
||||
* blank line separating the header from the body. Store the
|
||||
* header lines inside this InternetHeaders object. <p>
|
||||
* <p/>
|
||||
* Note that the header lines are added into this InternetHeaders
|
||||
* object, so any existing headers in this object will not be
|
||||
* affected.
|
||||
*
|
||||
* @param is RFC822 input stream
|
||||
*/
|
||||
public void load(InputStream is) throws MessagingException {
|
||||
// Read header lines until a blank line. It is valid
|
||||
// to have BodyParts with no header lines.
|
||||
String line;
|
||||
LineInputStream lis = new LineInputStream(is);
|
||||
String prevline = null; // the previous header line, as a string
|
||||
// a buffer to accumulate the header in, when we know it's needed
|
||||
StringBuffer lineBuffer = new StringBuffer();
|
||||
|
||||
try {
|
||||
//while ((line = lis.readLine()) != null) {
|
||||
do {
|
||||
line = lis.readLine();
|
||||
if (line != null &&
|
||||
(line.startsWith(" ") || line.startsWith("\t"))) {
|
||||
// continuation of header
|
||||
if (prevline != null) {
|
||||
lineBuffer.append(prevline);
|
||||
prevline = null;
|
||||
}
|
||||
lineBuffer.append("\r\n");
|
||||
lineBuffer.append(line);
|
||||
} else {
|
||||
// new header
|
||||
if (prevline != null)
|
||||
addHeaderLine(prevline);
|
||||
else if (lineBuffer.length() > 0) {
|
||||
// store previous header first
|
||||
addHeaderLine(lineBuffer.toString());
|
||||
lineBuffer.setLength(0);
|
||||
}
|
||||
prevline = line;
|
||||
}
|
||||
} while (line != null && line.length() > 0);
|
||||
} catch (IOException ioex) {
|
||||
throw new MessagingException("Error in input stream", ioex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all the values for the specified header. The
|
||||
* values are String objects. Returns <code>null</code>
|
||||
* if no headers with the specified name exist.
|
||||
*
|
||||
* @param name header name
|
||||
* @return array of header values, or null if none
|
||||
*/
|
||||
public String[] getHeader(String name) {
|
||||
// XXX - should we just step through in index order?
|
||||
FinalArrayList v = new FinalArrayList(); // accumulate return values
|
||||
|
||||
int len = headers.size();
|
||||
for( int i=0; i<len; i++ ) {
|
||||
hdr h = (hdr) headers.get(i);
|
||||
if (name.equalsIgnoreCase(h.name)) {
|
||||
v.add(h.getValue());
|
||||
}
|
||||
}
|
||||
if (v.size() == 0)
|
||||
return (null);
|
||||
// convert Vector to an array for return
|
||||
return (String[]) v.toArray(new String[v.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the headers for this header name, returned as a single
|
||||
* String, with headers separated by the delimiter. If the
|
||||
* delimiter is <code>null</code>, only the first header is
|
||||
* returned. Returns <code>null</code>
|
||||
* if no headers with the specified name exist.
|
||||
*
|
||||
* @param delimiter delimiter
|
||||
* @return the value fields for all headers with
|
||||
* this name, or null if none
|
||||
* @param name header name
|
||||
*/
|
||||
public String getHeader(String name, String delimiter) {
|
||||
String[] s = getHeader(name);
|
||||
|
||||
if (s == null)
|
||||
return null;
|
||||
|
||||
if ((s.length == 1) || delimiter == null)
|
||||
return s[0];
|
||||
|
||||
StringBuffer r = new StringBuffer(s[0]);
|
||||
for (int i = 1; i < s.length; i++) {
|
||||
r.append(delimiter);
|
||||
r.append(s[i]);
|
||||
}
|
||||
return r.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the first header line that matches name
|
||||
* to have value, adding a new header if no existing header
|
||||
* matches. Remove all matching headers but the first. <p>
|
||||
* <p/>
|
||||
* Note that RFC822 headers can only contain US-ASCII characters
|
||||
*
|
||||
* @param name header name
|
||||
* @param value header value
|
||||
*/
|
||||
public void setHeader(String name, String value) {
|
||||
boolean found = false;
|
||||
|
||||
for (int i = 0; i < headers.size(); i++) {
|
||||
hdr h = (hdr) headers.get(i);
|
||||
if (name.equalsIgnoreCase(h.name)) {
|
||||
if (!found) {
|
||||
int j;
|
||||
if (h.line != null && (j = h.line.indexOf(':')) >= 0) {
|
||||
h.line = h.line.substring(0, j + 1) + " " + value;
|
||||
} else {
|
||||
h.line = name + ": " + value;
|
||||
}
|
||||
found = true;
|
||||
} else {
|
||||
headers.remove(i);
|
||||
i--; // have to look at i again
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
addHeader(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a header with the specified name and value to the header list. <p>
|
||||
* <p/>
|
||||
* Note that RFC822 headers can only contain US-ASCII characters.
|
||||
*
|
||||
* @param name header name
|
||||
* @param value header value
|
||||
*/
|
||||
public void addHeader(String name, String value) {
|
||||
int pos = headers.size();
|
||||
for (int i = headers.size() - 1; i >= 0; i--) {
|
||||
hdr h = (hdr) headers.get(i);
|
||||
if (name.equalsIgnoreCase(h.name)) {
|
||||
headers.add(i + 1, new hdr(name, value));
|
||||
return;
|
||||
}
|
||||
// marker for default place to add new headers
|
||||
if (h.name.equals(":"))
|
||||
pos = i;
|
||||
}
|
||||
headers.add(pos, new hdr(name, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all header entries that match the given name
|
||||
*
|
||||
* @param name header name
|
||||
*/
|
||||
public void removeHeader(String name) {
|
||||
for (int i = 0; i < headers.size(); i++) {
|
||||
hdr h = (hdr) headers.get(i);
|
||||
if (name.equalsIgnoreCase(h.name)) {
|
||||
headers.remove(i);
|
||||
i--; // have to look at i again
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all the headers as an Enumeration of
|
||||
* {@link Header} objects.
|
||||
*
|
||||
* @return Header objects
|
||||
*/
|
||||
public FinalArrayList getAllHeaders() {
|
||||
return headers; // conceptually it should be read-only, but for performance reason I'm not wrapping it here
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an RFC822 header line to the header store.
|
||||
* If the line starts with a space or tab (a continuation line),
|
||||
* add it to the last header line in the list. <p>
|
||||
* <p/>
|
||||
* Note that RFC822 headers can only contain US-ASCII characters
|
||||
*
|
||||
* @param line raw RFC822 header line
|
||||
*/
|
||||
public void addHeaderLine(String line) {
|
||||
try {
|
||||
char c = line.charAt(0);
|
||||
if (c == ' ' || c == '\t') {
|
||||
hdr h = (hdr) headers.get(headers.size() - 1);
|
||||
h.line += "\r\n" + line;
|
||||
} else
|
||||
headers.add(new hdr(line));
|
||||
} catch (StringIndexOutOfBoundsException e) {
|
||||
// line is empty, ignore it
|
||||
return;
|
||||
} catch (NoSuchElementException e) {
|
||||
// XXX - vector is empty?
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all the header lines as a collection
|
||||
*/
|
||||
public List getAllHeaderLines() {
|
||||
if(headerValueView==null)
|
||||
headerValueView = new AbstractList() {
|
||||
public Object get(int index) {
|
||||
return ((hdr)headers.get(index)).line;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return headers.size();
|
||||
}
|
||||
};
|
||||
return headerValueView;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* A private utility class to represent an individual header.
|
||||
*/
|
||||
|
||||
class hdr implements Header {
|
||||
// XXX - should these be private?
|
||||
String name; // the canonicalized (trimmed) name of this header
|
||||
// XXX - should name be stored in lower case?
|
||||
String line; // the entire RFC822 header "line"
|
||||
|
||||
/*
|
||||
* Constructor that takes a line and splits out
|
||||
* the header name.
|
||||
*/
|
||||
hdr(String l) {
|
||||
int i = l.indexOf(':');
|
||||
if (i < 0) {
|
||||
// should never happen
|
||||
name = l.trim();
|
||||
} else {
|
||||
name = l.substring(0, i).trim();
|
||||
}
|
||||
line = l;
|
||||
}
|
||||
|
||||
/*
|
||||
* Constructor that takes a header name and value.
|
||||
*/
|
||||
hdr(String n, String v) {
|
||||
name = n;
|
||||
line = n + ": " + v;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the "name" part of the header line.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the "value" part of the header line.
|
||||
*/
|
||||
public String getValue() {
|
||||
int i = line.indexOf(':');
|
||||
if (i < 0)
|
||||
return line;
|
||||
|
||||
int j;
|
||||
if (name.equalsIgnoreCase("Content-Description")) {
|
||||
// Content-Description should retain the folded whitespace after header unfolding -
|
||||
// rf. RFC2822 section 2.2.3, rf. RFC2822 section 3.2.3
|
||||
for (j = i + 1; j < line.length(); j++) {
|
||||
char c = line.charAt(j);
|
||||
if (!(/*c == ' ' ||*/c == '\t' || c == '\r' || c == '\n'))
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// skip whitespace after ':'
|
||||
for (j = i + 1; j < line.length(); j++) {
|
||||
char c = line.charAt(j);
|
||||
if (!(c == ' ' || c == '\t' || c == '\r' || c == '\n'))
|
||||
break;
|
||||
}
|
||||
}
|
||||
return line.substring(j);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,653 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)MimeMultipart.java 1.31 03/01/29
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.packaging.mime.internet;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import javax.activation.DataSource;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.packaging.mime.*;
|
||||
import com.sun.xml.internal.messaging.saaj.packaging.mime.util.*;
|
||||
import com.sun.xml.internal.messaging.saaj.util.FinalArrayList;
|
||||
import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream;
|
||||
import com.sun.xml.internal.messaging.saaj.util.SAAJUtil;
|
||||
|
||||
/**
|
||||
* The MimeMultipart class is an implementation
|
||||
* that uses MIME conventions for the multipart data. <p>
|
||||
*
|
||||
* A MimeMultipart is obtained from a MimeBodyPart whose primary type
|
||||
* is "multipart" (by invoking the part's <code>getContent()</code> method)
|
||||
* or it can be created by a client as part of creating a new MimeMessage. <p>
|
||||
*
|
||||
* The default multipart subtype is "mixed". The other multipart
|
||||
* subtypes, such as "alternative", "related", and so on, can be
|
||||
* implemented as subclasses of MimeMultipart with additional methods
|
||||
* to implement the additional semantics of that type of multipart
|
||||
* content. The intent is that service providers, mail JavaBean writers
|
||||
* and mail clients will write many such subclasses and their Command
|
||||
* Beans, and will install them into the JavaBeans Activation
|
||||
* Framework, so that any JavaMail implementation and its clients can
|
||||
* transparently find and use these classes. Thus, a MIME multipart
|
||||
* handler is treated just like any other type handler, thereby
|
||||
* decoupling the process of providing multipart handlers from the
|
||||
* JavaMail API. Lacking these additional MimeMultipart subclasses,
|
||||
* all subtypes of MIME multipart data appear as MimeMultipart objects. <p>
|
||||
*
|
||||
* An application can directly construct a MIME multipart object of any
|
||||
* subtype by using the <code>MimeMultipart(String subtype)</code>
|
||||
* constructor. For example, to create a "multipart/alternative" object,
|
||||
* use <code>new MimeMultipart("alternative")</code>.
|
||||
*
|
||||
* @version 1.31, 03/01/29
|
||||
* @author John Mani
|
||||
* @author Bill Shannon
|
||||
* @author Max Spivak
|
||||
*/
|
||||
|
||||
//BM MimeMultipart can extend this
|
||||
public class MimeMultipart {
|
||||
|
||||
/**
|
||||
* The DataSource supplying our InputStream.
|
||||
*/
|
||||
protected DataSource ds = null;
|
||||
|
||||
/**
|
||||
* Have we parsed the data from our InputStream yet?
|
||||
* Defaults to true; set to false when our constructor is
|
||||
* given a DataSource with an InputStream that we need to
|
||||
* parse.
|
||||
*/
|
||||
protected boolean parsed = true;
|
||||
|
||||
/**
|
||||
* Vector of MimeBodyPart objects.
|
||||
*/
|
||||
protected FinalArrayList parts = new FinalArrayList(); // Holds BodyParts
|
||||
|
||||
/**
|
||||
* This field specifies the content-type of this multipart
|
||||
* object. It defaults to "multipart/mixed".
|
||||
*/
|
||||
protected ContentType contentType;
|
||||
|
||||
/**
|
||||
* The <code>MimeBodyPart</code> containing this <code>MimeMultipart</code>,
|
||||
* if known.
|
||||
* @since JavaMail 1.1
|
||||
*/
|
||||
protected MimeBodyPart parent;
|
||||
|
||||
protected static final boolean ignoreMissingEndBoundary;
|
||||
static {
|
||||
ignoreMissingEndBoundary = SAAJUtil.getSystemBoolean("saaj.mime.multipart.ignoremissingendboundary");
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor. An empty MimeMultipart object
|
||||
* is created. Its content type is set to "multipart/mixed".
|
||||
* A unique boundary string is generated and this string is
|
||||
* setup as the "boundary" parameter for the
|
||||
* <code>contentType</code> field. <p>
|
||||
*
|
||||
* MimeBodyParts may be added later.
|
||||
*/
|
||||
public MimeMultipart() {
|
||||
this("mixed");
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a MimeMultipart object of the given subtype.
|
||||
* A unique boundary string is generated and this string is
|
||||
* setup as the "boundary" parameter for the
|
||||
* <code>contentType</code> field. <p>
|
||||
*
|
||||
* MimeBodyParts may be added later.
|
||||
*/
|
||||
public MimeMultipart(String subtype) {
|
||||
//super();
|
||||
/*
|
||||
* Compute a boundary string.
|
||||
*/
|
||||
String boundary = UniqueValue.getUniqueBoundaryValue();
|
||||
contentType = new ContentType("multipart", subtype, null);
|
||||
contentType.setParameter("boundary", boundary);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a MimeMultipart object and its bodyparts from the
|
||||
* given DataSource. <p>
|
||||
*
|
||||
* This constructor handles as a special case the situation where the
|
||||
* given DataSource is a MultipartDataSource object.
|
||||
*
|
||||
* Otherwise, the DataSource is assumed to provide a MIME multipart
|
||||
* byte stream. The <code>parsed</code> flag is set to false. When
|
||||
* the data for the body parts are needed, the parser extracts the
|
||||
* "boundary" parameter from the content type of this DataSource,
|
||||
* skips the 'preamble' and reads bytes till the terminating
|
||||
* boundary and creates MimeBodyParts for each part of the stream.
|
||||
*
|
||||
* @param ds DataSource, can be a MultipartDataSource
|
||||
* @param ct
|
||||
* This must be the same information as {@link DataSource#getContentType()}.
|
||||
* All the callers of this method seem to have this object handy, so
|
||||
* for performance reason this method accepts it. Can be null.
|
||||
*/
|
||||
public MimeMultipart(DataSource ds, ContentType ct) throws MessagingException {
|
||||
// 'ds' was not a MultipartDataSource, we have
|
||||
// to parse this ourself.
|
||||
parsed = false;
|
||||
this.ds = ds;
|
||||
if (ct==null)
|
||||
contentType = new ContentType(ds.getContentType());
|
||||
else
|
||||
contentType = ct;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the subtype. This method should be invoked only on a new
|
||||
* MimeMultipart object created by the client. The default subtype
|
||||
* of such a multipart object is "mixed". <p>
|
||||
*
|
||||
* @param subtype Subtype
|
||||
*/
|
||||
public void setSubType(String subtype) {
|
||||
contentType.setSubType(subtype);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of enclosed MimeBodyPart objects.
|
||||
*
|
||||
* @return number of parts
|
||||
*/
|
||||
public int getCount() throws MessagingException {
|
||||
parse();
|
||||
if (parts == null)
|
||||
return 0;
|
||||
|
||||
return parts.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the specified MimeBodyPart. BodyParts are numbered starting at 0.
|
||||
*
|
||||
* @param index the index of the desired MimeBodyPart
|
||||
* @return the MimeBodyPart
|
||||
* @exception MessagingException if no such MimeBodyPart exists
|
||||
*/
|
||||
public MimeBodyPart getBodyPart(int index)
|
||||
throws MessagingException {
|
||||
parse();
|
||||
if (parts == null)
|
||||
throw new IndexOutOfBoundsException("No such BodyPart");
|
||||
|
||||
return (MimeBodyPart)parts.get(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the MimeBodyPart referred to by the given ContentID (CID).
|
||||
* Returns null if the part is not found.
|
||||
*
|
||||
* @param CID the ContentID of the desired part
|
||||
* @return the MimeBodyPart
|
||||
*/
|
||||
public MimeBodyPart getBodyPart(String CID)
|
||||
throws MessagingException {
|
||||
parse();
|
||||
|
||||
int count = getCount();
|
||||
for (int i = 0; i < count; i++) {
|
||||
MimeBodyPart part = getBodyPart(i);
|
||||
String s = part.getContentID();
|
||||
// Old versions of AXIS2 put angle brackets around the content
|
||||
// id but not the start param
|
||||
String sNoAngle = (s!= null) ? s.replaceFirst("^<", "").replaceFirst(">$", "")
|
||||
:null;
|
||||
if (s != null && (s.equals(CID) || CID.equals(sNoAngle)))
|
||||
return part;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update headers. The default implementation here just
|
||||
* calls the <code>updateHeaders</code> method on each of its
|
||||
* children BodyParts. <p>
|
||||
*
|
||||
* Note that the boundary parameter is already set up when
|
||||
* a new and empty MimeMultipart object is created. <p>
|
||||
*
|
||||
* This method is called when the <code>saveChanges</code>
|
||||
* method is invoked on the Message object containing this
|
||||
* MimeMultipart. This is typically done as part of the Message
|
||||
* send process, however note that a client is free to call
|
||||
* it any number of times. So if the header updating process is
|
||||
* expensive for a specific MimeMultipart subclass, then it
|
||||
* might itself want to track whether its internal state actually
|
||||
* did change, and do the header updating only if necessary.
|
||||
*/
|
||||
protected void updateHeaders() throws MessagingException {
|
||||
for (int i = 0; i < parts.size(); i++)
|
||||
((MimeBodyPart)parts.get(i)).updateHeaders();
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates through all the parts and outputs each Mime part
|
||||
* separated by a boundary.
|
||||
*/
|
||||
public void writeTo(OutputStream os)
|
||||
throws IOException, MessagingException {
|
||||
parse();
|
||||
|
||||
String boundary = "--" + contentType.getParameter("boundary");
|
||||
|
||||
for (int i = 0; i < parts.size(); i++) {
|
||||
OutputUtil.writeln(boundary, os); // put out boundary
|
||||
getBodyPart(i).writeTo(os);
|
||||
OutputUtil.writeln(os); // put out empty line
|
||||
}
|
||||
|
||||
// put out last boundary
|
||||
OutputUtil.writeAsAscii(boundary, os);
|
||||
OutputUtil.writeAsAscii("--", os);
|
||||
os.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the InputStream from our DataSource, constructing the
|
||||
* appropriate MimeBodyParts. The <code>parsed</code> flag is
|
||||
* set to true, and if true on entry nothing is done. This
|
||||
* method is called by all other methods that need data for
|
||||
* the body parts, to make sure the data has been parsed.
|
||||
*
|
||||
* @since JavaMail 1.2
|
||||
*/
|
||||
protected void parse() throws MessagingException {
|
||||
if (parsed)
|
||||
return;
|
||||
|
||||
InputStream in;
|
||||
SharedInputStream sin = null;
|
||||
long start = 0, end = 0;
|
||||
boolean foundClosingBoundary = false;
|
||||
|
||||
try {
|
||||
in = ds.getInputStream();
|
||||
if (!(in instanceof ByteArrayInputStream) &&
|
||||
!(in instanceof BufferedInputStream) &&
|
||||
!(in instanceof SharedInputStream))
|
||||
in = new BufferedInputStream(in);
|
||||
} catch (Exception ex) {
|
||||
throw new MessagingException("No inputstream from datasource");
|
||||
}
|
||||
if (in instanceof SharedInputStream)
|
||||
sin = (SharedInputStream)in;
|
||||
|
||||
String boundary = "--" + contentType.getParameter("boundary");
|
||||
byte[] bndbytes = ASCIIUtility.getBytes(boundary);
|
||||
int bl = bndbytes.length;
|
||||
|
||||
try {
|
||||
// Skip the preamble
|
||||
LineInputStream lin = new LineInputStream(in);
|
||||
String line;
|
||||
while ((line = lin.readLine()) != null) {
|
||||
/*
|
||||
* Strip trailing whitespace. Can't use trim method
|
||||
* because it's too aggressive. Some bogus MIME
|
||||
* messages will include control characters in the
|
||||
* boundary string.
|
||||
*/
|
||||
int i;
|
||||
for (i = line.length() - 1; i >= 0; i--) {
|
||||
char c = line.charAt(i);
|
||||
if (!(c == ' ' || c == '\t'))
|
||||
break;
|
||||
}
|
||||
line = line.substring(0, i + 1);
|
||||
if (line.equals(boundary))
|
||||
break;
|
||||
}
|
||||
if (line == null)
|
||||
throw new MessagingException("Missing start boundary");
|
||||
|
||||
/*
|
||||
* Read and process body parts until we see the
|
||||
* terminating boundary line (or EOF).
|
||||
*/
|
||||
boolean done = false;
|
||||
getparts:
|
||||
while (!done) {
|
||||
InternetHeaders headers = null;
|
||||
if (sin != null) {
|
||||
start = sin.getPosition();
|
||||
// skip headers
|
||||
while ((line = lin.readLine()) != null && line.length() > 0)
|
||||
;
|
||||
if (line == null) {
|
||||
if (!ignoreMissingEndBoundary) {
|
||||
throw new MessagingException("Missing End Boundary for Mime Package : EOF while skipping headers");
|
||||
}
|
||||
// assume there's just a missing end boundary
|
||||
break getparts;
|
||||
}
|
||||
} else {
|
||||
// collect the headers for this body part
|
||||
headers = createInternetHeaders(in);
|
||||
}
|
||||
|
||||
if (!in.markSupported())
|
||||
throw new MessagingException("Stream doesn't support mark");
|
||||
|
||||
ByteOutputStream buf = null;
|
||||
// if we don't have a shared input stream, we copy the data
|
||||
if (sin == null)
|
||||
buf = new ByteOutputStream();
|
||||
int b;
|
||||
boolean bol = true; // beginning of line flag
|
||||
// the two possible end of line characters
|
||||
int eol1 = -1, eol2 = -1;
|
||||
|
||||
/*
|
||||
* Read and save the content bytes in buf.
|
||||
*/
|
||||
for (;;) {
|
||||
if (bol) {
|
||||
/*
|
||||
* At the beginning of a line, check whether the
|
||||
* next line is a boundary.
|
||||
*/
|
||||
int i;
|
||||
in.mark(bl + 4 + 1000); // bnd + "--\r\n" + lots of LWSP
|
||||
// read bytes, matching against the boundary
|
||||
for (i = 0; i < bl; i++)
|
||||
if (in.read() != bndbytes[i])
|
||||
break;
|
||||
if (i == bl) {
|
||||
// matched the boundary, check for last boundary
|
||||
int b2 = in.read();
|
||||
if (b2 == '-') {
|
||||
if (in.read() == '-') {
|
||||
done = true;
|
||||
foundClosingBoundary = true;
|
||||
break; // ignore trailing text
|
||||
}
|
||||
}
|
||||
// skip linear whitespace
|
||||
while (b2 == ' ' || b2 == '\t')
|
||||
b2 = in.read();
|
||||
// check for end of line
|
||||
if (b2 == '\n')
|
||||
break; // got it! break out of the loop
|
||||
if (b2 == '\r') {
|
||||
in.mark(1);
|
||||
if (in.read() != '\n')
|
||||
in.reset();
|
||||
break; // got it! break out of the loop
|
||||
}
|
||||
}
|
||||
// failed to match, reset and proceed normally
|
||||
in.reset();
|
||||
|
||||
// if this is not the first line, write out the
|
||||
// end of line characters from the previous line
|
||||
if (buf != null && eol1 != -1) {
|
||||
buf.write(eol1);
|
||||
if (eol2 != -1)
|
||||
buf.write(eol2);
|
||||
eol1 = eol2 = -1;
|
||||
}
|
||||
}
|
||||
|
||||
// read the next byte
|
||||
if ((b = in.read()) < 0) {
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* If we're at the end of the line, save the eol characters
|
||||
* to be written out before the beginning of the next line.
|
||||
*/
|
||||
if (b == '\r' || b == '\n') {
|
||||
bol = true;
|
||||
if (sin != null)
|
||||
end = sin.getPosition() - 1;
|
||||
eol1 = b;
|
||||
if (b == '\r') {
|
||||
in.mark(1);
|
||||
if ((b = in.read()) == '\n')
|
||||
eol2 = b;
|
||||
else
|
||||
in.reset();
|
||||
}
|
||||
} else {
|
||||
bol = false;
|
||||
if (buf != null)
|
||||
buf.write(b);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a MimeBody element to represent this body part.
|
||||
*/
|
||||
MimeBodyPart part;
|
||||
if (sin != null)
|
||||
part = createMimeBodyPart(sin.newStream(start, end));
|
||||
else
|
||||
part = createMimeBodyPart(headers, buf.getBytes(), buf.getCount());
|
||||
addBodyPart(part);
|
||||
}
|
||||
} catch (IOException ioex) {
|
||||
throw new MessagingException("IO Error", ioex);
|
||||
}
|
||||
|
||||
if (!ignoreMissingEndBoundary && !foundClosingBoundary && sin== null) {
|
||||
throw new MessagingException("Missing End Boundary for Mime Package : EOF while skipping headers");
|
||||
}
|
||||
parsed = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and return an InternetHeaders object that loads the
|
||||
* headers from the given InputStream. Subclasses can override
|
||||
* this method to return a subclass of InternetHeaders, if
|
||||
* necessary. This implementation simply constructs and returns
|
||||
* an InternetHeaders object.
|
||||
*
|
||||
* @param is the InputStream to read the headers from
|
||||
* @exception MessagingException
|
||||
* @since JavaMail 1.2
|
||||
*/
|
||||
protected InternetHeaders createInternetHeaders(InputStream is)
|
||||
throws MessagingException {
|
||||
return new InternetHeaders(is);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and return a MimeBodyPart object to represent a
|
||||
* body part parsed from the InputStream. Subclasses can override
|
||||
* this method to return a subclass of MimeBodyPart, if
|
||||
* necessary. This implementation simply constructs and returns
|
||||
* a MimeBodyPart object.
|
||||
*
|
||||
* @param headers the headers for the body part
|
||||
* @param content the content of the body part
|
||||
* @since JavaMail 1.2
|
||||
*/
|
||||
protected MimeBodyPart createMimeBodyPart(InternetHeaders headers, byte[] content, int len) {
|
||||
return new MimeBodyPart(headers, content,len);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and return a MimeBodyPart object to represent a
|
||||
* body part parsed from the InputStream. Subclasses can override
|
||||
* this method to return a subclass of MimeBodyPart, if
|
||||
* necessary. This implementation simply constructs and returns
|
||||
* a MimeBodyPart object.
|
||||
*
|
||||
* @param is InputStream containing the body part
|
||||
* @exception MessagingException
|
||||
* @since JavaMail 1.2
|
||||
*/
|
||||
protected MimeBodyPart createMimeBodyPart(InputStream is) throws MessagingException {
|
||||
return new MimeBodyPart(is);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup this MimeMultipart object from the given MultipartDataSource. <p>
|
||||
*
|
||||
* The method adds the MultipartDataSource's MimeBodyPart
|
||||
* objects into this MimeMultipart. This MimeMultipart's contentType is
|
||||
* set to that of the MultipartDataSource. <p>
|
||||
*
|
||||
* This method is typically used in those cases where one
|
||||
* has a multipart data source that has already been pre-parsed into
|
||||
* the individual body parts (for example, an IMAP datasource), but
|
||||
* needs to create an appropriate MimeMultipart subclass that represents
|
||||
* a specific multipart subtype.
|
||||
*
|
||||
* @param mp MimeMultipart datasource
|
||||
*/
|
||||
|
||||
protected void setMultipartDataSource(MultipartDataSource mp)
|
||||
throws MessagingException {
|
||||
contentType = new ContentType(mp.getContentType());
|
||||
|
||||
int count = mp.getCount();
|
||||
for (int i = 0; i < count; i++)
|
||||
addBodyPart(mp.getBodyPart(i));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the content-type of this MimeMultipart. <p>
|
||||
*
|
||||
* This implementation just returns the value of the
|
||||
* <code>contentType</code> field.
|
||||
*
|
||||
* @return content-type
|
||||
* @see #contentType
|
||||
*/
|
||||
public ContentType getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified part from the multipart message.
|
||||
* Shifts all the parts after the removed part down one.
|
||||
*
|
||||
* @param part The part to remove
|
||||
* @return true if part removed, false otherwise
|
||||
* @exception MessagingException if no such MimeBodyPart exists
|
||||
*/
|
||||
public boolean removeBodyPart(MimeBodyPart part) throws MessagingException {
|
||||
if (parts == null)
|
||||
throw new MessagingException("No such body part");
|
||||
|
||||
boolean ret = parts.remove(part);
|
||||
part.setParent(null);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the part at specified location (starting from 0).
|
||||
* Shifts all the parts after the removed part down one.
|
||||
*
|
||||
* @param index Index of the part to remove
|
||||
* @exception IndexOutOfBoundsException if the given index
|
||||
* is out of range.
|
||||
*/
|
||||
public void removeBodyPart(int index) {
|
||||
if (parts == null)
|
||||
throw new IndexOutOfBoundsException("No such BodyPart");
|
||||
|
||||
MimeBodyPart part = (MimeBodyPart)parts.get(index);
|
||||
parts.remove(index);
|
||||
part.setParent(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a MimeBodyPart to the multipart. The MimeBodyPart is appended to
|
||||
* the list of existing Parts.
|
||||
*
|
||||
* @param part The MimeBodyPart to be appended
|
||||
*/
|
||||
public synchronized void addBodyPart(MimeBodyPart part) {
|
||||
if (parts == null)
|
||||
parts = new FinalArrayList();
|
||||
|
||||
parts.add(part);
|
||||
part.setParent(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a MimeBodyPart at position <code>index</code>.
|
||||
* If <code>index</code> is not the last one in the list,
|
||||
* the subsequent parts are shifted up. If <code>index</code>
|
||||
* is larger than the number of parts present, the
|
||||
* MimeBodyPart is appended to the end.
|
||||
*
|
||||
* @param part The MimeBodyPart to be inserted
|
||||
* @param index Location where to insert the part
|
||||
*/
|
||||
public synchronized void addBodyPart(MimeBodyPart part, int index) {
|
||||
if (parts == null)
|
||||
parts = new FinalArrayList();
|
||||
|
||||
parts.add(index,part);
|
||||
part.setParent(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the <code>MimeBodyPart</code> that contains this <code>MimeMultipart</code>
|
||||
* object, or <code>null</code> if not known.
|
||||
* @since JavaMail 1.1
|
||||
*/
|
||||
MimeBodyPart getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the parent of this <code>MimeMultipart</code> to be the specified
|
||||
* <code>MimeBodyPart</code>. Normally called by the <code>Message</code>
|
||||
* or <code>MimeBodyPart</code> <code>setContent(MimeMultipart)</code> method.
|
||||
* <code>parent</code> may be <code>null</code> if the
|
||||
* <code>MimeMultipart</code> is being removed from its containing
|
||||
* <code>MimeBodyPart</code>.
|
||||
* @since JavaMail 1.1
|
||||
*/
|
||||
void setParent(MimeBodyPart parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)MimePartDataSource.java 1.9 02/03/27
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.packaging.mime.internet;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.UnknownServiceException;
|
||||
|
||||
import javax.activation.DataSource;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.packaging.mime.MessagingException;
|
||||
|
||||
/**
|
||||
* A utility class that implements a DataSource out of
|
||||
* a MimeBodyPart. This class is primarily meant for service providers.
|
||||
*
|
||||
* @author John Mani
|
||||
*/
|
||||
|
||||
public final class MimePartDataSource implements DataSource {
|
||||
private final MimeBodyPart part;
|
||||
|
||||
/**
|
||||
* Constructor, that constructs a DataSource from a MimeBodyPart.
|
||||
*/
|
||||
public MimePartDataSource(MimeBodyPart part) {
|
||||
this.part = part;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an input stream from this MimeBodyPart. <p>
|
||||
*
|
||||
* This method applies the appropriate transfer-decoding, based
|
||||
* on the Content-Transfer-Encoding attribute of this MimeBodyPart.
|
||||
* Thus the returned input stream is a decoded stream of bytes.<p>
|
||||
*
|
||||
* This implementation obtains the raw content from the MimeBodyPart
|
||||
* using the <code>getContentStream()</code> method and decodes
|
||||
* it using the <code>MimeUtility.decode()</code> method.
|
||||
*
|
||||
* @return decoded input stream
|
||||
*/
|
||||
public InputStream getInputStream() throws IOException {
|
||||
|
||||
try {
|
||||
InputStream is = part.getContentStream();
|
||||
|
||||
String encoding = part.getEncoding();
|
||||
if (encoding != null)
|
||||
return MimeUtility.decode(is, encoding);
|
||||
else
|
||||
return is;
|
||||
} catch (MessagingException mex) {
|
||||
throw new IOException(mex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* DataSource method to return an output stream. <p>
|
||||
*
|
||||
* This implementation throws the UnknownServiceException.
|
||||
*/
|
||||
public OutputStream getOutputStream() throws IOException {
|
||||
throw new UnknownServiceException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content-type of this DataSource. <p>
|
||||
*
|
||||
* This implementation just invokes the <code>getContentType</code>
|
||||
* method on the MimeBodyPart.
|
||||
*/
|
||||
public String getContentType() {
|
||||
return part.getContentType();
|
||||
}
|
||||
|
||||
/**
|
||||
* DataSource method to return a name. <p>
|
||||
*
|
||||
* This implementation just returns an empty string.
|
||||
*/
|
||||
public String getName() {
|
||||
try {
|
||||
return part.getFileName();
|
||||
} catch (MessagingException mex) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.packaging.mime.internet;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.packaging.mime.MessagingException;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.AttachmentPartImpl;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import javax.activation.DataSource;
|
||||
import javax.xml.soap.AttachmentPart;
|
||||
import com.sun.xml.internal.org.jvnet.mimepull.MIMEConfig;
|
||||
import com.sun.xml.internal.org.jvnet.mimepull.MIMEMessage;
|
||||
import com.sun.xml.internal.org.jvnet.mimepull.MIMEPart;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Kumar
|
||||
*/
|
||||
public class MimePullMultipart extends MimeMultipart {
|
||||
|
||||
private InputStream in = null;
|
||||
private String boundary = null;
|
||||
private MIMEMessage mm = null;
|
||||
private DataSource dataSource = null;
|
||||
private ContentType contType = null;
|
||||
private String startParam = null;
|
||||
private MIMEPart soapPart = null;
|
||||
|
||||
public MimePullMultipart(DataSource ds, ContentType ct)
|
||||
throws MessagingException {
|
||||
parsed = false;
|
||||
if (ct==null)
|
||||
contType = new ContentType(ds.getContentType());
|
||||
else
|
||||
contType = ct;
|
||||
|
||||
dataSource = ds;
|
||||
boundary = contType.getParameter("boundary");
|
||||
}
|
||||
|
||||
public MIMEPart readAndReturnSOAPPart() throws MessagingException {
|
||||
if (soapPart != null) {
|
||||
throw new MessagingException("Inputstream from datasource was already consumed");
|
||||
}
|
||||
readSOAPPart();
|
||||
return soapPart;
|
||||
|
||||
}
|
||||
|
||||
protected void readSOAPPart() throws MessagingException {
|
||||
try {
|
||||
if (soapPart != null) {
|
||||
return;
|
||||
}
|
||||
in = dataSource.getInputStream();
|
||||
MIMEConfig config = new MIMEConfig(); //use defaults
|
||||
mm = new MIMEMessage(in, boundary, config);
|
||||
String st = contType.getParameter("start");
|
||||
if(startParam == null) {
|
||||
soapPart = mm.getPart(0);
|
||||
} else {
|
||||
// Strip <...> from root part's Content-I
|
||||
if (st != null && st.length() > 2 && st.charAt(0) == '<' && st.charAt(st.length()-1) == '>') {
|
||||
st = st.substring(1, st.length()-1);
|
||||
}
|
||||
startParam = st;
|
||||
soapPart = mm.getPart(startParam);
|
||||
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
throw new MessagingException("No inputstream from datasource", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void parseAll() throws MessagingException {
|
||||
if (parsed) {
|
||||
return;
|
||||
}
|
||||
if (soapPart == null) {
|
||||
readSOAPPart();
|
||||
}
|
||||
|
||||
List<MIMEPart> prts = mm.getAttachments();
|
||||
for(MIMEPart part : prts) {
|
||||
if (part != soapPart) {
|
||||
AttachmentPart attach = new AttachmentPartImpl(part);
|
||||
this.addBodyPart(new MimeBodyPart(part));
|
||||
}
|
||||
}
|
||||
parsed = true;
|
||||
}
|
||||
|
||||
protected void parse() throws MessagingException {
|
||||
parseAll();
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,237 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)ParameterList.java 1.10 03/02/12
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.packaging.mime.internet;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This class holds MIME parameters (attribute-value pairs).
|
||||
*
|
||||
* @version 1.10, 03/02/12
|
||||
* @author John Mani
|
||||
*/
|
||||
|
||||
public final class ParameterList {
|
||||
|
||||
private final HashMap list;
|
||||
|
||||
/**
|
||||
* No-arg Constructor.
|
||||
*/
|
||||
public ParameterList() {
|
||||
this.list = new HashMap();
|
||||
}
|
||||
|
||||
private ParameterList(HashMap m) {
|
||||
this.list = m;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor that takes a parameter-list string. The String
|
||||
* is parsed and the parameters are collected and stored internally.
|
||||
* A ParseException is thrown if the parse fails.
|
||||
* Note that an empty parameter-list string is valid and will be
|
||||
* parsed into an empty ParameterList.
|
||||
*
|
||||
* @param s the parameter-list string.
|
||||
* @exception ParseException if the parse fails.
|
||||
*/
|
||||
public ParameterList(String s) throws ParseException {
|
||||
HeaderTokenizer h = new HeaderTokenizer(s, HeaderTokenizer.MIME);
|
||||
HeaderTokenizer.Token tk;
|
||||
int type;
|
||||
String name;
|
||||
|
||||
list = new HashMap();
|
||||
while (true) {
|
||||
tk = h.next();
|
||||
type = tk.getType();
|
||||
|
||||
if (type == HeaderTokenizer.Token.EOF) // done
|
||||
return;
|
||||
|
||||
if ((char)type == ';') {
|
||||
// expect parameter name
|
||||
tk = h.next();
|
||||
// tolerate trailing semicolon, even though it violates the spec
|
||||
if (tk.getType() == HeaderTokenizer.Token.EOF)
|
||||
return;
|
||||
// parameter name must be a MIME Atom
|
||||
if (tk.getType() != HeaderTokenizer.Token.ATOM)
|
||||
throw new ParseException();
|
||||
name = tk.getValue().toLowerCase();
|
||||
|
||||
// expect '='
|
||||
tk = h.next();
|
||||
if ((char)tk.getType() != '=')
|
||||
throw new ParseException();
|
||||
|
||||
// expect parameter value
|
||||
tk = h.next();
|
||||
type = tk.getType();
|
||||
// parameter value must be a MIME Atom or Quoted String
|
||||
if (type != HeaderTokenizer.Token.ATOM &&
|
||||
type != HeaderTokenizer.Token.QUOTEDSTRING)
|
||||
throw new ParseException();
|
||||
|
||||
list.put(name, tk.getValue());
|
||||
} else
|
||||
throw new ParseException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of parameters in this list.
|
||||
*
|
||||
* @return number of parameters.
|
||||
*/
|
||||
public int size() {
|
||||
return list.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the specified parameter. Note that
|
||||
* parameter names are case-insensitive.
|
||||
*
|
||||
* @param name parameter name.
|
||||
* @return Value of the parameter. Returns
|
||||
* <code>null</code> if the parameter is not
|
||||
* present.
|
||||
*/
|
||||
public String get(String name) {
|
||||
return (String)list.get(name.trim().toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a parameter. If this parameter already exists, it is
|
||||
* replaced by this new value.
|
||||
*
|
||||
* @param name name of the parameter.
|
||||
* @param value value of the parameter.
|
||||
*/
|
||||
public void set(String name, String value) {
|
||||
list.put(name.trim().toLowerCase(), value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified parameter from this ParameterList.
|
||||
* This method does nothing if the parameter is not present.
|
||||
*
|
||||
* @param name name of the parameter.
|
||||
*/
|
||||
public void remove(String name) {
|
||||
list.remove(name.trim().toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an enumeration of the names of all parameters in this
|
||||
* list.
|
||||
*
|
||||
* @return Enumeration of all parameter names in this list.
|
||||
*/
|
||||
public Iterator getNames() {
|
||||
return list.keySet().iterator();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert this ParameterList into a MIME String. If this is
|
||||
* an empty list, an empty string is returned.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String toString() {
|
||||
return toString(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert this ParameterList into a MIME String. If this is
|
||||
* an empty list, an empty string is returned.
|
||||
*
|
||||
* The 'used' parameter specifies the number of character positions
|
||||
* already taken up in the field into which the resulting parameter
|
||||
* list is to be inserted. It's used to determine where to fold the
|
||||
* resulting parameter list.
|
||||
*
|
||||
* @param used number of character positions already used, in
|
||||
* the field into which the parameter list is to
|
||||
* be inserted.
|
||||
* @return String
|
||||
*/
|
||||
public String toString(int used) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
Iterator itr = list.entrySet().iterator();
|
||||
|
||||
while (itr.hasNext()) {
|
||||
Map.Entry e = (Map.Entry)itr.next();
|
||||
String name = (String)e.getKey();
|
||||
String value = quote((String)e.getValue());
|
||||
sb.append("; ");
|
||||
used += 2;
|
||||
int len = name.length() + value.length() + 1;
|
||||
if (used + len > 76) { // overflows ...
|
||||
sb.append("\r\n\t"); // .. start new continuation line
|
||||
used = 8; // account for the starting <tab> char
|
||||
}
|
||||
sb.append(name).append('=');
|
||||
used += name.length() + 1;
|
||||
if (used + value.length() > 76) { // still overflows ...
|
||||
// have to fold value
|
||||
String s = MimeUtility.fold(used, value);
|
||||
sb.append(s);
|
||||
int lastlf = s.lastIndexOf('\n');
|
||||
if (lastlf >= 0) // always true
|
||||
used += s.length() - lastlf - 1;
|
||||
else
|
||||
used += s.length();
|
||||
} else {
|
||||
sb.append(value);
|
||||
used += value.length();
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
// Quote a parameter value token if required.
|
||||
private String quote(String value) {
|
||||
if ("".equals(value))
|
||||
return "\"\"";
|
||||
return MimeUtility.quote(value, HeaderTokenizer.MIME);
|
||||
}
|
||||
|
||||
public ParameterList copy() {
|
||||
return new ParameterList((HashMap)list.clone());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)ParseException.java 1.3 02/03/27
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.packaging.mime.internet;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.packaging.mime.MessagingException;
|
||||
|
||||
/**
|
||||
* The exception thrown due to an error in parsing RFC822
|
||||
* or MIME headers
|
||||
*
|
||||
* @author John Mani
|
||||
*/
|
||||
|
||||
public class ParseException extends MessagingException {
|
||||
|
||||
/**
|
||||
* Constructs a ParseException with no detail message.
|
||||
*/
|
||||
public ParseException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a ParseException with the specified detail message.
|
||||
* @param s the detail message
|
||||
*/
|
||||
public ParseException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)SharedInputStream.java 1.2 02/03/27
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.packaging.mime.internet;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
// SAAJ doesn't utilize this, but I think it should.
|
||||
/**
|
||||
* An InputStream that is backed by data that can be shared by multiple
|
||||
* readers may implement this interface. This allows users of such an
|
||||
* InputStream to determine the current positionin the InputStream, and
|
||||
* to create new InputStreams representing a subset of the data in the
|
||||
* original InputStream. The new InputStream will access the same
|
||||
* underlying data as the original, without copying the data.
|
||||
*
|
||||
* @version 1.2, 02/03/27
|
||||
* @author Bill Shannon
|
||||
* @since JavaMail 1.2
|
||||
*/
|
||||
|
||||
public interface SharedInputStream {
|
||||
/**
|
||||
* Return the current position in the InputStream, as an
|
||||
* offset from the beginning of the InputStream.
|
||||
*
|
||||
* @return the current position
|
||||
*/
|
||||
public long getPosition();
|
||||
|
||||
/**
|
||||
* Return a new InputStream representing a subset of the data
|
||||
* from this InputStream, starting at <code>start</code> (inclusive)
|
||||
* up to <code>end</code> (exclusive). <code>start</code> must be
|
||||
* non-negative. If <code>end</code> is -1, the new stream ends
|
||||
* at the same place as this stream. The returned InputStream
|
||||
* will also implement the SharedInputStream interface.
|
||||
*
|
||||
* @param start the starting position
|
||||
* @param end the ending position + 1
|
||||
* @return the new stream
|
||||
*/
|
||||
public InputStream newStream(long start, long end);
|
||||
|
||||
/**
|
||||
* Writes the specified region to another {@link OutputStream}.
|
||||
*/
|
||||
public void writeTo(long start,long end, OutputStream out);
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)UniqueValue.java 1.6 02/03/27
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.packaging.mime.internet;
|
||||
|
||||
|
||||
/**
|
||||
* This is a utility class that generates unique values. The generated
|
||||
* String contains only US-ASCII characters and hence is safe for use
|
||||
* in RFC822 headers. <p>
|
||||
*
|
||||
* This is a package private class.
|
||||
*
|
||||
* @author John Mani
|
||||
* @author Max Spivak
|
||||
* @author Bill Shannon
|
||||
*/
|
||||
|
||||
class UniqueValue {
|
||||
/**
|
||||
* A global part number. Access is not synchronized because the
|
||||
* value is only one part of the unique value and so doesn't need
|
||||
* to be accurate.
|
||||
*/
|
||||
private static int part = 0;
|
||||
|
||||
/**
|
||||
* Get a unique value for use in a multipart boundary string.
|
||||
*
|
||||
* This implementation generates it by concatenating a global
|
||||
* part number, a newly created object's <code>hashCode()</code>,
|
||||
* and the current time (in milliseconds).
|
||||
*/
|
||||
public static String getUniqueBoundaryValue() {
|
||||
StringBuffer s = new StringBuffer();
|
||||
|
||||
// Unique string is ----=_Part_<part>_<hashcode>.<currentTime>
|
||||
s.append("----=_Part_").append(part++).append("_").
|
||||
append(s.hashCode()).append('.').
|
||||
append(System.currentTimeMillis());
|
||||
return s.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)ASCIIUtility.java 1.9 02/03/27
|
||||
*/
|
||||
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.packaging.mime.util;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class ASCIIUtility {
|
||||
|
||||
// Private constructor so that this class is not instantiated
|
||||
private ASCIIUtility() { }
|
||||
|
||||
|
||||
/**
|
||||
* Convert the bytes within the specified range of the given byte
|
||||
* array into a signed integer in the given radix . The range extends
|
||||
* from <code>start</code> till, but not including <code>end</code>. <p>
|
||||
*
|
||||
* Based on java.lang.Integer.parseInt()
|
||||
*/
|
||||
public static int parseInt(byte[] b, int start, int end, int radix)
|
||||
throws NumberFormatException {
|
||||
if (b == null)
|
||||
throw new NumberFormatException("null");
|
||||
|
||||
int result = 0;
|
||||
boolean negative = false;
|
||||
int i = start;
|
||||
int limit;
|
||||
int multmin;
|
||||
int digit;
|
||||
|
||||
if (end > start) {
|
||||
if (b[i] == '-') {
|
||||
negative = true;
|
||||
limit = Integer.MIN_VALUE;
|
||||
i++;
|
||||
} else {
|
||||
limit = -Integer.MAX_VALUE;
|
||||
}
|
||||
multmin = limit / radix;
|
||||
if (i < end) {
|
||||
digit = Character.digit((char)b[i++], radix);
|
||||
if (digit < 0) {
|
||||
throw new NumberFormatException(
|
||||
"illegal number: " + toString(b, start, end)
|
||||
);
|
||||
} else {
|
||||
result = -digit;
|
||||
}
|
||||
}
|
||||
while (i < end) {
|
||||
// Accumulating negatively avoids surprises near MAX_VALUE
|
||||
digit = Character.digit((char)b[i++], radix);
|
||||
if (digit < 0) {
|
||||
throw new NumberFormatException("illegal number");
|
||||
}
|
||||
if (result < multmin) {
|
||||
throw new NumberFormatException("illegal number");
|
||||
}
|
||||
result *= radix;
|
||||
if (result < limit + digit) {
|
||||
throw new NumberFormatException("illegal number");
|
||||
}
|
||||
result -= digit;
|
||||
}
|
||||
} else {
|
||||
throw new NumberFormatException("illegal number");
|
||||
}
|
||||
if (negative) {
|
||||
if (i > start + 1) {
|
||||
return result;
|
||||
} else { /* Only got "-" */
|
||||
throw new NumberFormatException("illegal number");
|
||||
}
|
||||
} else {
|
||||
return -result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the bytes within the specified range of the given byte
|
||||
* array into a String. The range extends from <code>start</code>
|
||||
* till, but not including <code>end</code>. <p>
|
||||
*/
|
||||
public static String toString(byte[] b, int start, int end) {
|
||||
int size = end - start;
|
||||
char[] theChars = new char[size];
|
||||
|
||||
for (int i = 0, j = start; i < size; )
|
||||
theChars[i++] = (char)(b[j++]&0xff);
|
||||
|
||||
return new String(theChars);
|
||||
}
|
||||
|
||||
public static byte[] getBytes(String s) {
|
||||
char [] chars= s.toCharArray();
|
||||
int size = chars.length;
|
||||
byte[] bytes = new byte[size];
|
||||
|
||||
for (int i = 0; i < size;)
|
||||
bytes[i] = (byte) chars[i++];
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @deprecated
|
||||
* this is an expensive operation that require an additional
|
||||
* buffer reallocation just to get the array of an exact size.
|
||||
* Unless you absolutely need the exact size array, don't use this.
|
||||
* Use {@link ByteOutputStream} and {@link ByteOutputStream#write(InputStream)}.
|
||||
*/
|
||||
public static byte[] getBytes(InputStream is) throws IOException {
|
||||
ByteOutputStream bos = new ByteOutputStream();
|
||||
try {
|
||||
bos.write(is);
|
||||
} finally {
|
||||
is.close();
|
||||
}
|
||||
return bos.toByteArray();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)BASE64DecoderStream.java 1.8 02/03/27
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.packaging.mime.util;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* This class implements a BASE64 Decoder. It is implemented as
|
||||
* a FilterInputStream, so one can just wrap this class around
|
||||
* any input stream and read bytes from this filter. The decoding
|
||||
* is done as the bytes are read out.
|
||||
*
|
||||
* @author John Mani
|
||||
* @author Bill Shannon
|
||||
*/
|
||||
|
||||
public class BASE64DecoderStream extends FilterInputStream {
|
||||
private byte[] buffer; // cache of decoded bytes
|
||||
private int bufsize = 0; // size of the cache
|
||||
private int index = 0; // index into the cache
|
||||
|
||||
/**
|
||||
* Create a BASE64 decoder that decodes the specified input stream
|
||||
* @param in the input stream
|
||||
*/
|
||||
public BASE64DecoderStream(InputStream in) {
|
||||
super(in);
|
||||
buffer = new byte[3];
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the next decoded byte from this input stream. The byte
|
||||
* is returned as an <code>int</code> in the range <code>0</code>
|
||||
* to <code>255</code>. If no byte is available because the end of
|
||||
* the stream has been reached, the value <code>-1</code> is returned.
|
||||
* This method blocks until input data is available, the end of the
|
||||
* stream is detected, or an exception is thrown.
|
||||
*
|
||||
* @return next byte of data, or <code>-1</code> if the end of the
|
||||
* stream is reached.
|
||||
* @exception IOException if an I/O error occurs.
|
||||
* @see java.io.FilterInputStream#in
|
||||
*/
|
||||
public int read() throws IOException {
|
||||
if (index >= bufsize) {
|
||||
decode(); // Fills up buffer
|
||||
if (bufsize == 0) // buffer is empty
|
||||
return -1;
|
||||
index = 0; // reset index into buffer
|
||||
}
|
||||
return buffer[index++] & 0xff; // Zero off the MSB
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads up to <code>len</code> decoded bytes of data from this input stream
|
||||
* into an array of bytes. This method blocks until some input is
|
||||
* available.
|
||||
* <p>
|
||||
*
|
||||
* @param buf the buffer into which the data is read.
|
||||
* @param off the start offset of the data.
|
||||
* @param len the maximum number of bytes read.
|
||||
* @return the total number of bytes read into the buffer, or
|
||||
* <code>-1</code> if there is no more data because the end of
|
||||
* the stream has been reached.
|
||||
* @exception IOException if an I/O error occurs.
|
||||
*/
|
||||
public int read(byte[] buf, int off, int len) throws IOException {
|
||||
int i, c;
|
||||
for (i = 0; i < len; i++) {
|
||||
if ((c = read()) == -1) {
|
||||
if (i == 0) // At end of stream, so we should
|
||||
i = -1; // return -1 , NOT 0.
|
||||
break;
|
||||
}
|
||||
buf[off+i] = (byte)c;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if this input stream supports marks. Currently this class
|
||||
* does not support marks
|
||||
*/
|
||||
public boolean markSupported() {
|
||||
return false; // Maybe later ..
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of bytes that can be read from this input
|
||||
* stream without blocking. However, this figure is only
|
||||
* a close approximation in case the original encoded stream
|
||||
* contains embedded CRLFs; since the CRLFs are discarded, not decoded
|
||||
*/
|
||||
public int available() throws IOException {
|
||||
// This is only an estimate, since in.available()
|
||||
// might include CRLFs too ..
|
||||
return ((in.available() * 3)/4 + (bufsize-index));
|
||||
}
|
||||
|
||||
/**
|
||||
* This character array provides the character to value map
|
||||
* based on RFC1521.
|
||||
*/
|
||||
private final static char pem_array[] = {
|
||||
'A','B','C','D','E','F','G','H', // 0
|
||||
'I','J','K','L','M','N','O','P', // 1
|
||||
'Q','R','S','T','U','V','W','X', // 2
|
||||
'Y','Z','a','b','c','d','e','f', // 3
|
||||
'g','h','i','j','k','l','m','n', // 4
|
||||
'o','p','q','r','s','t','u','v', // 5
|
||||
'w','x','y','z','0','1','2','3', // 6
|
||||
'4','5','6','7','8','9','+','/' // 7
|
||||
};
|
||||
|
||||
private final static byte pem_convert_array[] = new byte[256];
|
||||
|
||||
static {
|
||||
for (int i = 0; i < 255; i++)
|
||||
pem_convert_array[i] = -1;
|
||||
for(int i = 0; i < pem_array.length; i++)
|
||||
pem_convert_array[pem_array[i]] = (byte) i;
|
||||
}
|
||||
|
||||
/* The decoder algorithm */
|
||||
private byte[] decode_buffer = new byte[4];
|
||||
private void decode() throws IOException {
|
||||
bufsize = 0;
|
||||
/*
|
||||
* We need 4 valid base64 characters before we start decoding.
|
||||
* We skip anything that's not a valid base64 character (usually
|
||||
* just CRLF).
|
||||
*/
|
||||
int got = 0;
|
||||
while (got < 4) {
|
||||
int i = in.read();
|
||||
if (i == -1) {
|
||||
if (got == 0)
|
||||
return; // EOF before any data is ok
|
||||
throw new IOException("Error in encoded stream, got " + got);
|
||||
}
|
||||
if (i >= 0 && i < 256 && i == '=' || pem_convert_array[i] != -1)
|
||||
decode_buffer[got++] = (byte)i;
|
||||
}
|
||||
|
||||
byte a, b;
|
||||
a = pem_convert_array[decode_buffer[0] & 0xff];
|
||||
b = pem_convert_array[decode_buffer[1] & 0xff];
|
||||
// The first decoded byte
|
||||
buffer[bufsize++] = (byte)(((a << 2) & 0xfc) | ((b >>> 4) & 3));
|
||||
|
||||
if (decode_buffer[2] == '=') // End of this BASE64 encoding
|
||||
return;
|
||||
a = b;
|
||||
b = pem_convert_array[decode_buffer[2] & 0xff];
|
||||
// The second decoded byte
|
||||
buffer[bufsize++] = (byte)(((a << 4) & 0xf0) | ((b >>> 2) & 0xf));
|
||||
|
||||
if (decode_buffer[3] == '=') // End of this BASE64 encoding
|
||||
return;
|
||||
a = b;
|
||||
b = pem_convert_array[decode_buffer[3] & 0xff];
|
||||
// The third decoded byte
|
||||
buffer[bufsize++] = (byte)(((a << 6) & 0xc0) | (b & 0x3f));
|
||||
}
|
||||
|
||||
/**
|
||||
* Base64 decode a byte array. No line breaks are allowed.
|
||||
* This method is suitable for short strings, such as those
|
||||
* in the IMAP AUTHENTICATE protocol, but not to decode the
|
||||
* entire content of a MIME part.
|
||||
*
|
||||
* NOTE: inbuf may only contain valid base64 characters.
|
||||
* Whitespace is not ignored.
|
||||
*/
|
||||
public static byte[] decode(byte[] inbuf) {
|
||||
int size = (inbuf.length / 4) * 3;
|
||||
if (size == 0)
|
||||
return inbuf;
|
||||
|
||||
if (inbuf[inbuf.length - 1] == '=') {
|
||||
size--;
|
||||
if (inbuf[inbuf.length - 2] == '=')
|
||||
size--;
|
||||
}
|
||||
byte[] outbuf = new byte[size];
|
||||
|
||||
int inpos = 0, outpos = 0;
|
||||
size = inbuf.length;
|
||||
while (size > 0) {
|
||||
byte a, b;
|
||||
a = pem_convert_array[inbuf[inpos++] & 0xff];
|
||||
b = pem_convert_array[inbuf[inpos++] & 0xff];
|
||||
// The first decoded byte
|
||||
outbuf[outpos++] = (byte)(((a << 2) & 0xfc) | ((b >>> 4) & 3));
|
||||
|
||||
if (inbuf[inpos] == '=') // End of this BASE64 encoding
|
||||
return outbuf;
|
||||
a = b;
|
||||
b = pem_convert_array[inbuf[inpos++] & 0xff];
|
||||
// The second decoded byte
|
||||
outbuf[outpos++] = (byte)(((a << 4) & 0xf0) | ((b >>> 2) & 0xf));
|
||||
|
||||
if (inbuf[inpos] == '=') // End of this BASE64 encoding
|
||||
return outbuf;
|
||||
a = b;
|
||||
b = pem_convert_array[inbuf[inpos++] & 0xff];
|
||||
// The third decoded byte
|
||||
outbuf[outpos++] = (byte)(((a << 6) & 0xc0) | (b & 0x3f));
|
||||
size -= 4;
|
||||
}
|
||||
return outbuf;
|
||||
}
|
||||
|
||||
/*** begin TEST program ***
|
||||
public static void main(String argv[]) throws Exception {
|
||||
FileInputStream infile = new FileInputStream(argv[0]);
|
||||
BASE64DecoderStream decoder = new BASE64DecoderStream(infile);
|
||||
int c;
|
||||
|
||||
while ((c = decoder.read()) != -1)
|
||||
System.out.print((char)c);
|
||||
System.out.flush();
|
||||
}
|
||||
*** end TEST program ***/
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)BASE64EncoderStream.java 1.6 02/03/27
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.packaging.mime.util;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* This class implements a BASE64 Encoder. It is implemented as
|
||||
* a FilterOutputStream, so one can just wrap this class around
|
||||
* any output stream and write bytes into this filter. The Encoding
|
||||
* is done as the bytes are written out.
|
||||
*
|
||||
* @author John Mani
|
||||
* @author Bill Shannon
|
||||
*/
|
||||
|
||||
public class BASE64EncoderStream extends FilterOutputStream {
|
||||
private byte[] buffer; // cache of bytes that are yet to be encoded
|
||||
private int bufsize = 0; // size of the cache
|
||||
private int count = 0; // number of bytes that have been output
|
||||
private int bytesPerLine; // number of bytes per line
|
||||
|
||||
/**
|
||||
* Create a BASE64 encoder that encodes the specified input stream
|
||||
* @param out the output stream
|
||||
* @param bytesPerLine number of bytes per line. The encoder inserts
|
||||
* a CRLF sequence after the specified number of bytes
|
||||
*/
|
||||
public BASE64EncoderStream(OutputStream out, int bytesPerLine) {
|
||||
super(out);
|
||||
buffer = new byte[3];
|
||||
this.bytesPerLine = bytesPerLine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a BASE64 encoder that encodes the specified input stream.
|
||||
* Inserts the CRLF sequence after outputting 76 bytes.
|
||||
* @param out the output stream
|
||||
*/
|
||||
public BASE64EncoderStream(OutputStream out) {
|
||||
this(out, 76);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes <code>len</code> bytes from the specified
|
||||
* <code>byte</code> array starting at offset <code>off</code> to
|
||||
* this output stream.
|
||||
*
|
||||
* @param b the data.
|
||||
* @param off the start offset in the data.
|
||||
* @param len the number of bytes to write.
|
||||
* @exception IOException if an I/O error occurs.
|
||||
*/
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
for (int i = 0; i < len; i++)
|
||||
write(b[off + i]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes <code>b.length</code> bytes to this output stream.
|
||||
* @param b the data to be written.
|
||||
* @exception IOException if an I/O error occurs.
|
||||
*/
|
||||
public void write(byte[] b) throws IOException {
|
||||
write(b, 0, b.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes the specified <code>byte</code> to this output stream.
|
||||
* @param c the <code>byte</code>.
|
||||
* @exception IOException if an I/O error occurs.
|
||||
*/
|
||||
public void write(int c) throws IOException {
|
||||
buffer[bufsize++] = (byte)c;
|
||||
if (bufsize == 3) { // Encoding unit = 3 bytes
|
||||
encode();
|
||||
bufsize = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes this output stream and forces any buffered output bytes
|
||||
* to be encoded out to the stream.
|
||||
* @exception IOException if an I/O error occurs.
|
||||
*/
|
||||
public void flush() throws IOException {
|
||||
if (bufsize > 0) { // If there's unencoded characters in the buffer ..
|
||||
encode(); // .. encode them
|
||||
bufsize = 0;
|
||||
}
|
||||
out.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces any buffered output bytes to be encoded out to the stream
|
||||
* and closes this output stream
|
||||
*/
|
||||
public void close() throws IOException {
|
||||
flush();
|
||||
out.close();
|
||||
}
|
||||
|
||||
/** This array maps the characters to their 6 bit values */
|
||||
private final static char pem_array[] = {
|
||||
'A','B','C','D','E','F','G','H', // 0
|
||||
'I','J','K','L','M','N','O','P', // 1
|
||||
'Q','R','S','T','U','V','W','X', // 2
|
||||
'Y','Z','a','b','c','d','e','f', // 3
|
||||
'g','h','i','j','k','l','m','n', // 4
|
||||
'o','p','q','r','s','t','u','v', // 5
|
||||
'w','x','y','z','0','1','2','3', // 6
|
||||
'4','5','6','7','8','9','+','/' // 7
|
||||
};
|
||||
|
||||
private void encode() throws IOException {
|
||||
// If writing out this encoded unit will cause overflow,
|
||||
// start a new line.
|
||||
if (count + 4 > bytesPerLine) {
|
||||
out.write('\r');
|
||||
out.write('\n');
|
||||
count = 0;
|
||||
}
|
||||
|
||||
byte a, b, c;
|
||||
if (bufsize == 1) {
|
||||
a = buffer[0];
|
||||
b = 0;
|
||||
c = 0;
|
||||
out.write(pem_array[(a >>> 2) & 0x3F]);
|
||||
out.write(pem_array[((a << 4) & 0x30) + ((b >>> 4) & 0xf)]);
|
||||
out.write('='); // pad character
|
||||
out.write('='); // pad character
|
||||
} else if (bufsize == 2) {
|
||||
a = buffer[0];
|
||||
b = buffer[1];
|
||||
c = 0;
|
||||
out.write(pem_array[(a >>> 2) & 0x3F]);
|
||||
out.write(pem_array[((a << 4) & 0x30) + ((b >>> 4) & 0xf)]);
|
||||
out.write(pem_array[((b << 2) & 0x3c) + ((c >>> 6) & 0x3)]);
|
||||
out.write('='); // pad character
|
||||
} else {
|
||||
a = buffer[0];
|
||||
b = buffer[1];
|
||||
c = buffer[2];
|
||||
out.write(pem_array[(a >>> 2) & 0x3F]);
|
||||
out.write(pem_array[((a << 4) & 0x30) + ((b >>> 4) & 0xf)]);
|
||||
out.write(pem_array[((b << 2) & 0x3c) + ((c >>> 6) & 0x3)]);
|
||||
out.write(pem_array[c & 0x3F]);
|
||||
}
|
||||
|
||||
// increment count
|
||||
count += 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Base64 encode a byte array. No line breaks are inserted.
|
||||
* This method is suitable for short strings, such as those
|
||||
* in the IMAP AUTHENTICATE protocol, but not to encode the
|
||||
* entire content of a MIME part.
|
||||
*/
|
||||
public static byte[] encode(byte[] inbuf) {
|
||||
if (inbuf.length == 0)
|
||||
return inbuf;
|
||||
byte[] outbuf = new byte[((inbuf.length + 2) / 3) * 4];
|
||||
int inpos = 0, outpos = 0;
|
||||
int size = inbuf.length;
|
||||
while (size > 0) {
|
||||
byte a, b, c;
|
||||
if (size == 1) {
|
||||
a = inbuf[inpos++];
|
||||
b = 0;
|
||||
c = 0;
|
||||
outbuf[outpos++] = (byte)pem_array[(a >>> 2) & 0x3F];
|
||||
outbuf[outpos++] =
|
||||
(byte)pem_array[((a << 4) & 0x30) + ((b >>> 4) & 0xf)];
|
||||
outbuf[outpos++] = (byte)'='; // pad character
|
||||
outbuf[outpos++] = (byte)'='; // pad character
|
||||
} else if (size == 2) {
|
||||
a = inbuf[inpos++];
|
||||
b = inbuf[inpos++];
|
||||
c = 0;
|
||||
outbuf[outpos++] = (byte)pem_array[(a >>> 2) & 0x3F];
|
||||
outbuf[outpos++] =
|
||||
(byte)pem_array[((a << 4) & 0x30) + ((b >>> 4) & 0xf)];
|
||||
outbuf[outpos++] =
|
||||
(byte)pem_array[((b << 2) & 0x3c) + ((c >>> 6) & 0x3)];
|
||||
outbuf[outpos++] = (byte)'='; // pad character
|
||||
} else {
|
||||
a = inbuf[inpos++];
|
||||
b = inbuf[inpos++];
|
||||
c = inbuf[inpos++];
|
||||
outbuf[outpos++] = (byte)pem_array[(a >>> 2) & 0x3F];
|
||||
outbuf[outpos++] =
|
||||
(byte)pem_array[((a << 4) & 0x30) + ((b >>> 4) & 0xf)];
|
||||
outbuf[outpos++] =
|
||||
(byte)pem_array[((b << 2) & 0x3c) + ((c >>> 6) & 0x3)];
|
||||
outbuf[outpos++] = (byte)pem_array[c & 0x3F];
|
||||
}
|
||||
size -= 3;
|
||||
}
|
||||
return outbuf;
|
||||
}
|
||||
|
||||
/*** begin TEST program
|
||||
public static void main(String argv[]) throws Exception {
|
||||
FileInputStream infile = new FileInputStream(argv[0]);
|
||||
BASE64EncoderStream encoder = new BASE64EncoderStream(System.out);
|
||||
int c;
|
||||
|
||||
while ((c = infile.read()) != -1)
|
||||
encoder.write(c);
|
||||
encoder.close();
|
||||
}
|
||||
*** end TEST program **/
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)BEncoderStream.java 1.3 02/03/27
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.packaging.mime.util;
|
||||
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* This class implements a 'B' Encoder as defined by RFC2047 for
|
||||
* encoding MIME headers. It subclasses the BASE64EncoderStream
|
||||
* class.
|
||||
*
|
||||
* @author John Mani
|
||||
*/
|
||||
|
||||
public class BEncoderStream extends BASE64EncoderStream {
|
||||
|
||||
/**
|
||||
* Create a 'B' encoder that encodes the specified input stream.
|
||||
* @param out the output stream
|
||||
*/
|
||||
public BEncoderStream(OutputStream out) {
|
||||
super(out, Integer.MAX_VALUE); // MAX_VALUE is 2^31, should
|
||||
// suffice (!) to indicate that
|
||||
// CRLFs should not be inserted
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the length of the encoded version of this byte array.
|
||||
*/
|
||||
public static int encodedLength(byte[] b) {
|
||||
return ((b.length + 2)/3) * 4;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)LineInputStream.java 1.7 03/01/07
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.packaging.mime.util;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* This class is to support reading CRLF terminated lines that
|
||||
* contain only US-ASCII characters from an input stream. Provides
|
||||
* functionality that is similar to the deprecated
|
||||
* <code>DataInputStream.readLine()</code>. Expected use is to read
|
||||
* lines as String objects from a RFC822 stream.
|
||||
*
|
||||
* It is implemented as a FilterInputStream, so one can just wrap
|
||||
* this class around any input stream and read bytes from this filter.
|
||||
*
|
||||
* @author John Mani
|
||||
*/
|
||||
|
||||
public final class LineInputStream extends FilterInputStream {
|
||||
|
||||
private char[] lineBuffer = null; // reusable byte buffer
|
||||
|
||||
public LineInputStream(InputStream in) {
|
||||
super(in);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a line containing only ASCII characters from the input
|
||||
* stream. A line is terminated by a CR or NL or CR-NL sequence.
|
||||
* A common error is a CR-CR-NL sequence, which will also terminate
|
||||
* a line.
|
||||
* The line terminator is not returned as part of the returned
|
||||
* String. Returns null if no data is available. <p>
|
||||
*
|
||||
* This class is similar to the deprecated
|
||||
* <code>DataInputStream.readLine()</code>
|
||||
*/
|
||||
public String readLine() throws IOException {
|
||||
InputStream in = this.in;
|
||||
char[] buf = lineBuffer;
|
||||
|
||||
if (buf == null)
|
||||
buf = lineBuffer = new char[128];
|
||||
|
||||
int c1;
|
||||
int room = buf.length;
|
||||
int offset = 0;
|
||||
|
||||
while ((c1 = in.read()) != -1) {
|
||||
if (c1 == '\n') // Got NL, outa here.
|
||||
break;
|
||||
else if (c1 == '\r') {
|
||||
// Got CR, is the next char NL ?
|
||||
int c2 = in.read();
|
||||
if (c2 == '\r') // discard extraneous CR
|
||||
c2 = in.read();
|
||||
if (c2 != '\n') {
|
||||
// If not NL, push it back
|
||||
if (!(in instanceof PushbackInputStream))
|
||||
in = this.in = new PushbackInputStream(in);
|
||||
((PushbackInputStream)in).unread(c2);
|
||||
}
|
||||
break; // outa here.
|
||||
}
|
||||
|
||||
// Not CR, NL or CR-NL ...
|
||||
// .. Insert the byte into our byte buffer
|
||||
if (--room < 0) { // No room, need to grow.
|
||||
buf = new char[offset + 128];
|
||||
room = buf.length - offset - 1;
|
||||
System.arraycopy(lineBuffer, 0, buf, 0, offset);
|
||||
lineBuffer = buf;
|
||||
}
|
||||
buf[offset++] = (char)c1;
|
||||
}
|
||||
|
||||
if ((c1 == -1) && (offset == 0))
|
||||
return null;
|
||||
|
||||
return String.copyValueOf(buf, 0, offset);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)OutputUtil.java 1.6 02/03/27
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.packaging.mime.util;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* This class is to support writing out Strings as a sequence of bytes
|
||||
* terminated by a CRLF sequence. The String must contain only US-ASCII
|
||||
* characters.<p>
|
||||
*
|
||||
* The expected use is to write out RFC822 style headers to an output
|
||||
* stream. <p>
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public abstract class OutputUtil {
|
||||
private static byte[] newline = {'\r','\n'};
|
||||
|
||||
public static void writeln(String s,OutputStream out) throws IOException {
|
||||
writeAsAscii(s,out);
|
||||
writeln(out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a string as ASCII string.
|
||||
*/
|
||||
public static void writeAsAscii(String s,OutputStream out) throws IOException {
|
||||
int len = s.length();
|
||||
for( int i=0; i<len; i++ )
|
||||
out.write((byte)s.charAt(i));
|
||||
}
|
||||
|
||||
public static void writeln(OutputStream out) throws IOException {
|
||||
out.write(newline);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)QDecoderStream.java 1.5 02/03/27
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.packaging.mime.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* This class implements a Q Decoder as defined in RFC 2047
|
||||
* for decoding MIME headers. It subclasses the QPDecoderStream class.
|
||||
*
|
||||
* @author John Mani
|
||||
*/
|
||||
|
||||
public class QDecoderStream extends QPDecoderStream {
|
||||
|
||||
/**
|
||||
* Create a Q-decoder that decodes the specified input stream.
|
||||
* @param in the input stream
|
||||
*/
|
||||
public QDecoderStream(InputStream in) {
|
||||
super(in);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the next decoded byte from this input stream. The byte
|
||||
* is returned as an <code>int</code> in the range <code>0</code>
|
||||
* to <code>255</code>. If no byte is available because the end of
|
||||
* the stream has been reached, the value <code>-1</code> is returned.
|
||||
* This method blocks until input data is available, the end of the
|
||||
* stream is detected, or an exception is thrown.
|
||||
*
|
||||
* @return the next byte of data, or <code>-1</code> if the end of the
|
||||
* stream is reached.
|
||||
* @exception IOException if an I/O error occurs.
|
||||
*/
|
||||
public int read() throws IOException {
|
||||
int c = in.read();
|
||||
|
||||
if (c == '_') // Return '_' as ' '
|
||||
return ' ';
|
||||
else if (c == '=') {
|
||||
// QP Encoded atom. Get the next two bytes ..
|
||||
ba[0] = (byte)in.read();
|
||||
ba[1] = (byte)in.read();
|
||||
// .. and decode them
|
||||
try {
|
||||
return ASCIIUtility.parseInt(ba, 0, 2, 16);
|
||||
} catch (NumberFormatException nex) {
|
||||
throw new IOException("Error in QP stream " + nex.getMessage());
|
||||
}
|
||||
} else
|
||||
return c;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)QEncoderStream.java 1.4 02/03/27
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.packaging.mime.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* This class implements a Q Encoder as defined by RFC 2047 for
|
||||
* encoding MIME headers. It subclasses the QPEncoderStream class.
|
||||
*
|
||||
* @author John Mani
|
||||
*/
|
||||
|
||||
public class QEncoderStream extends QPEncoderStream {
|
||||
|
||||
private String specials;
|
||||
private static String WORD_SPECIALS = "=_?\"#$%&'(),.:;<>@[\\]^`{|}~";
|
||||
private static String TEXT_SPECIALS = "=_?";
|
||||
|
||||
/**
|
||||
* Create a Q encoder that encodes the specified input stream
|
||||
* @param out the output stream
|
||||
* @param encodingWord true if we are Q-encoding a word within a
|
||||
* phrase.
|
||||
*/
|
||||
public QEncoderStream(OutputStream out, boolean encodingWord) {
|
||||
super(out, Integer.MAX_VALUE); // MAX_VALUE is 2^31, should
|
||||
// suffice (!) to indicate that
|
||||
// CRLFs should not be inserted
|
||||
// when encoding rfc822 headers
|
||||
|
||||
// a RFC822 "word" token has more restrictions than a
|
||||
// RFC822 "text" token.
|
||||
specials = encodingWord ? WORD_SPECIALS : TEXT_SPECIALS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes the specified <code>byte</code> to this output stream.
|
||||
* @param c the <code>byte</code>.
|
||||
* @exception IOException if an I/O error occurs.
|
||||
*/
|
||||
public void write(int c) throws IOException {
|
||||
c = c & 0xff; // Turn off the MSB.
|
||||
if (c == ' ')
|
||||
output('_', false);
|
||||
else if (c < 040 || c >= 0177 || specials.indexOf(c) >= 0)
|
||||
// Encoding required.
|
||||
output(c, true);
|
||||
else // No encoding required
|
||||
output(c, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the length of the encoded version of this byte array.
|
||||
*/
|
||||
public static int encodedLength(byte[] b, boolean encodingWord) {
|
||||
int len = 0;
|
||||
String specials = encodingWord ? WORD_SPECIALS: TEXT_SPECIALS;
|
||||
for (int i = 0; i < b.length; i++) {
|
||||
int c = b[i] & 0xff; // Mask off MSB
|
||||
if (c < 040 || c >= 0177 || specials.indexOf(c) >= 0)
|
||||
// needs encoding
|
||||
len += 3; // Q-encoding is 1 -> 3 conversion
|
||||
else
|
||||
len++;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
/**** begin TEST program ***
|
||||
public static void main(String argv[]) throws Exception {
|
||||
FileInputStream infile = new FileInputStream(argv[0]);
|
||||
QEncoderStream encoder = new QEncoderStream(System.out);
|
||||
int c;
|
||||
|
||||
while ((c = infile.read()) != -1)
|
||||
encoder.write(c);
|
||||
encoder.close();
|
||||
}
|
||||
*** end TEST program ***/
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)QPDecoderStream.java 1.9 02/04/02
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.packaging.mime.util;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* This class implements a QP Decoder. It is implemented as
|
||||
* a FilterInputStream, so one can just wrap this class around
|
||||
* any input stream and read bytes from this filter. The decoding
|
||||
* is done as the bytes are read out.
|
||||
*
|
||||
* @author John Mani
|
||||
*/
|
||||
|
||||
public class QPDecoderStream extends FilterInputStream {
|
||||
protected byte[] ba = new byte[2];
|
||||
protected int spaces = 0;
|
||||
|
||||
/**
|
||||
* Create a Quoted Printable decoder that decodes the specified
|
||||
* input stream.
|
||||
* @param in the input stream
|
||||
*/
|
||||
public QPDecoderStream(InputStream in) {
|
||||
super(new PushbackInputStream(in, 2)); // pushback of size=2
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the next decoded byte from this input stream. The byte
|
||||
* is returned as an <code>int</code> in the range <code>0</code>
|
||||
* to <code>255</code>. If no byte is available because the end of
|
||||
* the stream has been reached, the value <code>-1</code> is returned.
|
||||
* This method blocks until input data is available, the end of the
|
||||
* stream is detected, or an exception is thrown.
|
||||
*
|
||||
* @return the next byte of data, or <code>-1</code> if the end of the
|
||||
* stream is reached.
|
||||
* @exception IOException if an I/O error occurs.
|
||||
*/
|
||||
public int read() throws IOException {
|
||||
if (spaces > 0) {
|
||||
// We have cached space characters, return one
|
||||
spaces--;
|
||||
return ' ';
|
||||
}
|
||||
|
||||
int c = in.read();
|
||||
|
||||
if (c == ' ') {
|
||||
// Got space, keep reading till we get a non-space char
|
||||
while ((c = in.read()) == ' ')
|
||||
spaces++;
|
||||
|
||||
if (c == '\r' || c == '\n' || c == -1)
|
||||
// If the non-space char is CR/LF/EOF, the spaces we got
|
||||
// so far is junk introduced during transport. Junk 'em.
|
||||
spaces = 0;
|
||||
else {
|
||||
// The non-space char is NOT CR/LF, the spaces are valid.
|
||||
((PushbackInputStream)in).unread(c);
|
||||
c = ' ';
|
||||
}
|
||||
return c; // return either <SPACE> or <CR/LF>
|
||||
}
|
||||
else if (c == '=') {
|
||||
// QP Encoded atom. Decode the next two bytes
|
||||
int a = in.read();
|
||||
|
||||
if (a == '\n') {
|
||||
/* Hmm ... not really confirming QP encoding, but lets
|
||||
* allow this as a LF terminated encoded line .. and
|
||||
* consider this a soft linebreak and recurse to fetch
|
||||
* the next char.
|
||||
*/
|
||||
return read();
|
||||
} else if (a == '\r') {
|
||||
// Expecting LF. This forms a soft linebreak to be ignored.
|
||||
int b = in.read();
|
||||
if (b != '\n')
|
||||
/* Not really confirming QP encoding, but
|
||||
* lets allow this as well.
|
||||
*/
|
||||
((PushbackInputStream)in).unread(b);
|
||||
return read();
|
||||
} else if (a == -1) {
|
||||
// Not valid QP encoding, but we be nice and tolerant here !
|
||||
return -1;
|
||||
} else {
|
||||
ba[0] = (byte)a;
|
||||
ba[1] = (byte)in.read();
|
||||
try {
|
||||
return ASCIIUtility.parseInt(ba, 0, 2, 16);
|
||||
} catch (NumberFormatException nex) {
|
||||
/*
|
||||
System.err.println(
|
||||
"Illegal characters in QP encoded stream: " +
|
||||
ASCIIUtility.toString(ba, 0, 2)
|
||||
);
|
||||
*/
|
||||
|
||||
((PushbackInputStream)in).unread(ba);
|
||||
return c;
|
||||
}
|
||||
}
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads up to <code>len</code> decoded bytes of data from this input stream
|
||||
* into an array of bytes. This method blocks until some input is
|
||||
* available.
|
||||
* <p>
|
||||
*
|
||||
* @param buf the buffer into which the data is read.
|
||||
* @param off the start offset of the data.
|
||||
* @param len the maximum number of bytes read.
|
||||
* @return the total number of bytes read into the buffer, or
|
||||
* <code>-1</code> if there is no more data because the end of
|
||||
* the stream has been reached.
|
||||
* @exception IOException if an I/O error occurs.
|
||||
*/
|
||||
public int read(byte[] buf, int off, int len) throws IOException {
|
||||
int i, c;
|
||||
for (i = 0; i < len; i++) {
|
||||
if ((c = read()) == -1) {
|
||||
if (i == 0) // At end of stream, so we should
|
||||
i = -1; // return -1 , NOT 0.
|
||||
break;
|
||||
}
|
||||
buf[off+i] = (byte)c;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if this input stream supports marks. Currently this class
|
||||
* does not support marks
|
||||
*/
|
||||
public boolean markSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of bytes that can be read from this input
|
||||
* stream without blocking. The QP algorithm does not permit
|
||||
* a priori knowledge of the number of bytes after decoding, so
|
||||
* this method just invokes the <code>available</code> method
|
||||
* of the original input stream.
|
||||
*/
|
||||
public int available() throws IOException {
|
||||
// This is bogus ! We don't really know how much
|
||||
// bytes are available *after* decoding
|
||||
return in.available();
|
||||
}
|
||||
|
||||
/**** begin TEST program
|
||||
public static void main(String argv[]) throws Exception {
|
||||
FileInputStream infile = new FileInputStream(argv[0]);
|
||||
QPDecoderStream decoder = new QPDecoderStream(infile);
|
||||
int c;
|
||||
|
||||
while ((c = decoder.read()) != -1)
|
||||
System.out.print((char)c);
|
||||
System.out.println();
|
||||
}
|
||||
*** end TEST program ****/
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)QPEncoderStream.java 1.6 02/03/27
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.packaging.mime.util;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* This class implements a Quoted Printable Encoder. It is implemented as
|
||||
* a FilterOutputStream, so one can just wrap this class around
|
||||
* any output stream and write bytes into this filter. The Encoding
|
||||
* is done as the bytes are written out.
|
||||
*
|
||||
* @author John Mani
|
||||
*/
|
||||
|
||||
public class QPEncoderStream extends FilterOutputStream {
|
||||
private int count = 0; // number of bytes that have been output
|
||||
private int bytesPerLine; // number of bytes per line
|
||||
private boolean gotSpace = false;
|
||||
private boolean gotCR = false;
|
||||
|
||||
/**
|
||||
* Create a QP encoder that encodes the specified input stream
|
||||
* @param out the output stream
|
||||
* @param bytesPerLine the number of bytes per line. The encoder
|
||||
* inserts a CRLF sequence after this many number
|
||||
* of bytes.
|
||||
*/
|
||||
public QPEncoderStream(OutputStream out, int bytesPerLine) {
|
||||
super(out);
|
||||
// Subtract 1 to account for the '=' in the soft-return
|
||||
// at the end of a line
|
||||
this.bytesPerLine = bytesPerLine - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a QP encoder that encodes the specified input stream.
|
||||
* Inserts the CRLF sequence after outputting 76 bytes.
|
||||
* @param out the output stream
|
||||
*/
|
||||
public QPEncoderStream(OutputStream out) {
|
||||
this(out, 76);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes <code>len</code> bytes from the specified
|
||||
* <code>byte</code> array starting at offset <code>off</code> to
|
||||
* this output stream.
|
||||
*
|
||||
* @param b the data.
|
||||
* @param off the start offset in the data.
|
||||
* @param len the number of bytes to write.
|
||||
* @exception IOException if an I/O error occurs.
|
||||
*/
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
for (int i = 0; i < len; i++)
|
||||
write(b[off + i]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes <code>b.length</code> bytes to this output stream.
|
||||
* @param b the data to be written.
|
||||
* @exception IOException if an I/O error occurs.
|
||||
*/
|
||||
public void write(byte[] b) throws IOException {
|
||||
write(b, 0, b.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes the specified <code>byte</code> to this output stream.
|
||||
* @param c the <code>byte</code>.
|
||||
* @exception IOException if an I/O error occurs.
|
||||
*/
|
||||
public void write(int c) throws IOException {
|
||||
c = c & 0xff; // Turn off the MSB.
|
||||
if (gotSpace) { // previous character was <SPACE>
|
||||
if (c == '\r' || c == '\n')
|
||||
// if CR/LF, we need to encode the <SPACE> char
|
||||
output(' ', true);
|
||||
else // no encoding required, just output the char
|
||||
output(' ', false);
|
||||
gotSpace = false;
|
||||
}
|
||||
|
||||
if (c == '\r') {
|
||||
gotCR = true;
|
||||
outputCRLF();
|
||||
} else {
|
||||
if (c == '\n') {
|
||||
if (gotCR)
|
||||
// This is a CRLF sequence, we already output the
|
||||
// corresponding CRLF when we got the CR, so ignore this
|
||||
;
|
||||
else
|
||||
outputCRLF();
|
||||
} else if (c == ' ') {
|
||||
gotSpace = true;
|
||||
} else if (c < 040 || c >= 0177 || c == '=')
|
||||
// Encoding required.
|
||||
output(c, true);
|
||||
else // No encoding required
|
||||
output(c, false);
|
||||
// whatever it was, it wasn't a CR
|
||||
gotCR = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes this output stream and forces any buffered output bytes
|
||||
* to be encoded out to the stream.
|
||||
* @exception IOException if an I/O error occurs.
|
||||
*/
|
||||
public void flush() throws IOException {
|
||||
out.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces any buffered output bytes to be encoded out to the stream
|
||||
* and closes this output stream
|
||||
*/
|
||||
public void close() throws IOException {
|
||||
out.close();
|
||||
}
|
||||
|
||||
private void outputCRLF() throws IOException {
|
||||
out.write('\r');
|
||||
out.write('\n');
|
||||
count = 0;
|
||||
}
|
||||
|
||||
// The encoding table
|
||||
private final static char hex[] = {
|
||||
'0','1', '2', '3', '4', '5', '6', '7',
|
||||
'8','9', 'A', 'B', 'C', 'D', 'E', 'F'
|
||||
};
|
||||
|
||||
protected void output(int c, boolean encode) throws IOException {
|
||||
if (encode) {
|
||||
if ((count += 3) > bytesPerLine) {
|
||||
out.write('=');
|
||||
out.write('\r');
|
||||
out.write('\n');
|
||||
count = 3; // set the next line's length
|
||||
}
|
||||
out.write('=');
|
||||
out.write(hex[c >> 4]);
|
||||
out.write(hex[c & 0xf]);
|
||||
} else {
|
||||
if (++count > bytesPerLine) {
|
||||
out.write('=');
|
||||
out.write('\r');
|
||||
out.write('\n');
|
||||
count = 1; // set the next line's length
|
||||
}
|
||||
out.write(c);
|
||||
}
|
||||
}
|
||||
|
||||
/**** begin TEST program ***
|
||||
public static void main(String argv[]) throws Exception {
|
||||
FileInputStream infile = new FileInputStream(argv[0]);
|
||||
QPEncoderStream encoder = new QPEncoderStream(System.out);
|
||||
int c;
|
||||
|
||||
while ((c = infile.read()) != -1)
|
||||
encoder.write(c);
|
||||
encoder.close();
|
||||
}
|
||||
*** end TEST program ***/
|
||||
}
|
||||
@@ -0,0 +1,257 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)UUDecoderStream.java 1.8 02/07/08
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.packaging.mime.util;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* This class implements a UUDecoder. It is implemented as
|
||||
* a FilterInputStream, so one can just wrap this class around
|
||||
* any input stream and read bytes from this filter. The decoding
|
||||
* is done as the bytes are read out.
|
||||
*
|
||||
* @author John Mani
|
||||
* @author Bill Shannon
|
||||
*/
|
||||
|
||||
public class UUDecoderStream extends FilterInputStream {
|
||||
private String name;
|
||||
private int mode;
|
||||
|
||||
private byte[] buffer; // cache of decoded bytes
|
||||
private int bufsize = 0; // size of the cache
|
||||
private int index = 0; // index into the cache
|
||||
private boolean gotPrefix = false;
|
||||
private boolean gotEnd = false;
|
||||
private LineInputStream lin;
|
||||
|
||||
/**
|
||||
* Create a UUdecoder that decodes the specified input stream
|
||||
* @param in the input stream
|
||||
*/
|
||||
public UUDecoderStream(InputStream in) {
|
||||
super(in);
|
||||
lin = new LineInputStream(in);
|
||||
buffer = new byte[45]; // max decoded chars in a line = 45
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the next decoded byte from this input stream. The byte
|
||||
* is returned as an <code>int</code> in the range <code>0</code>
|
||||
* to <code>255</code>. If no byte is available because the end of
|
||||
* the stream has been reached, the value <code>-1</code> is returned.
|
||||
* This method blocks until input data is available, the end of the
|
||||
* stream is detected, or an exception is thrown.
|
||||
*
|
||||
* @return next byte of data, or <code>-1</code> if the end of
|
||||
* stream is reached.
|
||||
* @exception IOException if an I/O error occurs.
|
||||
* @see java.io.FilterInputStream#in
|
||||
*/
|
||||
|
||||
public int read() throws IOException {
|
||||
if (index >= bufsize) {
|
||||
readPrefix();
|
||||
if (!decode())
|
||||
return -1;
|
||||
index = 0; // reset index into buffer
|
||||
}
|
||||
return buffer[index++] & 0xff; // return lower byte
|
||||
}
|
||||
|
||||
public int read(byte[] buf, int off, int len) throws IOException {
|
||||
int i, c;
|
||||
for (i = 0; i < len; i++) {
|
||||
if ((c = read()) == -1) {
|
||||
if (i == 0) // At end of stream, so we should
|
||||
i = -1; // return -1, NOT 0.
|
||||
break;
|
||||
}
|
||||
buf[off+i] = (byte)c;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
public boolean markSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public int available() throws IOException {
|
||||
// This is only an estimate, since in.available()
|
||||
// might include CRLFs too ..
|
||||
return ((in.available() * 3)/4 + (bufsize-index));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the "name" field from the prefix. This is meant to
|
||||
* be the pathname of the decoded file
|
||||
*
|
||||
* @return name of decoded file
|
||||
* @exception IOException if an I/O error occurs.
|
||||
*/
|
||||
public String getName() throws IOException {
|
||||
readPrefix();
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the "mode" field from the prefix. This is the permission
|
||||
* mode of the source file.
|
||||
*
|
||||
* @return permission mode of source file
|
||||
* @exception IOException if an I/O error occurs.
|
||||
*/
|
||||
public int getMode() throws IOException {
|
||||
readPrefix();
|
||||
return mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* UUencoded streams start off with the line:
|
||||
* "begin <mode> <filename>"
|
||||
* Search for this prefix and gobble it up.
|
||||
*/
|
||||
private void readPrefix() throws IOException {
|
||||
if (gotPrefix) // got the prefix
|
||||
return;
|
||||
|
||||
String s;
|
||||
for (;;) {
|
||||
// read till we get the prefix: "begin MODE FILENAME"
|
||||
s = lin.readLine(); // NOTE: readLine consumes CRLF pairs too
|
||||
if (s == null)
|
||||
throw new IOException("UUDecoder error: No Begin");
|
||||
if (s.regionMatches(true, 0, "begin", 0, 5)) {
|
||||
try {
|
||||
mode = Integer.parseInt(s.substring(6,9));
|
||||
} catch (NumberFormatException ex) {
|
||||
throw new IOException("UUDecoder error: " + ex.toString());
|
||||
}
|
||||
name = s.substring(10);
|
||||
gotPrefix = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean decode() throws IOException {
|
||||
|
||||
if (gotEnd)
|
||||
return false;
|
||||
bufsize = 0;
|
||||
String line;
|
||||
do {
|
||||
line = lin.readLine();
|
||||
|
||||
/*
|
||||
* Improperly encoded data sometimes omits the zero length
|
||||
* line that starts with a space character, we detect the
|
||||
* following "end" line here.
|
||||
*/
|
||||
if (line == null)
|
||||
throw new IOException("Missing End");
|
||||
if (line.regionMatches(true, 0, "end", 0, 3)) {
|
||||
gotEnd = true;
|
||||
return false;
|
||||
}
|
||||
} while (line.length() == 0);
|
||||
int count = line.charAt(0);
|
||||
if (count < ' ')
|
||||
throw new IOException("Buffer format error");
|
||||
|
||||
/*
|
||||
* The first character in a line is the number of original (not
|
||||
* the encoded atoms) characters in the line. Note that all the
|
||||
* code below has to handle the <SPACE> character that indicates
|
||||
* end of encoded stream.
|
||||
*/
|
||||
count = (count - ' ') & 0x3f;
|
||||
|
||||
if (count == 0) {
|
||||
line = lin.readLine();
|
||||
if (line == null || !line.regionMatches(true, 0, "end", 0, 3))
|
||||
throw new IOException("Missing End");
|
||||
gotEnd = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
int need = ((count * 8)+5)/6;
|
||||
//System.out.println("count " + count + ", need " + need + ", len " + line.length());
|
||||
if (line.length() < need + 1)
|
||||
throw new IOException("Short buffer error");
|
||||
|
||||
int i = 1;
|
||||
byte a, b;
|
||||
/*
|
||||
* A correct uuencoder always encodes 3 characters at a time, even
|
||||
* if there aren't 3 characters left. But since some people out
|
||||
* there have broken uuencoders we handle the case where they
|
||||
* don't include these "unnecessary" characters.
|
||||
*/
|
||||
while (bufsize < count) {
|
||||
// continue decoding until we get 'count' decoded chars
|
||||
a = (byte)((line.charAt(i++) - ' ') & 0x3f);
|
||||
b = (byte)((line.charAt(i++) - ' ') & 0x3f);
|
||||
buffer[bufsize++] = (byte)(((a << 2) & 0xfc) | ((b >>> 4) & 3));
|
||||
|
||||
if (bufsize < count) {
|
||||
a = b;
|
||||
b = (byte)((line.charAt(i++) - ' ') & 0x3f);
|
||||
buffer[bufsize++] =
|
||||
(byte)(((a << 4) & 0xf0) | ((b >>> 2) & 0xf));
|
||||
}
|
||||
|
||||
if (bufsize < count) {
|
||||
a = b;
|
||||
b = (byte)((line.charAt(i++) - ' ') & 0x3f);
|
||||
buffer[bufsize++] = (byte)(((a << 6) & 0xc0) | (b & 0x3f));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*** begin TEST program *****
|
||||
public static void main(String argv[]) throws Exception {
|
||||
FileInputStream infile = new FileInputStream(argv[0]);
|
||||
UUDecoderStream decoder = new UUDecoderStream(infile);
|
||||
int c;
|
||||
|
||||
try {
|
||||
while ((c = decoder.read()) != -1)
|
||||
System.out.write(c);
|
||||
System.out.flush();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
**** end TEST program ****/
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @(#)UUEncoderStream.java 1.3 02/03/27
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.packaging.mime.util;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* This class implements a UUEncoder. It is implemented as
|
||||
* a FilterOutputStream, so one can just wrap this class around
|
||||
* any output stream and write bytes into this filter. The Encoding
|
||||
* is done as the bytes are written out.
|
||||
*
|
||||
* @author John Mani
|
||||
*/
|
||||
|
||||
public class UUEncoderStream extends FilterOutputStream {
|
||||
private byte[] buffer; // cache of bytes that are yet to be encoded
|
||||
private int bufsize = 0; // size of the cache
|
||||
private boolean wrotePrefix = false;
|
||||
|
||||
protected String name; // name of file
|
||||
protected int mode; // permissions mode
|
||||
|
||||
/**
|
||||
* Create a UUencoder that encodes the specified input stream
|
||||
* @param out the output stream
|
||||
*/
|
||||
public UUEncoderStream(OutputStream out) {
|
||||
this(out, "encoder.buf", 644);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a UUencoder that encodes the specified input stream
|
||||
* @param out the output stream
|
||||
* @param name Specifies a name for the encoded buffer
|
||||
*/
|
||||
public UUEncoderStream(OutputStream out, String name) {
|
||||
this(out, name, 644);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a UUencoder that encodes the specified input stream
|
||||
* @param out the output stream
|
||||
* @param name Specifies a name for the encoded buffer
|
||||
* @param mode Specifies permission mode for the encoded buffer
|
||||
*/
|
||||
public UUEncoderStream(OutputStream out, String name, int mode) {
|
||||
super(out);
|
||||
this.name = name;
|
||||
this.mode = mode;
|
||||
buffer = new byte[45];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up the buffer name and permission mode.
|
||||
* This method has any effect only if it is invoked before
|
||||
* you start writing into the output stream
|
||||
*/
|
||||
public void setNameMode(String name, int mode) {
|
||||
this.name = name;
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
for (int i = 0; i < len; i++)
|
||||
write(b[off + i]);
|
||||
}
|
||||
|
||||
public void write(byte[] data) throws IOException {
|
||||
write(data, 0, data.length);
|
||||
}
|
||||
|
||||
public void write(int c) throws IOException {
|
||||
/* buffer up characters till we get a line's worth, then encode
|
||||
* and write them out. Max number of characters allowed per
|
||||
* line is 45.
|
||||
*/
|
||||
buffer[bufsize++] = (byte)c;
|
||||
if (bufsize == 45) {
|
||||
writePrefix();
|
||||
encode();
|
||||
bufsize = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void flush() throws IOException {
|
||||
if (bufsize > 0) { // If there's unencoded characters in the buffer
|
||||
writePrefix();
|
||||
encode(); // .. encode them
|
||||
}
|
||||
writeSuffix();
|
||||
out.flush();
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
flush();
|
||||
out.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write out the prefix: "begin <mode> <name>"
|
||||
*/
|
||||
private void writePrefix() throws IOException {
|
||||
if (!wrotePrefix) {
|
||||
PrintStream ps = new PrintStream(out);
|
||||
ps.println("begin " + mode + " " + name);
|
||||
ps.flush();
|
||||
wrotePrefix = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a single line containing space and the suffix line
|
||||
* containing the single word "end" (terminated by a newline)
|
||||
*/
|
||||
private void writeSuffix() throws IOException {
|
||||
PrintStream ps = new PrintStream(out);
|
||||
ps.println(" \nend");
|
||||
ps.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode a line.
|
||||
* Start off with the character count, followed by the encoded atoms
|
||||
* and terminate with LF. (or is it CRLF or the local line-terminator ?)
|
||||
* Take three bytes and encodes them into 4 characters
|
||||
* If bufsize if not a multiple of 3, the remaining bytes are filled
|
||||
* with '1'. This insures that the last line won't end in spaces
|
||||
* and potentiallly be truncated.
|
||||
*/
|
||||
private void encode() throws IOException {
|
||||
byte a, b, c;
|
||||
int c1, c2, c3, c4;
|
||||
int i = 0;
|
||||
|
||||
// Start off with the count of characters in the line
|
||||
out.write((bufsize & 0x3f) + ' ');
|
||||
|
||||
while (i < bufsize) {
|
||||
a = buffer[i++];
|
||||
if (i < bufsize) {
|
||||
b = buffer[i++];
|
||||
if (i < bufsize)
|
||||
c = buffer[i++];
|
||||
else // default c to 1
|
||||
c = 1;
|
||||
}
|
||||
else { // default b & c to 1
|
||||
b = 1;
|
||||
c = 1;
|
||||
}
|
||||
|
||||
c1 = (a >>> 2) & 0x3f;
|
||||
c2 = ((a << 4) & 0x30) | ((b >>> 4) & 0xf);
|
||||
c3 = ((b << 2) & 0x3c) | ((c >>> 6) & 0x3);
|
||||
c4 = c & 0x3f;
|
||||
out.write(c1 + ' ');
|
||||
out.write(c2 + ' ');
|
||||
out.write(c3 + ' ');
|
||||
out.write(c4 + ' ');
|
||||
}
|
||||
// Terminate with LF. (should it be CRLF or local line-terminator ?)
|
||||
out.write('\n');
|
||||
}
|
||||
|
||||
/**** begin TEST program *****
|
||||
public static void main(String argv[]) throws Exception {
|
||||
FileInputStream infile = new FileInputStream(argv[0]);
|
||||
UUEncoderStream encoder = new UUEncoderStream(System.out);
|
||||
int c;
|
||||
|
||||
while ((c = infile.read()) != -1)
|
||||
encoder.write(c);
|
||||
encoder.close();
|
||||
}
|
||||
**** end TEST program *****/
|
||||
}
|
||||
@@ -0,0 +1,607 @@
|
||||
/*
|
||||
* 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.soap;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.packaging.mime.util.ASCIIUtility;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.packaging.mime.Header;
|
||||
import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.MimePartDataSource;
|
||||
import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.InternetHeaders;
|
||||
import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.MimeBodyPart;
|
||||
import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.MimeUtility;
|
||||
import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream;
|
||||
import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.activation.*;
|
||||
import javax.xml.soap.*;
|
||||
import com.sun.xml.internal.org.jvnet.mimepull.MIMEPart;
|
||||
|
||||
/**
|
||||
* Implementation of attachments.
|
||||
*
|
||||
* @author Anil Vijendran (akv@eng.sun.com)
|
||||
*/
|
||||
public class AttachmentPartImpl extends AttachmentPart {
|
||||
|
||||
protected static final Logger log =
|
||||
Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
|
||||
"com.sun.xml.internal.messaging.saaj.soap.LocalStrings");
|
||||
|
||||
private final MimeHeaders headers;
|
||||
private MimeBodyPart rawContent = null;
|
||||
private DataHandler dataHandler = null;
|
||||
|
||||
//alternate impl that uses a MIMEPart
|
||||
private MIMEPart mimePart = 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 AttachmentPartImpl(MIMEPart part) {
|
||||
headers = new MimeHeaders();
|
||||
mimePart = part;
|
||||
List<? extends com.sun.xml.internal.org.jvnet.mimepull.Header> hdrs = part.getAllHeaders();
|
||||
for (com.sun.xml.internal.org.jvnet.mimepull.Header hd : hdrs) {
|
||||
headers.addHeader(hd.getName(), hd.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public int getSize() throws SOAPException {
|
||||
byte[] bytes;
|
||||
if (mimePart != null) {
|
||||
try {
|
||||
return mimePart.read().available();
|
||||
} catch (IOException e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if ((rawContent == null) && (dataHandler == null))
|
||||
return 0;
|
||||
|
||||
if (rawContent != null) {
|
||||
try {
|
||||
return rawContent.getSize();
|
||||
} catch (Exception ex) {
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0573.soap.attachment.getrawbytes.ioexception",
|
||||
new String[] { ex.getLocalizedMessage()});
|
||||
throw new SOAPExceptionImpl("Raw InputStream Error: " + ex);
|
||||
}
|
||||
} else {
|
||||
ByteOutputStream bout = new ByteOutputStream();
|
||||
try {
|
||||
dataHandler.writeTo(bout);
|
||||
} catch (IOException ex) {
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0501.soap.data.handler.err",
|
||||
new String[] { ex.getLocalizedMessage()});
|
||||
throw new SOAPExceptionImpl("Data handler error: " + ex);
|
||||
}
|
||||
return bout.size();
|
||||
}
|
||||
}
|
||||
|
||||
public void clearContent() {
|
||||
if (mimePart != null) {
|
||||
mimePart.close();
|
||||
mimePart = null;
|
||||
}
|
||||
dataHandler = null;
|
||||
rawContent = null;
|
||||
}
|
||||
|
||||
public Object getContent() throws SOAPException {
|
||||
try {
|
||||
if (mimePart != null) {
|
||||
//return an inputstream
|
||||
return mimePart.read();
|
||||
}
|
||||
if (dataHandler != null) {
|
||||
return getDataHandler().getContent();
|
||||
} else if (rawContent != null) {
|
||||
return rawContent.getContent();
|
||||
} else {
|
||||
log.severe("SAAJ0572.soap.no.content.for.attachment");
|
||||
throw new SOAPExceptionImpl("No data handler/content associated with this attachment");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
log.log(Level.SEVERE, "SAAJ0575.soap.attachment.getcontent.exception", ex);
|
||||
throw new SOAPExceptionImpl(ex.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void setContent(Object object, String contentType)
|
||||
throws IllegalArgumentException {
|
||||
if (mimePart != null) {
|
||||
mimePart.close();
|
||||
mimePart = null;
|
||||
}
|
||||
DataHandler dh = new DataHandler(object, contentType);
|
||||
|
||||
setDataHandler(dh);
|
||||
}
|
||||
|
||||
|
||||
public DataHandler getDataHandler() throws SOAPException {
|
||||
if (mimePart != null) {
|
||||
//return an inputstream
|
||||
return new DataHandler(new DataSource() {
|
||||
|
||||
public InputStream getInputStream() throws IOException {
|
||||
return mimePart.read();
|
||||
}
|
||||
|
||||
public OutputStream getOutputStream() throws IOException {
|
||||
throw new UnsupportedOperationException("getOutputStream cannot be supported : You have enabled LazyAttachments Option");
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return mimePart.getContentType();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "MIMEPart Wrapper DataSource";
|
||||
}
|
||||
});
|
||||
}
|
||||
if (dataHandler == null) {
|
||||
if (rawContent != null) {
|
||||
return new DataHandler(new MimePartDataSource(rawContent));
|
||||
}
|
||||
log.severe("SAAJ0502.soap.no.handler.for.attachment");
|
||||
throw new SOAPExceptionImpl("No data handler associated with this attachment");
|
||||
}
|
||||
return dataHandler;
|
||||
}
|
||||
|
||||
public void setDataHandler(DataHandler dataHandler)
|
||||
throws IllegalArgumentException {
|
||||
if (mimePart != null) {
|
||||
mimePart.close();
|
||||
mimePart = null;
|
||||
}
|
||||
if (dataHandler == null) {
|
||||
log.severe("SAAJ0503.soap.no.null.to.dataHandler");
|
||||
throw new IllegalArgumentException("Null dataHandler argument to setDataHandler");
|
||||
}
|
||||
this.dataHandler = dataHandler;
|
||||
rawContent = null;
|
||||
|
||||
if (log.isLoggable(Level.FINE))
|
||||
log.log(Level.FINE, "SAAJ0580.soap.set.Content-Type",
|
||||
new String[] { dataHandler.getContentType() });
|
||||
setMimeHeader("Content-Type", dataHandler.getContentType());
|
||||
}
|
||||
|
||||
public void removeAllMimeHeaders() {
|
||||
headers.removeAllHeaders();
|
||||
}
|
||||
|
||||
public void removeMimeHeader(String header) {
|
||||
headers.removeHeader(header);
|
||||
}
|
||||
|
||||
public String[] getMimeHeader(String name) {
|
||||
return headers.getHeader(name);
|
||||
}
|
||||
|
||||
public void setMimeHeader(String name, String value) {
|
||||
headers.setHeader(name, value);
|
||||
}
|
||||
|
||||
public void addMimeHeader(String name, String value) {
|
||||
headers.addHeader(name, value);
|
||||
}
|
||||
|
||||
public Iterator getAllMimeHeaders() {
|
||||
return headers.getAllHeaders();
|
||||
}
|
||||
|
||||
public Iterator getMatchingMimeHeaders(String[] names) {
|
||||
return headers.getMatchingHeaders(names);
|
||||
}
|
||||
|
||||
public Iterator getNonMatchingMimeHeaders(String[] names) {
|
||||
return headers.getNonMatchingHeaders(names);
|
||||
}
|
||||
|
||||
boolean hasAllHeaders(MimeHeaders hdrs) {
|
||||
if (hdrs != null) {
|
||||
Iterator i = hdrs.getAllHeaders();
|
||||
while (i.hasNext()) {
|
||||
MimeHeader hdr = (MimeHeader) i.next();
|
||||
String[] values = headers.getHeader(hdr.getName());
|
||||
boolean found = false;
|
||||
|
||||
if (values != null) {
|
||||
for (int j = 0; j < values.length; j++)
|
||||
if (hdr.getValue().equalsIgnoreCase(values[j])) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
MimeBodyPart getMimePart() throws SOAPException {
|
||||
try {
|
||||
if (this.mimePart != null) {
|
||||
return new MimeBodyPart(mimePart);
|
||||
}
|
||||
if (rawContent != null) {
|
||||
copyMimeHeaders(headers, rawContent);
|
||||
return rawContent;
|
||||
}
|
||||
|
||||
MimeBodyPart envelope = new MimeBodyPart();
|
||||
|
||||
envelope.setDataHandler(dataHandler);
|
||||
copyMimeHeaders(headers, envelope);
|
||||
|
||||
return envelope;
|
||||
} catch (Exception ex) {
|
||||
log.severe("SAAJ0504.soap.cannot.externalize.attachment");
|
||||
throw new SOAPExceptionImpl("Unable to externalize attachment", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static void copyMimeHeaders(MimeHeaders headers, MimeBodyPart mbp)
|
||||
throws SOAPException {
|
||||
|
||||
Iterator i = headers.getAllHeaders();
|
||||
|
||||
while (i.hasNext())
|
||||
try {
|
||||
MimeHeader mh = (MimeHeader) i.next();
|
||||
|
||||
mbp.setHeader(mh.getName(), mh.getValue());
|
||||
} catch (Exception ex) {
|
||||
log.severe("SAAJ0505.soap.cannot.copy.mime.hdr");
|
||||
throw new SOAPExceptionImpl("Unable to copy MIME header", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static void copyMimeHeaders(MimeBodyPart mbp, AttachmentPartImpl ap)
|
||||
throws SOAPException {
|
||||
try {
|
||||
List hdr = mbp.getAllHeaders();
|
||||
int sz = hdr.size();
|
||||
for( int i=0; i<sz; i++ ) {
|
||||
Header h = (Header)hdr.get(i);
|
||||
if(h.getName().equalsIgnoreCase("Content-Type"))
|
||||
continue; // skip
|
||||
ap.addMimeHeader(h.getName(), h.getValue());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
log.severe("SAAJ0506.soap.cannot.copy.mime.hdrs.into.attachment");
|
||||
throw new SOAPExceptionImpl(
|
||||
"Unable to copy MIME headers into attachment",
|
||||
ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void setBase64Content(InputStream content, String contentType)
|
||||
throws SOAPException {
|
||||
|
||||
if (mimePart != null) {
|
||||
mimePart.close();
|
||||
mimePart = null;
|
||||
}
|
||||
dataHandler = null;
|
||||
InputStream decoded = null;
|
||||
try {
|
||||
decoded = MimeUtility.decode(content, "base64");
|
||||
InternetHeaders hdrs = new InternetHeaders();
|
||||
hdrs.setHeader("Content-Type", contentType);
|
||||
//TODO: reading the entire attachment here is ineffcient. Somehow the MimeBodyPart
|
||||
// Ctor with inputStream causes problems based on the InputStream
|
||||
// has markSupported()==true
|
||||
ByteOutputStream bos = new ByteOutputStream();
|
||||
bos.write(decoded);
|
||||
rawContent = new MimeBodyPart(hdrs, bos.getBytes(), bos.getCount());
|
||||
setMimeHeader("Content-Type", contentType);
|
||||
} catch (Exception e) {
|
||||
log.log(Level.SEVERE, "SAAJ0578.soap.attachment.setbase64content.exception", e);
|
||||
throw new SOAPExceptionImpl(e.getLocalizedMessage());
|
||||
} finally {
|
||||
try {
|
||||
decoded.close();
|
||||
} catch (IOException ex) {
|
||||
throw new SOAPException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public InputStream getBase64Content() throws SOAPException {
|
||||
InputStream stream;
|
||||
if (mimePart != null) {
|
||||
stream = mimePart.read();
|
||||
} else if (rawContent != null) {
|
||||
try {
|
||||
stream = rawContent.getInputStream();
|
||||
} catch (Exception e) {
|
||||
log.log(Level.SEVERE,"SAAJ0579.soap.attachment.getbase64content.exception", e);
|
||||
throw new SOAPExceptionImpl(e.getLocalizedMessage());
|
||||
}
|
||||
} else if (dataHandler != null) {
|
||||
try {
|
||||
stream = dataHandler.getInputStream();
|
||||
} catch (IOException e) {
|
||||
log.severe("SAAJ0574.soap.attachment.datahandler.ioexception");
|
||||
throw new SOAPExceptionImpl("DataHandler error" + e);
|
||||
}
|
||||
} else {
|
||||
log.severe("SAAJ0572.soap.no.content.for.attachment");
|
||||
throw new SOAPExceptionImpl("No data handler/content associated with this attachment");
|
||||
}
|
||||
|
||||
//TODO: Write a BASE64EncoderInputStream instead,
|
||||
// this code below is inefficient
|
||||
// where we are trying to read the whole attachment first
|
||||
int len;
|
||||
int size = 1024;
|
||||
byte [] buf;
|
||||
if (stream != null) {
|
||||
try {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(size);
|
||||
//TODO: try and optimize this on the same lines as
|
||||
// ByteOutputStream : to eliminate the temp buffer here
|
||||
OutputStream ret = MimeUtility.encode(bos, "base64");
|
||||
buf = new byte[size];
|
||||
while ((len = stream.read(buf, 0, size)) != -1) {
|
||||
ret.write(buf, 0, len);
|
||||
}
|
||||
ret.flush();
|
||||
buf = bos.toByteArray();
|
||||
return new ByteArrayInputStream(buf);
|
||||
} catch (Exception e) {
|
||||
// throw new SOAPException
|
||||
log.log(Level.SEVERE,"SAAJ0579.soap.attachment.getbase64content.exception", e);
|
||||
throw new SOAPExceptionImpl(e.getLocalizedMessage());
|
||||
} finally {
|
||||
try {
|
||||
stream.close();
|
||||
} catch (IOException ex) {
|
||||
//close the stream
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//throw new SOAPException
|
||||
log.log(Level.SEVERE,"SAAJ0572.soap.no.content.for.attachment");
|
||||
throw new SOAPExceptionImpl("No data handler/content associated with this attachment");
|
||||
}
|
||||
}
|
||||
|
||||
public void setRawContent(InputStream content, String contentType)
|
||||
throws SOAPException {
|
||||
if (mimePart != null) {
|
||||
mimePart.close();
|
||||
mimePart = null;
|
||||
}
|
||||
dataHandler = null;
|
||||
try {
|
||||
InternetHeaders hdrs = new InternetHeaders();
|
||||
hdrs.setHeader("Content-Type", contentType);
|
||||
//TODO: reading the entire attachment here is ineffcient. Somehow the MimeBodyPart
|
||||
// Ctor with inputStream causes problems based on whether the InputStream has
|
||||
// markSupported()==true or false
|
||||
ByteOutputStream bos = new ByteOutputStream();
|
||||
bos.write(content);
|
||||
rawContent = new MimeBodyPart(hdrs, bos.getBytes(), bos.getCount());
|
||||
setMimeHeader("Content-Type", contentType);
|
||||
} catch (Exception e) {
|
||||
log.log(Level.SEVERE, "SAAJ0576.soap.attachment.setrawcontent.exception", e);
|
||||
throw new SOAPExceptionImpl(e.getLocalizedMessage());
|
||||
} finally {
|
||||
try {
|
||||
content.close();
|
||||
} catch (IOException ex) {
|
||||
throw new SOAPException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public void setRawContentBytes(byte[] content, String contentType)
|
||||
throws SOAPException {
|
||||
if (content == null) {
|
||||
throw new SOAPExceptionImpl("Null content passed to setRawContentBytes");
|
||||
}
|
||||
dataHandler = null;
|
||||
try {
|
||||
InternetHeaders hdrs = new InternetHeaders();
|
||||
hdrs.setHeader("Content-Type", contentType);
|
||||
rawContent = new MimeBodyPart(hdrs, content, content.length);
|
||||
setMimeHeader("Content-Type", contentType);
|
||||
} catch (Exception e) {
|
||||
log.log(Level.SEVERE, "SAAJ0576.soap.attachment.setrawcontent.exception", e);
|
||||
throw new SOAPExceptionImpl(e.getLocalizedMessage());
|
||||
}
|
||||
} */
|
||||
|
||||
public void setRawContentBytes(
|
||||
byte[] content, int off, int len, String contentType)
|
||||
throws SOAPException {
|
||||
if (mimePart != null) {
|
||||
mimePart.close();
|
||||
mimePart = null;
|
||||
}
|
||||
if (content == null) {
|
||||
throw new SOAPExceptionImpl("Null content passed to setRawContentBytes");
|
||||
}
|
||||
dataHandler = null;
|
||||
try {
|
||||
InternetHeaders hdrs = new InternetHeaders();
|
||||
hdrs.setHeader("Content-Type", contentType);
|
||||
rawContent = new MimeBodyPart(hdrs, content, off, len);
|
||||
setMimeHeader("Content-Type", contentType);
|
||||
} catch (Exception e) {
|
||||
log.log(Level.SEVERE,
|
||||
"SAAJ0576.soap.attachment.setrawcontent.exception", e);
|
||||
throw new SOAPExceptionImpl(e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public InputStream getRawContent() throws SOAPException {
|
||||
if (mimePart != null) {
|
||||
return mimePart.read();
|
||||
}
|
||||
if (rawContent != null) {
|
||||
try {
|
||||
return rawContent.getInputStream();
|
||||
} catch (Exception e) {
|
||||
log.log(Level.SEVERE,"SAAJ0577.soap.attachment.getrawcontent.exception", e);
|
||||
throw new SOAPExceptionImpl(e.getLocalizedMessage());
|
||||
}
|
||||
} else if (dataHandler != null) {
|
||||
try {
|
||||
return dataHandler.getInputStream();
|
||||
} catch (IOException e) {
|
||||
log.severe("SAAJ0574.soap.attachment.datahandler.ioexception");
|
||||
throw new SOAPExceptionImpl("DataHandler error" + e);
|
||||
}
|
||||
} else {
|
||||
log.severe("SAAJ0572.soap.no.content.for.attachment");
|
||||
throw new SOAPExceptionImpl("No data handler/content associated with this attachment");
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] getRawContentBytes() throws SOAPException {
|
||||
InputStream ret;
|
||||
if (mimePart != null) {
|
||||
try {
|
||||
ret = mimePart.read();
|
||||
return ASCIIUtility.getBytes(ret);
|
||||
} catch (IOException ex) {
|
||||
log.log(Level.SEVERE,"SAAJ0577.soap.attachment.getrawcontent.exception", ex);
|
||||
throw new SOAPExceptionImpl(ex);
|
||||
}
|
||||
}
|
||||
if (rawContent != null) {
|
||||
try {
|
||||
ret = rawContent.getInputStream();
|
||||
return ASCIIUtility.getBytes(ret);
|
||||
} catch (Exception e) {
|
||||
log.log(Level.SEVERE,"SAAJ0577.soap.attachment.getrawcontent.exception", e);
|
||||
throw new SOAPExceptionImpl(e);
|
||||
}
|
||||
} else if (dataHandler != null) {
|
||||
try {
|
||||
ret = dataHandler.getInputStream();
|
||||
return ASCIIUtility.getBytes(ret);
|
||||
} catch (IOException e) {
|
||||
log.severe("SAAJ0574.soap.attachment.datahandler.ioexception");
|
||||
throw new SOAPExceptionImpl("DataHandler error" + e);
|
||||
}
|
||||
} else {
|
||||
log.severe("SAAJ0572.soap.no.content.for.attachment");
|
||||
throw new SOAPExceptionImpl("No data handler/content associated with this attachment");
|
||||
}
|
||||
}
|
||||
|
||||
// attachments are equal if they are the same reference
|
||||
public boolean equals(Object o) {
|
||||
return (this == o);
|
||||
}
|
||||
|
||||
// In JDK 8 we get a warning if we implement equals() but not hashCode().
|
||||
// There is no intuitive value for this, the default one in Object is fine.
|
||||
public int hashCode() {
|
||||
return super.hashCode();
|
||||
}
|
||||
|
||||
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");
|
||||
// this handler seems to be not used according VCS history ...
|
||||
// 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,86 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.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,55 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.soap;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import javax.xml.soap.SOAPEnvelope;
|
||||
import javax.xml.transform.Source;
|
||||
|
||||
/**
|
||||
* Different implementations for SOAP Envelope must all implement this
|
||||
* interface.
|
||||
*
|
||||
* @author Anil Vijendran (akv@eng.sun.com)
|
||||
*/
|
||||
public interface Envelope extends SOAPEnvelope {
|
||||
/**
|
||||
* Get the content as a JAXP Source.
|
||||
*/
|
||||
Source getContent();
|
||||
|
||||
/**
|
||||
* Output the content.
|
||||
*/
|
||||
void output(OutputStream out) throws IOException;
|
||||
|
||||
/**
|
||||
* Output the content.
|
||||
*/
|
||||
void output(OutputStream out, boolean isFastInfoset) throws IOException;
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2014, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.soap;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.util.JAXMStreamSource;
|
||||
import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants;
|
||||
import com.sun.xml.internal.messaging.saaj.util.ParserPool;
|
||||
import com.sun.xml.internal.messaging.saaj.util.RejectDoctypeSaxFilter;
|
||||
import com.sun.xml.internal.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;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
import javax.xml.transform.sax.SAXSource;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* EnvelopeFactory creates SOAP Envelope objects using different
|
||||
* underlying implementations.
|
||||
*/
|
||||
public class EnvelopeFactory {
|
||||
|
||||
protected static final Logger
|
||||
log = Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
|
||||
"com.sun.xml.internal.messaging.saaj.soap.LocalStrings");
|
||||
|
||||
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 {
|
||||
// Insert SAX filter to disallow Document Type Declarations since
|
||||
// they are not legal in SOAP
|
||||
SAXParser saxParser = null;
|
||||
if (src instanceof StreamSource) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
try {
|
||||
saxParser = parserPool.get().get();
|
||||
} catch (Exception e) {
|
||||
log.severe("SAAJ0601.util.newSAXParser.exception");
|
||||
throw new SOAPExceptionImpl(
|
||||
"Couldn't get a SAX parser while constructing a envelope",
|
||||
e);
|
||||
}
|
||||
InputSource is = SAXSource.sourceToInputSource(src);
|
||||
if (is.getEncoding() == null && soapPart.getSourceCharsetEncoding() != null) {
|
||||
is.setEncoding(soapPart.getSourceCharsetEncoding());
|
||||
}
|
||||
XMLReader rejectFilter;
|
||||
try {
|
||||
rejectFilter = new RejectDoctypeSaxFilter(saxParser);
|
||||
} catch (Exception ex) {
|
||||
log.severe("SAAJ0510.soap.cannot.create.envelope");
|
||||
throw new SOAPExceptionImpl(
|
||||
"Unable to create envelope from given source: ",
|
||||
ex);
|
||||
}
|
||||
src = new SAXSource(rejectFilter, is);
|
||||
}
|
||||
|
||||
try {
|
||||
Transformer transformer =
|
||||
EfficientStreamingTransformer.newTransformer();
|
||||
DOMResult result = new DOMResult(soapPart);
|
||||
transformer.transform(src, result);
|
||||
|
||||
Envelope env = (Envelope) soapPart.getEnvelope();
|
||||
return env;
|
||||
} catch (Exception ex) {
|
||||
if (ex instanceof SOAPVersionMismatchException) {
|
||||
throw (SOAPVersionMismatchException) ex;
|
||||
}
|
||||
log.severe("SAAJ0511.soap.cannot.create.envelope");
|
||||
throw new SOAPExceptionImpl(
|
||||
"Unable to create envelope from given source: ",
|
||||
ex);
|
||||
} finally {
|
||||
if (saxParser != null) {
|
||||
parserPool.get().returnParser(saxParser);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.soap;
|
||||
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.activation.*;
|
||||
import javax.xml.transform.Source;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.util.FastInfosetReflection;
|
||||
|
||||
/**
|
||||
* JAF data handler for Fast Infoset content
|
||||
*
|
||||
* @author Santiago Pericas-Geertsen
|
||||
*/
|
||||
public class FastInfosetDataContentHandler implements DataContentHandler {
|
||||
public static final String STR_SRC = "com.sun.xml.internal.org.jvnet.fastinfoset.FastInfosetSource";
|
||||
|
||||
public FastInfosetDataContentHandler() {
|
||||
}
|
||||
|
||||
/**
|
||||
* return the DataFlavors for this <code>DataContentHandler</code>
|
||||
* @return The DataFlavors.
|
||||
*/
|
||||
public DataFlavor[] getTransferDataFlavors() { // throws Exception;
|
||||
DataFlavor flavors[] = new DataFlavor[1];
|
||||
flavors[0] = new ActivationDataFlavor(
|
||||
FastInfosetReflection.getFastInfosetSource_class(),
|
||||
"application/fastinfoset", "Fast Infoset");
|
||||
return flavors;
|
||||
}
|
||||
|
||||
/**
|
||||
* return the Transfer Data of type DataFlavor from InputStream
|
||||
* @param df The DataFlavor.
|
||||
* @param ins The InputStream corresponding to the data.
|
||||
* @return The constructed Object.
|
||||
*/
|
||||
public Object getTransferData(DataFlavor flavor, DataSource dataSource)
|
||||
throws IOException
|
||||
{
|
||||
if (flavor.getMimeType().startsWith("application/fastinfoset")) {
|
||||
try {
|
||||
if (flavor.getRepresentationClass().getName().equals(STR_SRC)) {
|
||||
return FastInfosetReflection.FastInfosetSource_new(
|
||||
dataSource.getInputStream());
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IOException(e.getMessage());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object getContent(DataSource dataSource) throws IOException {
|
||||
try {
|
||||
return FastInfosetReflection.FastInfosetSource_new(
|
||||
dataSource.getInputStream());
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IOException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* construct an object from a byte stream
|
||||
* (similar semantically to previous method, we are deciding
|
||||
* which one to support)
|
||||
*/
|
||||
public void writeTo(Object obj, String mimeType, OutputStream os)
|
||||
throws IOException
|
||||
{
|
||||
if (!mimeType.equals("application/fastinfoset")) {
|
||||
throw new IOException("Invalid content type \"" + mimeType
|
||||
+ "\" for FastInfosetDCH");
|
||||
}
|
||||
|
||||
try {
|
||||
InputStream is = FastInfosetReflection.FastInfosetSource_getInputStream(
|
||||
(Source) obj);
|
||||
|
||||
int n; byte[] buffer = new byte[4096];
|
||||
while ((n = is.read(buffer)) != -1) {
|
||||
os.write(buffer, 0, n);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IOException(
|
||||
"Error copying FI source to output stream " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.soap;
|
||||
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.io.*;
|
||||
import java.awt.*;
|
||||
|
||||
import javax.activation.*;
|
||||
|
||||
/**
|
||||
* DataContentHandler for image/gif.
|
||||
*
|
||||
* @author Ana Lindstrom-Tamer
|
||||
*/
|
||||
public class GifDataContentHandler extends Component implements DataContentHandler {
|
||||
private static ActivationDataFlavor myDF =
|
||||
new ActivationDataFlavor(
|
||||
java.awt.Image.class,
|
||||
"image/gif",
|
||||
"GIF Image");
|
||||
|
||||
protected ActivationDataFlavor getDF() {
|
||||
return myDF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the DataFlavors for this <code>DataContentHandler</code>.
|
||||
*
|
||||
* @return The DataFlavors
|
||||
*/
|
||||
public DataFlavor[] getTransferDataFlavors() { // throws Exception;
|
||||
return new DataFlavor[] { getDF()};
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Transfer Data of type DataFlavor from InputStream.
|
||||
*
|
||||
* @param df The DataFlavor
|
||||
* @param ins The InputStream corresponding to the data
|
||||
* @return String object
|
||||
*/
|
||||
public Object getTransferData(DataFlavor df, DataSource ds)
|
||||
throws IOException {
|
||||
// use myDF.equals to be sure to get ActivationDataFlavor.equals,
|
||||
// which properly ignores Content-Type parameters in comparison
|
||||
if (getDF().equals(df))
|
||||
return getContent(ds);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object getContent(DataSource ds) throws IOException {
|
||||
InputStream is = ds.getInputStream();
|
||||
int pos = 0;
|
||||
int count;
|
||||
byte buf[] = new byte[1024];
|
||||
|
||||
while ((count = is.read(buf, pos, buf.length - pos)) != -1) {
|
||||
pos += count;
|
||||
if (pos >= buf.length) {
|
||||
int size = buf.length;
|
||||
if (size < 256*1024)
|
||||
size += size;
|
||||
else
|
||||
size += 256*1024;
|
||||
byte tbuf[] = new byte[size];
|
||||
System.arraycopy(buf, 0, tbuf, 0, pos);
|
||||
buf = tbuf;
|
||||
}
|
||||
}
|
||||
Toolkit tk = Toolkit.getDefaultToolkit();
|
||||
return tk.createImage(buf, 0, pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the object to the output stream, using the specified MIME type.
|
||||
*/
|
||||
public void writeTo(Object obj, String type, OutputStream os)
|
||||
throws IOException {
|
||||
if (obj != null && !(obj instanceof Image))
|
||||
throw new IOException("\"" + getDF().getMimeType() +
|
||||
"\" DataContentHandler requires Image object, " +
|
||||
"was given object of type " + obj.getClass().toString());
|
||||
|
||||
throw new IOException(getDF().getMimeType() + " encoding not supported");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.soap;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.activation.*;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants;
|
||||
|
||||
public class ImageDataContentHandler extends Component
|
||||
implements DataContentHandler {
|
||||
|
||||
protected static final Logger log =
|
||||
Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
|
||||
"com.sun.xml.internal.messaging.saaj.soap.LocalStrings");
|
||||
|
||||
private DataFlavor[] flavor;
|
||||
|
||||
public ImageDataContentHandler() {
|
||||
String[] mimeTypes = ImageIO.getReaderMIMETypes();
|
||||
flavor = new DataFlavor[mimeTypes.length];
|
||||
for(int i=0; i < mimeTypes.length; i++) {
|
||||
flavor[i] = new ActivationDataFlavor(
|
||||
java.awt.Image.class, mimeTypes[i], "Image");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of DataFlavor objects indicating the flavors the
|
||||
* data can be provided in. The array should be ordered according to
|
||||
* preference for providing the data (from most richly descriptive to
|
||||
* least descriptive).
|
||||
*
|
||||
* @return The DataFlavors.
|
||||
*/
|
||||
public DataFlavor[] getTransferDataFlavors() {
|
||||
return (DataFlavor[]) Arrays.copyOf(flavor, flavor.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an object which represents the data to be transferred.
|
||||
* The class of the object returned is defined by the representation class
|
||||
* of the flavor.
|
||||
*
|
||||
* @param df The DataFlavor representing the requested type.
|
||||
* @param ds The DataSource representing the data to be converted.
|
||||
* @return The constructed Object.
|
||||
*/
|
||||
public Object getTransferData(DataFlavor df, DataSource ds)
|
||||
throws IOException {
|
||||
for (int i=0; i < flavor.length; i++) {
|
||||
if (flavor[i].equals(df)) {
|
||||
return getContent(ds);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an object representing the data in its most preferred form.
|
||||
* Generally this will be the form described by the first DataFlavor
|
||||
* returned by the <code>getTransferDataFlavors</code> method.
|
||||
*
|
||||
* @param ds The DataSource representing the data to be converted.
|
||||
* @return The constructed Object.
|
||||
*/
|
||||
public Object getContent(DataSource ds) throws IOException {
|
||||
return ImageIO.read(new BufferedInputStream(ds.getInputStream()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the object to a byte stream of the specified MIME type
|
||||
* and write it to the output stream.
|
||||
*
|
||||
* @param obj The object to be converted.
|
||||
* @param mimeType The requested MIME type of the resulting byte stream.
|
||||
* @param os The output stream into which to write the converted
|
||||
* byte stream.
|
||||
*/
|
||||
|
||||
public void writeTo(Object obj, String type, OutputStream os)
|
||||
throws IOException {
|
||||
|
||||
try {
|
||||
BufferedImage bufImage = null;
|
||||
if (obj instanceof BufferedImage) {
|
||||
bufImage = (BufferedImage)obj;
|
||||
} else if (obj instanceof Image) {
|
||||
bufImage = render((Image)obj);
|
||||
} else {
|
||||
log.log(Level.SEVERE,
|
||||
"SAAJ0520.soap.invalid.obj.type",
|
||||
new String[] { obj.getClass().toString() });
|
||||
throw new IOException(
|
||||
"ImageDataContentHandler requires Image object, "
|
||||
+ "was given object of type "
|
||||
+ obj.getClass().toString());
|
||||
}
|
||||
ImageWriter writer = null;
|
||||
Iterator i = ImageIO.getImageWritersByMIMEType(type);
|
||||
if (i.hasNext()) {
|
||||
writer = (ImageWriter)i.next();
|
||||
}
|
||||
if (writer != null) {
|
||||
ImageOutputStream stream = null;
|
||||
stream = ImageIO.createImageOutputStream(os);
|
||||
writer.setOutput(stream);
|
||||
writer.write(bufImage);
|
||||
writer.dispose();
|
||||
stream.close();
|
||||
} else {
|
||||
log.log(Level.SEVERE, "SAAJ0526.soap.unsupported.mime.type",
|
||||
new String[] { type });
|
||||
throw new IOException("Unsupported mime type:"+ type);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.severe("SAAJ0525.soap.cannot.encode.img");
|
||||
throw new IOException("Unable to encode the image to a stream "
|
||||
+ e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private BufferedImage render(Image img) throws InterruptedException {
|
||||
|
||||
MediaTracker tracker = new MediaTracker(this);
|
||||
tracker.addImage(img, 0);
|
||||
tracker.waitForAll();
|
||||
BufferedImage bufImage = new BufferedImage(img.getWidth(null),
|
||||
img.getHeight(null), BufferedImage.TYPE_INT_RGB);
|
||||
Graphics g = bufImage.createGraphics();
|
||||
g.drawImage(img, 0, 0, null);
|
||||
g.dispose();
|
||||
return bufImage;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.soap;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.*;
|
||||
|
||||
import javax.activation.*;
|
||||
|
||||
//import com.sun.image.codec.jpeg.*;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
/**
|
||||
* JAF data handler for Jpeg content
|
||||
*
|
||||
* @author Ana Lindstrom-Tamer
|
||||
*/
|
||||
|
||||
public class JpegDataContentHandler
|
||||
extends Component
|
||||
implements DataContentHandler {
|
||||
public static final String STR_SRC = "java.awt.Image";
|
||||
|
||||
/**
|
||||
* return the DataFlavors for this <code>DataContentHandler</code>
|
||||
* @return The DataFlavors.
|
||||
*/
|
||||
public DataFlavor[] getTransferDataFlavors() { // throws Exception;
|
||||
DataFlavor flavors[] = new DataFlavor[1];
|
||||
|
||||
try {
|
||||
flavors[0] =
|
||||
new ActivationDataFlavor(
|
||||
Class.forName(STR_SRC),
|
||||
"image/jpeg",
|
||||
"JPEG");
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
return flavors;
|
||||
}
|
||||
|
||||
/**
|
||||
* return the Transfer Data of type DataFlavor from InputStream
|
||||
* @param df The DataFlavor.
|
||||
* @param ins The InputStream corresponding to the data.
|
||||
* @return The constructed Object.
|
||||
*/
|
||||
public Object getTransferData(DataFlavor df, DataSource ds) {
|
||||
|
||||
// this is sort of hacky, but will work for the
|
||||
// sake of testing...
|
||||
if (df.getMimeType().startsWith("image/jpeg")) {
|
||||
if (df.getRepresentationClass().getName().equals(STR_SRC)) {
|
||||
InputStream inputStream = null;
|
||||
BufferedImage jpegLoadImage = null;
|
||||
|
||||
try {
|
||||
inputStream = ds.getInputStream();
|
||||
jpegLoadImage = ImageIO.read(inputStream);
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
return jpegLoadImage;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Object getContent(DataSource ds) { // throws Exception;
|
||||
InputStream inputStream = null;
|
||||
BufferedImage jpegLoadImage = null;
|
||||
|
||||
try {
|
||||
inputStream = ds.getInputStream();
|
||||
jpegLoadImage = ImageIO.read(inputStream);
|
||||
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
return (Image) jpegLoadImage;
|
||||
}
|
||||
|
||||
/**
|
||||
* construct an object from a byte stream
|
||||
* (similar semantically to previous method, we are deciding
|
||||
* which one to support)
|
||||
*/
|
||||
public void writeTo(Object obj, String mimeType, OutputStream os)
|
||||
throws IOException {
|
||||
if (!mimeType.equals("image/jpeg"))
|
||||
throw new IOException(
|
||||
"Invalid content type \""
|
||||
+ mimeType
|
||||
+ "\" for ImageContentHandler");
|
||||
|
||||
if (obj == null) {
|
||||
throw new IOException("Null object for ImageContentHandler");
|
||||
}
|
||||
|
||||
try {
|
||||
BufferedImage bufImage = null;
|
||||
if (obj instanceof BufferedImage) {
|
||||
bufImage = (BufferedImage) obj;
|
||||
|
||||
} else {
|
||||
Image img = (Image) obj;
|
||||
MediaTracker tracker = new MediaTracker(this);
|
||||
tracker.addImage(img, 0);
|
||||
tracker.waitForAll();
|
||||
if (tracker.isErrorAny()) {
|
||||
throw new IOException("Error while loading image");
|
||||
}
|
||||
bufImage =
|
||||
new BufferedImage(
|
||||
img.getWidth(null),
|
||||
img.getHeight(null),
|
||||
BufferedImage.TYPE_INT_RGB);
|
||||
|
||||
Graphics g = bufImage.createGraphics();
|
||||
g.drawImage(img, 0, 0, null);
|
||||
}
|
||||
ImageIO.write(bufImage, "jpeg", os);
|
||||
|
||||
} catch (Exception ex) {
|
||||
throw new IOException(
|
||||
"Unable to run the JPEG Encoder on a stream "
|
||||
+ ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.soap;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.xml.soap.*;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.ContentType;
|
||||
import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.ParseException;
|
||||
import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.ver1_1.Message1_1Impl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.ver1_2.Message1_2Impl;
|
||||
import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants;
|
||||
import com.sun.xml.internal.messaging.saaj.util.TeeInputStream;
|
||||
|
||||
/**
|
||||
* A factory for creating SOAP messages.
|
||||
*
|
||||
* Converted to a placeholder for common functionality between SOAP
|
||||
* implementations.
|
||||
*
|
||||
* @author Phil Goodwin (phil.goodwin@sun.com)
|
||||
*/
|
||||
public class MessageFactoryImpl extends MessageFactory {
|
||||
|
||||
protected static final Logger log =
|
||||
Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
|
||||
"com.sun.xml.internal.messaging.saaj.soap.LocalStrings");
|
||||
|
||||
protected OutputStream listener;
|
||||
|
||||
protected boolean lazyAttachments = false;
|
||||
|
||||
public OutputStream listen(OutputStream newListener) {
|
||||
OutputStream oldListener = listener;
|
||||
listener = newListener;
|
||||
return oldListener;
|
||||
}
|
||||
|
||||
public SOAPMessage createMessage() throws SOAPException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public SOAPMessage createMessage(boolean isFastInfoset,
|
||||
boolean acceptFastInfoset) throws SOAPException
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public SOAPMessage createMessage(MimeHeaders headers, InputStream in)
|
||||
throws SOAPException, IOException {
|
||||
String contentTypeString = MessageImpl.getContentType(headers);
|
||||
|
||||
if (listener != null) {
|
||||
in = new TeeInputStream(in, listener);
|
||||
}
|
||||
|
||||
try {
|
||||
ContentType contentType = new ContentType(contentTypeString);
|
||||
int stat = MessageImpl.identifyContentType(contentType);
|
||||
|
||||
if (MessageImpl.isSoap1_1Content(stat)) {
|
||||
return new Message1_1Impl(headers,contentType,stat,in);
|
||||
} else if (MessageImpl.isSoap1_2Content(stat)) {
|
||||
return new Message1_2Impl(headers,contentType,stat,in);
|
||||
} else {
|
||||
log.severe("SAAJ0530.soap.unknown.Content-Type");
|
||||
throw new SOAPExceptionImpl("Unrecognized Content-Type");
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
log.severe("SAAJ0531.soap.cannot.parse.Content-Type");
|
||||
throw new SOAPExceptionImpl(
|
||||
"Unable to parse content type: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected static final String getContentType(MimeHeaders headers) {
|
||||
String[] values = headers.getHeader("Content-Type");
|
||||
if (values == null)
|
||||
return null;
|
||||
else
|
||||
return values[0];
|
||||
}
|
||||
|
||||
public void setLazyAttachmentOptimization(boolean flag) {
|
||||
lazyAttachments = flag;
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.soap;
|
||||
|
||||
import java.io.*;
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import javax.activation.*;
|
||||
import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.MimeMultipart;
|
||||
import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.ContentType;
|
||||
import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream;
|
||||
|
||||
public class MultipartDataContentHandler implements DataContentHandler {
|
||||
private ActivationDataFlavor myDF = new ActivationDataFlavor(
|
||||
com.sun.xml.internal.messaging.saaj.packaging.mime.internet.MimeMultipart.class,
|
||||
"multipart/mixed",
|
||||
"Multipart");
|
||||
|
||||
/**
|
||||
* Return the DataFlavors for this <code>DataContentHandler</code>.
|
||||
*
|
||||
* @return The DataFlavors
|
||||
*/
|
||||
public DataFlavor[] getTransferDataFlavors() { // throws Exception;
|
||||
return new DataFlavor[] { myDF };
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Transfer Data of type DataFlavor from InputStream.
|
||||
*
|
||||
* @param df The DataFlavor
|
||||
* @param ins The InputStream corresponding to the data
|
||||
* @return String object
|
||||
*/
|
||||
public Object getTransferData(DataFlavor df, DataSource ds) {
|
||||
// use myDF.equals to be sure to get ActivationDataFlavor.equals,
|
||||
// which properly ignores Content-Type parameters in comparison
|
||||
if (myDF.equals(df))
|
||||
return getContent(ds);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the content.
|
||||
*/
|
||||
public Object getContent(DataSource ds) {
|
||||
try {
|
||||
return new MimeMultipart(
|
||||
ds, new ContentType(ds.getContentType()));
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the object to the output stream, using the specific MIME type.
|
||||
*/
|
||||
public void writeTo(Object obj, String mimeType, OutputStream os)
|
||||
throws IOException {
|
||||
if (obj instanceof MimeMultipart) {
|
||||
try {
|
||||
//TODO: temporarily allow only ByteOutputStream
|
||||
// Need to add writeTo(OutputStream) on MimeMultipart
|
||||
ByteOutputStream baos = null;
|
||||
if (os instanceof ByteOutputStream) {
|
||||
baos = (ByteOutputStream)os;
|
||||
} else {
|
||||
throw new IOException("Input Stream expected to be a com.sun.xml.internal.messaging.saaj.util.ByteOutputStream, but found " +
|
||||
os.getClass().getName());
|
||||
}
|
||||
((MimeMultipart)obj).writeTo(baos);
|
||||
} catch (Exception e) {
|
||||
throw new IOException(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.soap;
|
||||
|
||||
import javax.xml.soap.SAAJMetaFactory;
|
||||
import javax.xml.soap.SOAPConstants;
|
||||
import javax.xml.soap.MessageFactory;
|
||||
import javax.xml.soap.SOAPFactory;
|
||||
import javax.xml.soap.SOAPException;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants;
|
||||
|
||||
public class SAAJMetaFactoryImpl extends SAAJMetaFactory {
|
||||
|
||||
protected static final Logger log =
|
||||
Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
|
||||
"com.sun.xml.internal.messaging.saaj.soap.LocalStrings");
|
||||
|
||||
protected MessageFactory newMessageFactory(String protocol)
|
||||
throws SOAPException {
|
||||
if (SOAPConstants.SOAP_1_1_PROTOCOL.equals(protocol)) {
|
||||
return new com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl();
|
||||
} else if (SOAPConstants.SOAP_1_2_PROTOCOL.equals(protocol)) {
|
||||
return new com.sun.xml.internal.messaging.saaj.soap.ver1_2.SOAPMessageFactory1_2Impl();
|
||||
} else if (SOAPConstants.DYNAMIC_SOAP_PROTOCOL.equals(protocol)) {
|
||||
return new com.sun.xml.internal.messaging.saaj.soap.dynamic.SOAPMessageFactoryDynamicImpl();
|
||||
} else {
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0569.soap.unknown.protocol",
|
||||
new Object[] {protocol, "MessageFactory"});
|
||||
throw new SOAPException("Unknown Protocol: " + protocol +
|
||||
" specified for creating MessageFactory");
|
||||
}
|
||||
}
|
||||
|
||||
protected SOAPFactory newSOAPFactory(String protocol)
|
||||
throws SOAPException {
|
||||
if (SOAPConstants.SOAP_1_1_PROTOCOL.equals(protocol)) {
|
||||
return new com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPFactory1_1Impl();
|
||||
} else if (SOAPConstants.SOAP_1_2_PROTOCOL.equals(protocol)) {
|
||||
return new com.sun.xml.internal.messaging.saaj.soap.ver1_2.SOAPFactory1_2Impl();
|
||||
} else if (SOAPConstants.DYNAMIC_SOAP_PROTOCOL.equals(protocol)) {
|
||||
return new com.sun.xml.internal.messaging.saaj.soap.dynamic.SOAPFactoryDynamicImpl();
|
||||
} else {
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0569.soap.unknown.protocol",
|
||||
new Object[] {protocol, "SOAPFactory"});
|
||||
throw new SOAPException("Unknown Protocol: " + protocol +
|
||||
" specified for creating SOAPFactory");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author SAAJ RI Development Team
|
||||
*/
|
||||
package com.sun.xml.internal.messaging.saaj.soap;
|
||||
|
||||
public interface SOAPDocument {
|
||||
SOAPPartImpl getSOAPPart();
|
||||
SOAPDocumentImpl getDocument();
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author SAAJ RI Development Team
|
||||
*/
|
||||
package com.sun.xml.internal.messaging.saaj.soap;
|
||||
|
||||
import com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl;
|
||||
import com.sun.org.apache.xerces.internal.dom.DocumentFragmentImpl;
|
||||
|
||||
public class SOAPDocumentFragment extends DocumentFragmentImpl {
|
||||
|
||||
public SOAPDocumentFragment(CoreDocumentImpl ownerDoc) {
|
||||
super(ownerDoc);
|
||||
}
|
||||
|
||||
public SOAPDocumentFragment() {
|
||||
super();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author SAAJ RI Development Team
|
||||
*/
|
||||
package com.sun.xml.internal.messaging.saaj.soap;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.sun.org.apache.xerces.internal.dom.DocumentImpl;
|
||||
import org.w3c.dom.*;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.soap.impl.*;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants;
|
||||
|
||||
public class SOAPDocumentImpl extends DocumentImpl implements SOAPDocument {
|
||||
|
||||
private static final String XMLNS = "xmlns".intern();
|
||||
protected static final Logger log =
|
||||
Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
|
||||
"com.sun.xml.internal.messaging.saaj.soap.LocalStrings");
|
||||
|
||||
SOAPPartImpl enclosingSOAPPart;
|
||||
|
||||
public SOAPDocumentImpl(SOAPPartImpl enclosingDocument) {
|
||||
this.enclosingSOAPPart = enclosingDocument;
|
||||
}
|
||||
|
||||
// public SOAPDocumentImpl(boolean grammarAccess) {
|
||||
// super(grammarAccess);
|
||||
// }
|
||||
//
|
||||
// public SOAPDocumentImpl(DocumentType doctype) {
|
||||
// super(doctype);
|
||||
// }
|
||||
//
|
||||
// public SOAPDocumentImpl(DocumentType doctype, boolean grammarAccess) {
|
||||
// super(doctype, grammarAccess);
|
||||
// }
|
||||
|
||||
public SOAPPartImpl getSOAPPart() {
|
||||
if (enclosingSOAPPart == null) {
|
||||
log.severe("SAAJ0541.soap.fragment.not.bound.to.part");
|
||||
throw new RuntimeException("Could not complete operation. Fragment not bound to SOAP part.");
|
||||
}
|
||||
return enclosingSOAPPart;
|
||||
}
|
||||
|
||||
public SOAPDocumentImpl getDocument() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public DocumentType getDoctype() {
|
||||
// SOAP means no DTD, No DTD means no doctype (SOAP 1.2 only?)
|
||||
return null;
|
||||
}
|
||||
|
||||
public DOMImplementation getImplementation() {
|
||||
return super.getImplementation();
|
||||
}
|
||||
|
||||
public Element getDocumentElement() {
|
||||
// This had better be an Envelope!
|
||||
getSOAPPart().doGetDocumentElement();
|
||||
return doGetDocumentElement();
|
||||
}
|
||||
|
||||
protected Element doGetDocumentElement() {
|
||||
return super.getDocumentElement();
|
||||
}
|
||||
|
||||
public Element createElement(String tagName) throws DOMException {
|
||||
return ElementFactory.createElement(
|
||||
this,
|
||||
NameImpl.getLocalNameFromTagName(tagName),
|
||||
NameImpl.getPrefixFromTagName(tagName),
|
||||
null);
|
||||
}
|
||||
|
||||
public DocumentFragment createDocumentFragment() {
|
||||
return new SOAPDocumentFragment(this);
|
||||
}
|
||||
|
||||
public org.w3c.dom.Text createTextNode(String data) {
|
||||
return new TextImpl(this, data);
|
||||
}
|
||||
|
||||
public Comment createComment(String data) {
|
||||
return new CommentImpl(this, data);
|
||||
}
|
||||
|
||||
public CDATASection createCDATASection(String data) throws DOMException {
|
||||
return new CDATAImpl(this, data);
|
||||
}
|
||||
|
||||
public ProcessingInstruction createProcessingInstruction(
|
||||
String target,
|
||||
String data)
|
||||
throws DOMException {
|
||||
log.severe("SAAJ0542.soap.proc.instructions.not.allowed.in.docs");
|
||||
throw new UnsupportedOperationException("Processing Instructions are not allowed in SOAP documents");
|
||||
}
|
||||
|
||||
public Attr createAttribute(String name) throws DOMException {
|
||||
boolean isQualifiedName = (name.indexOf(":") > 0);
|
||||
if (isQualifiedName) {
|
||||
String nsUri = null;
|
||||
String prefix = name.substring(0, name.indexOf(":"));
|
||||
//cannot do anything to resolve the URI if prefix is not
|
||||
//XMLNS.
|
||||
if (XMLNS.equals(prefix)) {
|
||||
nsUri = ElementImpl.XMLNS_URI;
|
||||
return createAttributeNS(nsUri, name);
|
||||
}
|
||||
}
|
||||
|
||||
return super.createAttribute(name);
|
||||
}
|
||||
|
||||
public EntityReference createEntityReference(String name)
|
||||
throws DOMException {
|
||||
log.severe("SAAJ0543.soap.entity.refs.not.allowed.in.docs");
|
||||
throw new UnsupportedOperationException("Entity References are not allowed in SOAP documents");
|
||||
}
|
||||
|
||||
public NodeList getElementsByTagName(String tagname) {
|
||||
return super.getElementsByTagName(tagname);
|
||||
}
|
||||
|
||||
public org.w3c.dom.Node importNode(Node importedNode, boolean deep)
|
||||
throws DOMException {
|
||||
return super.importNode(importedNode, deep);
|
||||
}
|
||||
|
||||
public Element createElementNS(String namespaceURI, String qualifiedName)
|
||||
throws DOMException {
|
||||
return ElementFactory.createElement(
|
||||
this,
|
||||
NameImpl.getLocalNameFromTagName(qualifiedName),
|
||||
NameImpl.getPrefixFromTagName(qualifiedName),
|
||||
namespaceURI);
|
||||
}
|
||||
|
||||
public Attr createAttributeNS(String namespaceURI, String qualifiedName)
|
||||
throws DOMException {
|
||||
return super.createAttributeNS(namespaceURI, qualifiedName);
|
||||
}
|
||||
|
||||
public NodeList getElementsByTagNameNS(
|
||||
String namespaceURI,
|
||||
String localName) {
|
||||
return super.getElementsByTagNameNS(namespaceURI, localName);
|
||||
}
|
||||
|
||||
public Element getElementById(String elementId) {
|
||||
return super.getElementById(elementId);
|
||||
}
|
||||
|
||||
public Node cloneNode(boolean deep) {
|
||||
SOAPPartImpl newSoapPart = getSOAPPart().doCloneNode();
|
||||
super.cloneNode(newSoapPart.getDocument(), deep);
|
||||
return newSoapPart;
|
||||
}
|
||||
|
||||
public void cloneNode(SOAPDocumentImpl newdoc, boolean deep) {
|
||||
super.cloneNode(newdoc, deep);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.soap;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.*;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.soap.impl.ElementFactory;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.impl.ElementImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.util.*;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Attr;
|
||||
|
||||
public abstract class SOAPFactoryImpl extends SOAPFactory {
|
||||
|
||||
protected static final Logger
|
||||
log = Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
|
||||
"com.sun.xml.internal.messaging.saaj.soap.LocalStrings");
|
||||
|
||||
protected abstract SOAPDocumentImpl createDocument();
|
||||
|
||||
public SOAPElement createElement(String tagName) throws SOAPException {
|
||||
if (tagName == null) {
|
||||
log.log(
|
||||
Level.SEVERE,"SAAJ0567.soap.null.input",
|
||||
new Object[] {"tagName","SOAPFactory.createElement"});
|
||||
throw new SOAPException("Null tagName argument passed to createElement");
|
||||
}
|
||||
return ElementFactory.createElement(createDocument(),
|
||||
NameImpl.createFromTagName(tagName));
|
||||
}
|
||||
|
||||
public SOAPElement createElement(Name name) throws SOAPException {
|
||||
// @since SAAJ 1.3
|
||||
// If the Name was null it would cause a NullPointerException in earlier release
|
||||
if (name == null) {
|
||||
log.log(Level.SEVERE,"SAAJ0567.soap.null.input",
|
||||
new Object[] {"name","SOAPFactory.createElement"});
|
||||
throw new SOAPException("Null name argument passed to createElement");
|
||||
}
|
||||
return ElementFactory.createElement(createDocument(), name);
|
||||
}
|
||||
|
||||
public SOAPElement createElement(QName qname) throws SOAPException {
|
||||
if (qname == null) {
|
||||
log.log(Level.SEVERE,"SAAJ0567.soap.null.input",
|
||||
new Object[] {"qname","SOAPFactory.createElement"});
|
||||
throw new SOAPException("Null qname argument passed to createElement");
|
||||
}
|
||||
return ElementFactory.createElement(createDocument(),qname);
|
||||
}
|
||||
|
||||
public SOAPElement createElement(
|
||||
String localName,
|
||||
String prefix,
|
||||
String uri) throws SOAPException {
|
||||
|
||||
// @since SAAJ 1.3
|
||||
// if prefix !=null but localName== null then in earlier releases it would create
|
||||
// a Qualified Name <prefix>:null which is not meaningful
|
||||
if (localName == null) {
|
||||
log.log(Level.SEVERE,"SAAJ0567.soap.null.input",
|
||||
new Object[] {"localName","SOAPFactory.createElement"});
|
||||
throw new SOAPException("Null localName argument passed to createElement");
|
||||
}
|
||||
return ElementFactory.createElement(createDocument(), localName, prefix, uri);
|
||||
}
|
||||
|
||||
public Name createName(String localName, String prefix, String uri)
|
||||
throws SOAPException {
|
||||
// @since SAAJ 1.3
|
||||
// if localName==null, earlier impl would create Name with localName=""
|
||||
// which is absurd.
|
||||
if (localName == null) {
|
||||
log.log(
|
||||
Level.SEVERE,"SAAJ0567.soap.null.input",
|
||||
new Object[] {"localName","SOAPFactory.createName"});
|
||||
throw new SOAPException("Null localName argument passed to createName");
|
||||
}
|
||||
return NameImpl.create(localName, prefix, uri);
|
||||
}
|
||||
|
||||
public Name createName(String localName) throws SOAPException {
|
||||
// @since SAAJ 1.3
|
||||
// if localName==null, earlier impl would create Name with localName=null
|
||||
// which is absurd.
|
||||
if (localName == null) {
|
||||
log.log(
|
||||
Level.SEVERE,"SAAJ0567.soap.null.input",
|
||||
new Object[] {"localName","SOAPFactory.createName"});
|
||||
throw new SOAPException("Null localName argument passed to createName");
|
||||
}
|
||||
return NameImpl.createFromUnqualifiedName(localName);
|
||||
}
|
||||
|
||||
// Note: the child elements might still be org.w3c.dom.Element's, but the
|
||||
// getChildElements will do the conversion to SOAPElement when called.
|
||||
public SOAPElement createElement(Element domElement) throws SOAPException {
|
||||
if (domElement == null) {
|
||||
return null;
|
||||
}
|
||||
return convertToSoapElement(domElement);
|
||||
}
|
||||
|
||||
private SOAPElement convertToSoapElement(Element element) throws SOAPException {
|
||||
|
||||
if (element instanceof SOAPElement) {
|
||||
return (SOAPElement) element;
|
||||
}
|
||||
|
||||
SOAPElement copy = createElement(
|
||||
element.getLocalName(),
|
||||
element.getPrefix(),
|
||||
element.getNamespaceURI());
|
||||
|
||||
Document ownerDoc = copy.getOwnerDocument();
|
||||
|
||||
NamedNodeMap attrMap = element.getAttributes();
|
||||
for (int i=0; i < attrMap.getLength(); i++) {
|
||||
Attr nextAttr = (Attr)attrMap.item(i);
|
||||
Attr importedAttr = (Attr)ownerDoc.importNode(nextAttr, true);
|
||||
copy.setAttributeNodeNS(importedAttr);
|
||||
}
|
||||
|
||||
|
||||
NodeList nl = element.getChildNodes();
|
||||
for (int i=0; i < nl.getLength(); i++) {
|
||||
org.w3c.dom.Node next = nl.item(i);
|
||||
org.w3c.dom.Node imported = ownerDoc.importNode(next, true);
|
||||
copy.appendChild(imported);
|
||||
}
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
public Detail createDetail() throws SOAPException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public SOAPFault createFault(String reasonText, QName faultCode) throws SOAPException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public SOAPFault createFault() throws SOAPException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Created on Nov 19, 2002
|
||||
*
|
||||
* To change this generated comment edit the template variable "filecomment":
|
||||
* Window>Preferences>Java>Templates.
|
||||
* To enable and disable the creation of file comments go to
|
||||
* Window>Preferences>Java>Code Generation.
|
||||
*/
|
||||
package com.sun.xml.internal.messaging.saaj.soap;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
|
||||
|
||||
public class SOAPIOException extends IOException {
|
||||
SOAPExceptionImpl soapException;
|
||||
|
||||
public SOAPIOException() {
|
||||
super();
|
||||
soapException = new SOAPExceptionImpl();
|
||||
soapException.fillInStackTrace();
|
||||
}
|
||||
|
||||
public SOAPIOException(String s) {
|
||||
super();
|
||||
soapException = new SOAPExceptionImpl(s);
|
||||
soapException.fillInStackTrace();
|
||||
}
|
||||
|
||||
public SOAPIOException(String reason, Throwable cause) {
|
||||
super();
|
||||
soapException = new SOAPExceptionImpl(reason, cause);
|
||||
soapException.fillInStackTrace();
|
||||
}
|
||||
|
||||
public SOAPIOException(Throwable cause) {
|
||||
super(cause.toString());
|
||||
soapException = new SOAPExceptionImpl(cause);
|
||||
soapException.fillInStackTrace();
|
||||
}
|
||||
|
||||
public Throwable fillInStackTrace() {
|
||||
if (soapException != null) {
|
||||
soapException.fillInStackTrace();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getLocalizedMessage() {
|
||||
return soapException.getLocalizedMessage();
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return soapException.getMessage();
|
||||
}
|
||||
|
||||
public void printStackTrace() {
|
||||
soapException.printStackTrace();
|
||||
}
|
||||
|
||||
public void printStackTrace(PrintStream s) {
|
||||
soapException.printStackTrace(s);
|
||||
}
|
||||
|
||||
public void printStackTrace(PrintWriter s) {
|
||||
soapException.printStackTrace(s);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return soapException.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,814 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.soap;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Iterator;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.activation.DataHandler;
|
||||
import javax.activation.DataSource;
|
||||
import javax.xml.soap.*;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.w3c.dom.*;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.MimeBodyPart;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.impl.ElementImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.impl.EnvelopeImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.util.*;
|
||||
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.sax.SAXSource;
|
||||
|
||||
/**
|
||||
* SOAPPartImpl is the first attachment. This contains the XML/SOAP document.
|
||||
*
|
||||
* @author Anil Vijendran (anil@sun.com)
|
||||
*/
|
||||
public abstract class SOAPPartImpl extends SOAPPart implements SOAPDocument {
|
||||
protected static final Logger log =
|
||||
Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
|
||||
"com.sun.xml.internal.messaging.saaj.soap.LocalStrings");
|
||||
|
||||
protected MimeHeaders headers;
|
||||
protected Envelope envelope;
|
||||
protected Source source;
|
||||
protected SOAPDocumentImpl document;
|
||||
|
||||
//flag to indicate if a setContent happened.
|
||||
private boolean sourceWasSet = false;
|
||||
|
||||
// Records whether the input source had an xml decl or not.
|
||||
protected boolean omitXmlDecl = true;
|
||||
|
||||
// Records the charset encoding of the input stream source if provided.
|
||||
protected String sourceCharsetEncoding = null;
|
||||
|
||||
/**
|
||||
* Reference to containing message (may be null)
|
||||
*/
|
||||
protected MessageImpl message;
|
||||
|
||||
static final boolean lazyContentLength;
|
||||
static {
|
||||
lazyContentLength = SAAJUtil.getSystemBoolean("saaj.lazy.contentlength");
|
||||
}
|
||||
|
||||
protected SOAPPartImpl() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
protected SOAPPartImpl(MessageImpl message) {
|
||||
document = new SOAPDocumentImpl(this);
|
||||
headers = new MimeHeaders();
|
||||
this.message = message;
|
||||
headers.setHeader("Content-Type", getContentType());
|
||||
}
|
||||
|
||||
protected abstract String getContentType();
|
||||
protected abstract Envelope createEnvelopeFromSource()
|
||||
throws SOAPException;
|
||||
protected abstract Envelope createEmptyEnvelope(String prefix)
|
||||
throws SOAPException;
|
||||
protected abstract SOAPPartImpl duplicateType();
|
||||
|
||||
protected String getContentTypeString() {
|
||||
return getContentType();
|
||||
}
|
||||
|
||||
public boolean isFastInfoset() {
|
||||
return (message != null) ? message.isFastInfoset() : false;
|
||||
}
|
||||
|
||||
public SOAPEnvelope getEnvelope() throws SOAPException {
|
||||
|
||||
// If there is no SOAP envelope already created, then create
|
||||
// one from a source if one exists. If there is a newer source
|
||||
// then use that source.
|
||||
|
||||
if (sourceWasSet)
|
||||
sourceWasSet = false;
|
||||
|
||||
lookForEnvelope();
|
||||
if (envelope != null) {
|
||||
if (source != null) { // there's a newer source, use it
|
||||
document.removeChild(envelope);
|
||||
envelope = createEnvelopeFromSource();
|
||||
}
|
||||
} else if (source != null) {
|
||||
envelope = createEnvelopeFromSource();
|
||||
} else {
|
||||
envelope = createEmptyEnvelope(null);
|
||||
document.insertBefore(envelope, null);
|
||||
}
|
||||
return envelope;
|
||||
}
|
||||
|
||||
protected void lookForEnvelope() throws SOAPException {
|
||||
Element envelopeChildElement = document.doGetDocumentElement();
|
||||
if (envelopeChildElement == null || envelopeChildElement instanceof Envelope) {
|
||||
envelope = (EnvelopeImpl) envelopeChildElement;
|
||||
} else if (!(envelopeChildElement instanceof ElementImpl)) {
|
||||
log.severe("SAAJ0512.soap.incorrect.factory.used");
|
||||
throw new SOAPExceptionImpl("Unable to create envelope: incorrect factory used during tree construction");
|
||||
} else {
|
||||
ElementImpl soapElement = (ElementImpl) envelopeChildElement;
|
||||
if (soapElement.getLocalName().equalsIgnoreCase("Envelope")) {
|
||||
String prefix = soapElement.getPrefix();
|
||||
String uri = (prefix == null) ? soapElement.getNamespaceURI() : soapElement.getNamespaceURI(prefix);
|
||||
if(!uri.equals(NameImpl.SOAP11_NAMESPACE) && !uri.equals(NameImpl.SOAP12_NAMESPACE)) {
|
||||
log.severe("SAAJ0513.soap.unknown.ns");
|
||||
throw new SOAPVersionMismatchException("Unable to create envelope from given source because the namespace was not recognized");
|
||||
}
|
||||
} else {
|
||||
log.severe("SAAJ0514.soap.root.elem.not.named.envelope");
|
||||
throw new SOAPExceptionImpl(
|
||||
"Unable to create envelope from given source because the root element is not named \"Envelope\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeAllMimeHeaders() {
|
||||
headers.removeAllHeaders();
|
||||
}
|
||||
|
||||
public void removeMimeHeader(String header) {
|
||||
headers.removeHeader(header);
|
||||
}
|
||||
|
||||
public String[] getMimeHeader(String name) {
|
||||
return headers.getHeader(name);
|
||||
}
|
||||
|
||||
public void setMimeHeader(String name, String value) {
|
||||
headers.setHeader(name, value);
|
||||
}
|
||||
|
||||
public void addMimeHeader(String name, String value) {
|
||||
headers.addHeader(name, value);
|
||||
}
|
||||
|
||||
public Iterator getAllMimeHeaders() {
|
||||
return headers.getAllHeaders();
|
||||
}
|
||||
|
||||
public Iterator getMatchingMimeHeaders(String[] names) {
|
||||
return headers.getMatchingHeaders(names);
|
||||
}
|
||||
|
||||
public Iterator getNonMatchingMimeHeaders(String[] names) {
|
||||
return headers.getNonMatchingHeaders(names);
|
||||
}
|
||||
|
||||
public Source getContent() throws SOAPException {
|
||||
if (source != null) {
|
||||
InputStream bis = null;
|
||||
if (source instanceof JAXMStreamSource) {
|
||||
StreamSource streamSource = (StreamSource)source;
|
||||
bis = streamSource.getInputStream();
|
||||
} else if (FastInfosetReflection.isFastInfosetSource(source)) {
|
||||
// FastInfosetSource inherits from SAXSource
|
||||
SAXSource saxSource = (SAXSource)source;
|
||||
bis = saxSource.getInputSource().getByteStream();
|
||||
}
|
||||
|
||||
if (bis != null) {
|
||||
try {
|
||||
bis.reset();
|
||||
} catch (IOException e) {
|
||||
/* This exception will never be thrown.
|
||||
*
|
||||
* The setContent method will modify the source
|
||||
* if StreamSource to JAXMStreamSource, that uses
|
||||
* a ByteInputStream, and for a FastInfosetSource will
|
||||
* replace the InputStream with a ByteInputStream.
|
||||
*/
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
return ((Envelope) getEnvelope()).getContent();
|
||||
}
|
||||
|
||||
public void setContent(Source source) throws SOAPException {
|
||||
try {
|
||||
if (source instanceof StreamSource) {
|
||||
InputStream is = ((StreamSource) source).getInputStream();
|
||||
Reader rdr = ((StreamSource) source).getReader();
|
||||
|
||||
if (is != null) {
|
||||
this.source = new JAXMStreamSource(is);
|
||||
} else if (rdr != null) {
|
||||
this.source = new JAXMStreamSource(rdr);
|
||||
} else {
|
||||
log.severe("SAAJ0544.soap.no.valid.reader.for.src");
|
||||
throw new SOAPExceptionImpl("Source does not have a valid Reader or InputStream");
|
||||
}
|
||||
}
|
||||
else if (FastInfosetReflection.isFastInfosetSource(source)) {
|
||||
// InputStream is = source.getInputStream()
|
||||
InputStream is = FastInfosetReflection.FastInfosetSource_getInputStream(source);
|
||||
|
||||
/*
|
||||
* Underlying stream must be ByteInputStream for getContentAsStream(). We pay the
|
||||
* cost of copying the underlying bytes here to avoid multiple copies every time
|
||||
* getBytes() is called on a ByteInputStream.
|
||||
*/
|
||||
if (!(is instanceof ByteInputStream)) {
|
||||
ByteOutputStream bout = new ByteOutputStream();
|
||||
bout.write(is);
|
||||
|
||||
// source.setInputStream(new ByteInputStream(...))
|
||||
FastInfosetReflection.FastInfosetSource_setInputStream(
|
||||
source, bout.newInputStream());
|
||||
}
|
||||
this.source = source;
|
||||
}
|
||||
else {
|
||||
this.source = source;
|
||||
}
|
||||
sourceWasSet = true;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
|
||||
log.severe("SAAJ0545.soap.cannot.set.src.for.part");
|
||||
throw new SOAPExceptionImpl(
|
||||
"Error setting the source for SOAPPart: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public InputStream getContentAsStream() throws IOException {
|
||||
if (source != null) {
|
||||
InputStream is = null;
|
||||
|
||||
// Allow message to be transcode if so requested
|
||||
if (source instanceof StreamSource && !isFastInfoset()) {
|
||||
is = ((StreamSource) source).getInputStream();
|
||||
}
|
||||
else if (FastInfosetReflection.isFastInfosetSource(source) &&
|
||||
isFastInfoset())
|
||||
{
|
||||
try {
|
||||
// InputStream is = source.getInputStream()
|
||||
is = FastInfosetReflection.FastInfosetSource_getInputStream(source);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IOException(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
if (is != null) {
|
||||
if (lazyContentLength) {
|
||||
return is;
|
||||
}
|
||||
if (!(is instanceof ByteInputStream)) {
|
||||
log.severe("SAAJ0546.soap.stream.incorrect.type");
|
||||
throw new IOException("Internal error: stream not of the right type");
|
||||
}
|
||||
return (ByteInputStream) is;
|
||||
}
|
||||
// need to do something here for reader...
|
||||
// for now we'll see if we can fallback...
|
||||
}
|
||||
|
||||
ByteOutputStream b = new ByteOutputStream();
|
||||
|
||||
Envelope env = null;
|
||||
|
||||
try {
|
||||
env = (Envelope) getEnvelope();
|
||||
env.output(b, isFastInfoset());
|
||||
}
|
||||
catch (SOAPException soapException) {
|
||||
log.severe("SAAJ0547.soap.cannot.externalize");
|
||||
throw new SOAPIOException(
|
||||
"SOAP exception while trying to externalize: ",
|
||||
soapException);
|
||||
}
|
||||
|
||||
return b.newInputStream();
|
||||
}
|
||||
|
||||
MimeBodyPart getMimePart() throws SOAPException {
|
||||
try {
|
||||
MimeBodyPart headerEnvelope = new MimeBodyPart();
|
||||
|
||||
headerEnvelope.setDataHandler(getDataHandler());
|
||||
AttachmentPartImpl.copyMimeHeaders(headers, headerEnvelope);
|
||||
|
||||
return headerEnvelope;
|
||||
} catch (SOAPException ex) {
|
||||
throw ex;
|
||||
} catch (Exception ex) {
|
||||
log.severe("SAAJ0548.soap.cannot.externalize.hdr");
|
||||
throw new SOAPExceptionImpl("Unable to externalize header", ex);
|
||||
}
|
||||
}
|
||||
|
||||
MimeHeaders getMimeHeaders() {
|
||||
return headers;
|
||||
}
|
||||
|
||||
DataHandler getDataHandler() {
|
||||
DataSource ds = new DataSource() {
|
||||
public OutputStream getOutputStream() throws IOException {
|
||||
throw new IOException("Illegal Operation");
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return getContentTypeString();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return getContentId();
|
||||
}
|
||||
|
||||
public InputStream getInputStream() throws IOException {
|
||||
return getContentAsStream();
|
||||
}
|
||||
};
|
||||
return new DataHandler(ds);
|
||||
}
|
||||
|
||||
public SOAPDocumentImpl getDocument() {
|
||||
handleNewSource();
|
||||
return document;
|
||||
}
|
||||
|
||||
public SOAPPartImpl getSOAPPart() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public DocumentType getDoctype() {
|
||||
return document.getDoctype();
|
||||
}
|
||||
|
||||
// Forward all of these calls to the document to ensure that they work the
|
||||
// same way whether they are called from here or directly from the document.
|
||||
// If the document needs any help from this SOAPPart then
|
||||
// Make it use a call-back as in doGetDocumentElement() below
|
||||
public DOMImplementation getImplementation() {
|
||||
return document.getImplementation();
|
||||
}
|
||||
|
||||
public Element getDocumentElement() {
|
||||
// If there is no SOAP envelope already created, then create
|
||||
// one from a source if one exists. If there is a newer source
|
||||
// then use that source.
|
||||
try {
|
||||
getEnvelope();
|
||||
} catch (SOAPException e) {
|
||||
}
|
||||
return document.getDocumentElement();
|
||||
}
|
||||
|
||||
protected void doGetDocumentElement() {
|
||||
handleNewSource();
|
||||
try {
|
||||
lookForEnvelope();
|
||||
} catch (SOAPException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public Element createElement(String tagName) throws DOMException {
|
||||
return document.createElement(tagName);
|
||||
}
|
||||
|
||||
public DocumentFragment createDocumentFragment() {
|
||||
return document.createDocumentFragment();
|
||||
}
|
||||
|
||||
public org.w3c.dom.Text createTextNode(String data) {
|
||||
return document.createTextNode(data);
|
||||
}
|
||||
|
||||
public Comment createComment(String data) {
|
||||
return document.createComment(data);
|
||||
}
|
||||
|
||||
public CDATASection createCDATASection(String data) throws DOMException {
|
||||
return document.createCDATASection(data);
|
||||
}
|
||||
|
||||
public ProcessingInstruction createProcessingInstruction(
|
||||
String target,
|
||||
String data)
|
||||
throws DOMException {
|
||||
return document.createProcessingInstruction(target, data);
|
||||
}
|
||||
|
||||
public Attr createAttribute(String name) throws DOMException {
|
||||
return document.createAttribute(name);
|
||||
}
|
||||
|
||||
public EntityReference createEntityReference(String name)
|
||||
throws DOMException {
|
||||
return document.createEntityReference(name);
|
||||
}
|
||||
|
||||
public NodeList getElementsByTagName(String tagname) {
|
||||
handleNewSource();
|
||||
return document.getElementsByTagName(tagname);
|
||||
}
|
||||
|
||||
public org.w3c.dom.Node importNode(
|
||||
org.w3c.dom.Node importedNode,
|
||||
boolean deep)
|
||||
throws DOMException {
|
||||
handleNewSource();
|
||||
return document.importNode(importedNode, deep);
|
||||
}
|
||||
|
||||
public Element createElementNS(String namespaceURI, String qualifiedName)
|
||||
throws DOMException {
|
||||
return document.createElementNS(namespaceURI, qualifiedName);
|
||||
}
|
||||
|
||||
public Attr createAttributeNS(String namespaceURI, String qualifiedName)
|
||||
throws DOMException {
|
||||
return document.createAttributeNS(namespaceURI, qualifiedName);
|
||||
}
|
||||
|
||||
public NodeList getElementsByTagNameNS(
|
||||
String namespaceURI,
|
||||
String localName) {
|
||||
handleNewSource();
|
||||
return document.getElementsByTagNameNS(namespaceURI, localName);
|
||||
}
|
||||
|
||||
public Element getElementById(String elementId) {
|
||||
handleNewSource();
|
||||
return document.getElementById(elementId);
|
||||
}
|
||||
public org.w3c.dom.Node appendChild(org.w3c.dom.Node newChild)
|
||||
throws DOMException {
|
||||
handleNewSource();
|
||||
return document.appendChild(newChild);
|
||||
}
|
||||
|
||||
public org.w3c.dom.Node cloneNode(boolean deep) {
|
||||
handleNewSource();
|
||||
return document.cloneNode(deep);
|
||||
}
|
||||
|
||||
protected SOAPPartImpl doCloneNode() {
|
||||
handleNewSource();
|
||||
SOAPPartImpl newSoapPart = duplicateType();
|
||||
|
||||
newSoapPart.headers = MimeHeadersUtil.copy(this.headers);
|
||||
newSoapPart.source = this.source;
|
||||
return newSoapPart;
|
||||
}
|
||||
|
||||
public NamedNodeMap getAttributes() {
|
||||
return document.getAttributes();
|
||||
}
|
||||
|
||||
public NodeList getChildNodes() {
|
||||
handleNewSource();
|
||||
return document.getChildNodes();
|
||||
}
|
||||
|
||||
public org.w3c.dom.Node getFirstChild() {
|
||||
handleNewSource();
|
||||
return document.getFirstChild();
|
||||
}
|
||||
|
||||
public org.w3c.dom.Node getLastChild() {
|
||||
handleNewSource();
|
||||
return document.getLastChild();
|
||||
}
|
||||
|
||||
public String getLocalName() {
|
||||
return document.getLocalName();
|
||||
}
|
||||
|
||||
public String getNamespaceURI() {
|
||||
return document.getNamespaceURI();
|
||||
}
|
||||
|
||||
public org.w3c.dom.Node getNextSibling() {
|
||||
handleNewSource();
|
||||
return document.getNextSibling();
|
||||
}
|
||||
|
||||
public String getNodeName() {
|
||||
return document.getNodeName();
|
||||
}
|
||||
|
||||
public short getNodeType() {
|
||||
return document.getNodeType();
|
||||
}
|
||||
|
||||
public String getNodeValue() throws DOMException {
|
||||
return document.getNodeValue();
|
||||
}
|
||||
|
||||
public Document getOwnerDocument() {
|
||||
return document.getOwnerDocument();
|
||||
}
|
||||
|
||||
public org.w3c.dom.Node getParentNode() {
|
||||
return document.getParentNode();
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return document.getPrefix();
|
||||
}
|
||||
|
||||
public org.w3c.dom.Node getPreviousSibling() {
|
||||
return document.getPreviousSibling();
|
||||
}
|
||||
|
||||
public boolean hasAttributes() {
|
||||
return document.hasAttributes();
|
||||
}
|
||||
|
||||
public boolean hasChildNodes() {
|
||||
handleNewSource();
|
||||
return document.hasChildNodes();
|
||||
}
|
||||
|
||||
public org.w3c.dom.Node insertBefore(
|
||||
org.w3c.dom.Node arg0,
|
||||
org.w3c.dom.Node arg1)
|
||||
throws DOMException {
|
||||
handleNewSource();
|
||||
return document.insertBefore(arg0, arg1);
|
||||
}
|
||||
|
||||
public boolean isSupported(String arg0, String arg1) {
|
||||
return document.isSupported(arg0, arg1);
|
||||
}
|
||||
|
||||
public void normalize() {
|
||||
handleNewSource();
|
||||
document.normalize();
|
||||
}
|
||||
|
||||
public org.w3c.dom.Node removeChild(org.w3c.dom.Node arg0)
|
||||
throws DOMException {
|
||||
handleNewSource();
|
||||
return document.removeChild(arg0);
|
||||
}
|
||||
|
||||
public org.w3c.dom.Node replaceChild(
|
||||
org.w3c.dom.Node arg0,
|
||||
org.w3c.dom.Node arg1)
|
||||
throws DOMException {
|
||||
handleNewSource();
|
||||
return document.replaceChild(arg0, arg1);
|
||||
}
|
||||
|
||||
public void setNodeValue(String arg0) throws DOMException {
|
||||
document.setNodeValue(arg0);
|
||||
}
|
||||
|
||||
public void setPrefix(String arg0) throws DOMException {
|
||||
document.setPrefix(arg0);
|
||||
}
|
||||
|
||||
private void handleNewSource() {
|
||||
if (sourceWasSet) {
|
||||
// There is a newer source use that source.
|
||||
try {
|
||||
getEnvelope();
|
||||
} catch (SOAPException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected XMLDeclarationParser lookForXmlDecl() throws SOAPException {
|
||||
if ((source != null) && (source instanceof StreamSource)) {
|
||||
|
||||
Reader reader = null;
|
||||
|
||||
InputStream inputStream = ((StreamSource) source).getInputStream();
|
||||
if (inputStream != null) {
|
||||
if (getSourceCharsetEncoding() == null) {
|
||||
reader = new InputStreamReader(inputStream);
|
||||
} else {
|
||||
try {
|
||||
reader =
|
||||
new InputStreamReader(
|
||||
inputStream, getSourceCharsetEncoding());
|
||||
} catch (UnsupportedEncodingException uee) {
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0551.soap.unsupported.encoding",
|
||||
new Object[] {getSourceCharsetEncoding()});
|
||||
throw new SOAPExceptionImpl(
|
||||
"Unsupported encoding " + getSourceCharsetEncoding(),
|
||||
uee);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
reader = ((StreamSource) source).getReader();
|
||||
}
|
||||
if (reader != null) {
|
||||
PushbackReader pushbackReader =
|
||||
new PushbackReader(reader, 4096); //some size to unread <?xml ....?>
|
||||
XMLDeclarationParser ev =
|
||||
new XMLDeclarationParser(pushbackReader);
|
||||
try {
|
||||
ev.parse();
|
||||
} catch (Exception e) {
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0552.soap.xml.decl.parsing.failed");
|
||||
throw new SOAPExceptionImpl(
|
||||
"XML declaration parsing failed", e);
|
||||
}
|
||||
String xmlDecl = ev.getXmlDeclaration();
|
||||
if ((xmlDecl != null) && (xmlDecl.length() > 0)) {
|
||||
this.omitXmlDecl = false;
|
||||
}
|
||||
if (lazyContentLength) {
|
||||
source = new StreamSource(pushbackReader);
|
||||
}
|
||||
return ev;
|
||||
}
|
||||
} else if ((source != null) && (source instanceof DOMSource)) {
|
||||
//TODO: A Domsource maynot contain XMLDecl ?.
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setSourceCharsetEncoding(String charset) {
|
||||
this.sourceCharsetEncoding = charset;
|
||||
}
|
||||
|
||||
public org.w3c.dom.Node renameNode(org.w3c.dom.Node n, String namespaceURI, String qualifiedName)
|
||||
throws DOMException {
|
||||
handleNewSource();
|
||||
return document.renameNode(n, namespaceURI, qualifiedName);
|
||||
}
|
||||
|
||||
public void normalizeDocument() {
|
||||
document.normalizeDocument();
|
||||
}
|
||||
|
||||
public DOMConfiguration getDomConfig() {
|
||||
return document.getDomConfig();
|
||||
}
|
||||
|
||||
public org.w3c.dom.Node adoptNode(org.w3c.dom.Node source) throws DOMException {
|
||||
handleNewSource();
|
||||
return document.adoptNode(source);
|
||||
}
|
||||
|
||||
public void setDocumentURI(String documentURI) {
|
||||
document.setDocumentURI(documentURI);
|
||||
}
|
||||
|
||||
public String getDocumentURI() {
|
||||
return document.getDocumentURI();
|
||||
}
|
||||
|
||||
public void setStrictErrorChecking(boolean strictErrorChecking) {
|
||||
document.setStrictErrorChecking(strictErrorChecking);
|
||||
}
|
||||
|
||||
public String getInputEncoding() {
|
||||
return document.getInputEncoding();
|
||||
}
|
||||
|
||||
public String getXmlEncoding() {
|
||||
return document.getXmlEncoding();
|
||||
}
|
||||
|
||||
public boolean getXmlStandalone() {
|
||||
return document.getXmlStandalone();
|
||||
}
|
||||
|
||||
public void setXmlStandalone(boolean xmlStandalone) throws DOMException {
|
||||
document.setXmlStandalone(xmlStandalone);
|
||||
}
|
||||
|
||||
public String getXmlVersion() {
|
||||
return document.getXmlVersion();
|
||||
}
|
||||
|
||||
public void setXmlVersion(String xmlVersion) throws DOMException {
|
||||
document.setXmlVersion(xmlVersion);
|
||||
}
|
||||
|
||||
public boolean getStrictErrorChecking() {
|
||||
return document.getStrictErrorChecking();
|
||||
}
|
||||
|
||||
// DOM L3 methods from org.w3c.dom.Node
|
||||
public String getBaseURI() {
|
||||
return document.getBaseURI();
|
||||
}
|
||||
|
||||
public short compareDocumentPosition(org.w3c.dom.Node other)
|
||||
throws DOMException {
|
||||
return document.compareDocumentPosition(other);
|
||||
}
|
||||
|
||||
public String getTextContent()
|
||||
throws DOMException {
|
||||
return document.getTextContent();
|
||||
}
|
||||
|
||||
public void setTextContent(String textContent) throws DOMException {
|
||||
document.setTextContent(textContent);
|
||||
}
|
||||
|
||||
public boolean isSameNode(org.w3c.dom.Node other) {
|
||||
return document.isSameNode(other);
|
||||
}
|
||||
|
||||
public String lookupPrefix(String namespaceURI) {
|
||||
return document.lookupPrefix(namespaceURI);
|
||||
}
|
||||
|
||||
public boolean isDefaultNamespace(String namespaceURI) {
|
||||
return document.isDefaultNamespace(namespaceURI);
|
||||
}
|
||||
|
||||
public String lookupNamespaceURI(String prefix) {
|
||||
return document.lookupNamespaceURI(prefix);
|
||||
}
|
||||
|
||||
public boolean isEqualNode(org.w3c.dom.Node arg) {
|
||||
return document.isEqualNode(arg);
|
||||
}
|
||||
|
||||
public Object getFeature(String feature,
|
||||
String version) {
|
||||
return document.getFeature(feature,version);
|
||||
}
|
||||
|
||||
public Object setUserData(String key,
|
||||
Object data,
|
||||
UserDataHandler handler) {
|
||||
return document.setUserData(key, data, handler);
|
||||
}
|
||||
|
||||
public Object getUserData(String key) {
|
||||
return document.getUserData(key);
|
||||
}
|
||||
|
||||
public void recycleNode() {
|
||||
// Nothing seems to be required to be done here
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
log.severe("SAAJ0571.soappart.setValue.not.defined");
|
||||
throw new IllegalStateException("Setting value of a soap part is not defined");
|
||||
}
|
||||
|
||||
public void setParentElement(SOAPElement parent) throws SOAPException {
|
||||
log.severe("SAAJ0570.soappart.parent.element.not.defined");
|
||||
throw new SOAPExceptionImpl("The parent element of a soap part is not defined");
|
||||
}
|
||||
|
||||
public SOAPElement getParentElement() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void detachNode() {
|
||||
// Nothing seems to be required to be done here
|
||||
}
|
||||
|
||||
public String getSourceCharsetEncoding() {
|
||||
return sourceCharsetEncoding;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.soap;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
|
||||
|
||||
public class SOAPVersionMismatchException extends SOAPExceptionImpl {
|
||||
/**
|
||||
* Constructs a <code>SOAPExceptionImpl</code> object with no
|
||||
* reason or embedded <code>Throwable</code> object.
|
||||
*/
|
||||
public SOAPVersionMismatchException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>SOAPExceptionImpl</code> object with the given
|
||||
* <code>String</code> as the reason for the exception being thrown.
|
||||
*
|
||||
* @param reason a description of what caused the exception
|
||||
*/
|
||||
public SOAPVersionMismatchException(String reason) {
|
||||
super(reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>SOAPExceptionImpl</code> object with the given
|
||||
* <code>String</code> as the reason for the exception being thrown
|
||||
* and the given <code>Throwable</code> object as an embedded
|
||||
* exception.
|
||||
*
|
||||
* @param reason a description of what caused the exception
|
||||
* @param cause a <code>Throwable</code> object that is to
|
||||
* be embedded in this <code>SOAPExceptionImpl</code> object
|
||||
*/
|
||||
public SOAPVersionMismatchException(String reason, Throwable cause) {
|
||||
super(reason, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>SOAPExceptionImpl</code> object initialized
|
||||
* with the given <code>Throwable</code> object.
|
||||
*/
|
||||
public SOAPVersionMismatchException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.soap;
|
||||
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.io.*;
|
||||
|
||||
import javax.activation.*;
|
||||
import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.MimeUtility;
|
||||
import com.sun.xml.internal.messaging.saaj.packaging.mime.util.ASCIIUtility;
|
||||
import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.ContentType;
|
||||
|
||||
/**
|
||||
* JAF data content handler for text/plain --> String
|
||||
*
|
||||
*/
|
||||
public class StringDataContentHandler implements DataContentHandler {
|
||||
private static ActivationDataFlavor myDF = new ActivationDataFlavor(
|
||||
java.lang.String.class,
|
||||
"text/plain",
|
||||
"Text String");
|
||||
|
||||
protected ActivationDataFlavor getDF() {
|
||||
return myDF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the DataFlavors for this <code>DataContentHandler</code>.
|
||||
*
|
||||
* @return The DataFlavors
|
||||
*/
|
||||
public DataFlavor[] getTransferDataFlavors() {
|
||||
return new DataFlavor[] { getDF() };
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Transfer Data of type DataFlavor from InputStream.
|
||||
*
|
||||
* @param df The DataFlavor
|
||||
* @param ds The DataSource corresponding to the data
|
||||
* @return String object
|
||||
*/
|
||||
public Object getTransferData(DataFlavor df, DataSource ds)
|
||||
throws IOException {
|
||||
// use myDF.equals to be sure to get ActivationDataFlavor.equals,
|
||||
// which properly ignores Content-Type parameters in comparison
|
||||
if (getDF().equals(df))
|
||||
return getContent(ds);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object getContent(DataSource ds) throws IOException {
|
||||
String enc = null;
|
||||
InputStreamReader is = null;
|
||||
|
||||
try {
|
||||
enc = getCharset(ds.getContentType());
|
||||
is = new InputStreamReader(ds.getInputStream(), enc);
|
||||
} catch (IllegalArgumentException iex) {
|
||||
/*
|
||||
* An unknown charset of the form ISO-XXX-XXX will cause
|
||||
* the JDK to throw an IllegalArgumentException. The
|
||||
* JDK will attempt to create a classname using this string,
|
||||
* but valid classnames must not contain the character '-',
|
||||
* and this results in an IllegalArgumentException, rather than
|
||||
* the expected UnsupportedEncodingException. Yikes.
|
||||
*/
|
||||
throw new UnsupportedEncodingException(enc);
|
||||
}
|
||||
|
||||
try {
|
||||
int pos = 0;
|
||||
int count;
|
||||
char buf[] = new char[1024];
|
||||
|
||||
while ((count = is.read(buf, pos, buf.length - pos)) != -1) {
|
||||
pos += count;
|
||||
if (pos >= buf.length) {
|
||||
int size = buf.length;
|
||||
if (size < 256*1024)
|
||||
size += size;
|
||||
else
|
||||
size += 256*1024;
|
||||
char tbuf[] = new char[size];
|
||||
System.arraycopy(buf, 0, tbuf, 0, pos);
|
||||
buf = tbuf;
|
||||
}
|
||||
}
|
||||
return new String(buf, 0, pos);
|
||||
} finally {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException ex) { }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the object to the output stream, using the specified MIME type.
|
||||
*/
|
||||
public void writeTo(Object obj, String type, OutputStream os)
|
||||
throws IOException {
|
||||
if (!(obj instanceof String))
|
||||
throw new IOException("\"" + getDF().getMimeType() +
|
||||
"\" DataContentHandler requires String object, " +
|
||||
"was given object of type " + obj.getClass().toString());
|
||||
|
||||
String enc = null;
|
||||
OutputStreamWriter osw = null;
|
||||
|
||||
try {
|
||||
enc = getCharset(type);
|
||||
osw = new OutputStreamWriter(os, enc);
|
||||
} catch (IllegalArgumentException iex) {
|
||||
/*
|
||||
* An unknown charset of the form ISO-XXX-XXX will cause
|
||||
* the JDK to throw an IllegalArgumentException. The
|
||||
* JDK will attempt to create a classname using this string,
|
||||
* but valid classnames must not contain the character '-',
|
||||
* and this results in an IllegalArgumentException, rather than
|
||||
* the expected UnsupportedEncodingException. Yikes.
|
||||
*/
|
||||
throw new UnsupportedEncodingException(enc);
|
||||
}
|
||||
|
||||
String s = (String)obj;
|
||||
osw.write(s, 0, s.length());
|
||||
osw.flush();
|
||||
}
|
||||
|
||||
private String getCharset(String type) {
|
||||
try {
|
||||
ContentType ct = new ContentType(type);
|
||||
String charset = ct.getParameter("charset");
|
||||
if (charset == null)
|
||||
// If the charset parameter is absent, use US-ASCII.
|
||||
charset = "us-ascii";
|
||||
return MimeUtility.javaCharset(charset);
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.soap;
|
||||
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import javax.activation.*;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.util.transform.EfficientStreamingTransformer;
|
||||
|
||||
/**
|
||||
* JAF data handler for XML content
|
||||
*
|
||||
* @author Anil Vijendran
|
||||
*/
|
||||
public class XmlDataContentHandler implements DataContentHandler {
|
||||
public static final String STR_SRC = "javax.xml.transform.stream.StreamSource";
|
||||
private static Class streamSourceClass = null;
|
||||
|
||||
public XmlDataContentHandler() throws ClassNotFoundException {
|
||||
if (streamSourceClass == null) {
|
||||
streamSourceClass = Class.forName(STR_SRC);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* return the DataFlavors for this <code>DataContentHandler</code>
|
||||
* @return The DataFlavors.
|
||||
*/
|
||||
public DataFlavor[] getTransferDataFlavors() { // throws Exception;
|
||||
DataFlavor flavors[] = new DataFlavor[2];
|
||||
|
||||
flavors[0] =
|
||||
new ActivationDataFlavor(streamSourceClass, "text/xml", "XML");
|
||||
flavors[1] =
|
||||
new ActivationDataFlavor(streamSourceClass, "application/xml", "XML");
|
||||
|
||||
return flavors;
|
||||
}
|
||||
|
||||
/**
|
||||
* return the Transfer Data of type DataFlavor from InputStream
|
||||
* @param df The DataFlavor.
|
||||
* @param ins The InputStream corresponding to the data.
|
||||
* @return The constructed Object.
|
||||
*/
|
||||
public Object getTransferData(DataFlavor flavor, DataSource dataSource)
|
||||
throws IOException {
|
||||
if (flavor.getMimeType().startsWith("text/xml") ||
|
||||
flavor.getMimeType().startsWith("application/xml")) {
|
||||
if (flavor.getRepresentationClass().getName().equals(STR_SRC)) {
|
||||
return new StreamSource(dataSource.getInputStream());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Object getContent(DataSource dataSource) throws IOException {
|
||||
return new StreamSource(dataSource.getInputStream());
|
||||
}
|
||||
|
||||
/**
|
||||
* construct an object from a byte stream
|
||||
* (similar semantically to previous method, we are deciding
|
||||
* which one to support)
|
||||
*/
|
||||
public void writeTo(Object obj, String mimeType, OutputStream os)
|
||||
throws IOException {
|
||||
if (!mimeType.startsWith("text/xml") && !mimeType.startsWith("application/xml"))
|
||||
throw new IOException(
|
||||
"Invalid content type \"" + mimeType + "\" for XmlDCH");
|
||||
|
||||
|
||||
try {
|
||||
Transformer transformer = EfficientStreamingTransformer.newTransformer();
|
||||
StreamResult result = new StreamResult(os);
|
||||
if (obj instanceof DataSource) {
|
||||
// Streaming transform applies only to javax.xml.transform.StreamSource
|
||||
transformer.transform((Source) getContent((DataSource)obj), result);
|
||||
} else {
|
||||
Source src=null;
|
||||
if (obj instanceof String) {
|
||||
src= new StreamSource(new java.io.StringReader((String) obj));
|
||||
} else {
|
||||
src=(Source) obj;
|
||||
}
|
||||
transformer.transform(src, result);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new IOException(
|
||||
"Unable to run the JAXP transformer on a stream "
|
||||
+ ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author SAAJ RI Development Team
|
||||
*/
|
||||
package com.sun.xml.internal.messaging.saaj.soap.dynamic;
|
||||
|
||||
import javax.xml.soap.Detail;
|
||||
import javax.xml.soap.SOAPException;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPFactoryImpl;
|
||||
|
||||
public class SOAPFactoryDynamicImpl extends SOAPFactoryImpl {
|
||||
protected SOAPDocumentImpl createDocument() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Detail createDetail() throws SOAPException {
|
||||
throw new UnsupportedOperationException(
|
||||
"createDetail() not supported for Dynamic Protocol");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author SAAJ RI Development Team
|
||||
*/
|
||||
package com.sun.xml.internal.messaging.saaj.soap.dynamic;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.xml.soap.*;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.MessageFactoryImpl;
|
||||
|
||||
public class SOAPMessageFactoryDynamicImpl extends MessageFactoryImpl {
|
||||
public SOAPMessage createMessage() throws SOAPException {
|
||||
throw new UnsupportedOperationException(
|
||||
"createMessage() not supported for Dynamic Protocol");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.soap.impl;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.*;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
|
||||
/**
|
||||
* All elements of the SOAP-ENV:BODY.
|
||||
*
|
||||
* @author Anil Vijendran (akv@eng.sun.com)
|
||||
*/
|
||||
public abstract class BodyElementImpl
|
||||
extends ElementImpl
|
||||
implements SOAPBodyElement {
|
||||
|
||||
public BodyElementImpl(SOAPDocumentImpl ownerDoc, Name qname) {
|
||||
super(ownerDoc, qname);
|
||||
}
|
||||
|
||||
public BodyElementImpl(SOAPDocumentImpl ownerDoc, QName qname) {
|
||||
super(ownerDoc, qname);
|
||||
}
|
||||
|
||||
public void setParentElement(SOAPElement element) throws SOAPException {
|
||||
if (! (element instanceof SOAPBody)) {
|
||||
log.severe("SAAJ0101.impl.parent.of.body.elem.mustbe.body");
|
||||
throw new SOAPException("Parent of a SOAPBodyElement has to be a SOAPBody");
|
||||
}
|
||||
super.setParentElement(element);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,325 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.soap.impl;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.*;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.w3c.dom.*;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocument;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
|
||||
|
||||
/**
|
||||
* The implementation of SOAP-ENV:BODY or the SOAPBody abstraction.
|
||||
*
|
||||
* @author Anil Vijendran (anil@sun.com)
|
||||
*/
|
||||
public abstract class BodyImpl extends ElementImpl implements SOAPBody {
|
||||
private SOAPFault fault;
|
||||
|
||||
protected BodyImpl(SOAPDocumentImpl ownerDoc, NameImpl bodyName) {
|
||||
super(ownerDoc, bodyName);
|
||||
}
|
||||
|
||||
protected abstract NameImpl getFaultName(String name);
|
||||
protected abstract boolean isFault(SOAPElement child);
|
||||
protected abstract SOAPBodyElement createBodyElement(Name name);
|
||||
protected abstract SOAPBodyElement createBodyElement(QName name);
|
||||
protected abstract SOAPFault createFaultElement();
|
||||
protected abstract QName getDefaultFaultCode();
|
||||
|
||||
public SOAPFault addFault() throws SOAPException {
|
||||
if (hasFault()) {
|
||||
log.severe("SAAJ0110.impl.fault.already.exists");
|
||||
throw new SOAPExceptionImpl("Error: Fault already exists");
|
||||
}
|
||||
|
||||
fault = createFaultElement();
|
||||
|
||||
addNode(fault);
|
||||
|
||||
fault.setFaultCode(getDefaultFaultCode());
|
||||
fault.setFaultString("Fault string, and possibly fault code, not set");
|
||||
|
||||
return fault;
|
||||
}
|
||||
|
||||
public SOAPFault addFault(
|
||||
Name faultCode,
|
||||
String faultString,
|
||||
Locale locale)
|
||||
throws SOAPException {
|
||||
|
||||
SOAPFault fault = addFault();
|
||||
fault.setFaultCode(faultCode);
|
||||
fault.setFaultString(faultString, locale);
|
||||
return fault;
|
||||
}
|
||||
|
||||
public SOAPFault addFault(
|
||||
QName faultCode,
|
||||
String faultString,
|
||||
Locale locale)
|
||||
throws SOAPException {
|
||||
|
||||
SOAPFault fault = addFault();
|
||||
fault.setFaultCode(faultCode);
|
||||
fault.setFaultString(faultString, locale);
|
||||
return fault;
|
||||
}
|
||||
|
||||
public SOAPFault addFault(Name faultCode, String faultString)
|
||||
throws SOAPException {
|
||||
|
||||
SOAPFault fault = addFault();
|
||||
fault.setFaultCode(faultCode);
|
||||
fault.setFaultString(faultString);
|
||||
return fault;
|
||||
}
|
||||
|
||||
public SOAPFault addFault(QName faultCode, String faultString)
|
||||
throws SOAPException {
|
||||
|
||||
SOAPFault fault = addFault();
|
||||
fault.setFaultCode(faultCode);
|
||||
fault.setFaultString(faultString);
|
||||
return fault;
|
||||
}
|
||||
|
||||
void initializeFault() {
|
||||
FaultImpl flt = (FaultImpl) findFault();
|
||||
fault = flt;
|
||||
}
|
||||
|
||||
protected SOAPElement findFault() {
|
||||
Iterator eachChild = getChildElementNodes();
|
||||
while (eachChild.hasNext()) {
|
||||
SOAPElement child = (SOAPElement) eachChild.next();
|
||||
if (isFault(child)) {
|
||||
return child;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean hasFault() {
|
||||
initializeFault();
|
||||
return fault != null;
|
||||
}
|
||||
|
||||
public SOAPFault getFault() {
|
||||
if (hasFault())
|
||||
return fault;
|
||||
return null;
|
||||
}
|
||||
|
||||
public SOAPBodyElement addBodyElement(Name name) throws SOAPException {
|
||||
SOAPBodyElement newBodyElement =
|
||||
(SOAPBodyElement) ElementFactory.createNamedElement(
|
||||
((SOAPDocument) getOwnerDocument()).getDocument(),
|
||||
name.getLocalName(),
|
||||
name.getPrefix(),
|
||||
name.getURI());
|
||||
if (newBodyElement == null) {
|
||||
newBodyElement = createBodyElement(name);
|
||||
}
|
||||
addNode(newBodyElement);
|
||||
return newBodyElement;
|
||||
}
|
||||
|
||||
public SOAPBodyElement addBodyElement(QName qname) throws SOAPException {
|
||||
SOAPBodyElement newBodyElement =
|
||||
(SOAPBodyElement) ElementFactory.createNamedElement(
|
||||
((SOAPDocument) getOwnerDocument()).getDocument(),
|
||||
qname.getLocalPart(),
|
||||
qname.getPrefix(),
|
||||
qname.getNamespaceURI());
|
||||
if (newBodyElement == null) {
|
||||
newBodyElement = createBodyElement(qname);
|
||||
}
|
||||
addNode(newBodyElement);
|
||||
return newBodyElement;
|
||||
}
|
||||
|
||||
public void setParentElement(SOAPElement element) throws SOAPException {
|
||||
|
||||
if (!(element instanceof SOAPEnvelope)) {
|
||||
log.severe("SAAJ0111.impl.body.parent.must.be.envelope");
|
||||
throw new SOAPException("Parent of SOAPBody has to be a SOAPEnvelope");
|
||||
}
|
||||
super.setParentElement(element);
|
||||
}
|
||||
|
||||
protected SOAPElement addElement(Name name) throws SOAPException {
|
||||
return addBodyElement(name);
|
||||
}
|
||||
|
||||
protected SOAPElement addElement(QName name) throws SOAPException {
|
||||
return addBodyElement(name);
|
||||
}
|
||||
|
||||
// public Node insertBefore(Node newElement, Node ref) throws DOMException {
|
||||
// if (!(newElement instanceof SOAPBodyElement) && (newElement instanceof SOAPElement)) {
|
||||
// newElement = new ElementWrapper((ElementImpl) newElement);
|
||||
// }
|
||||
// return super.insertBefore(newElement, ref);
|
||||
// }
|
||||
//
|
||||
// public Node replaceChild(Node newElement, Node ref) throws DOMException {
|
||||
// if (!(newElement instanceof SOAPBodyElement) && (newElement instanceof SOAPElement)) {
|
||||
// newElement = new ElementWrapper((ElementImpl) newElement);
|
||||
// }
|
||||
// return super.replaceChild(newElement, ref);
|
||||
// }
|
||||
|
||||
public SOAPBodyElement addDocument(Document document)
|
||||
throws SOAPException {
|
||||
/*
|
||||
|
||||
Element rootNode =
|
||||
document.getDocumentElement();
|
||||
// Causes all deferred nodes to be inflated
|
||||
rootNode.normalize();
|
||||
adoptElement(rootNode);
|
||||
SOAPBodyElement bodyElement = (SOAPBodyElement) convertToSoapElement(rootNode);
|
||||
addNode(bodyElement);
|
||||
return bodyElement;
|
||||
*/
|
||||
///*
|
||||
SOAPBodyElement newBodyElement = null;
|
||||
DocumentFragment docFrag = document.createDocumentFragment();
|
||||
Element rootElement = document.getDocumentElement();
|
||||
if(rootElement != null) {
|
||||
docFrag.appendChild(rootElement);
|
||||
|
||||
Document ownerDoc = getOwnerDocument();
|
||||
// This copies the whole tree which could be very big so it's slow.
|
||||
// However, it does have the advantage of actually working.
|
||||
org.w3c.dom.Node replacingNode = ownerDoc.importNode(docFrag, true);
|
||||
// Adding replacingNode at the last of the children list of body
|
||||
addNode(replacingNode);
|
||||
Iterator i =
|
||||
getChildElements(NameImpl.copyElementName(rootElement));
|
||||
// Return the child element with the required name which is at the
|
||||
// end of the list
|
||||
while(i.hasNext())
|
||||
newBodyElement = (SOAPBodyElement) i.next();
|
||||
}
|
||||
return newBodyElement;
|
||||
//*/
|
||||
}
|
||||
|
||||
protected SOAPElement convertToSoapElement(Element element) {
|
||||
if ((element instanceof SOAPBodyElement) &&
|
||||
//this check is required because ElementImpl currently
|
||||
// implements SOAPBodyElement
|
||||
!(element.getClass().equals(ElementImpl.class))) {
|
||||
return (SOAPElement) element;
|
||||
} else {
|
||||
return replaceElementWithSOAPElement(
|
||||
element,
|
||||
(ElementImpl) createBodyElement(NameImpl
|
||||
.copyElementName(element)));
|
||||
}
|
||||
}
|
||||
|
||||
public SOAPElement setElementQName(QName newName) throws SOAPException {
|
||||
log.log(Level.SEVERE,
|
||||
"SAAJ0146.impl.invalid.name.change.requested",
|
||||
new Object[] {elementQName.getLocalPart(),
|
||||
newName.getLocalPart()});
|
||||
throw new SOAPException("Cannot change name for "
|
||||
+ elementQName.getLocalPart() + " to "
|
||||
+ newName.getLocalPart());
|
||||
}
|
||||
|
||||
public Document extractContentAsDocument() throws SOAPException {
|
||||
|
||||
Iterator eachChild = getChildElements();
|
||||
javax.xml.soap.Node firstBodyElement = null;
|
||||
|
||||
while (eachChild.hasNext() &&
|
||||
!(firstBodyElement instanceof SOAPElement))
|
||||
firstBodyElement = (javax.xml.soap.Node) eachChild.next();
|
||||
|
||||
boolean exactlyOneChildElement = true;
|
||||
if (firstBodyElement == null)
|
||||
exactlyOneChildElement = false;
|
||||
else {
|
||||
for (org.w3c.dom.Node node = firstBodyElement.getNextSibling();
|
||||
node != null;
|
||||
node = node.getNextSibling()) {
|
||||
|
||||
if (node instanceof Element) {
|
||||
exactlyOneChildElement = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!exactlyOneChildElement) {
|
||||
log.log(Level.SEVERE,
|
||||
"SAAJ0250.impl.body.should.have.exactly.one.child");
|
||||
throw new SOAPException("Cannot extract Document from body");
|
||||
}
|
||||
|
||||
Document document = null;
|
||||
try {
|
||||
DocumentBuilderFactory factory =
|
||||
new com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl();
|
||||
factory.setNamespaceAware(true);
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
document = builder.newDocument();
|
||||
|
||||
Element rootElement = (Element) document.importNode(
|
||||
firstBodyElement,
|
||||
true);
|
||||
|
||||
document.appendChild(rootElement);
|
||||
|
||||
} catch(Exception e) {
|
||||
log.log(Level.SEVERE,
|
||||
"SAAJ0251.impl.cannot.extract.document.from.body");
|
||||
throw new SOAPExceptionImpl(
|
||||
"Unable to extract Document from body", e);
|
||||
}
|
||||
|
||||
firstBodyElement.detachNode();
|
||||
|
||||
return document;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.soap.impl;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.xml.soap.SOAPElement;
|
||||
import javax.xml.soap.SOAPException;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants;
|
||||
|
||||
public class CDATAImpl
|
||||
extends com.sun.org.apache.xerces.internal.dom.CDATASectionImpl
|
||||
implements javax.xml.soap.Text {
|
||||
|
||||
protected static final Logger log =
|
||||
Logger.getLogger(LogDomainConstants.SOAP_IMPL_DOMAIN,
|
||||
"com.sun.xml.internal.messaging.saaj.soap.impl.LocalStrings");
|
||||
|
||||
static final String cdataUC = "<![CDATA[";
|
||||
static final String cdataLC = "<![cdata[";
|
||||
|
||||
public CDATAImpl(SOAPDocumentImpl ownerDoc, String text) {
|
||||
super(ownerDoc, text);
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
String nodeValue = getNodeValue();
|
||||
return (nodeValue.equals("") ? null : nodeValue);
|
||||
}
|
||||
|
||||
public void setValue(String text) {
|
||||
setNodeValue(text);
|
||||
}
|
||||
|
||||
public void setParentElement(SOAPElement parent) throws SOAPException {
|
||||
if (parent == null) {
|
||||
log.severe("SAAJ0145.impl.no.null.to.parent.elem");
|
||||
throw new SOAPException("Cannot pass NULL to setParentElement");
|
||||
}
|
||||
((ElementImpl) parent).addNode(this);
|
||||
}
|
||||
|
||||
public SOAPElement getParentElement() {
|
||||
return (SOAPElement) getParentNode();
|
||||
}
|
||||
|
||||
|
||||
public void detachNode() {
|
||||
org.w3c.dom.Node parent = getParentNode();
|
||||
if (parent != null) {
|
||||
parent.removeChild(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void recycleNode() {
|
||||
detachNode();
|
||||
// TBD
|
||||
// - add this to the factory so subsequent
|
||||
// creations can reuse this object.
|
||||
}
|
||||
|
||||
public boolean isComment() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.soap.impl;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.xml.soap.SOAPElement;
|
||||
import javax.xml.soap.SOAPException;
|
||||
|
||||
import org.w3c.dom.DOMException;
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants;
|
||||
|
||||
public class CommentImpl
|
||||
extends com.sun.org.apache.xerces.internal.dom.CommentImpl
|
||||
implements javax.xml.soap.Text, org.w3c.dom.Comment {
|
||||
|
||||
protected static final Logger log =
|
||||
Logger.getLogger(LogDomainConstants.SOAP_IMPL_DOMAIN,
|
||||
"com.sun.xml.internal.messaging.saaj.soap.impl.LocalStrings");
|
||||
protected static ResourceBundle rb =
|
||||
log.getResourceBundle();
|
||||
|
||||
public CommentImpl(SOAPDocumentImpl ownerDoc, String text) {
|
||||
super(ownerDoc, text);
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
String nodeValue = getNodeValue();
|
||||
return (nodeValue.equals("") ? null : nodeValue);
|
||||
}
|
||||
|
||||
public void setValue(String text) {
|
||||
setNodeValue(text);
|
||||
}
|
||||
|
||||
|
||||
public void setParentElement(SOAPElement element) throws SOAPException {
|
||||
if (element == null) {
|
||||
log.severe("SAAJ0112.impl.no.null.to.parent.elem");
|
||||
throw new SOAPException("Cannot pass NULL to setParentElement");
|
||||
}
|
||||
((ElementImpl) element).addNode(this);
|
||||
}
|
||||
|
||||
public SOAPElement getParentElement() {
|
||||
return (SOAPElement) getParentNode();
|
||||
}
|
||||
|
||||
public void detachNode() {
|
||||
org.w3c.dom.Node parent = getParentNode();
|
||||
if (parent != null) {
|
||||
parent.removeChild(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void recycleNode() {
|
||||
detachNode();
|
||||
// TBD
|
||||
// - add this to the factory so subsequent
|
||||
// creations can reuse this object.
|
||||
}
|
||||
|
||||
public boolean isComment() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Text splitText(int offset) throws DOMException {
|
||||
log.severe("SAAJ0113.impl.cannot.split.text.from.comment");
|
||||
throw new UnsupportedOperationException("Cannot split text from a Comment Node.");
|
||||
}
|
||||
|
||||
public Text replaceWholeText(String content) throws DOMException {
|
||||
log.severe("SAAJ0114.impl.cannot.replace.wholetext.from.comment");
|
||||
throw new UnsupportedOperationException("Cannot replace Whole Text from a Comment Node.");
|
||||
}
|
||||
|
||||
public String getWholeText() {
|
||||
//TODO: maybe we have to implement this in future.
|
||||
throw new UnsupportedOperationException("Not Supported");
|
||||
}
|
||||
|
||||
public boolean isElementContentWhitespace() {
|
||||
//TODO: maybe we have to implement this in future.
|
||||
throw new UnsupportedOperationException("Not Supported");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.soap.impl;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.DetailEntry;
|
||||
import javax.xml.soap.Name;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
|
||||
public abstract class DetailEntryImpl
|
||||
extends ElementImpl
|
||||
implements DetailEntry {
|
||||
public DetailEntryImpl(SOAPDocumentImpl ownerDoc, Name qname) {
|
||||
super(ownerDoc, qname);
|
||||
}
|
||||
public DetailEntryImpl(SOAPDocumentImpl ownerDoc, QName qname) {
|
||||
super(ownerDoc, qname);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2017, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.soap.impl;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.*;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
|
||||
|
||||
public abstract class DetailImpl extends FaultElementImpl implements Detail {
|
||||
public DetailImpl(SOAPDocumentImpl ownerDoc, NameImpl detailName) {
|
||||
super(ownerDoc, detailName);
|
||||
}
|
||||
|
||||
protected abstract DetailEntry createDetailEntry(Name name);
|
||||
protected abstract DetailEntry createDetailEntry(QName name);
|
||||
|
||||
public DetailEntry addDetailEntry(Name name) throws SOAPException {
|
||||
DetailEntry entry = createDetailEntry(name);
|
||||
addNode(entry);
|
||||
return entry;
|
||||
}
|
||||
|
||||
public DetailEntry addDetailEntry(QName qname) throws SOAPException {
|
||||
DetailEntry entry = createDetailEntry(qname);
|
||||
addNode(entry);
|
||||
return entry;
|
||||
}
|
||||
|
||||
protected SOAPElement addElement(Name name) throws SOAPException {
|
||||
return addDetailEntry(name);
|
||||
}
|
||||
|
||||
protected SOAPElement addElement(QName name) throws SOAPException {
|
||||
return addDetailEntry(name);
|
||||
}
|
||||
|
||||
protected SOAPElement convertToSoapElement(Element element) {
|
||||
if (element instanceof DetailEntry) {
|
||||
return (SOAPElement) element;
|
||||
} else {
|
||||
DetailEntry detailEntry =
|
||||
createDetailEntry(NameImpl.copyElementName(element));
|
||||
return replaceElementWithSOAPElement(
|
||||
element,
|
||||
(ElementImpl) detailEntry);
|
||||
}
|
||||
}
|
||||
|
||||
public Iterator getDetailEntries() {
|
||||
return new Iterator() {
|
||||
Iterator eachNode = getChildElementNodes();
|
||||
SOAPElement next = null;
|
||||
SOAPElement last = null;
|
||||
|
||||
public boolean hasNext() {
|
||||
if (next == null) {
|
||||
while (eachNode.hasNext()) {
|
||||
next = (SOAPElement) eachNode.next();
|
||||
if (next instanceof DetailEntry) {
|
||||
break;
|
||||
}
|
||||
next = null;
|
||||
}
|
||||
}
|
||||
return next != null;
|
||||
}
|
||||
|
||||
public Object next() {
|
||||
if (!hasNext()) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
last = next;
|
||||
next = null;
|
||||
return last;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
if (last == null) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
SOAPElement target = last;
|
||||
removeChild(target);
|
||||
last = null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected boolean isStandardFaultElement() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.soap.impl;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.*;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.ver1_1.*;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.ver1_2.*;
|
||||
|
||||
|
||||
public class ElementFactory {
|
||||
public static SOAPElement createElement(
|
||||
SOAPDocumentImpl ownerDocument,
|
||||
Name name) {
|
||||
return createElement(
|
||||
ownerDocument,
|
||||
name.getLocalName(),
|
||||
name.getPrefix(),
|
||||
name.getURI());
|
||||
}
|
||||
public static SOAPElement createElement(
|
||||
SOAPDocumentImpl ownerDocument,
|
||||
QName name) {
|
||||
return createElement(
|
||||
ownerDocument,
|
||||
name.getLocalPart(),
|
||||
name.getPrefix(),
|
||||
name.getNamespaceURI());
|
||||
}
|
||||
|
||||
public static SOAPElement createElement(
|
||||
SOAPDocumentImpl ownerDocument,
|
||||
String localName,
|
||||
String prefix,
|
||||
String namespaceUri) {
|
||||
|
||||
|
||||
if (ownerDocument == null) {
|
||||
if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) {
|
||||
ownerDocument = new SOAPPart1_1Impl().getDocument();
|
||||
} else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) {
|
||||
ownerDocument = new SOAPPart1_2Impl().getDocument();
|
||||
} else {
|
||||
ownerDocument = new SOAPDocumentImpl(null);
|
||||
}
|
||||
}
|
||||
|
||||
SOAPElement newElement =
|
||||
createNamedElement(ownerDocument, localName, prefix, namespaceUri);
|
||||
|
||||
return newElement != null
|
||||
? newElement
|
||||
: new ElementImpl(
|
||||
ownerDocument,
|
||||
namespaceUri,
|
||||
NameImpl.createQName(prefix, localName));
|
||||
}
|
||||
|
||||
public static SOAPElement createNamedElement(
|
||||
SOAPDocumentImpl ownerDocument,
|
||||
String localName,
|
||||
String prefix,
|
||||
String namespaceUri) {
|
||||
|
||||
if (prefix == null) {
|
||||
prefix = NameImpl.SOAP_ENVELOPE_PREFIX;
|
||||
}
|
||||
|
||||
if (localName.equalsIgnoreCase("Envelope")) {
|
||||
if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) {
|
||||
return new Envelope1_1Impl(ownerDocument, prefix);
|
||||
} else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) {
|
||||
return new Envelope1_2Impl(ownerDocument, prefix);
|
||||
}
|
||||
}
|
||||
if (localName.equalsIgnoreCase("Body")) {
|
||||
if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) {
|
||||
return new Body1_1Impl(ownerDocument, prefix);
|
||||
} else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) {
|
||||
return new Body1_2Impl(ownerDocument, prefix);
|
||||
}
|
||||
}
|
||||
if (localName.equalsIgnoreCase("Header")) {
|
||||
if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) {
|
||||
return new Header1_1Impl(ownerDocument, prefix);
|
||||
} else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) {
|
||||
return new Header1_2Impl(ownerDocument, prefix);
|
||||
}
|
||||
}
|
||||
if (localName.equalsIgnoreCase("Fault")) {
|
||||
SOAPFault fault = null;
|
||||
if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) {
|
||||
fault = new Fault1_1Impl(ownerDocument, prefix);
|
||||
} else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) {
|
||||
fault = new Fault1_2Impl(ownerDocument, prefix);
|
||||
}
|
||||
|
||||
if (fault != null) {
|
||||
// try {
|
||||
// fault.addNamespaceDeclaration(
|
||||
// NameImpl.SOAP_ENVELOPE_PREFIX,
|
||||
// SOAPConstants.URI_NS_SOAP_ENVELOPE);
|
||||
// fault.setFaultCode(
|
||||
// NameImpl.create(
|
||||
// "Server",
|
||||
// NameImpl.SOAP_ENVELOPE_PREFIX,
|
||||
// SOAPConstants.URI_NS_SOAP_ENVELOPE));
|
||||
// fault.setFaultString(
|
||||
// "Fault string, and possibly fault code, not set");
|
||||
// } catch (SOAPException e) {
|
||||
// }
|
||||
return fault;
|
||||
}
|
||||
|
||||
}
|
||||
if (localName.equalsIgnoreCase("Detail")) {
|
||||
if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) {
|
||||
return new Detail1_1Impl(ownerDocument, prefix);
|
||||
} else if (NameImpl.SOAP12_NAMESPACE.equals(namespaceUri)) {
|
||||
return new Detail1_2Impl(ownerDocument, prefix);
|
||||
}
|
||||
}
|
||||
if (localName.equalsIgnoreCase("faultcode")
|
||||
|| localName.equalsIgnoreCase("faultstring")
|
||||
|| localName.equalsIgnoreCase("faultactor")) {
|
||||
// SOAP 1.2 does not have fault(code/string/actor)
|
||||
// So there is no else case required
|
||||
if (NameImpl.SOAP11_NAMESPACE.equals(namespaceUri)) {
|
||||
return new FaultElement1_1Impl(ownerDocument,
|
||||
localName,
|
||||
prefix);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static void invalidCreate(String msg) {
|
||||
throw new TreeException(msg);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,360 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.soap.impl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.logging.Level;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.*;
|
||||
import javax.xml.transform.*;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.sax.*;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.Envelope;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.util.FastInfosetReflection;
|
||||
import com.sun.xml.internal.messaging.saaj.util.transform.EfficientStreamingTransformer;
|
||||
|
||||
/**
|
||||
* Our implementation of the SOAP envelope.
|
||||
*
|
||||
* @author Anil Vijendran (anil@sun.com)
|
||||
*/
|
||||
public abstract class EnvelopeImpl extends ElementImpl implements Envelope {
|
||||
protected HeaderImpl header;
|
||||
protected BodyImpl body;
|
||||
String omitXmlDecl = "yes";
|
||||
String charset = "utf-8";
|
||||
String xmlDecl = null;
|
||||
|
||||
protected EnvelopeImpl(SOAPDocumentImpl ownerDoc, Name name) {
|
||||
super(ownerDoc, name);
|
||||
}
|
||||
|
||||
protected EnvelopeImpl(SOAPDocumentImpl ownerDoc, QName name) {
|
||||
super(ownerDoc, name);
|
||||
}
|
||||
|
||||
protected EnvelopeImpl(
|
||||
SOAPDocumentImpl ownerDoc,
|
||||
NameImpl name,
|
||||
boolean createHeader,
|
||||
boolean createBody)
|
||||
throws SOAPException {
|
||||
this(ownerDoc, name);
|
||||
|
||||
ensureNamespaceIsDeclared(
|
||||
getElementQName().getPrefix(), getElementQName().getNamespaceURI());
|
||||
|
||||
// XXX
|
||||
if (createHeader)
|
||||
addHeader();
|
||||
|
||||
if (createBody)
|
||||
addBody();
|
||||
}
|
||||
|
||||
protected abstract NameImpl getHeaderName(String prefix);
|
||||
protected abstract NameImpl getBodyName(String prefix);
|
||||
|
||||
public SOAPHeader addHeader() throws SOAPException {
|
||||
return addHeader(null);
|
||||
}
|
||||
|
||||
public SOAPHeader addHeader(String prefix) throws SOAPException {
|
||||
|
||||
if (prefix == null || prefix.equals("")) {
|
||||
prefix = getPrefix();
|
||||
}
|
||||
|
||||
NameImpl headerName = getHeaderName(prefix);
|
||||
NameImpl bodyName = getBodyName(prefix);
|
||||
|
||||
HeaderImpl header = null;
|
||||
SOAPElement firstChild = null;
|
||||
|
||||
Iterator eachChild = getChildElementNodes();
|
||||
if (eachChild.hasNext()) {
|
||||
firstChild = (SOAPElement) eachChild.next();
|
||||
if (firstChild.getElementName().equals(headerName)) {
|
||||
log.severe("SAAJ0120.impl.header.already.exists");
|
||||
throw new SOAPExceptionImpl("Can't add a header when one is already present.");
|
||||
} else if (!firstChild.getElementName().equals(bodyName)) {
|
||||
log.severe("SAAJ0121.impl.invalid.first.child.of.envelope");
|
||||
throw new SOAPExceptionImpl("First child of Envelope must be either a Header or Body");
|
||||
}
|
||||
}
|
||||
|
||||
header = (HeaderImpl) createElement(headerName);
|
||||
insertBefore(header, firstChild);
|
||||
header.ensureNamespaceIsDeclared(headerName.getPrefix(), headerName.getURI());
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
protected void lookForHeader() throws SOAPException {
|
||||
NameImpl headerName = getHeaderName(null);
|
||||
|
||||
HeaderImpl hdr = (HeaderImpl) findChild(headerName);
|
||||
header = hdr;
|
||||
}
|
||||
|
||||
public SOAPHeader getHeader() throws SOAPException {
|
||||
lookForHeader();
|
||||
return header;
|
||||
}
|
||||
|
||||
protected void lookForBody() throws SOAPException {
|
||||
NameImpl bodyName = getBodyName(null);
|
||||
|
||||
BodyImpl bodyChildElement = (BodyImpl) findChild(bodyName);
|
||||
body = bodyChildElement;
|
||||
}
|
||||
|
||||
public SOAPBody addBody() throws SOAPException {
|
||||
return addBody(null);
|
||||
}
|
||||
|
||||
public SOAPBody addBody(String prefix) throws SOAPException {
|
||||
lookForBody();
|
||||
|
||||
if (prefix == null || prefix.equals("")) {
|
||||
prefix = getPrefix();
|
||||
}
|
||||
|
||||
if (body == null) {
|
||||
NameImpl bodyName = getBodyName(prefix);
|
||||
body = (BodyImpl) createElement(bodyName);
|
||||
insertBefore(body, null);
|
||||
body.ensureNamespaceIsDeclared(bodyName.getPrefix(), bodyName.getURI());
|
||||
} else {
|
||||
log.severe("SAAJ0122.impl.body.already.exists");
|
||||
throw new SOAPExceptionImpl("Can't add a body when one is already present.");
|
||||
}
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
protected SOAPElement addElement(Name name) throws SOAPException {
|
||||
if (getBodyName(null).equals(name)) {
|
||||
return addBody(name.getPrefix());
|
||||
}
|
||||
if (getHeaderName(null).equals(name)) {
|
||||
return addHeader(name.getPrefix());
|
||||
}
|
||||
|
||||
return super.addElement(name);
|
||||
}
|
||||
|
||||
protected SOAPElement addElement(QName name) throws SOAPException {
|
||||
if (getBodyName(null).equals(NameImpl.convertToName(name))) {
|
||||
return addBody(name.getPrefix());
|
||||
}
|
||||
if (getHeaderName(null).equals(NameImpl.convertToName(name))) {
|
||||
return addHeader(name.getPrefix());
|
||||
}
|
||||
|
||||
return super.addElement(name);
|
||||
}
|
||||
|
||||
public SOAPBody getBody() throws SOAPException {
|
||||
lookForBody();
|
||||
return body;
|
||||
}
|
||||
|
||||
public Source getContent() {
|
||||
return new DOMSource(getOwnerDocument());
|
||||
}
|
||||
|
||||
public Name createName(String localName, String prefix, String uri)
|
||||
throws SOAPException {
|
||||
|
||||
// validating parameters before passing them on
|
||||
// to make sure that the namespace specification rules are followed
|
||||
|
||||
// reserved xmlns prefix cannot be used.
|
||||
if ("xmlns".equals(prefix)) {
|
||||
log.severe("SAAJ0123.impl.no.reserved.xmlns");
|
||||
throw new SOAPExceptionImpl("Cannot declare reserved xmlns prefix");
|
||||
}
|
||||
// Qualified name cannot be xmlns.
|
||||
if ((prefix == null) && ("xmlns".equals(localName))) {
|
||||
log.severe("SAAJ0124.impl.qualified.name.cannot.be.xmlns");
|
||||
throw new SOAPExceptionImpl("Qualified name cannot be xmlns");
|
||||
}
|
||||
|
||||
return NameImpl.create(localName, prefix, uri);
|
||||
}
|
||||
|
||||
public Name createName(String localName, String prefix)
|
||||
throws SOAPException {
|
||||
String namespace = getNamespaceURI(prefix);
|
||||
if (namespace == null) {
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0126.impl.cannot.locate.ns",
|
||||
new String[] { prefix });
|
||||
throw new SOAPExceptionImpl(
|
||||
"Unable to locate namespace for prefix " + prefix);
|
||||
}
|
||||
return NameImpl.create(localName, prefix, namespace);
|
||||
}
|
||||
|
||||
public Name createName(String localName) throws SOAPException {
|
||||
return NameImpl.createFromUnqualifiedName(localName);
|
||||
}
|
||||
|
||||
public void setOmitXmlDecl(String value) {
|
||||
this.omitXmlDecl = value;
|
||||
}
|
||||
|
||||
public void setXmlDecl(String value) {
|
||||
this.xmlDecl = value;
|
||||
}
|
||||
|
||||
private String getOmitXmlDecl() {
|
||||
return this.omitXmlDecl;
|
||||
}
|
||||
|
||||
public void setCharsetEncoding(String value) {
|
||||
charset = value;
|
||||
}
|
||||
|
||||
public void output(OutputStream out) throws IOException {
|
||||
try {
|
||||
Transformer transformer =
|
||||
EfficientStreamingTransformer.newTransformer();
|
||||
|
||||
transformer.setOutputProperty(
|
||||
OutputKeys.OMIT_XML_DECLARATION, "yes");
|
||||
/*omitXmlDecl);*/
|
||||
// no equivalent for "setExpandEmptyElements"
|
||||
transformer.setOutputProperty(
|
||||
OutputKeys.ENCODING,
|
||||
charset);
|
||||
|
||||
if (omitXmlDecl.equals("no") && xmlDecl == null) {
|
||||
xmlDecl = "<?xml version=\"" + getOwnerDocument().getXmlVersion() + "\" encoding=\"" +
|
||||
charset + "\" ?>";
|
||||
}
|
||||
|
||||
StreamResult result = new StreamResult(out);
|
||||
if (xmlDecl != null) {
|
||||
OutputStreamWriter writer = new OutputStreamWriter(out, charset);
|
||||
writer.write(xmlDecl);
|
||||
writer.flush();
|
||||
result = new StreamResult(writer);
|
||||
}
|
||||
|
||||
if (log.isLoggable(Level.FINE)) {
|
||||
log.log(Level.FINE, "SAAJ0190.impl.set.xml.declaration",
|
||||
new String[] { omitXmlDecl });
|
||||
log.log(Level.FINE, "SAAJ0191.impl.set.encoding",
|
||||
new String[] { charset });
|
||||
}
|
||||
|
||||
//StreamResult result = new StreamResult(out);
|
||||
transformer.transform(getContent(), result);
|
||||
} catch (Exception ex) {
|
||||
throw new IOException(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize to FI if boolean parameter set.
|
||||
*/
|
||||
public void output(OutputStream out, boolean isFastInfoset)
|
||||
throws IOException
|
||||
{
|
||||
if (!isFastInfoset) {
|
||||
output(out);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
// Run transform and generate FI output from content
|
||||
Source source = getContent();
|
||||
Transformer transformer = EfficientStreamingTransformer.newTransformer();
|
||||
transformer.transform(getContent(),
|
||||
FastInfosetReflection.FastInfosetResult_new(out));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IOException(ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// public void prettyPrint(OutputStream out) throws IOException {
|
||||
// if (getDocument() == null)
|
||||
// initDocument();
|
||||
//
|
||||
// OutputFormat format = OutputFormat.createPrettyPrint();
|
||||
//
|
||||
// format.setIndentSize(2);
|
||||
// format.setNewlines(true);
|
||||
// format.setTrimText(true);
|
||||
// format.setPadText(true);
|
||||
// format.setExpandEmptyElements(false);
|
||||
//
|
||||
// XMLWriter writer = new XMLWriter(out, format);
|
||||
// writer.write(getDocument());
|
||||
// }
|
||||
//
|
||||
// public void prettyPrint(Writer out) throws IOException {
|
||||
// if (getDocument() == null)
|
||||
// initDocument();
|
||||
//
|
||||
// OutputFormat format = OutputFormat.createPrettyPrint();
|
||||
//
|
||||
// format.setIndentSize(2);
|
||||
// format.setNewlines(true);
|
||||
// format.setTrimText(true);
|
||||
// format.setPadText(true);
|
||||
// format.setExpandEmptyElements(false);
|
||||
//
|
||||
// XMLWriter writer = new XMLWriter(out, format);
|
||||
// writer.write(getDocument());
|
||||
// }
|
||||
|
||||
|
||||
public SOAPElement setElementQName(QName newName) throws SOAPException {
|
||||
log.log(Level.SEVERE,
|
||||
"SAAJ0146.impl.invalid.name.change.requested",
|
||||
new Object[] {elementQName.getLocalPart(),
|
||||
newName.getLocalPart()});
|
||||
throw new SOAPException("Cannot change name for "
|
||||
+ elementQName.getLocalPart() + " to "
|
||||
+ newName.getLocalPart());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.soap.impl;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.SOAPException;
|
||||
import javax.xml.soap.SOAPElement;
|
||||
import javax.xml.soap.SOAPFaultElement;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
|
||||
|
||||
public abstract class FaultElementImpl
|
||||
extends ElementImpl
|
||||
implements SOAPFaultElement {
|
||||
|
||||
protected FaultElementImpl(SOAPDocumentImpl ownerDoc, NameImpl qname) {
|
||||
super(ownerDoc, qname);
|
||||
}
|
||||
|
||||
protected FaultElementImpl(SOAPDocumentImpl ownerDoc, QName qname) {
|
||||
super(ownerDoc, qname);
|
||||
}
|
||||
|
||||
protected abstract boolean isStandardFaultElement();
|
||||
|
||||
public SOAPElement setElementQName(QName newName) throws SOAPException {
|
||||
log.log(Level.SEVERE,
|
||||
"SAAJ0146.impl.invalid.name.change.requested",
|
||||
new Object[] {elementQName.getLocalPart(),
|
||||
newName.getLocalPart()});
|
||||
throw new SOAPException("Cannot change name for "
|
||||
+ elementQName.getLocalPart() + " to "
|
||||
+ newName.getLocalPart());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,346 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.soap.impl;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.*;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
|
||||
|
||||
public abstract class FaultImpl extends ElementImpl implements SOAPFault {
|
||||
|
||||
/* This can also represent a fault reason element */
|
||||
protected SOAPFaultElement faultStringElement;
|
||||
|
||||
/* This can also represent a fault role element */
|
||||
protected SOAPFaultElement faultActorElement;
|
||||
|
||||
protected SOAPFaultElement faultCodeElement;
|
||||
|
||||
protected Detail detail;
|
||||
|
||||
protected FaultImpl(SOAPDocumentImpl ownerDoc, NameImpl name) {
|
||||
super(ownerDoc, name);
|
||||
}
|
||||
|
||||
|
||||
protected abstract NameImpl getDetailName();
|
||||
protected abstract NameImpl getFaultCodeName();
|
||||
protected abstract NameImpl getFaultStringName();
|
||||
protected abstract NameImpl getFaultActorName();
|
||||
protected abstract DetailImpl createDetail();
|
||||
protected abstract FaultElementImpl createSOAPFaultElement(String localName);
|
||||
protected abstract FaultElementImpl createSOAPFaultElement(QName qname);
|
||||
protected abstract FaultElementImpl createSOAPFaultElement(Name qname);
|
||||
protected abstract void checkIfStandardFaultCode(String faultCode, String uri) throws SOAPException;
|
||||
protected abstract void finallySetFaultCode(String faultcode) throws SOAPException;
|
||||
protected abstract boolean isStandardFaultElement(String localName);
|
||||
protected abstract QName getDefaultFaultCode();
|
||||
|
||||
|
||||
protected void findFaultCodeElement() {
|
||||
this.faultCodeElement =
|
||||
(SOAPFaultElement) findChild(getFaultCodeName());
|
||||
}
|
||||
|
||||
protected void findFaultActorElement() {
|
||||
this.faultActorElement =
|
||||
(SOAPFaultElement) findChild(getFaultActorName());
|
||||
}
|
||||
|
||||
protected void findFaultStringElement() {
|
||||
this.faultStringElement =
|
||||
(SOAPFaultElement) findChild(getFaultStringName());
|
||||
}
|
||||
|
||||
public void setFaultCode(String faultCode) throws SOAPException {
|
||||
setFaultCode(
|
||||
NameImpl.getLocalNameFromTagName(faultCode),
|
||||
NameImpl.getPrefixFromTagName(faultCode),
|
||||
null);
|
||||
}
|
||||
|
||||
public void setFaultCode(String faultCode, String prefix, String uri)
|
||||
throws SOAPException {
|
||||
|
||||
if (prefix == null || "".equals(prefix)) {
|
||||
if (uri != null && !"".equals(uri)) {
|
||||
prefix = getNamespacePrefix(uri);
|
||||
if (prefix == null || "".equals(prefix)) {
|
||||
prefix = "ns0";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.faultCodeElement == null)
|
||||
findFaultCodeElement();
|
||||
|
||||
if (this.faultCodeElement == null)
|
||||
this.faultCodeElement = addFaultCodeElement();
|
||||
else
|
||||
this.faultCodeElement.removeContents();
|
||||
|
||||
if (uri == null || "".equals(uri)) {
|
||||
uri = this.faultCodeElement.getNamespaceURI(prefix);
|
||||
}
|
||||
if (uri == null || "".equals(uri)) {
|
||||
if (prefix != null && !"".equals(prefix)) {
|
||||
//cannot allow an empty URI for a non-Empty prefix
|
||||
log.log(Level.SEVERE, "SAAJ0140.impl.no.ns.URI", new Object[]{prefix + ":" + faultCode});
|
||||
throw new SOAPExceptionImpl("Empty/Null NamespaceURI specified for faultCode \"" + prefix + ":" + faultCode + "\"");
|
||||
} else {
|
||||
uri = "";
|
||||
}
|
||||
}
|
||||
checkIfStandardFaultCode(faultCode, uri);
|
||||
((FaultElementImpl) this.faultCodeElement).ensureNamespaceIsDeclared(prefix, uri);
|
||||
|
||||
if (prefix == null || "".equals(prefix)) {
|
||||
finallySetFaultCode(faultCode);
|
||||
} else {
|
||||
finallySetFaultCode(prefix + ":" + faultCode);
|
||||
}
|
||||
}
|
||||
|
||||
public void setFaultCode(Name faultCodeQName) throws SOAPException {
|
||||
setFaultCode(
|
||||
faultCodeQName.getLocalName(),
|
||||
faultCodeQName.getPrefix(),
|
||||
faultCodeQName.getURI());
|
||||
}
|
||||
|
||||
public void setFaultCode(QName faultCodeQName) throws SOAPException {
|
||||
setFaultCode(
|
||||
faultCodeQName.getLocalPart(),
|
||||
faultCodeQName.getPrefix(),
|
||||
faultCodeQName.getNamespaceURI());
|
||||
}
|
||||
|
||||
protected static QName convertCodeToQName(
|
||||
String code,
|
||||
SOAPElement codeContainingElement) {
|
||||
|
||||
int prefixIndex = code.indexOf(':');
|
||||
if (prefixIndex == -1) {
|
||||
return new QName(code);
|
||||
}
|
||||
|
||||
String prefix = code.substring(0, prefixIndex);
|
||||
String nsName =((ElementImpl) codeContainingElement).lookupNamespaceURI(prefix);
|
||||
//((ElementImpl) codeContainingElement).getNamespaceURI(prefix);
|
||||
return new QName(nsName, getLocalPart(code), prefix);
|
||||
}
|
||||
|
||||
protected void initializeDetail() {
|
||||
NameImpl detailName = getDetailName();
|
||||
detail = (Detail) findChild(detailName);
|
||||
}
|
||||
|
||||
public Detail getDetail() {
|
||||
if (detail == null)
|
||||
initializeDetail();
|
||||
if ((detail != null) && (detail.getParentNode() == null)) {
|
||||
// a detach node was called on it
|
||||
detail = null;
|
||||
}
|
||||
return detail;
|
||||
}
|
||||
|
||||
public Detail addDetail() throws SOAPException {
|
||||
if (detail == null)
|
||||
initializeDetail();
|
||||
if (detail == null) {
|
||||
detail = createDetail();
|
||||
addNode(detail);
|
||||
return detail;
|
||||
} else {
|
||||
// Log
|
||||
throw new SOAPExceptionImpl("Error: Detail already exists");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasDetail() {
|
||||
return (getDetail() != null);
|
||||
}
|
||||
|
||||
public abstract void setFaultActor(String faultActor) throws SOAPException;
|
||||
|
||||
public String getFaultActor() {
|
||||
if (this.faultActorElement == null)
|
||||
findFaultActorElement();
|
||||
if (this.faultActorElement != null) {
|
||||
return this.faultActorElement.getValue();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public SOAPElement setElementQName(QName newName) throws SOAPException {
|
||||
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0146.impl.invalid.name.change.requested",
|
||||
new Object[] {elementQName.getLocalPart(), newName.getLocalPart()});
|
||||
throw new SOAPException(
|
||||
"Cannot change name for " + elementQName.getLocalPart() + " to " + newName.getLocalPart());
|
||||
}
|
||||
|
||||
protected SOAPElement convertToSoapElement(Element element) {
|
||||
if (element instanceof SOAPFaultElement) {
|
||||
return (SOAPElement) element;
|
||||
} else if (element instanceof SOAPElement) {
|
||||
SOAPElement soapElement = (SOAPElement) element;
|
||||
if (getDetailName().equals(soapElement.getElementName())) {
|
||||
return replaceElementWithSOAPElement(element, createDetail());
|
||||
} else {
|
||||
String localName =
|
||||
soapElement.getElementName().getLocalName();
|
||||
if (isStandardFaultElement(localName))
|
||||
return replaceElementWithSOAPElement(
|
||||
element,
|
||||
createSOAPFaultElement(soapElement.getElementQName()));
|
||||
return soapElement;
|
||||
}
|
||||
} else {
|
||||
Name elementName = NameImpl.copyElementName(element);
|
||||
ElementImpl newElement;
|
||||
if (getDetailName().equals(elementName)) {
|
||||
newElement = (ElementImpl) createDetail();
|
||||
} else {
|
||||
String localName = elementName.getLocalName();
|
||||
if (isStandardFaultElement(localName))
|
||||
newElement =
|
||||
(ElementImpl) createSOAPFaultElement(elementName);
|
||||
else
|
||||
newElement = (ElementImpl) createElement(elementName);
|
||||
}
|
||||
return replaceElementWithSOAPElement(element, newElement);
|
||||
}
|
||||
}
|
||||
|
||||
protected SOAPFaultElement addFaultCodeElement() throws SOAPException {
|
||||
if (this.faultCodeElement == null)
|
||||
findFaultCodeElement();
|
||||
if (this.faultCodeElement == null) {
|
||||
this.faultCodeElement =
|
||||
addSOAPFaultElement(getFaultCodeName().getLocalName());
|
||||
return this.faultCodeElement;
|
||||
} else {
|
||||
throw new SOAPExceptionImpl("Error: Faultcode already exists");
|
||||
}
|
||||
}
|
||||
|
||||
private SOAPFaultElement addFaultStringElement() throws SOAPException {
|
||||
if (this.faultStringElement == null)
|
||||
findFaultStringElement();
|
||||
if (this.faultStringElement == null) {
|
||||
this.faultStringElement =
|
||||
addSOAPFaultElement(getFaultStringName().getLocalName());
|
||||
return this.faultStringElement;
|
||||
} else {
|
||||
// Log
|
||||
throw new SOAPExceptionImpl("Error: Faultstring already exists");
|
||||
}
|
||||
}
|
||||
|
||||
private SOAPFaultElement addFaultActorElement() throws SOAPException {
|
||||
if (this.faultActorElement == null)
|
||||
findFaultActorElement();
|
||||
if (this.faultActorElement == null) {
|
||||
this.faultActorElement =
|
||||
addSOAPFaultElement(getFaultActorName().getLocalName());
|
||||
return this.faultActorElement;
|
||||
} else {
|
||||
// Log
|
||||
throw new SOAPExceptionImpl("Error: Faultactor already exists");
|
||||
}
|
||||
}
|
||||
|
||||
protected SOAPElement addElement(Name name) throws SOAPException {
|
||||
if (getDetailName().equals(name)) {
|
||||
return addDetail();
|
||||
} else if(getFaultCodeName().equals(name)) {
|
||||
return addFaultCodeElement();
|
||||
} else if(getFaultStringName().equals(name)) {
|
||||
return addFaultStringElement();
|
||||
} else if(getFaultActorName().equals(name)) {
|
||||
return addFaultActorElement();
|
||||
}
|
||||
return super.addElement(name);
|
||||
}
|
||||
|
||||
protected SOAPElement addElement(QName name) throws SOAPException {
|
||||
return addElement(NameImpl.convertToName(name));
|
||||
}
|
||||
|
||||
protected FaultElementImpl addSOAPFaultElement(String localName)
|
||||
throws SOAPException {
|
||||
|
||||
FaultElementImpl faultElem = createSOAPFaultElement(localName);
|
||||
addNode(faultElem);
|
||||
return faultElem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an xml:lang attribute value into a Locale object
|
||||
*/
|
||||
protected static Locale xmlLangToLocale(String xmlLang) {
|
||||
if (xmlLang == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Spec uses hyphen as separator
|
||||
int index = xmlLang.indexOf("-");
|
||||
|
||||
// Accept underscore as separator as well
|
||||
if (index == -1) {
|
||||
index = xmlLang.indexOf("_");
|
||||
}
|
||||
|
||||
if (index == -1) {
|
||||
// No separator so assume only a language component
|
||||
return new Locale(xmlLang, "");
|
||||
}
|
||||
|
||||
String language = xmlLang.substring(0, index);
|
||||
String country = xmlLang.substring(index + 1);
|
||||
return new Locale(language, country);
|
||||
}
|
||||
|
||||
protected static String localeToXmlLang(Locale locale) {
|
||||
String xmlLang = locale.getLanguage();
|
||||
String country = locale.getCountry();
|
||||
if (!"".equals(country)) {
|
||||
xmlLang += "-" + country;
|
||||
}
|
||||
return xmlLang;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.soap.impl;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.*;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
|
||||
|
||||
public abstract class HeaderElementImpl
|
||||
extends ElementImpl
|
||||
implements SOAPHeaderElement {
|
||||
|
||||
protected static Name RELAY_ATTRIBUTE_LOCAL_NAME =
|
||||
NameImpl.createFromTagName("relay");
|
||||
protected static Name MUST_UNDERSTAND_ATTRIBUTE_LOCAL_NAME =
|
||||
NameImpl.createFromTagName("mustUnderstand");
|
||||
|
||||
public HeaderElementImpl(SOAPDocumentImpl ownerDoc, Name qname) {
|
||||
super(ownerDoc, qname);
|
||||
}
|
||||
public HeaderElementImpl(SOAPDocumentImpl ownerDoc, QName qname) {
|
||||
super(ownerDoc, qname);
|
||||
}
|
||||
|
||||
protected abstract NameImpl getActorAttributeName();
|
||||
protected abstract NameImpl getRoleAttributeName();
|
||||
protected abstract NameImpl getMustunderstandAttributeName();
|
||||
protected abstract boolean getMustunderstandAttributeValue(String str);
|
||||
protected abstract String getMustunderstandLiteralValue(boolean mu);
|
||||
protected abstract NameImpl getRelayAttributeName();
|
||||
protected abstract boolean getRelayAttributeValue(String str);
|
||||
protected abstract String getRelayLiteralValue(boolean mu);
|
||||
protected abstract String getActorOrRole();
|
||||
|
||||
|
||||
public void setParentElement(SOAPElement element) throws SOAPException {
|
||||
if (!(element instanceof SOAPHeader)) {
|
||||
log.severe("SAAJ0130.impl.header.elem.parent.mustbe.header");
|
||||
throw new SOAPException("Parent of a SOAPHeaderElement has to be a SOAPHeader");
|
||||
}
|
||||
|
||||
super.setParentElement(element);
|
||||
}
|
||||
|
||||
public void setActor(String actorUri) {
|
||||
try {
|
||||
removeAttribute(getActorAttributeName());
|
||||
addAttribute((Name) getActorAttributeName(), actorUri);
|
||||
} catch (SOAPException ex) {
|
||||
}
|
||||
}
|
||||
|
||||
//SOAP 1.2 supports Role
|
||||
public void setRole(String roleUri) throws SOAPException {
|
||||
// runtime exception thrown if called for SOAP 1.1
|
||||
removeAttribute(getRoleAttributeName());
|
||||
addAttribute((Name) getRoleAttributeName(), roleUri);
|
||||
}
|
||||
|
||||
|
||||
Name actorAttNameWithoutNS = NameImpl.createFromTagName("actor");
|
||||
|
||||
public String getActor() {
|
||||
String actor = getAttributeValue(getActorAttributeName());
|
||||
return actor;
|
||||
}
|
||||
|
||||
Name roleAttNameWithoutNS = NameImpl.createFromTagName("role");
|
||||
|
||||
public String getRole() {
|
||||
// runtime exception thrown for 1.1
|
||||
String role = getAttributeValue(getRoleAttributeName());
|
||||
return role;
|
||||
}
|
||||
|
||||
public void setMustUnderstand(boolean mustUnderstand) {
|
||||
try {
|
||||
removeAttribute(getMustunderstandAttributeName());
|
||||
addAttribute(
|
||||
(Name) getMustunderstandAttributeName(),
|
||||
getMustunderstandLiteralValue(mustUnderstand));
|
||||
} catch (SOAPException ex) {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getMustUnderstand() {
|
||||
String mu = getAttributeValue(getMustunderstandAttributeName());
|
||||
|
||||
if (mu != null)
|
||||
return getMustunderstandAttributeValue(mu);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setRelay(boolean relay) throws SOAPException {
|
||||
// runtime exception thrown for 1.1
|
||||
removeAttribute(getRelayAttributeName());
|
||||
addAttribute(
|
||||
(Name) getRelayAttributeName(),
|
||||
getRelayLiteralValue(relay));
|
||||
}
|
||||
|
||||
public boolean getRelay() {
|
||||
String mu = getAttributeValue(getRelayAttributeName());
|
||||
if (mu != null)
|
||||
return getRelayAttributeValue(mu);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,305 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.soap.impl;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.*;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocument;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
|
||||
|
||||
public abstract class HeaderImpl extends ElementImpl implements SOAPHeader {
|
||||
protected static final boolean MUST_UNDERSTAND_ONLY = false;
|
||||
|
||||
protected HeaderImpl(SOAPDocumentImpl ownerDoc, NameImpl name) {
|
||||
super(ownerDoc, name);
|
||||
}
|
||||
|
||||
protected abstract SOAPHeaderElement createHeaderElement(Name name)
|
||||
throws SOAPException;
|
||||
protected abstract SOAPHeaderElement createHeaderElement(QName name)
|
||||
throws SOAPException;
|
||||
protected abstract NameImpl getNotUnderstoodName();
|
||||
protected abstract NameImpl getUpgradeName();
|
||||
protected abstract NameImpl getSupportedEnvelopeName();
|
||||
|
||||
public SOAPHeaderElement addHeaderElement(Name name) throws SOAPException {
|
||||
SOAPElement newHeaderElement =
|
||||
ElementFactory.createNamedElement(
|
||||
((SOAPDocument) getOwnerDocument()).getDocument(),
|
||||
name.getLocalName(),
|
||||
name.getPrefix(),
|
||||
name.getURI());
|
||||
if (newHeaderElement == null
|
||||
|| !(newHeaderElement instanceof SOAPHeaderElement)) {
|
||||
newHeaderElement = createHeaderElement(name);
|
||||
}
|
||||
|
||||
// header elements must be namespace qualified
|
||||
// check that URI is not empty, ensuring that the element is NS qualified.
|
||||
String uri = newHeaderElement.getElementQName().getNamespaceURI();
|
||||
if ((uri == null) || ("").equals(uri)) {
|
||||
log.severe("SAAJ0131.impl.header.elems.ns.qualified");
|
||||
throw new SOAPExceptionImpl("HeaderElements must be namespace qualified");
|
||||
}
|
||||
addNode(newHeaderElement);
|
||||
return (SOAPHeaderElement) newHeaderElement;
|
||||
}
|
||||
|
||||
public SOAPHeaderElement addHeaderElement(QName name) throws SOAPException {
|
||||
SOAPElement newHeaderElement =
|
||||
ElementFactory.createNamedElement(
|
||||
((SOAPDocument) getOwnerDocument()).getDocument(),
|
||||
name.getLocalPart(),
|
||||
name.getPrefix(),
|
||||
name.getNamespaceURI());
|
||||
if (newHeaderElement == null
|
||||
|| !(newHeaderElement instanceof SOAPHeaderElement)) {
|
||||
newHeaderElement = createHeaderElement(name);
|
||||
}
|
||||
|
||||
// header elements must be namespace qualified
|
||||
// check that URI is not empty, ensuring that the element is NS qualified.
|
||||
String uri = newHeaderElement.getElementQName().getNamespaceURI();
|
||||
if ((uri == null) || ("").equals(uri)) {
|
||||
log.severe("SAAJ0131.impl.header.elems.ns.qualified");
|
||||
throw new SOAPExceptionImpl("HeaderElements must be namespace qualified");
|
||||
}
|
||||
addNode(newHeaderElement);
|
||||
return (SOAPHeaderElement) newHeaderElement;
|
||||
}
|
||||
|
||||
protected SOAPElement addElement(Name name) throws SOAPException {
|
||||
return addHeaderElement(name);
|
||||
}
|
||||
|
||||
protected SOAPElement addElement(QName name) throws SOAPException {
|
||||
return addHeaderElement(name);
|
||||
}
|
||||
|
||||
public Iterator examineHeaderElements(String actor) {
|
||||
return getHeaderElementsForActor(actor, false, false);
|
||||
}
|
||||
|
||||
public Iterator extractHeaderElements(String actor) {
|
||||
return getHeaderElementsForActor(actor, true, false);
|
||||
}
|
||||
|
||||
protected Iterator getHeaderElementsForActor(
|
||||
String actor,
|
||||
boolean detach,
|
||||
boolean mustUnderstand) {
|
||||
if (actor == null || actor.equals("")) {
|
||||
log.severe("SAAJ0132.impl.invalid.value.for.actor.or.role");
|
||||
throw new IllegalArgumentException("Invalid value for actor or role");
|
||||
}
|
||||
return getHeaderElements(actor, detach, mustUnderstand);
|
||||
}
|
||||
|
||||
protected Iterator getHeaderElements(
|
||||
String actor,
|
||||
boolean detach,
|
||||
boolean mustUnderstand) {
|
||||
List elementList = new ArrayList();
|
||||
|
||||
Iterator eachChild = getChildElements();
|
||||
|
||||
Object currentChild = iterate(eachChild);
|
||||
while (currentChild != null) {
|
||||
if (!(currentChild instanceof SOAPHeaderElement)) {
|
||||
currentChild = iterate(eachChild);
|
||||
} else {
|
||||
HeaderElementImpl currentElement =
|
||||
(HeaderElementImpl) currentChild;
|
||||
currentChild = iterate(eachChild);
|
||||
|
||||
boolean isMustUnderstandMatching =
|
||||
(!mustUnderstand || currentElement.getMustUnderstand());
|
||||
boolean doAdd = false;
|
||||
if (actor == null && isMustUnderstandMatching) {
|
||||
doAdd = true;
|
||||
} else {
|
||||
String currentActor = currentElement.getActorOrRole();
|
||||
if (currentActor == null) {
|
||||
currentActor = "";
|
||||
}
|
||||
|
||||
if (currentActor.equalsIgnoreCase(actor)
|
||||
&& isMustUnderstandMatching) {
|
||||
doAdd = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (doAdd) {
|
||||
elementList.add(currentElement);
|
||||
if (detach) {
|
||||
currentElement.detachNode();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return elementList.listIterator();
|
||||
}
|
||||
|
||||
private Object iterate(Iterator each) {
|
||||
return each.hasNext() ? each.next() : null;
|
||||
}
|
||||
|
||||
public void setParentElement(SOAPElement element) throws SOAPException {
|
||||
if (!(element instanceof SOAPEnvelope)) {
|
||||
log.severe("SAAJ0133.impl.header.parent.mustbe.envelope");
|
||||
throw new SOAPException("Parent of SOAPHeader has to be a SOAPEnvelope");
|
||||
}
|
||||
super.setParentElement(element);
|
||||
}
|
||||
|
||||
// overriding ElementImpl's method to ensure that HeaderElements are
|
||||
// namespace qualified. Holds for both SOAP versions.
|
||||
// TODO - This check needs to be made for other addChildElement() methods
|
||||
// as well.
|
||||
public SOAPElement addChildElement(String localName) throws SOAPException {
|
||||
|
||||
SOAPElement element = super.addChildElement(localName);
|
||||
// check that URI is not empty, ensuring that the element is NS qualified.
|
||||
String uri = element.getElementName().getURI();
|
||||
if ((uri == null) || ("").equals(uri)) {
|
||||
log.severe("SAAJ0134.impl.header.elems.ns.qualified");
|
||||
throw new SOAPExceptionImpl("HeaderElements must be namespace qualified");
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
public Iterator examineAllHeaderElements() {
|
||||
return getHeaderElements(null, false, MUST_UNDERSTAND_ONLY);
|
||||
}
|
||||
|
||||
public Iterator examineMustUnderstandHeaderElements(String actor) {
|
||||
return getHeaderElements(actor, false, true);
|
||||
|
||||
}
|
||||
|
||||
public Iterator extractAllHeaderElements() {
|
||||
return getHeaderElements(null, true, false);
|
||||
}
|
||||
|
||||
public SOAPHeaderElement addUpgradeHeaderElement(Iterator supportedSoapUris)
|
||||
throws SOAPException {
|
||||
if (supportedSoapUris == null) {
|
||||
log.severe("SAAJ0411.ver1_2.no.null.supportedURIs");
|
||||
throw new SOAPException("Argument cannot be null; iterator of supportedURIs cannot be null");
|
||||
}
|
||||
if (!supportedSoapUris.hasNext()) {
|
||||
log.severe("SAAJ0412.ver1_2.no.empty.list.of.supportedURIs");
|
||||
throw new SOAPException("List of supported URIs cannot be empty");
|
||||
}
|
||||
Name upgradeName = getUpgradeName();
|
||||
SOAPHeaderElement upgradeHeaderElement =
|
||||
(SOAPHeaderElement) addChildElement(upgradeName);
|
||||
Name supportedEnvelopeName = getSupportedEnvelopeName();
|
||||
int i = 0;
|
||||
while (supportedSoapUris.hasNext()) {
|
||||
SOAPElement subElement =
|
||||
upgradeHeaderElement.addChildElement(supportedEnvelopeName);
|
||||
String ns = "ns" + Integer.toString(i);
|
||||
subElement.addAttribute(
|
||||
NameImpl.createFromUnqualifiedName("qname"),
|
||||
ns + ":Envelope");
|
||||
subElement.addNamespaceDeclaration(
|
||||
ns,
|
||||
(String) supportedSoapUris.next());
|
||||
i ++;
|
||||
}
|
||||
return upgradeHeaderElement;
|
||||
}
|
||||
|
||||
public SOAPHeaderElement addUpgradeHeaderElement(String supportedSoapUri)
|
||||
throws SOAPException {
|
||||
return addUpgradeHeaderElement(new String[] {supportedSoapUri});
|
||||
}
|
||||
|
||||
public SOAPHeaderElement addUpgradeHeaderElement(String[] supportedSoapUris)
|
||||
throws SOAPException {
|
||||
|
||||
if (supportedSoapUris == null) {
|
||||
log.severe("SAAJ0411.ver1_2.no.null.supportedURIs");
|
||||
throw new SOAPException("Argument cannot be null; array of supportedURIs cannot be null");
|
||||
}
|
||||
if (supportedSoapUris.length == 0) {
|
||||
log.severe("SAAJ0412.ver1_2.no.empty.list.of.supportedURIs");
|
||||
throw new SOAPException("List of supported URIs cannot be empty");
|
||||
}
|
||||
Name upgradeName = getUpgradeName();
|
||||
SOAPHeaderElement upgradeHeaderElement =
|
||||
(SOAPHeaderElement) addChildElement(upgradeName);
|
||||
Name supportedEnvelopeName = getSupportedEnvelopeName();
|
||||
for (int i = 0; i < supportedSoapUris.length; i ++) {
|
||||
SOAPElement subElement =
|
||||
upgradeHeaderElement.addChildElement(supportedEnvelopeName);
|
||||
String ns = "ns" + Integer.toString(i);
|
||||
subElement.addAttribute(
|
||||
NameImpl.createFromUnqualifiedName("qname"),
|
||||
ns + ":Envelope");
|
||||
subElement.addNamespaceDeclaration(ns, supportedSoapUris[i]);
|
||||
}
|
||||
return upgradeHeaderElement;
|
||||
}
|
||||
|
||||
protected SOAPElement convertToSoapElement(Element element) {
|
||||
if (element instanceof SOAPHeaderElement) {
|
||||
return (SOAPElement) element;
|
||||
} else {
|
||||
SOAPHeaderElement headerElement;
|
||||
try {
|
||||
headerElement =
|
||||
createHeaderElement(NameImpl.copyElementName(element));
|
||||
} catch (SOAPException e) {
|
||||
throw new ClassCastException("Could not convert Element to SOAPHeaderElement: " + e.getMessage());
|
||||
}
|
||||
return replaceElementWithSOAPElement(
|
||||
element,
|
||||
(ElementImpl) headerElement);
|
||||
}
|
||||
}
|
||||
|
||||
public SOAPElement setElementQName(QName newName) throws SOAPException {
|
||||
log.log(Level.SEVERE,
|
||||
"SAAJ0146.impl.invalid.name.change.requested",
|
||||
new Object[] {elementQName.getLocalPart(),
|
||||
newName.getLocalPart()});
|
||||
throw new SOAPException("Cannot change name for "
|
||||
+ elementQName.getLocalPart() + " to "
|
||||
+ newName.getLocalPart());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.soap.impl;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.xml.soap.SOAPElement;
|
||||
import javax.xml.soap.SOAPException;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants;
|
||||
|
||||
public class TextImpl
|
||||
extends com.sun.org.apache.xerces.internal.dom.TextImpl
|
||||
implements javax.xml.soap.Text, org.w3c.dom.Text {
|
||||
|
||||
protected static final Logger log =
|
||||
Logger.getLogger(LogDomainConstants.SOAP_IMPL_DOMAIN,
|
||||
"com.sun.xml.internal.messaging.saaj.soap.impl.LocalStrings");
|
||||
|
||||
public TextImpl(SOAPDocumentImpl ownerDoc, String text) {
|
||||
super(ownerDoc, text);
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
String nodeValue = getNodeValue();
|
||||
return (nodeValue.equals("") ? null : nodeValue);
|
||||
}
|
||||
|
||||
public void setValue(String text) {
|
||||
setNodeValue(text);
|
||||
}
|
||||
|
||||
public void setParentElement(SOAPElement parent) throws SOAPException {
|
||||
if (parent == null) {
|
||||
log.severe("SAAJ0126.impl.cannot.locate.ns");
|
||||
throw new SOAPException("Cannot pass NULL to setParentElement");
|
||||
}
|
||||
((ElementImpl) parent).addNode(this);
|
||||
}
|
||||
|
||||
public SOAPElement getParentElement() {
|
||||
return (SOAPElement) getParentNode();
|
||||
}
|
||||
|
||||
|
||||
public void detachNode() {
|
||||
org.w3c.dom.Node parent = getParentNode();
|
||||
if (parent != null) {
|
||||
parent.removeChild(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void recycleNode() {
|
||||
detachNode();
|
||||
// TBD
|
||||
// - add this to the factory so subsequent
|
||||
// creations can reuse this object.
|
||||
}
|
||||
|
||||
public boolean isComment() {
|
||||
String txt = getNodeValue();
|
||||
if (txt == null) {
|
||||
return false;
|
||||
}
|
||||
return txt.startsWith("<!--") && txt.endsWith("-->");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.soap.impl;
|
||||
|
||||
public class TreeException extends RuntimeException {
|
||||
public TreeException(String reason) {
|
||||
super(reason);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,561 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.soap.name;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.Name;
|
||||
import javax.xml.soap.SOAPConstants;
|
||||
|
||||
//import com.sun.org.apache.xerces.internal.xni.NamespaceContext;
|
||||
import org.w3c.dom.Element;
|
||||
import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants;
|
||||
|
||||
public class NameImpl implements Name {
|
||||
public static final String XML_NAMESPACE_PREFIX = "xml";
|
||||
public static final String XML_SCHEMA_NAMESPACE_PREFIX = "xs";
|
||||
public static final String SOAP_ENVELOPE_PREFIX = "SOAP-ENV";
|
||||
|
||||
public static final String XML_NAMESPACE =
|
||||
"http://www.w3.org/XML/1998/namespace";
|
||||
public static final String SOAP11_NAMESPACE =
|
||||
SOAPConstants.URI_NS_SOAP_ENVELOPE;
|
||||
public static final String SOAP12_NAMESPACE =
|
||||
SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE;
|
||||
public static final String XML_SCHEMA_NAMESPACE =
|
||||
"http://www.w3.org/2001/XMLSchema";
|
||||
|
||||
protected String uri = "";
|
||||
protected String localName = "";
|
||||
protected String prefix = "";
|
||||
private String qualifiedName = null;
|
||||
|
||||
protected static final Logger log =
|
||||
Logger.getLogger(LogDomainConstants.NAMING_DOMAIN,
|
||||
"com.sun.xml.internal.messaging.saaj.soap.name.LocalStrings");
|
||||
|
||||
/**
|
||||
* XML Information Set REC
|
||||
* all namespace attributes (including those named xmlns,
|
||||
* whose [prefix] property has no value) have a namespace URI of http://www.w3.org/2000/xmlns/
|
||||
*/
|
||||
public final static String XMLNS_URI = "http://www.w3.org/2000/xmlns/".intern();
|
||||
|
||||
protected NameImpl(String name) {
|
||||
this.localName = name == null ? "" : name;
|
||||
}
|
||||
|
||||
protected NameImpl(String name, String prefix, String uri) {
|
||||
this.uri = uri == null ? "" : uri;
|
||||
this.localName = name == null ? "" : name;
|
||||
this.prefix = prefix == null ? "" : prefix;
|
||||
|
||||
if (this.prefix.equals("xmlns") && this.uri.equals("")) {
|
||||
this.uri = XMLNS_URI;
|
||||
}
|
||||
if (this.uri.equals(XMLNS_URI) && this.prefix.equals("")) {
|
||||
this.prefix = "xmlns";
|
||||
}
|
||||
}
|
||||
|
||||
public static Name convertToName(QName qname) {
|
||||
return new NameImpl(qname.getLocalPart(),
|
||||
qname.getPrefix(),
|
||||
qname.getNamespaceURI());
|
||||
}
|
||||
|
||||
public static QName convertToQName(Name name) {
|
||||
return new QName(name.getURI(),
|
||||
name.getLocalName(),
|
||||
name.getPrefix());
|
||||
}
|
||||
|
||||
public static NameImpl createFromUnqualifiedName(String name) {
|
||||
return new NameImpl(name);
|
||||
}
|
||||
|
||||
public static Name createFromTagName(String tagName) {
|
||||
return createFromTagAndUri(tagName, "");
|
||||
}
|
||||
|
||||
public static Name createFromQualifiedName(
|
||||
String qualifiedName,
|
||||
String uri) {
|
||||
return createFromTagAndUri(qualifiedName, uri);
|
||||
}
|
||||
|
||||
protected static Name createFromTagAndUri(String tagName, String uri) {
|
||||
if (tagName == null) {
|
||||
log.severe("SAAJ0201.name.not.created.from.null.tag");
|
||||
throw new IllegalArgumentException("Cannot create a name from a null tag.");
|
||||
}
|
||||
int index = tagName.indexOf(':');
|
||||
if (index < 0) {
|
||||
return new NameImpl(tagName, "", uri);
|
||||
} else {
|
||||
return new NameImpl(
|
||||
tagName.substring(index + 1),
|
||||
tagName.substring(0, index),
|
||||
uri);
|
||||
}
|
||||
}
|
||||
|
||||
protected static int getPrefixSeparatorIndex(String qualifiedName) {
|
||||
int index = qualifiedName.indexOf(':');
|
||||
if (index < 0) {
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0202.name.invalid.arg.format",
|
||||
new String[] { qualifiedName });
|
||||
throw new IllegalArgumentException(
|
||||
"Argument \""
|
||||
+ qualifiedName
|
||||
+ "\" must be of the form: \"prefix:localName\"");
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
public static String getPrefixFromQualifiedName(String qualifiedName) {
|
||||
return qualifiedName.substring(
|
||||
0,
|
||||
getPrefixSeparatorIndex(qualifiedName));
|
||||
}
|
||||
|
||||
public static String getLocalNameFromQualifiedName(String qualifiedName) {
|
||||
return qualifiedName.substring(
|
||||
getPrefixSeparatorIndex(qualifiedName) + 1);
|
||||
}
|
||||
|
||||
public static String getPrefixFromTagName(String tagName) {
|
||||
if (isQualified(tagName)) {
|
||||
return getPrefixFromQualifiedName(tagName);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String getLocalNameFromTagName(String tagName) {
|
||||
if (isQualified(tagName)) {
|
||||
return getLocalNameFromQualifiedName(tagName);
|
||||
}
|
||||
return tagName;
|
||||
}
|
||||
|
||||
public static boolean isQualified(String tagName) {
|
||||
return tagName.indexOf(':') >= 0;
|
||||
}
|
||||
|
||||
public static NameImpl create(String name, String prefix, String uri) {
|
||||
if (prefix == null)
|
||||
prefix = "";
|
||||
if (uri == null)
|
||||
uri = "";
|
||||
if (name == null)
|
||||
name = "";
|
||||
|
||||
if (!uri.equals("") && !name.equals("")) {
|
||||
if (uri.equals(NameImpl.SOAP11_NAMESPACE)) {
|
||||
if (name.equalsIgnoreCase("Envelope"))
|
||||
return createEnvelope1_1Name(prefix);
|
||||
else if (name.equalsIgnoreCase("Header"))
|
||||
return createHeader1_1Name(prefix);
|
||||
else if (name.equalsIgnoreCase("Body"))
|
||||
return createBody1_1Name(prefix);
|
||||
else if (name.equalsIgnoreCase("Fault"))
|
||||
return createFault1_1Name(prefix);
|
||||
else
|
||||
return new SOAP1_1Name(name, prefix);
|
||||
} else if (uri.equals(SOAP12_NAMESPACE)) {
|
||||
if (name.equalsIgnoreCase("Envelope"))
|
||||
return createEnvelope1_2Name(prefix);
|
||||
else if (name.equalsIgnoreCase("Header"))
|
||||
return createHeader1_2Name(prefix);
|
||||
else if (name.equalsIgnoreCase("Body"))
|
||||
return createBody1_2Name(prefix);
|
||||
else if (
|
||||
name.equals("Fault")
|
||||
|| name.equals("Reason")
|
||||
|| name.equals("Detail"))
|
||||
return createFault1_2Name(name, prefix);
|
||||
else if (name.equals("Code") || name.equals("Subcode"))
|
||||
return createCodeSubcode1_2Name(prefix, name);
|
||||
else
|
||||
return new SOAP1_2Name(name, prefix);
|
||||
}
|
||||
|
||||
}
|
||||
return new NameImpl(name, prefix, uri);
|
||||
}
|
||||
|
||||
public static String createQName(String prefix, String localName) {
|
||||
if (prefix == null || prefix.equals("")) {
|
||||
return localName;
|
||||
}
|
||||
return prefix + ":" + localName;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof Name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Name otherName = (Name) obj;
|
||||
|
||||
if (!uri.equals(otherName.getURI())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!localName.equals(otherName.getLocalName())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return localName.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the local name part of this XML Name.
|
||||
*
|
||||
* @return a string for the local name.
|
||||
*/
|
||||
public String getLocalName() {
|
||||
return localName;
|
||||
}
|
||||
|
||||
/* getQualifiedName is inherited from QName */
|
||||
|
||||
/**
|
||||
* Returns the prefix associated with the namespace of the name.
|
||||
*
|
||||
* @return the prefix as a string.
|
||||
*/
|
||||
public String getPrefix() {
|
||||
return prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the URI associated of the namespace.
|
||||
*
|
||||
* @return the uri as a string.
|
||||
*/
|
||||
public String getURI() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a String version of the name suitable for use in an XML document.
|
||||
*/
|
||||
public String getQualifiedName() {
|
||||
if (qualifiedName == null) {
|
||||
if (prefix != null && prefix.length() > 0) {
|
||||
qualifiedName = prefix + ":" + localName;
|
||||
} else {
|
||||
qualifiedName = localName;
|
||||
}
|
||||
}
|
||||
return qualifiedName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a name object for a SOAP1.1 Envelope.
|
||||
*/
|
||||
public static NameImpl createEnvelope1_1Name(String prefix) {
|
||||
return new Envelope1_1Name(prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a name object for a SOAP1.2 Envelope.
|
||||
*/
|
||||
public static NameImpl createEnvelope1_2Name(String prefix) {
|
||||
return new Envelope1_2Name(prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a name object for a SOAP1.1 Header.
|
||||
*/
|
||||
public static NameImpl createHeader1_1Name(String prefix) {
|
||||
return new Header1_1Name(prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a name object for a SOAP1.2 Header.
|
||||
*/
|
||||
public static NameImpl createHeader1_2Name(String prefix) {
|
||||
return new Header1_2Name(prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a name object for a SOAP1.1 Body.
|
||||
*/
|
||||
public static NameImpl createBody1_1Name(String prefix) {
|
||||
return new Body1_1Name(prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a name object for a SOAP1.2 Body.
|
||||
*/
|
||||
public static NameImpl createBody1_2Name(String prefix) {
|
||||
return new Body1_2Name(prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a name object for a SOAP1.1 Fault.
|
||||
*/
|
||||
public static NameImpl createFault1_1Name(String prefix) {
|
||||
return new Fault1_1Name(prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a name object for a SOAP1.2 NotUnderstood element.
|
||||
*/
|
||||
public static NameImpl createNotUnderstood1_2Name(String prefix) {
|
||||
return new NotUnderstood1_2Name(prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a name object for a SOAP1.2 Upgrade element.
|
||||
*/
|
||||
public static NameImpl createUpgrade1_2Name(String prefix) {
|
||||
return new Upgrade1_2Name(prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a name object for a SOAP1.2 SupportedEnvelope Upgrade element.
|
||||
*/
|
||||
public static NameImpl createSupportedEnvelope1_2Name(String prefix) {
|
||||
return new SupportedEnvelope1_2Name(prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a name object for a SOAP1.2
|
||||
* Fault, Reason or Detail.
|
||||
*
|
||||
* @param localName Local Name of element
|
||||
*/
|
||||
public static NameImpl createFault1_2Name(
|
||||
String localName,
|
||||
String prefix) {
|
||||
return new Fault1_2Name(localName, prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a name object for a SOAP1.2 Fault/Code or Subcode.
|
||||
*
|
||||
* @param localName Either "Code" or "Subcode"
|
||||
*/
|
||||
public static NameImpl createCodeSubcode1_2Name(
|
||||
String prefix,
|
||||
String localName) {
|
||||
return new CodeSubcode1_2Name(localName, prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a name object for a SOAP1.1 Fault Detail.
|
||||
*/
|
||||
public static NameImpl createDetail1_1Name() {
|
||||
return new Detail1_1Name();
|
||||
}
|
||||
|
||||
public static NameImpl createDetail1_1Name(String prefix) {
|
||||
return new Detail1_1Name(prefix);
|
||||
}
|
||||
|
||||
public static NameImpl createFaultElement1_1Name(String localName) {
|
||||
return new FaultElement1_1Name(localName);
|
||||
}
|
||||
|
||||
public static NameImpl createFaultElement1_1Name(String localName,
|
||||
String prefix) {
|
||||
return new FaultElement1_1Name(localName, prefix);
|
||||
}
|
||||
|
||||
public static NameImpl createSOAP11Name(String string) {
|
||||
return new SOAP1_1Name(string, null);
|
||||
}
|
||||
public static NameImpl createSOAP12Name(String string) {
|
||||
return new SOAP1_2Name(string, null);
|
||||
}
|
||||
|
||||
public static NameImpl createSOAP12Name(String localName, String prefix) {
|
||||
return new SOAP1_2Name(localName, prefix);
|
||||
}
|
||||
|
||||
public static NameImpl createXmlName(String localName) {
|
||||
return new NameImpl(localName, XML_NAMESPACE_PREFIX, XML_NAMESPACE);
|
||||
}
|
||||
|
||||
public static Name copyElementName(Element element) {
|
||||
String localName = element.getLocalName();
|
||||
String prefix = element.getPrefix();
|
||||
String uri = element.getNamespaceURI();
|
||||
return create(localName, prefix, uri);
|
||||
}
|
||||
|
||||
|
||||
static class SOAP1_1Name extends NameImpl {
|
||||
SOAP1_1Name(String name, String prefix) {
|
||||
super(
|
||||
name,
|
||||
(prefix == null || prefix.equals(""))
|
||||
? NameImpl.SOAP_ENVELOPE_PREFIX
|
||||
: prefix,
|
||||
NameImpl.SOAP11_NAMESPACE);
|
||||
}
|
||||
}
|
||||
|
||||
static class Envelope1_1Name extends SOAP1_1Name {
|
||||
Envelope1_1Name(String prefix) {
|
||||
super("Envelope", prefix);
|
||||
}
|
||||
}
|
||||
|
||||
static class Header1_1Name extends SOAP1_1Name {
|
||||
Header1_1Name(String prefix) {
|
||||
super("Header", prefix);
|
||||
}
|
||||
}
|
||||
|
||||
static class Body1_1Name extends SOAP1_1Name {
|
||||
Body1_1Name(String prefix) {
|
||||
super("Body", prefix);
|
||||
}
|
||||
}
|
||||
|
||||
static class Fault1_1Name extends NameImpl {
|
||||
Fault1_1Name(String prefix) {
|
||||
super(
|
||||
"Fault",
|
||||
(prefix == null || prefix.equals(""))
|
||||
? SOAP_ENVELOPE_PREFIX
|
||||
: prefix,
|
||||
SOAP11_NAMESPACE);
|
||||
}
|
||||
}
|
||||
|
||||
static class Detail1_1Name extends NameImpl {
|
||||
Detail1_1Name() {
|
||||
super("detail");
|
||||
}
|
||||
|
||||
Detail1_1Name(String prefix) {
|
||||
super("detail", prefix, "");
|
||||
}
|
||||
}
|
||||
|
||||
static class FaultElement1_1Name extends NameImpl {
|
||||
FaultElement1_1Name(String localName) {
|
||||
super(localName);
|
||||
}
|
||||
|
||||
FaultElement1_1Name(String localName, String prefix) {
|
||||
super(localName, prefix, "");
|
||||
}
|
||||
}
|
||||
|
||||
static class SOAP1_2Name extends NameImpl {
|
||||
SOAP1_2Name(String name, String prefix) {
|
||||
super(
|
||||
name,
|
||||
(prefix == null || prefix.equals(""))
|
||||
? SOAPConstants.SOAP_ENV_PREFIX
|
||||
: prefix,
|
||||
SOAP12_NAMESPACE);
|
||||
}
|
||||
}
|
||||
|
||||
static class Envelope1_2Name extends SOAP1_2Name {
|
||||
Envelope1_2Name(String prefix) {
|
||||
super("Envelope", prefix);
|
||||
}
|
||||
}
|
||||
|
||||
static class Header1_2Name extends SOAP1_2Name {
|
||||
Header1_2Name(String prefix) {
|
||||
super("Header", prefix);
|
||||
}
|
||||
}
|
||||
|
||||
static class Body1_2Name extends SOAP1_2Name {
|
||||
Body1_2Name(String prefix) {
|
||||
super("Body", prefix);
|
||||
}
|
||||
}
|
||||
|
||||
static class Fault1_2Name extends NameImpl {
|
||||
Fault1_2Name(String name, String prefix) {
|
||||
super(
|
||||
(name == null || name.equals("")) ? "Fault" : name,
|
||||
(prefix == null || prefix.equals(""))
|
||||
? SOAPConstants.SOAP_ENV_PREFIX
|
||||
: prefix,
|
||||
SOAP12_NAMESPACE);
|
||||
}
|
||||
}
|
||||
|
||||
static class NotUnderstood1_2Name extends NameImpl {
|
||||
NotUnderstood1_2Name(String prefix) {
|
||||
super(
|
||||
"NotUnderstood",
|
||||
(prefix == null || prefix.equals(""))
|
||||
? SOAPConstants.SOAP_ENV_PREFIX
|
||||
: prefix,
|
||||
SOAP12_NAMESPACE);
|
||||
}
|
||||
}
|
||||
|
||||
static class Upgrade1_2Name extends NameImpl {
|
||||
Upgrade1_2Name(String prefix) {
|
||||
super(
|
||||
"Upgrade",
|
||||
(prefix == null || prefix.equals(""))
|
||||
? SOAPConstants.SOAP_ENV_PREFIX
|
||||
: prefix,
|
||||
SOAP12_NAMESPACE);
|
||||
}
|
||||
}
|
||||
|
||||
static class SupportedEnvelope1_2Name extends NameImpl {
|
||||
SupportedEnvelope1_2Name(String prefix) {
|
||||
super(
|
||||
"SupportedEnvelope",
|
||||
(prefix == null || prefix.equals(""))
|
||||
? SOAPConstants.SOAP_ENV_PREFIX
|
||||
: prefix,
|
||||
SOAP12_NAMESPACE);
|
||||
}
|
||||
}
|
||||
|
||||
static class CodeSubcode1_2Name extends SOAP1_2Name {
|
||||
CodeSubcode1_2Name(String prefix, String localName) {
|
||||
super(prefix, localName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author SAAJ RI Development Team
|
||||
*/
|
||||
package com.sun.xml.internal.messaging.saaj.soap.ver1_1;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.*;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocument;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.impl.BodyImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
|
||||
|
||||
public class Body1_1Impl extends BodyImpl {
|
||||
public Body1_1Impl(SOAPDocumentImpl ownerDocument, String prefix) {
|
||||
super(ownerDocument, NameImpl.createBody1_1Name(prefix));
|
||||
}
|
||||
|
||||
public SOAPFault addSOAP12Fault(QName faultCode, String faultReason, Locale locale) {
|
||||
// log message here
|
||||
throw new UnsupportedOperationException("Not supported in SOAP 1.1");
|
||||
}
|
||||
|
||||
protected NameImpl getFaultName(String name) {
|
||||
// Ignore name
|
||||
return NameImpl.createFault1_1Name(null);
|
||||
}
|
||||
|
||||
protected SOAPBodyElement createBodyElement(Name name) {
|
||||
return new BodyElement1_1Impl(
|
||||
((SOAPDocument) getOwnerDocument()).getDocument(),
|
||||
name);
|
||||
}
|
||||
|
||||
protected SOAPBodyElement createBodyElement(QName name) {
|
||||
return new BodyElement1_1Impl(
|
||||
((SOAPDocument) getOwnerDocument()).getDocument(),
|
||||
name);
|
||||
}
|
||||
|
||||
protected QName getDefaultFaultCode() {
|
||||
return new QName(SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE, "Server");
|
||||
}
|
||||
|
||||
protected boolean isFault(SOAPElement child) {
|
||||
// SOAP 1.1 faults always use the default name
|
||||
return child.getElementName().equals(getFaultName(null));
|
||||
}
|
||||
|
||||
protected SOAPFault createFaultElement() {
|
||||
return new Fault1_1Impl(
|
||||
((SOAPDocument) getOwnerDocument()).getDocument(), getPrefix());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author SAAJ RI Development Team
|
||||
*/
|
||||
package com.sun.xml.internal.messaging.saaj.soap.ver1_1;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.Name;
|
||||
import javax.xml.soap.SOAPElement;
|
||||
import javax.xml.soap.SOAPException;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.impl.BodyElementImpl;
|
||||
|
||||
public class BodyElement1_1Impl extends BodyElementImpl {
|
||||
|
||||
public BodyElement1_1Impl(SOAPDocumentImpl ownerDoc, Name qname) {
|
||||
super(ownerDoc, qname);
|
||||
}
|
||||
public BodyElement1_1Impl(SOAPDocumentImpl ownerDoc, QName qname) {
|
||||
super(ownerDoc, qname);
|
||||
}
|
||||
public SOAPElement setElementQName(QName newName) throws SOAPException {
|
||||
BodyElementImpl copy =
|
||||
new BodyElement1_1Impl((SOAPDocumentImpl) getOwnerDocument(), newName);
|
||||
return replaceElementWithSOAPElement(this,copy);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author SAAJ RI Development Team
|
||||
*/
|
||||
package com.sun.xml.internal.messaging.saaj.soap.ver1_1;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.DetailEntry;
|
||||
import javax.xml.soap.Name;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.impl.DetailImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
|
||||
|
||||
public class Detail1_1Impl extends DetailImpl {
|
||||
|
||||
public Detail1_1Impl(SOAPDocumentImpl ownerDoc, String prefix) {
|
||||
super(ownerDoc, NameImpl.createDetail1_1Name(prefix));
|
||||
}
|
||||
public Detail1_1Impl(SOAPDocumentImpl ownerDoc) {
|
||||
super(ownerDoc, NameImpl.createDetail1_1Name());
|
||||
}
|
||||
protected DetailEntry createDetailEntry(Name name) {
|
||||
return new DetailEntry1_1Impl(
|
||||
(SOAPDocumentImpl) getOwnerDocument(),
|
||||
name);
|
||||
}
|
||||
protected DetailEntry createDetailEntry(QName name) {
|
||||
return new DetailEntry1_1Impl(
|
||||
(SOAPDocumentImpl) getOwnerDocument(),
|
||||
name);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author SAAJ RI Development Team
|
||||
*/
|
||||
package com.sun.xml.internal.messaging.saaj.soap.ver1_1;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.Name;
|
||||
import javax.xml.soap.SOAPElement;
|
||||
import javax.xml.soap.SOAPException;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.impl.DetailEntryImpl;
|
||||
|
||||
public class DetailEntry1_1Impl extends DetailEntryImpl {
|
||||
|
||||
public DetailEntry1_1Impl(SOAPDocumentImpl ownerDoc, Name qname) {
|
||||
super(ownerDoc, qname);
|
||||
}
|
||||
public DetailEntry1_1Impl(SOAPDocumentImpl ownerDoc, QName qname) {
|
||||
super(ownerDoc, qname);
|
||||
}
|
||||
public SOAPElement setElementQName(QName newName) throws SOAPException {
|
||||
DetailEntryImpl copy =
|
||||
new DetailEntry1_1Impl((SOAPDocumentImpl) getOwnerDocument(), newName);
|
||||
return replaceElementWithSOAPElement(this,copy);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author SAAJ RI Development Team
|
||||
*/
|
||||
package com.sun.xml.internal.messaging.saaj.soap.ver1_1;
|
||||
|
||||
import javax.xml.soap.SOAPException;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.impl.EnvelopeImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
|
||||
|
||||
public class Envelope1_1Impl extends EnvelopeImpl {
|
||||
|
||||
public Envelope1_1Impl(SOAPDocumentImpl ownerDoc, String prefix){
|
||||
super(ownerDoc, NameImpl.createEnvelope1_1Name(prefix));
|
||||
}
|
||||
Envelope1_1Impl(
|
||||
SOAPDocumentImpl ownerDoc,
|
||||
String prefix,
|
||||
boolean createHeader,
|
||||
boolean createBody)
|
||||
throws SOAPException {
|
||||
super(
|
||||
ownerDoc,
|
||||
NameImpl.createEnvelope1_1Name(prefix),
|
||||
createHeader,
|
||||
createBody);
|
||||
}
|
||||
protected NameImpl getBodyName(String prefix) {
|
||||
return NameImpl.createBody1_1Name(prefix);
|
||||
}
|
||||
|
||||
protected NameImpl getHeaderName(String prefix) {
|
||||
return NameImpl.createHeader1_1Name(prefix);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,387 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author SAAJ RI Development Team
|
||||
*/
|
||||
package com.sun.xml.internal.messaging.saaj.soap.ver1_1;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.SOAPElement;
|
||||
import javax.xml.soap.SOAPFaultElement;
|
||||
import javax.xml.soap.SOAPException;
|
||||
import javax.xml.soap.SOAPConstants;
|
||||
import javax.xml.soap.Name;
|
||||
import javax.xml.soap.Name;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocument;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.impl.*;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants;
|
||||
import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
|
||||
|
||||
|
||||
public class Fault1_1Impl extends FaultImpl {
|
||||
|
||||
protected static final Logger log =
|
||||
Logger.getLogger(
|
||||
LogDomainConstants.SOAP_VER1_1_DOMAIN,
|
||||
"com.sun.xml.internal.messaging.saaj.soap.ver1_1.LocalStrings");
|
||||
|
||||
public Fault1_1Impl(SOAPDocumentImpl ownerDocument, String prefix) {
|
||||
super(ownerDocument, NameImpl.createFault1_1Name(prefix));
|
||||
}
|
||||
|
||||
protected NameImpl getDetailName() {
|
||||
return NameImpl.createDetail1_1Name();
|
||||
}
|
||||
|
||||
protected NameImpl getFaultCodeName() {
|
||||
return NameImpl.createFromUnqualifiedName("faultcode");
|
||||
}
|
||||
|
||||
protected NameImpl getFaultStringName() {
|
||||
return NameImpl.createFromUnqualifiedName("faultstring");
|
||||
}
|
||||
|
||||
protected NameImpl getFaultActorName() {
|
||||
return NameImpl.createFromUnqualifiedName("faultactor");
|
||||
}
|
||||
|
||||
protected DetailImpl createDetail() {
|
||||
return new Detail1_1Impl(
|
||||
((SOAPDocument) getOwnerDocument()).getDocument());
|
||||
}
|
||||
|
||||
protected FaultElementImpl createSOAPFaultElement(String localName) {
|
||||
return new FaultElement1_1Impl(
|
||||
((SOAPDocument) getOwnerDocument()).getDocument(),
|
||||
localName);
|
||||
}
|
||||
|
||||
protected void checkIfStandardFaultCode(String faultCode, String uri)
|
||||
throws SOAPException {
|
||||
// SOAP 1.1 doesn't seem to mandate using faultcode from a particular
|
||||
// set of values.
|
||||
// Also need to be backward compatible.
|
||||
}
|
||||
|
||||
protected void finallySetFaultCode(String faultcode) throws SOAPException {
|
||||
this.faultCodeElement.addTextNode(faultcode);
|
||||
}
|
||||
|
||||
public String getFaultCode() {
|
||||
if (this.faultCodeElement == null)
|
||||
findFaultCodeElement();
|
||||
return this.faultCodeElement.getValue();
|
||||
}
|
||||
|
||||
public Name getFaultCodeAsName() {
|
||||
|
||||
String faultcodeString = getFaultCode();
|
||||
if (faultcodeString == null) {
|
||||
return null;
|
||||
}
|
||||
int prefixIndex = faultcodeString.indexOf(':');
|
||||
if (prefixIndex == -1) {
|
||||
// Not a valid SOAP message, but we return the unqualified name
|
||||
// anyway since some apps do not strictly conform to SOAP
|
||||
// specs. A message that does not contain a <faultcode>
|
||||
// element itself is also not valid in which case we return
|
||||
// null instead of throwing an exception so this is consistent.
|
||||
return NameImpl.createFromUnqualifiedName(faultcodeString);
|
||||
}
|
||||
|
||||
// Get the prefix and map it to a namespace name (AKA namespace URI)
|
||||
String prefix = faultcodeString.substring(0, prefixIndex);
|
||||
if (this.faultCodeElement == null)
|
||||
findFaultCodeElement();
|
||||
String nsName = this.faultCodeElement.getNamespaceURI(prefix);
|
||||
return NameImpl.createFromQualifiedName(faultcodeString, nsName);
|
||||
}
|
||||
|
||||
public QName getFaultCodeAsQName() {
|
||||
String faultcodeString = getFaultCode();
|
||||
if (faultcodeString == null) {
|
||||
return null;
|
||||
}
|
||||
if (this.faultCodeElement == null)
|
||||
findFaultCodeElement();
|
||||
return convertCodeToQName(faultcodeString, this.faultCodeElement);
|
||||
}
|
||||
|
||||
public void setFaultString(String faultString) throws SOAPException {
|
||||
|
||||
if (this.faultStringElement == null)
|
||||
findFaultStringElement();
|
||||
|
||||
if (this.faultStringElement == null)
|
||||
this.faultStringElement = addSOAPFaultElement("faultstring");
|
||||
else {
|
||||
this.faultStringElement.removeContents();
|
||||
//this.faultStringElement.removeAttributeNS("http://www.w3.org/XML/1998/namespace", "lang");
|
||||
this.faultStringElement.removeAttribute("xml:lang");
|
||||
}
|
||||
|
||||
this.faultStringElement.addTextNode(faultString);
|
||||
}
|
||||
|
||||
public String getFaultString() {
|
||||
if (this.faultStringElement == null)
|
||||
findFaultStringElement();
|
||||
return this.faultStringElement.getValue();
|
||||
|
||||
}
|
||||
|
||||
public Locale getFaultStringLocale() {
|
||||
if (this.faultStringElement == null)
|
||||
findFaultStringElement();
|
||||
if (this.faultStringElement != null) {
|
||||
String xmlLangAttr =
|
||||
this.faultStringElement.getAttributeValue(
|
||||
NameImpl.createFromUnqualifiedName("xml:lang"));
|
||||
if (xmlLangAttr != null)
|
||||
return xmlLangToLocale(xmlLangAttr);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setFaultString(String faultString, Locale locale)
|
||||
throws SOAPException {
|
||||
setFaultString(faultString);
|
||||
this.faultStringElement.addAttribute(
|
||||
NameImpl.createFromTagName("xml:lang"),
|
||||
localeToXmlLang(locale));
|
||||
}
|
||||
|
||||
protected boolean isStandardFaultElement(String localName) {
|
||||
if (localName.equalsIgnoreCase("detail") ||
|
||||
localName.equalsIgnoreCase("faultcode") ||
|
||||
localName.equalsIgnoreCase("faultstring") ||
|
||||
localName.equalsIgnoreCase("faultactor")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void appendFaultSubcode(QName subcode) {
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
|
||||
"appendFaultSubcode");
|
||||
throw new UnsupportedOperationException("Not supported in SOAP 1.1");
|
||||
}
|
||||
|
||||
public void removeAllFaultSubcodes() {
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
|
||||
"removeAllFaultSubcodes");
|
||||
throw new UnsupportedOperationException("Not supported in SOAP 1.1");
|
||||
}
|
||||
|
||||
public Iterator getFaultSubcodes() {
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
|
||||
"getFaultSubcodes");
|
||||
throw new UnsupportedOperationException("Not supported in SOAP 1.1");
|
||||
}
|
||||
|
||||
public String getFaultReasonText(Locale locale) {
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
|
||||
"getFaultReasonText");
|
||||
throw new UnsupportedOperationException("Not supported in SOAP 1.1");
|
||||
}
|
||||
|
||||
public Iterator getFaultReasonTexts() {
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
|
||||
"getFaultReasonTexts");
|
||||
throw new UnsupportedOperationException("Not supported in SOAP 1.1");
|
||||
}
|
||||
|
||||
public Iterator getFaultReasonLocales() {
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
|
||||
"getFaultReasonLocales");
|
||||
throw new UnsupportedOperationException("Not supported in SOAP 1.1");
|
||||
}
|
||||
|
||||
public void addFaultReasonText(String text, java.util.Locale locale)
|
||||
throws SOAPException {
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
|
||||
"addFaultReasonText");
|
||||
throw new UnsupportedOperationException("Not supported in SOAP 1.1");
|
||||
}
|
||||
|
||||
public String getFaultRole() {
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
|
||||
"getFaultRole");
|
||||
throw new UnsupportedOperationException("Not supported in SOAP 1.1");
|
||||
}
|
||||
|
||||
public void setFaultRole(String uri) {
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
|
||||
"setFaultRole");
|
||||
throw new UnsupportedOperationException("Not supported in SOAP 1.1");
|
||||
}
|
||||
|
||||
public String getFaultNode() {
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
|
||||
"getFaultNode");
|
||||
throw new UnsupportedOperationException("Not supported in SOAP 1.1");
|
||||
}
|
||||
|
||||
public void setFaultNode(String uri) {
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
|
||||
"setFaultNode");
|
||||
throw new UnsupportedOperationException("Not supported in SOAP 1.1");
|
||||
}
|
||||
|
||||
protected QName getDefaultFaultCode() {
|
||||
return new QName(SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE, "Server");
|
||||
}
|
||||
|
||||
public SOAPElement addChildElement(SOAPElement element)
|
||||
throws SOAPException {
|
||||
String localName = element.getLocalName();
|
||||
if ("Detail".equalsIgnoreCase(localName)) {
|
||||
if (hasDetail()) {
|
||||
log.severe("SAAJ0305.ver1_2.detail.exists.error");
|
||||
throw new SOAPExceptionImpl("Cannot add Detail, Detail already exists");
|
||||
}
|
||||
}
|
||||
return super.addChildElement(element);
|
||||
}
|
||||
|
||||
protected FaultElementImpl createSOAPFaultElement(QName qname) {
|
||||
return new FaultElement1_1Impl(
|
||||
((SOAPDocument) getOwnerDocument()).getDocument(),
|
||||
qname);
|
||||
}
|
||||
|
||||
protected FaultElementImpl createSOAPFaultElement(Name qname) {
|
||||
return new FaultElement1_1Impl(
|
||||
((SOAPDocument) getOwnerDocument()).getDocument(),
|
||||
(NameImpl)qname);
|
||||
}
|
||||
|
||||
public void setFaultCode(String faultCode, String prefix, String uri)
|
||||
throws SOAPException {
|
||||
if (prefix == null || "".equals(prefix)) {
|
||||
if (uri != null && !"".equals(uri)) {
|
||||
prefix = getNamespacePrefix(uri);
|
||||
if (prefix == null || "".equals(prefix)) {
|
||||
prefix = "ns0";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.faultCodeElement == null)
|
||||
findFaultCodeElement();
|
||||
|
||||
if (this.faultCodeElement == null)
|
||||
this.faultCodeElement = addFaultCodeElement();
|
||||
else
|
||||
this.faultCodeElement.removeContents();
|
||||
|
||||
if (uri == null || "".equals(uri)) {
|
||||
if (prefix != null && !"".equals("prefix")) {
|
||||
uri = this.faultCodeElement.getNamespaceURI(prefix);
|
||||
}
|
||||
}
|
||||
|
||||
if (uri == null || "".equals(uri)) {
|
||||
if (prefix != null && !"".equals(prefix)) {
|
||||
//cannot allow an empty URI for a non-Empty prefix
|
||||
log.log(Level.SEVERE, "SAAJ0307.impl.no.ns.URI", new Object[]{prefix + ":" + faultCode});
|
||||
throw new SOAPExceptionImpl("Empty/Null NamespaceURI specified for faultCode \"" + prefix + ":" + faultCode + "\"");
|
||||
} else {
|
||||
uri = "";
|
||||
}
|
||||
}
|
||||
|
||||
checkIfStandardFaultCode(faultCode, uri);
|
||||
((FaultElementImpl) this.faultCodeElement).ensureNamespaceIsDeclared(prefix, uri);
|
||||
|
||||
if (prefix == null || "".equals(prefix)) {
|
||||
finallySetFaultCode(faultCode);
|
||||
} else {
|
||||
finallySetFaultCode(prefix + ":" + faultCode);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean standardFaultCode(String faultCode) {
|
||||
if (faultCode.equals("VersionMismatch") || faultCode.equals("MustUnderstand")
|
||||
|| faultCode.equals("Client") || faultCode.equals("Server")) {
|
||||
return true;
|
||||
}
|
||||
if (faultCode.startsWith("VersionMismatch.") || faultCode.startsWith("MustUnderstand.")
|
||||
|| faultCode.startsWith("Client.") || faultCode.startsWith("Server.")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setFaultActor(String faultActor) throws SOAPException {
|
||||
if (this.faultActorElement == null)
|
||||
findFaultActorElement();
|
||||
if (this.faultActorElement != null)
|
||||
this.faultActorElement.detachNode();
|
||||
if (faultActor == null)
|
||||
return;
|
||||
this.faultActorElement =
|
||||
createSOAPFaultElement(getFaultActorName());
|
||||
this.faultActorElement.addTextNode(faultActor);
|
||||
if (hasDetail()) {
|
||||
insertBefore(this.faultActorElement, this.detail);
|
||||
return;
|
||||
}
|
||||
addNode(this.faultActorElement);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author SAAJ RI Development Team
|
||||
*/
|
||||
package com.sun.xml.internal.messaging.saaj.soap.ver1_1;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.SOAPElement;
|
||||
import javax.xml.soap.SOAPException;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.impl.FaultElementImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
|
||||
|
||||
public class FaultElement1_1Impl extends FaultElementImpl {
|
||||
|
||||
public FaultElement1_1Impl(SOAPDocumentImpl ownerDoc, NameImpl qname) {
|
||||
super(ownerDoc, qname);
|
||||
}
|
||||
|
||||
public FaultElement1_1Impl(SOAPDocumentImpl ownerDoc, QName qname) {
|
||||
super(ownerDoc, qname);
|
||||
}
|
||||
|
||||
public FaultElement1_1Impl(SOAPDocumentImpl ownerDoc,
|
||||
String localName) {
|
||||
super(ownerDoc, NameImpl.createFaultElement1_1Name(localName));
|
||||
}
|
||||
|
||||
public FaultElement1_1Impl(SOAPDocumentImpl ownerDoc,
|
||||
String localName,
|
||||
String prefix) {
|
||||
super(ownerDoc,
|
||||
NameImpl.createFaultElement1_1Name(localName, prefix));
|
||||
}
|
||||
|
||||
protected boolean isStandardFaultElement() {
|
||||
String localName = elementQName.getLocalPart();
|
||||
if (localName.equalsIgnoreCase("faultcode") ||
|
||||
localName.equalsIgnoreCase("faultstring") ||
|
||||
localName.equalsIgnoreCase("faultactor")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public SOAPElement setElementQName(QName newName) throws SOAPException {
|
||||
if (!isStandardFaultElement()) {
|
||||
FaultElement1_1Impl copy =
|
||||
new FaultElement1_1Impl((SOAPDocumentImpl) getOwnerDocument(), newName);
|
||||
return replaceElementWithSOAPElement(this,copy);
|
||||
} else {
|
||||
return super.setElementQName(newName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author SAAJ RI Development Team
|
||||
*/
|
||||
package com.sun.xml.internal.messaging.saaj.soap.ver1_1;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Iterator;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.*;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocument;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.impl.HeaderImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants;
|
||||
|
||||
public class Header1_1Impl extends HeaderImpl {
|
||||
|
||||
protected static final Logger log =
|
||||
Logger.getLogger(LogDomainConstants.SOAP_VER1_1_DOMAIN,
|
||||
"com.sun.xml.internal.messaging.saaj.soap.ver1_1.LocalStrings");
|
||||
|
||||
public Header1_1Impl(SOAPDocumentImpl ownerDocument, String prefix) {
|
||||
super(ownerDocument, NameImpl.createHeader1_1Name(prefix));
|
||||
}
|
||||
|
||||
protected NameImpl getNotUnderstoodName() {
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0301.ver1_1.hdr.op.unsupported.in.SOAP1.1",
|
||||
new String[] { "getNotUnderstoodName" });
|
||||
throw new UnsupportedOperationException("Not supported by SOAP 1.1");
|
||||
}
|
||||
|
||||
protected NameImpl getUpgradeName() {
|
||||
return NameImpl.create(
|
||||
"Upgrade",
|
||||
getPrefix(),
|
||||
SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE);
|
||||
}
|
||||
|
||||
protected NameImpl getSupportedEnvelopeName() {
|
||||
return NameImpl.create(
|
||||
"SupportedEnvelope",
|
||||
getPrefix(),
|
||||
SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE);
|
||||
}
|
||||
|
||||
public SOAPHeaderElement addNotUnderstoodHeaderElement(QName name)
|
||||
throws SOAPException {
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0301.ver1_1.hdr.op.unsupported.in.SOAP1.1",
|
||||
new String[] { "addNotUnderstoodHeaderElement" });
|
||||
throw new UnsupportedOperationException("Not supported by SOAP 1.1");
|
||||
}
|
||||
|
||||
protected SOAPHeaderElement createHeaderElement(Name name) {
|
||||
return new HeaderElement1_1Impl(
|
||||
((SOAPDocument) getOwnerDocument()).getDocument(),
|
||||
name);
|
||||
}
|
||||
protected SOAPHeaderElement createHeaderElement(QName name) {
|
||||
return new HeaderElement1_1Impl(
|
||||
((SOAPDocument) getOwnerDocument()).getDocument(),
|
||||
name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author SAAJ RI Development Team
|
||||
*/
|
||||
package com.sun.xml.internal.messaging.saaj.soap.ver1_1;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.Name;
|
||||
import javax.xml.soap.SOAPException;
|
||||
import javax.xml.soap.SOAPElement;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.impl.HeaderElementImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants;
|
||||
|
||||
public class HeaderElement1_1Impl extends HeaderElementImpl {
|
||||
|
||||
protected static final Logger log =
|
||||
Logger.getLogger(LogDomainConstants.SOAP_VER1_1_DOMAIN,
|
||||
"com.sun.xml.internal.messaging.saaj.soap.ver1_1.LocalStrings");
|
||||
|
||||
public HeaderElement1_1Impl(SOAPDocumentImpl ownerDoc, Name qname) {
|
||||
super(ownerDoc, qname);
|
||||
}
|
||||
public HeaderElement1_1Impl(SOAPDocumentImpl ownerDoc, QName qname) {
|
||||
super(ownerDoc, qname);
|
||||
}
|
||||
|
||||
public SOAPElement setElementQName(QName newName) throws SOAPException {
|
||||
HeaderElementImpl copy =
|
||||
new HeaderElement1_1Impl((SOAPDocumentImpl) getOwnerDocument(), newName);
|
||||
return replaceElementWithSOAPElement(this,copy);
|
||||
}
|
||||
|
||||
protected NameImpl getActorAttributeName() {
|
||||
return NameImpl.create("actor", null, NameImpl.SOAP11_NAMESPACE);
|
||||
}
|
||||
|
||||
// role not supported by SOAP 1.1
|
||||
protected NameImpl getRoleAttributeName() {
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0302.ver1_1.hdr.attr.unsupported.in.SOAP1.1",
|
||||
new String[] { "Role" });
|
||||
throw new UnsupportedOperationException("Role not supported by SOAP 1.1");
|
||||
}
|
||||
|
||||
protected NameImpl getMustunderstandAttributeName() {
|
||||
return NameImpl.create("mustUnderstand", null, NameImpl.SOAP11_NAMESPACE);
|
||||
}
|
||||
|
||||
// mustUnderstand attribute has literal value "1" or "0"
|
||||
protected String getMustunderstandLiteralValue(boolean mustUnderstand) {
|
||||
return (mustUnderstand == true ? "1" : "0");
|
||||
}
|
||||
|
||||
protected boolean getMustunderstandAttributeValue(String mu) {
|
||||
if ("1".equals(mu) || "true".equalsIgnoreCase(mu))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// relay not supported by SOAP 1.1
|
||||
protected NameImpl getRelayAttributeName() {
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0302.ver1_1.hdr.attr.unsupported.in.SOAP1.1",
|
||||
new String[] { "Relay" });
|
||||
throw new UnsupportedOperationException("Relay not supported by SOAP 1.1");
|
||||
}
|
||||
|
||||
protected String getRelayLiteralValue(boolean relayAttr) {
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0302.ver1_1.hdr.attr.unsupported.in.SOAP1.1",
|
||||
new String[] { "Relay" });
|
||||
throw new UnsupportedOperationException("Relay not supported by SOAP 1.1");
|
||||
}
|
||||
|
||||
protected boolean getRelayAttributeValue(String mu) {
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0302.ver1_1.hdr.attr.unsupported.in.SOAP1.1",
|
||||
new String[] { "Relay" });
|
||||
throw new UnsupportedOperationException("Relay not supported by SOAP 1.1");
|
||||
}
|
||||
|
||||
protected String getActorOrRole() {
|
||||
return getActor();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author SAAJ RI Development Team
|
||||
*/
|
||||
package com.sun.xml.internal.messaging.saaj.soap.ver1_1;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.xml.soap.*;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.ContentType;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.MessageImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants;
|
||||
|
||||
public class Message1_1Impl extends MessageImpl implements SOAPConstants {
|
||||
|
||||
protected static final Logger log =
|
||||
Logger.getLogger(LogDomainConstants.SOAP_VER1_1_DOMAIN,
|
||||
"com.sun.xml.internal.messaging.saaj.soap.ver1_1.LocalStrings");
|
||||
|
||||
public Message1_1Impl() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Message1_1Impl(boolean isFastInfoset, boolean acceptFastInfoset) {
|
||||
super(isFastInfoset, acceptFastInfoset);
|
||||
}
|
||||
|
||||
public Message1_1Impl(SOAPMessage msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
// unused. can we delete this? - Kohsuke
|
||||
public Message1_1Impl(MimeHeaders headers, InputStream in)
|
||||
throws IOException, SOAPExceptionImpl {
|
||||
super(headers, in);
|
||||
}
|
||||
|
||||
public Message1_1Impl(MimeHeaders headers, ContentType ct, int stat, InputStream in)
|
||||
throws SOAPExceptionImpl {
|
||||
super(headers,ct,stat,in);
|
||||
}
|
||||
|
||||
public SOAPPart getSOAPPart() {
|
||||
if (soapPartImpl == null) {
|
||||
soapPartImpl = new SOAPPart1_1Impl(this);
|
||||
}
|
||||
return soapPartImpl;
|
||||
}
|
||||
|
||||
protected boolean isCorrectSoapVersion(int contentTypeId) {
|
||||
return (contentTypeId & SOAP1_1_FLAG) != 0;
|
||||
}
|
||||
|
||||
public String getAction() {
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
|
||||
new String[] { "Action" });
|
||||
throw new UnsupportedOperationException("Operation not supported by SOAP 1.1");
|
||||
}
|
||||
|
||||
public void setAction(String type) {
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
|
||||
new String[] { "Action" });
|
||||
throw new UnsupportedOperationException("Operation not supported by SOAP 1.1");
|
||||
}
|
||||
|
||||
public String getCharset() {
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
|
||||
new String[] { "Charset" });
|
||||
throw new UnsupportedOperationException("Operation not supported by SOAP 1.1");
|
||||
}
|
||||
|
||||
public void setCharset(String charset) {
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0303.ver1_1.msg.op.unsupported.in.SOAP1.1",
|
||||
new String[] { "Charset" });
|
||||
throw new UnsupportedOperationException("Operation not supported by SOAP 1.1");
|
||||
}
|
||||
|
||||
protected String getExpectedContentType() {
|
||||
return isFastInfoset ? "application/fastinfoset" : "text/xml";
|
||||
}
|
||||
|
||||
protected String getExpectedAcceptHeader() {
|
||||
String accept = "text/xml, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2";
|
||||
return acceptFastInfoset ? ("application/fastinfoset, " + accept) : accept;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author SAAJ RI Development Team
|
||||
*/
|
||||
package com.sun.xml.internal.messaging.saaj.soap.ver1_1;
|
||||
|
||||
import javax.xml.soap.Detail;
|
||||
import javax.xml.soap.SOAPException;
|
||||
import javax.xml.soap.SOAPFault;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPFactoryImpl;
|
||||
|
||||
public class SOAPFactory1_1Impl extends SOAPFactoryImpl {
|
||||
protected SOAPDocumentImpl createDocument() {
|
||||
return (new SOAPPart1_1Impl()).getDocument();
|
||||
}
|
||||
|
||||
public Detail createDetail() throws SOAPException {
|
||||
return new Detail1_1Impl(createDocument());
|
||||
}
|
||||
|
||||
public SOAPFault createFault(String reasonText, QName faultCode)
|
||||
throws SOAPException {
|
||||
if (faultCode == null) {
|
||||
throw new IllegalArgumentException("faultCode argument for createFault was passed NULL");
|
||||
}
|
||||
if (reasonText == null) {
|
||||
throw new IllegalArgumentException("reasonText argument for createFault was passed NULL");
|
||||
}
|
||||
Fault1_1Impl fault = new Fault1_1Impl(createDocument(), null);
|
||||
fault.setFaultCode(faultCode);
|
||||
fault.setFaultString(reasonText);
|
||||
return fault;
|
||||
}
|
||||
|
||||
public SOAPFault createFault() throws SOAPException {
|
||||
Fault1_1Impl fault = new Fault1_1Impl(createDocument(), null);
|
||||
fault.setFaultCode(fault.getDefaultFaultCode());
|
||||
fault.setFaultString("Fault string, and possibly fault code, not set");
|
||||
return fault;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author SAAJ RI Development Team
|
||||
*/
|
||||
package com.sun.xml.internal.messaging.saaj.soap.ver1_1;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.xml.soap.*;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.MessageFactoryImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.MessageImpl;
|
||||
|
||||
public class SOAPMessageFactory1_1Impl extends MessageFactoryImpl {
|
||||
|
||||
public SOAPMessage createMessage() throws SOAPException {
|
||||
return new Message1_1Impl();
|
||||
}
|
||||
|
||||
public SOAPMessage createMessage(boolean isFastInfoset,
|
||||
boolean acceptFastInfoset) throws SOAPException
|
||||
{
|
||||
return new Message1_1Impl(isFastInfoset, acceptFastInfoset);
|
||||
}
|
||||
|
||||
public SOAPMessage createMessage(MimeHeaders headers, InputStream in) throws IOException, SOAPExceptionImpl {
|
||||
|
||||
if (headers == null) {
|
||||
headers = new MimeHeaders();
|
||||
}
|
||||
|
||||
if (getContentType(headers) == null) {
|
||||
headers.setHeader("Content-Type", SOAPConstants.SOAP_1_1_CONTENT_TYPE);
|
||||
}
|
||||
|
||||
MessageImpl msg = new Message1_1Impl(headers, in);
|
||||
msg.setLazyAttachments(lazyAttachments);
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author SAAJ RI Development Team
|
||||
*/
|
||||
package com.sun.xml.internal.messaging.saaj.soap.ver1_1;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.xml.soap.SOAPConstants;
|
||||
import javax.xml.soap.SOAPException;
|
||||
import javax.xml.transform.Source;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.soap.*;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.impl.EnvelopeImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants;
|
||||
import com.sun.xml.internal.messaging.saaj.util.XMLDeclarationParser;
|
||||
|
||||
public class SOAPPart1_1Impl extends SOAPPartImpl implements SOAPConstants {
|
||||
|
||||
protected static final Logger log =
|
||||
Logger.getLogger(LogDomainConstants.SOAP_VER1_1_DOMAIN,
|
||||
"com.sun.xml.internal.messaging.saaj.soap.ver1_1.LocalStrings");
|
||||
|
||||
public SOAPPart1_1Impl() {
|
||||
super();
|
||||
}
|
||||
|
||||
public SOAPPart1_1Impl(MessageImpl message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
protected String getContentType() {
|
||||
return isFastInfoset() ? "application/fastinfoset" : "text/xml";
|
||||
}
|
||||
|
||||
protected Envelope createEnvelopeFromSource() throws SOAPException {
|
||||
// Record the presence of xml declaration before the envelope gets
|
||||
// created.
|
||||
XMLDeclarationParser parser = lookForXmlDecl();
|
||||
Source tmp = source;
|
||||
source = null;
|
||||
EnvelopeImpl envelope =
|
||||
(EnvelopeImpl) EnvelopeFactory.createEnvelope(tmp, this);
|
||||
|
||||
if (!envelope.getNamespaceURI().equals(SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE)) {
|
||||
log.severe("SAAJ0304.ver1_1.msg.invalid.SOAP1.1");
|
||||
throw new SOAPException("InputStream does not represent a valid SOAP 1.1 Message");
|
||||
}
|
||||
|
||||
if (parser != null && !omitXmlDecl) {
|
||||
envelope.setOmitXmlDecl("no");
|
||||
envelope.setXmlDecl(parser.getXmlDeclaration());
|
||||
envelope.setCharsetEncoding(parser.getEncoding());
|
||||
}
|
||||
return envelope;
|
||||
}
|
||||
|
||||
protected Envelope createEmptyEnvelope(String prefix)
|
||||
throws SOAPException {
|
||||
return new Envelope1_1Impl(getDocument(), prefix, true, true);
|
||||
}
|
||||
|
||||
protected SOAPPartImpl duplicateType() {
|
||||
return new SOAPPart1_1Impl();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author SAAJ RI Development Team
|
||||
*/
|
||||
package com.sun.xml.internal.messaging.saaj.soap.ver1_2;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.*;
|
||||
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocument;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.impl.BodyImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
|
||||
|
||||
public class Body1_2Impl extends BodyImpl {
|
||||
|
||||
protected static final Logger log =
|
||||
Logger.getLogger(Body1_2Impl.class.getName(),
|
||||
"com.sun.xml.internal.messaging.saaj.soap.ver1_2.LocalStrings");
|
||||
|
||||
public Body1_2Impl(SOAPDocumentImpl ownerDocument, String prefix) {
|
||||
super(ownerDocument, NameImpl.createBody1_2Name(prefix));
|
||||
}
|
||||
|
||||
protected NameImpl getFaultName(String name) {
|
||||
return NameImpl.createFault1_2Name(name, null);
|
||||
}
|
||||
|
||||
protected SOAPBodyElement createBodyElement(Name name) {
|
||||
return new BodyElement1_2Impl(
|
||||
((SOAPDocument) getOwnerDocument()).getDocument(),
|
||||
name);
|
||||
}
|
||||
protected SOAPBodyElement createBodyElement(QName name) {
|
||||
return new BodyElement1_2Impl(
|
||||
((SOAPDocument) getOwnerDocument()).getDocument(),
|
||||
name);
|
||||
}
|
||||
|
||||
protected QName getDefaultFaultCode() {
|
||||
return SOAPConstants.SOAP_RECEIVER_FAULT;
|
||||
}
|
||||
|
||||
public SOAPFault addFault() throws SOAPException {
|
||||
if (hasAnyChildElement()) {
|
||||
log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
|
||||
throw new SOAPExceptionImpl(
|
||||
"No other element except Fault allowed in SOAPBody");
|
||||
}
|
||||
return super.addFault();
|
||||
}
|
||||
|
||||
/*
|
||||
* Override setEncodingStyle of ElementImpl to restrict adding encodingStyle
|
||||
* attribute to SOAP Body (SOAP 1.2 spec, part 1, section 5.1.1)
|
||||
*/
|
||||
public void setEncodingStyle(String encodingStyle) throws SOAPException {
|
||||
log.severe("SAAJ0401.ver1_2.no.encodingstyle.in.body");
|
||||
throw new SOAPExceptionImpl("encodingStyle attribute cannot appear on Body");
|
||||
}
|
||||
|
||||
/*
|
||||
* Override addAttribute of ElementImpl to restrict adding encodingStyle
|
||||
* attribute to SOAP Body (SOAP 1.2 spec, part 1, section 5.1.1)
|
||||
*/
|
||||
public SOAPElement addAttribute(Name name, String value)
|
||||
throws SOAPException {
|
||||
if (name.getLocalName().equals("encodingStyle")
|
||||
&& name.getURI().equals(NameImpl.SOAP12_NAMESPACE)) {
|
||||
|
||||
setEncodingStyle(value);
|
||||
}
|
||||
return super.addAttribute(name, value);
|
||||
}
|
||||
|
||||
public SOAPElement addAttribute(QName name, String value)
|
||||
throws SOAPException {
|
||||
if (name.getLocalPart().equals("encodingStyle")
|
||||
&& name.getNamespaceURI().equals(NameImpl.SOAP12_NAMESPACE)) {
|
||||
|
||||
setEncodingStyle(value);
|
||||
}
|
||||
return super.addAttribute(name, value);
|
||||
}
|
||||
|
||||
protected boolean isFault(SOAPElement child) {
|
||||
return (child.getElementName().getURI().equals(
|
||||
SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE) &&
|
||||
child.getElementName().getLocalName().equals(
|
||||
"Fault"));
|
||||
}
|
||||
|
||||
protected SOAPFault createFaultElement() {
|
||||
return new Fault1_2Impl(
|
||||
((SOAPDocument) getOwnerDocument()).getDocument(), getPrefix());
|
||||
}
|
||||
|
||||
/*
|
||||
* section 5.4 of SOAP1.2 candidate recommendation says that a
|
||||
* SOAP message MUST contain a single Fault element as the only
|
||||
* child element of the SOAP Body.
|
||||
*/
|
||||
public SOAPBodyElement addBodyElement(Name name) throws SOAPException {
|
||||
if (hasFault()) {
|
||||
log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
|
||||
throw new SOAPExceptionImpl(
|
||||
"No other element except Fault allowed in SOAPBody");
|
||||
}
|
||||
return super.addBodyElement(name);
|
||||
}
|
||||
|
||||
public SOAPBodyElement addBodyElement(QName name) throws SOAPException {
|
||||
if (hasFault()) {
|
||||
log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
|
||||
throw new SOAPExceptionImpl(
|
||||
"No other element except Fault allowed in SOAPBody");
|
||||
}
|
||||
return super.addBodyElement(name);
|
||||
}
|
||||
|
||||
protected SOAPElement addElement(Name name) throws SOAPException {
|
||||
if (hasFault()) {
|
||||
log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
|
||||
throw new SOAPExceptionImpl(
|
||||
"No other element except Fault allowed in SOAPBody");
|
||||
}
|
||||
return super.addElement(name);
|
||||
}
|
||||
|
||||
protected SOAPElement addElement(QName name) throws SOAPException {
|
||||
if (hasFault()) {
|
||||
log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
|
||||
throw new SOAPExceptionImpl(
|
||||
"No other element except Fault allowed in SOAPBody");
|
||||
}
|
||||
return super.addElement(name);
|
||||
}
|
||||
|
||||
public SOAPElement addChildElement(Name name) throws SOAPException {
|
||||
if (hasFault()) {
|
||||
log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
|
||||
throw new SOAPExceptionImpl(
|
||||
"No other element except Fault allowed in SOAPBody");
|
||||
}
|
||||
return super.addChildElement(name);
|
||||
}
|
||||
|
||||
public SOAPElement addChildElement(QName name) throws SOAPException {
|
||||
if (hasFault()) {
|
||||
log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
|
||||
throw new SOAPExceptionImpl(
|
||||
"No other element except Fault allowed in SOAPBody");
|
||||
}
|
||||
return super.addChildElement(name);
|
||||
}
|
||||
|
||||
private boolean hasAnyChildElement() {
|
||||
Node currentNode = getFirstChild();
|
||||
while (currentNode != null) {
|
||||
if (currentNode.getNodeType() == Node.ELEMENT_NODE)
|
||||
return true;
|
||||
currentNode = currentNode.getNextSibling();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author SAAJ RI Development Team
|
||||
*/
|
||||
package com.sun.xml.internal.messaging.saaj.soap.ver1_2;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.Name;
|
||||
import javax.xml.soap.SOAPException;
|
||||
import javax.xml.soap.SOAPElement;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.impl.BodyElementImpl;
|
||||
|
||||
public class BodyElement1_2Impl extends BodyElementImpl {
|
||||
|
||||
public BodyElement1_2Impl(SOAPDocumentImpl ownerDoc, Name qname) {
|
||||
super(ownerDoc, qname);
|
||||
}
|
||||
|
||||
public BodyElement1_2Impl(SOAPDocumentImpl ownerDoc, QName qname) {
|
||||
super(ownerDoc, qname);
|
||||
}
|
||||
|
||||
public SOAPElement setElementQName(QName newName) throws SOAPException {
|
||||
BodyElementImpl copy =
|
||||
new BodyElement1_2Impl((SOAPDocumentImpl) getOwnerDocument(), newName);
|
||||
return replaceElementWithSOAPElement(this,copy);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author SAAJ RI Development Team
|
||||
*/
|
||||
package com.sun.xml.internal.messaging.saaj.soap.ver1_2;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.*;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocument;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.impl.DetailImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
|
||||
|
||||
public class Detail1_2Impl extends DetailImpl {
|
||||
|
||||
protected static final Logger log =
|
||||
Logger.getLogger(Detail1_2Impl.class.getName(),
|
||||
"com.sun.xml.internal.messaging.saaj.soap.ver1_2.LocalStrings");
|
||||
|
||||
public Detail1_2Impl(SOAPDocumentImpl ownerDocument, String prefix) {
|
||||
super(ownerDocument, NameImpl.createSOAP12Name("Detail", prefix));
|
||||
}
|
||||
|
||||
public Detail1_2Impl(SOAPDocumentImpl ownerDocument) {
|
||||
super(ownerDocument, NameImpl.createSOAP12Name("Detail"));
|
||||
}
|
||||
|
||||
protected DetailEntry createDetailEntry(Name name) {
|
||||
return new DetailEntry1_2Impl(
|
||||
((SOAPDocument) getOwnerDocument()).getDocument(),
|
||||
name);
|
||||
}
|
||||
|
||||
protected DetailEntry createDetailEntry(QName name) {
|
||||
return new DetailEntry1_2Impl(
|
||||
((SOAPDocument) getOwnerDocument()).getDocument(),
|
||||
name);
|
||||
}
|
||||
|
||||
/*
|
||||
* Override setEncodingStyle of ElementImpl to restrict adding encodingStyle
|
||||
* attribute to SOAP Detail (SOAP 1.2 spec, part 1, section 5.1.1)
|
||||
*/
|
||||
public void setEncodingStyle(String encodingStyle) throws SOAPException {
|
||||
log.severe("SAAJ0403.ver1_2.no.encodingStyle.in.detail");
|
||||
throw new SOAPExceptionImpl("EncodingStyle attribute cannot appear in Detail");
|
||||
}
|
||||
|
||||
public SOAPElement addAttribute(Name name, String value)
|
||||
throws SOAPException {
|
||||
if (name.getLocalName().equals("encodingStyle")
|
||||
&& name.getURI().equals(NameImpl.SOAP12_NAMESPACE)) {
|
||||
setEncodingStyle(value);
|
||||
}
|
||||
return super.addAttribute(name, value);
|
||||
}
|
||||
|
||||
public SOAPElement addAttribute(QName name, String value)
|
||||
throws SOAPException {
|
||||
if (name.getLocalPart().equals("encodingStyle")
|
||||
&& name.getNamespaceURI().equals(NameImpl.SOAP12_NAMESPACE)) {
|
||||
setEncodingStyle(value);
|
||||
}
|
||||
return super.addAttribute(name, value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author SAAJ RI Development Team
|
||||
*/
|
||||
package com.sun.xml.internal.messaging.saaj.soap.ver1_2;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.Name;
|
||||
import javax.xml.soap.SOAPException;
|
||||
import javax.xml.soap.SOAPElement;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.impl.DetailEntryImpl;
|
||||
|
||||
public class DetailEntry1_2Impl extends DetailEntryImpl {
|
||||
|
||||
public DetailEntry1_2Impl(SOAPDocumentImpl ownerDoc, Name qname) {
|
||||
super(ownerDoc, qname);
|
||||
}
|
||||
|
||||
public DetailEntry1_2Impl(SOAPDocumentImpl ownerDoc, QName qname) {
|
||||
super(ownerDoc, qname);
|
||||
}
|
||||
|
||||
public SOAPElement setElementQName(QName newName) throws SOAPException {
|
||||
DetailEntryImpl copy =
|
||||
new DetailEntry1_2Impl((SOAPDocumentImpl) getOwnerDocument(), newName);
|
||||
return replaceElementWithSOAPElement(this,copy);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author SAAJ RI Development Team
|
||||
*/
|
||||
package com.sun.xml.internal.messaging.saaj.soap.ver1_2;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.*;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.impl.EnvelopeImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
|
||||
|
||||
public class Envelope1_2Impl extends EnvelopeImpl {
|
||||
|
||||
protected static final Logger log =
|
||||
Logger.getLogger(Envelope1_2Impl.class.getName(),
|
||||
"com.sun.xml.internal.messaging.saaj.soap.ver1_2.LocalStrings");
|
||||
|
||||
public Envelope1_2Impl(SOAPDocumentImpl ownerDoc, String prefix) {
|
||||
super(ownerDoc, NameImpl.createEnvelope1_2Name(prefix));
|
||||
}
|
||||
|
||||
public Envelope1_2Impl(
|
||||
SOAPDocumentImpl ownerDoc,
|
||||
String prefix,
|
||||
boolean createHeader,
|
||||
boolean createBody)
|
||||
throws SOAPException {
|
||||
super(
|
||||
ownerDoc,
|
||||
NameImpl.createEnvelope1_2Name(prefix),
|
||||
createHeader,
|
||||
createBody);
|
||||
}
|
||||
|
||||
protected NameImpl getBodyName(String prefix) {
|
||||
return NameImpl.createBody1_2Name(prefix);
|
||||
}
|
||||
|
||||
protected NameImpl getHeaderName(String prefix) {
|
||||
return NameImpl.createHeader1_2Name(prefix);
|
||||
}
|
||||
|
||||
/*
|
||||
* Override setEncodingStyle of ElementImpl to restrict adding encodingStyle
|
||||
* attribute to SOAP Envelope (SOAP 1.2 spec, part 1, section 5.1.1)
|
||||
*/
|
||||
public void setEncodingStyle(String encodingStyle) throws SOAPException {
|
||||
log.severe("SAAJ0404.ver1_2.no.encodingStyle.in.envelope");
|
||||
throw new SOAPExceptionImpl("encodingStyle attribute cannot appear on Envelope");
|
||||
}
|
||||
|
||||
/*
|
||||
* Override addAttribute of ElementImpl to restrict adding encodingStyle
|
||||
* attribute to SOAP Envelope (SOAP 1.2 spec, part 1, section 5.1.1)
|
||||
*/
|
||||
public SOAPElement addAttribute(Name name, String value)
|
||||
throws SOAPException {
|
||||
if (name.getLocalName().equals("encodingStyle")
|
||||
&& name.getURI().equals(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE)) {
|
||||
setEncodingStyle(value);
|
||||
}
|
||||
return super.addAttribute(name, value);
|
||||
}
|
||||
|
||||
public SOAPElement addAttribute(QName name, String value)
|
||||
throws SOAPException {
|
||||
if (name.getLocalPart().equals("encodingStyle")
|
||||
&& name.getNamespaceURI().equals(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE)) {
|
||||
setEncodingStyle(value);
|
||||
}
|
||||
return super.addAttribute(name, value);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Override addChildElement method to ensure that no element
|
||||
* is added after body in SOAP 1.2.
|
||||
*/
|
||||
public SOAPElement addChildElement(Name name) throws SOAPException {
|
||||
// check if body already exists
|
||||
if (getBody() != null) {
|
||||
log.severe("SAAJ0405.ver1_2.body.must.last.in.envelope");
|
||||
throw new SOAPExceptionImpl(
|
||||
"Body must be the last element in" + " SOAP Envelope");
|
||||
}
|
||||
return super.addChildElement(name);
|
||||
}
|
||||
|
||||
public SOAPElement addChildElement(QName name) throws SOAPException {
|
||||
// check if body already exists
|
||||
if (getBody() != null) {
|
||||
log.severe("SAAJ0405.ver1_2.body.must.last.in.envelope");
|
||||
throw new SOAPExceptionImpl(
|
||||
"Body must be the last element in" + " SOAP Envelope");
|
||||
}
|
||||
return super.addChildElement(name);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Ideally we should be overriding other addChildElement() methods as well
|
||||
* but we are not adding them here since internally all those call the
|
||||
* method addChildElement(Name name).
|
||||
* In future, if this behaviour changes, then we would need to override
|
||||
* all the rest of them as well.
|
||||
*
|
||||
*/
|
||||
|
||||
public SOAPElement addTextNode(String text) throws SOAPException {
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0416.ver1_2.adding.text.not.legal",
|
||||
getElementQName());
|
||||
throw new SOAPExceptionImpl("Adding text to SOAP 1.2 Envelope is not legal");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,562 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author SAAJ RI Development Team
|
||||
*/
|
||||
package com.sun.xml.internal.messaging.saaj.soap.ver1_2;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.*;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocument;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.impl.*;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants;
|
||||
|
||||
|
||||
public class Fault1_2Impl extends FaultImpl {
|
||||
|
||||
protected static final Logger log =
|
||||
Logger.getLogger(
|
||||
LogDomainConstants.SOAP_VER1_2_DOMAIN,
|
||||
"com.sun.xml.internal.messaging.saaj.soap.ver1_2.LocalStrings");
|
||||
|
||||
private static final QName textName =
|
||||
new QName(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE, "Text");
|
||||
private final QName valueName =
|
||||
new QName(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE, "Value", getPrefix());
|
||||
private final QName subcodeName =
|
||||
new QName(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE, "Subcode", getPrefix());
|
||||
|
||||
private SOAPElement innermostSubCodeElement = null;
|
||||
|
||||
public Fault1_2Impl(SOAPDocumentImpl ownerDoc, String name, String prefix) {
|
||||
super(ownerDoc, NameImpl.createFault1_2Name(name, prefix));
|
||||
}
|
||||
|
||||
public Fault1_2Impl(SOAPDocumentImpl ownerDocument, String prefix) {
|
||||
super(ownerDocument, NameImpl.createFault1_2Name(null, prefix));
|
||||
}
|
||||
|
||||
protected NameImpl getDetailName() {
|
||||
return NameImpl.createSOAP12Name("Detail", getPrefix());
|
||||
}
|
||||
|
||||
protected NameImpl getFaultCodeName() {
|
||||
return NameImpl.createSOAP12Name("Code", getPrefix());
|
||||
}
|
||||
|
||||
protected NameImpl getFaultStringName() {
|
||||
return getFaultReasonName();
|
||||
}
|
||||
|
||||
protected NameImpl getFaultActorName() {
|
||||
return getFaultRoleName();
|
||||
}
|
||||
|
||||
private NameImpl getFaultRoleName() {
|
||||
return NameImpl.createSOAP12Name("Role", getPrefix());
|
||||
}
|
||||
|
||||
private NameImpl getFaultReasonName() {
|
||||
return NameImpl.createSOAP12Name("Reason", getPrefix());
|
||||
}
|
||||
|
||||
private NameImpl getFaultReasonTextName() {
|
||||
return NameImpl.createSOAP12Name("Text", getPrefix());
|
||||
}
|
||||
|
||||
private NameImpl getFaultNodeName() {
|
||||
return NameImpl.createSOAP12Name("Node", getPrefix());
|
||||
}
|
||||
|
||||
private static NameImpl getXmlLangName() {
|
||||
return NameImpl.createXmlName("lang");
|
||||
}
|
||||
|
||||
protected DetailImpl createDetail() {
|
||||
return new Detail1_2Impl(
|
||||
((SOAPDocument) getOwnerDocument()).getDocument());
|
||||
}
|
||||
|
||||
protected FaultElementImpl createSOAPFaultElement(String localName) {
|
||||
return new FaultElement1_2Impl(
|
||||
((SOAPDocument) getOwnerDocument()).getDocument(),
|
||||
localName);
|
||||
}
|
||||
|
||||
protected void checkIfStandardFaultCode(String faultCode, String uri)
|
||||
throws SOAPException {
|
||||
QName qname = new QName(uri, faultCode);
|
||||
if (SOAPConstants.SOAP_DATAENCODINGUNKNOWN_FAULT.equals(qname) ||
|
||||
SOAPConstants.SOAP_MUSTUNDERSTAND_FAULT.equals(qname) ||
|
||||
SOAPConstants.SOAP_RECEIVER_FAULT.equals(qname) ||
|
||||
SOAPConstants.SOAP_SENDER_FAULT.equals(qname) ||
|
||||
SOAPConstants.SOAP_VERSIONMISMATCH_FAULT.equals(qname))
|
||||
return;
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0435.ver1_2.code.not.standard",
|
||||
qname);
|
||||
throw new SOAPExceptionImpl(qname + " is not a standard Code value");
|
||||
}
|
||||
|
||||
protected void finallySetFaultCode(String faultcode) throws SOAPException {
|
||||
SOAPElement value = this.faultCodeElement.addChildElement(valueName);
|
||||
value.addTextNode(faultcode);
|
||||
}
|
||||
|
||||
private void findReasonElement() {
|
||||
findFaultStringElement();
|
||||
}
|
||||
|
||||
public Iterator getFaultReasonTexts() throws SOAPException {
|
||||
// Fault Reason has similar semantics as faultstring
|
||||
if (this.faultStringElement == null)
|
||||
findReasonElement();
|
||||
Iterator eachTextElement =
|
||||
this.faultStringElement.getChildElements(textName);
|
||||
List texts = new ArrayList();
|
||||
while (eachTextElement.hasNext()) {
|
||||
SOAPElement textElement = (SOAPElement) eachTextElement.next();
|
||||
Locale thisLocale = getLocale(textElement);
|
||||
if (thisLocale == null) {
|
||||
log.severe("SAAJ0431.ver1_2.xml.lang.missing");
|
||||
throw new SOAPExceptionImpl("\"xml:lang\" attribute is not present on the Text element");
|
||||
}
|
||||
texts.add(textElement.getValue());
|
||||
}
|
||||
if (texts.isEmpty()) {
|
||||
log.severe("SAAJ0434.ver1_2.text.element.not.present");
|
||||
throw new SOAPExceptionImpl("env:Text must be present inside env:Reason");
|
||||
}
|
||||
return texts.iterator();
|
||||
}
|
||||
|
||||
public void addFaultReasonText(String text, java.util.Locale locale)
|
||||
throws SOAPException {
|
||||
|
||||
if (locale == null) {
|
||||
log.severe("SAAJ0430.ver1_2.locale.required");
|
||||
throw new SOAPException("locale is required and must not be null");
|
||||
}
|
||||
|
||||
// Fault Reason has similar semantics as faultstring
|
||||
if (this.faultStringElement == null)
|
||||
findReasonElement();
|
||||
SOAPElement reasonText;
|
||||
|
||||
if (this.faultStringElement == null) {
|
||||
this.faultStringElement = addSOAPFaultElement("Reason");
|
||||
reasonText =
|
||||
this.faultStringElement.addChildElement(
|
||||
getFaultReasonTextName());
|
||||
} else {
|
||||
removeDefaultFaultString();
|
||||
reasonText = getFaultReasonTextElement(locale);
|
||||
if (reasonText != null) {
|
||||
reasonText.removeContents();
|
||||
} else {
|
||||
reasonText =
|
||||
this.faultStringElement.addChildElement(
|
||||
getFaultReasonTextName());
|
||||
}
|
||||
}
|
||||
|
||||
String xmlLang = localeToXmlLang(locale);
|
||||
reasonText.addAttribute(getXmlLangName(), xmlLang);
|
||||
reasonText.addTextNode(text);
|
||||
}
|
||||
|
||||
private void removeDefaultFaultString() throws SOAPException {
|
||||
SOAPElement reasonText = getFaultReasonTextElement(Locale.getDefault());
|
||||
if (reasonText != null) {
|
||||
String defaultFaultString =
|
||||
"Fault string, and possibly fault code, not set";
|
||||
if (defaultFaultString.equals(reasonText.getValue())) {
|
||||
reasonText.detachNode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getFaultReasonText(Locale locale) throws SOAPException {
|
||||
|
||||
if (locale == null)
|
||||
return null;
|
||||
|
||||
// Fault Reason has similar semantics as faultstring
|
||||
if (this.faultStringElement == null)
|
||||
findReasonElement();
|
||||
|
||||
if (this.faultStringElement != null) {
|
||||
SOAPElement textElement = getFaultReasonTextElement(locale);
|
||||
if (textElement != null) {
|
||||
textElement.normalize();
|
||||
return textElement.getFirstChild().getNodeValue();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Iterator getFaultReasonLocales() throws SOAPException {
|
||||
// Fault Reason has similar semantics as faultstring
|
||||
if (this.faultStringElement == null)
|
||||
findReasonElement();
|
||||
Iterator eachTextElement =
|
||||
this.faultStringElement.getChildElements(textName);
|
||||
List localeSet = new ArrayList();
|
||||
while (eachTextElement.hasNext()) {
|
||||
SOAPElement textElement = (SOAPElement) eachTextElement.next();
|
||||
Locale thisLocale = getLocale(textElement);
|
||||
if (thisLocale == null) {
|
||||
log.severe("SAAJ0431.ver1_2.xml.lang.missing");
|
||||
throw new SOAPExceptionImpl("\"xml:lang\" attribute is not present on the Text element");
|
||||
}
|
||||
localeSet.add(thisLocale);
|
||||
}
|
||||
if (localeSet.isEmpty()) {
|
||||
log.severe("SAAJ0434.ver1_2.text.element.not.present");
|
||||
throw new SOAPExceptionImpl("env:Text elements with mandatory xml:lang attributes must be present inside env:Reason");
|
||||
}
|
||||
return localeSet.iterator();
|
||||
}
|
||||
|
||||
public Locale getFaultStringLocale() {
|
||||
Locale locale = null;
|
||||
try {
|
||||
locale = (Locale) getFaultReasonLocales().next();
|
||||
} catch (SOAPException e) {}
|
||||
return locale;
|
||||
}
|
||||
|
||||
/*
|
||||
* This method assumes that locale and faultStringElement are non-null
|
||||
*/
|
||||
private SOAPElement getFaultReasonTextElement(Locale locale)
|
||||
throws SOAPException {
|
||||
|
||||
// Fault Reason has similar semantics as faultstring
|
||||
Iterator eachTextElement =
|
||||
this.faultStringElement.getChildElements(textName);
|
||||
while (eachTextElement.hasNext()) {
|
||||
SOAPElement textElement = (SOAPElement) eachTextElement.next();
|
||||
Locale thisLocale = getLocale(textElement);
|
||||
if (thisLocale == null) {
|
||||
log.severe("SAAJ0431.ver1_2.xml.lang.missing");
|
||||
throw new SOAPExceptionImpl("\"xml:lang\" attribute is not present on the Text element");
|
||||
}
|
||||
if (thisLocale.equals(locale)) {
|
||||
return textElement;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFaultNode() {
|
||||
SOAPElement faultNode = findChild(getFaultNodeName());
|
||||
if (faultNode == null) {
|
||||
return null;
|
||||
}
|
||||
return faultNode.getValue();
|
||||
}
|
||||
|
||||
public void setFaultNode(String uri) throws SOAPException {
|
||||
SOAPElement faultNode = findChild(getFaultNodeName());
|
||||
if (faultNode != null) {
|
||||
faultNode.detachNode();
|
||||
}
|
||||
faultNode = createSOAPFaultElement(getFaultNodeName());
|
||||
faultNode = faultNode.addTextNode(uri);
|
||||
if (getFaultRole() != null) {
|
||||
insertBefore(faultNode, this.faultActorElement);
|
||||
return;
|
||||
}
|
||||
if (hasDetail()) {
|
||||
insertBefore(faultNode, this.detail);
|
||||
return;
|
||||
}
|
||||
addNode(faultNode);
|
||||
}
|
||||
|
||||
public String getFaultRole() {
|
||||
return getFaultActor();
|
||||
}
|
||||
|
||||
public void setFaultRole(String uri) throws SOAPException {
|
||||
if (this.faultActorElement == null)
|
||||
findFaultActorElement();
|
||||
if (this.faultActorElement != null)
|
||||
this.faultActorElement.detachNode();
|
||||
this.faultActorElement =
|
||||
createSOAPFaultElement(getFaultActorName());
|
||||
this.faultActorElement.addTextNode(uri);
|
||||
if (hasDetail()) {
|
||||
insertBefore(this.faultActorElement, this.detail);
|
||||
return;
|
||||
}
|
||||
addNode(this.faultActorElement);
|
||||
}
|
||||
|
||||
public String getFaultCode() {
|
||||
if (this.faultCodeElement == null)
|
||||
findFaultCodeElement();
|
||||
Iterator codeValues =
|
||||
this.faultCodeElement.getChildElements(valueName);
|
||||
return ((SOAPElement) codeValues.next()).getValue();
|
||||
}
|
||||
|
||||
public QName getFaultCodeAsQName() {
|
||||
String faultcode = getFaultCode();
|
||||
if (faultcode == null) {
|
||||
return null;
|
||||
}
|
||||
if (this.faultCodeElement == null)
|
||||
findFaultCodeElement();
|
||||
Iterator valueElements =
|
||||
this.faultCodeElement.getChildElements(valueName);
|
||||
return convertCodeToQName(
|
||||
faultcode,
|
||||
(SOAPElement) valueElements.next());
|
||||
}
|
||||
|
||||
public Name getFaultCodeAsName() {
|
||||
String faultcode = getFaultCode();
|
||||
if (faultcode == null) {
|
||||
return null;
|
||||
}
|
||||
if (this.faultCodeElement == null)
|
||||
findFaultCodeElement();
|
||||
Iterator valueElements =
|
||||
this.faultCodeElement.getChildElements(valueName);
|
||||
return NameImpl.convertToName(
|
||||
convertCodeToQName(
|
||||
faultcode,
|
||||
(SOAPElement) valueElements.next()));
|
||||
}
|
||||
|
||||
public String getFaultString() {
|
||||
String reason = null;
|
||||
try {
|
||||
//reason = getFaultReasonText(Locale.getDefault());
|
||||
//if (reason == null)
|
||||
reason = (String) getFaultReasonTexts().next();
|
||||
} catch (SOAPException e) {}
|
||||
return reason;
|
||||
}
|
||||
|
||||
public void setFaultString(String faultString) throws SOAPException {
|
||||
addFaultReasonText(faultString, Locale.getDefault());
|
||||
}
|
||||
|
||||
public void setFaultString(
|
||||
String faultString,
|
||||
Locale locale)
|
||||
throws SOAPException {
|
||||
addFaultReasonText(faultString, locale);
|
||||
}
|
||||
|
||||
public void appendFaultSubcode(QName subcode) throws SOAPException {
|
||||
if (subcode == null) {
|
||||
return;
|
||||
}
|
||||
if (subcode.getNamespaceURI() == null ||
|
||||
"".equals(subcode.getNamespaceURI())) {
|
||||
|
||||
log.severe("SAAJ0432.ver1_2.subcode.not.ns.qualified");
|
||||
throw new SOAPExceptionImpl("A Subcode must be namespace-qualified");
|
||||
}
|
||||
if (innermostSubCodeElement == null) {
|
||||
if (faultCodeElement == null)
|
||||
findFaultCodeElement();
|
||||
innermostSubCodeElement = faultCodeElement;
|
||||
}
|
||||
String prefix = null;
|
||||
if (subcode.getPrefix() == null || "".equals(subcode.getPrefix())) {
|
||||
prefix =
|
||||
((ElementImpl) innermostSubCodeElement).getNamespacePrefix(
|
||||
subcode.getNamespaceURI());
|
||||
} else
|
||||
prefix = subcode.getPrefix();
|
||||
if (prefix == null || "".equals(prefix)) {
|
||||
prefix = "ns1";
|
||||
}
|
||||
innermostSubCodeElement =
|
||||
innermostSubCodeElement.addChildElement(subcodeName);
|
||||
SOAPElement subcodeValueElement =
|
||||
innermostSubCodeElement.addChildElement(valueName);
|
||||
((ElementImpl) subcodeValueElement).ensureNamespaceIsDeclared(
|
||||
prefix,
|
||||
subcode.getNamespaceURI());
|
||||
subcodeValueElement.addTextNode(prefix + ":" + subcode.getLocalPart());
|
||||
}
|
||||
|
||||
public void removeAllFaultSubcodes() {
|
||||
if (this.faultCodeElement == null)
|
||||
findFaultCodeElement();
|
||||
Iterator subcodeElements =
|
||||
this.faultCodeElement.getChildElements(subcodeName);
|
||||
if (subcodeElements.hasNext()) {
|
||||
SOAPElement subcode = (SOAPElement) subcodeElements.next();
|
||||
subcode.detachNode();
|
||||
}
|
||||
}
|
||||
|
||||
public Iterator getFaultSubcodes() {
|
||||
if (this.faultCodeElement == null)
|
||||
findFaultCodeElement();
|
||||
final List subcodeList = new ArrayList();
|
||||
SOAPElement currentCodeElement = this.faultCodeElement;
|
||||
Iterator subcodeElements =
|
||||
currentCodeElement.getChildElements(subcodeName);
|
||||
while (subcodeElements.hasNext()) {
|
||||
currentCodeElement = (ElementImpl) subcodeElements.next();
|
||||
Iterator valueElements =
|
||||
currentCodeElement.getChildElements(valueName);
|
||||
SOAPElement valueElement = (SOAPElement) valueElements.next();
|
||||
String code = valueElement.getValue();
|
||||
subcodeList.add(convertCodeToQName(code, valueElement));
|
||||
subcodeElements = currentCodeElement.getChildElements(subcodeName);
|
||||
}
|
||||
//return subcodeList.iterator();
|
||||
return new Iterator() {
|
||||
Iterator subCodeIter = subcodeList.iterator();
|
||||
|
||||
public boolean hasNext() {
|
||||
return subCodeIter.hasNext();
|
||||
}
|
||||
|
||||
public Object next() {
|
||||
return subCodeIter.next();
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException(
|
||||
"Method remove() not supported on SubCodes Iterator");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static Locale getLocale(SOAPElement reasonText) {
|
||||
return xmlLangToLocale(reasonText.getAttributeValue(getXmlLangName()));
|
||||
}
|
||||
|
||||
/*
|
||||
* Override setEncodingStyle of ElementImpl to restrict adding encodingStyle
|
||||
* attribute to SOAP Fault (SOAP 1.2 spec, part 1, section 5.1.1)
|
||||
*/
|
||||
public void setEncodingStyle(String encodingStyle) throws SOAPException {
|
||||
log.severe("SAAJ0407.ver1_2.no.encodingStyle.in.fault");
|
||||
throw new SOAPExceptionImpl("encodingStyle attribute cannot appear on Fault");
|
||||
}
|
||||
|
||||
public SOAPElement addAttribute(Name name, String value)
|
||||
throws SOAPException {
|
||||
if (name.getLocalName().equals("encodingStyle")
|
||||
&& name.getURI().equals(NameImpl.SOAP12_NAMESPACE)) {
|
||||
setEncodingStyle(value);
|
||||
}
|
||||
return super.addAttribute(name, value);
|
||||
}
|
||||
|
||||
public SOAPElement addAttribute(QName name, String value)
|
||||
throws SOAPException {
|
||||
if (name.getLocalPart().equals("encodingStyle")
|
||||
&& name.getNamespaceURI().equals(NameImpl.SOAP12_NAMESPACE)) {
|
||||
setEncodingStyle(value);
|
||||
}
|
||||
return super.addAttribute(name, value);
|
||||
}
|
||||
|
||||
public SOAPElement addTextNode(String text) throws SOAPException {
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0416.ver1_2.adding.text.not.legal",
|
||||
getElementQName());
|
||||
throw new SOAPExceptionImpl("Adding text to SOAP 1.2 Fault is not legal");
|
||||
}
|
||||
|
||||
public SOAPElement addChildElement(SOAPElement element)
|
||||
throws SOAPException {
|
||||
String localName = element.getLocalName();
|
||||
if ("Detail".equalsIgnoreCase(localName)) {
|
||||
if (hasDetail()) {
|
||||
log.severe("SAAJ0436.ver1_2.detail.exists.error");
|
||||
throw new SOAPExceptionImpl("Cannot add Detail, Detail already exists");
|
||||
}
|
||||
String uri = element.getElementQName().getNamespaceURI();
|
||||
if (!uri.equals(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE)) {
|
||||
log.severe("SAAJ0437.ver1_2.version.mismatch.error");
|
||||
throw new SOAPExceptionImpl("Cannot add Detail, Incorrect SOAP version specified for Detail element");
|
||||
}
|
||||
}
|
||||
if (element instanceof Detail1_2Impl) {
|
||||
ElementImpl importedElement = (ElementImpl) importElement(element);
|
||||
addNode(importedElement);
|
||||
return convertToSoapElement(importedElement);
|
||||
} else
|
||||
return super.addChildElement(element);
|
||||
}
|
||||
|
||||
protected boolean isStandardFaultElement(String localName) {
|
||||
if (localName.equalsIgnoreCase("code") ||
|
||||
localName.equalsIgnoreCase("reason") ||
|
||||
localName.equalsIgnoreCase("node") ||
|
||||
localName.equalsIgnoreCase("role") ||
|
||||
localName.equalsIgnoreCase("detail")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected QName getDefaultFaultCode() {
|
||||
return SOAPConstants.SOAP_SENDER_FAULT;
|
||||
}
|
||||
|
||||
protected FaultElementImpl createSOAPFaultElement(QName qname) {
|
||||
return new FaultElement1_2Impl(
|
||||
((SOAPDocument) getOwnerDocument()).getDocument(),
|
||||
qname);
|
||||
}
|
||||
|
||||
protected FaultElementImpl createSOAPFaultElement(Name qname) {
|
||||
return new FaultElement1_2Impl(
|
||||
((SOAPDocument) getOwnerDocument()).getDocument(),
|
||||
(NameImpl)qname);
|
||||
}
|
||||
|
||||
public void setFaultActor(String faultActor) throws SOAPException {
|
||||
this.setFaultRole(faultActor);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author SAAJ RI Development Team
|
||||
*/
|
||||
package com.sun.xml.internal.messaging.saaj.soap.ver1_2;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.SOAPException;
|
||||
import javax.xml.soap.SOAPElement;
|
||||
import javax.xml.soap.Name;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.impl.FaultElementImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
|
||||
|
||||
public class FaultElement1_2Impl extends FaultElementImpl {
|
||||
|
||||
public FaultElement1_2Impl(SOAPDocumentImpl ownerDoc, NameImpl qname) {
|
||||
super(ownerDoc, qname);
|
||||
}
|
||||
|
||||
public FaultElement1_2Impl(SOAPDocumentImpl ownerDoc, QName qname) {
|
||||
super(ownerDoc, qname);
|
||||
}
|
||||
|
||||
public FaultElement1_2Impl(SOAPDocumentImpl ownerDoc, String localName) {
|
||||
super(ownerDoc, NameImpl.createSOAP12Name(localName));
|
||||
}
|
||||
|
||||
protected boolean isStandardFaultElement() {
|
||||
String localName = elementQName.getLocalPart();
|
||||
if (localName.equalsIgnoreCase("code") ||
|
||||
localName.equalsIgnoreCase("reason") ||
|
||||
localName.equalsIgnoreCase("node") ||
|
||||
localName.equalsIgnoreCase("role")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public SOAPElement setElementQName(QName newName) throws SOAPException {
|
||||
if (!isStandardFaultElement()) {
|
||||
FaultElement1_2Impl copy =
|
||||
new FaultElement1_2Impl((SOAPDocumentImpl) getOwnerDocument(), newName);
|
||||
return replaceElementWithSOAPElement(this,copy);
|
||||
} else {
|
||||
return super.setElementQName(newName);
|
||||
}
|
||||
}
|
||||
|
||||
public void setEncodingStyle(String encodingStyle) throws SOAPException {
|
||||
log.severe("SAAJ0408.ver1_2.no.encodingStyle.in.fault.child");
|
||||
throw new SOAPExceptionImpl("encodingStyle attribute cannot appear on a Fault child element");
|
||||
}
|
||||
|
||||
public SOAPElement addAttribute(Name name, String value)
|
||||
throws SOAPException {
|
||||
if (name.getLocalName().equals("encodingStyle")
|
||||
&& name.getURI().equals(NameImpl.SOAP12_NAMESPACE)) {
|
||||
setEncodingStyle(value);
|
||||
}
|
||||
return super.addAttribute(name, value);
|
||||
}
|
||||
|
||||
public SOAPElement addAttribute(QName name, String value)
|
||||
throws SOAPException {
|
||||
if (name.getLocalPart().equals("encodingStyle")
|
||||
&& name.getNamespaceURI().equals(NameImpl.SOAP12_NAMESPACE)) {
|
||||
setEncodingStyle(value);
|
||||
}
|
||||
return super.addAttribute(name, value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author SAAJ RI Development Team
|
||||
*/
|
||||
package com.sun.xml.internal.messaging.saaj.soap.ver1_2;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Iterator;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.*;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocument;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.impl.HeaderElementImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.impl.HeaderImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants;
|
||||
|
||||
|
||||
public class Header1_2Impl extends HeaderImpl {
|
||||
|
||||
protected static final Logger log =
|
||||
Logger.getLogger(
|
||||
LogDomainConstants.SOAP_VER1_2_DOMAIN,
|
||||
"com.sun.xml.internal.messaging.saaj.soap.ver1_2.LocalStrings");
|
||||
|
||||
public Header1_2Impl(SOAPDocumentImpl ownerDocument, String prefix) {
|
||||
super(ownerDocument, NameImpl.createHeader1_2Name(prefix));
|
||||
}
|
||||
|
||||
protected NameImpl getNotUnderstoodName() {
|
||||
return NameImpl.createNotUnderstood1_2Name(null);
|
||||
}
|
||||
|
||||
protected NameImpl getUpgradeName() {
|
||||
return NameImpl.createUpgrade1_2Name(null);
|
||||
}
|
||||
|
||||
protected NameImpl getSupportedEnvelopeName() {
|
||||
return NameImpl.createSupportedEnvelope1_2Name(null);
|
||||
}
|
||||
|
||||
public SOAPHeaderElement addNotUnderstoodHeaderElement(final QName sourceName)
|
||||
throws SOAPException {
|
||||
|
||||
if (sourceName == null) {
|
||||
log.severe("SAAJ0410.ver1_2.no.null.to.addNotUnderstoodHeader");
|
||||
throw new SOAPException("Cannot pass NULL to addNotUnderstoodHeaderElement");
|
||||
}
|
||||
if ("".equals(sourceName.getNamespaceURI())) {
|
||||
log.severe("SAAJ0417.ver1_2.qname.not.ns.qualified");
|
||||
throw new SOAPException("The qname passed to addNotUnderstoodHeaderElement must be namespace-qualified");
|
||||
}
|
||||
String prefix = sourceName.getPrefix();
|
||||
if ("".equals(prefix)) {
|
||||
prefix = "ns1";
|
||||
}
|
||||
Name notunderstoodName = getNotUnderstoodName();
|
||||
SOAPHeaderElement notunderstoodHeaderElement =
|
||||
(SOAPHeaderElement) addChildElement(notunderstoodName);
|
||||
notunderstoodHeaderElement.addAttribute(
|
||||
NameImpl.createFromUnqualifiedName("qname"),
|
||||
getQualifiedName(
|
||||
new QName(
|
||||
sourceName.getNamespaceURI(),
|
||||
sourceName.getLocalPart(),
|
||||
prefix)));
|
||||
notunderstoodHeaderElement.addNamespaceDeclaration(
|
||||
prefix,
|
||||
sourceName.getNamespaceURI());
|
||||
return notunderstoodHeaderElement;
|
||||
}
|
||||
|
||||
public SOAPElement addTextNode(String text) throws SOAPException {
|
||||
log.log(
|
||||
Level.SEVERE,
|
||||
"SAAJ0416.ver1_2.adding.text.not.legal",
|
||||
getElementQName());
|
||||
throw new SOAPExceptionImpl("Adding text to SOAP 1.2 Header is not legal");
|
||||
}
|
||||
|
||||
protected SOAPHeaderElement createHeaderElement(Name name)
|
||||
throws SOAPException {
|
||||
String uri = name.getURI();
|
||||
if (uri == null || uri.equals("")) {
|
||||
log.severe("SAAJ0413.ver1_2.header.elems.must.be.ns.qualified");
|
||||
throw new SOAPExceptionImpl("SOAP 1.2 header elements must be namespace qualified");
|
||||
}
|
||||
return new HeaderElement1_2Impl(
|
||||
((SOAPDocument) getOwnerDocument()).getDocument(),
|
||||
name);
|
||||
}
|
||||
|
||||
protected SOAPHeaderElement createHeaderElement(QName name)
|
||||
throws SOAPException {
|
||||
String uri = name.getNamespaceURI();
|
||||
if (uri == null || uri.equals("")) {
|
||||
log.severe("SAAJ0413.ver1_2.header.elems.must.be.ns.qualified");
|
||||
throw new SOAPExceptionImpl("SOAP 1.2 header elements must be namespace qualified");
|
||||
}
|
||||
return new HeaderElement1_2Impl(
|
||||
((SOAPDocument) getOwnerDocument()).getDocument(),
|
||||
name);
|
||||
}
|
||||
|
||||
public void setEncodingStyle(String encodingStyle) throws SOAPException {
|
||||
log.severe("SAAJ0409.ver1_2.no.encodingstyle.in.header");
|
||||
throw new SOAPExceptionImpl("encodingStyle attribute cannot appear on Header");
|
||||
}
|
||||
|
||||
public SOAPElement addAttribute(Name name, String value)
|
||||
throws SOAPException {
|
||||
if (name.getLocalName().equals("encodingStyle")
|
||||
&& name.getURI().equals(NameImpl.SOAP12_NAMESPACE)) {
|
||||
|
||||
setEncodingStyle(value);
|
||||
}
|
||||
return super.addAttribute(name, value);
|
||||
}
|
||||
|
||||
public SOAPElement addAttribute(QName name, String value)
|
||||
throws SOAPException {
|
||||
if (name.getLocalPart().equals("encodingStyle")
|
||||
&& name.getNamespaceURI().equals(NameImpl.SOAP12_NAMESPACE)) {
|
||||
|
||||
setEncodingStyle(value);
|
||||
}
|
||||
return super.addAttribute(name, value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author SAAJ RI Development Team
|
||||
*/
|
||||
package com.sun.xml.internal.messaging.saaj.soap.ver1_2;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.Name;
|
||||
import javax.xml.soap.SOAPElement;
|
||||
import javax.xml.soap.SOAPException;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.impl.HeaderElementImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
|
||||
|
||||
public class HeaderElement1_2Impl extends HeaderElementImpl {
|
||||
|
||||
private static final Logger log =
|
||||
Logger.getLogger(HeaderElement1_2Impl.class.getName(),
|
||||
"com.sun.xml.internal.messaging.saaj.soap.ver1_2.LocalStrings");
|
||||
|
||||
public HeaderElement1_2Impl(SOAPDocumentImpl ownerDoc, Name qname) {
|
||||
super(ownerDoc, qname);
|
||||
}
|
||||
public HeaderElement1_2Impl(SOAPDocumentImpl ownerDoc, QName qname) {
|
||||
super(ownerDoc, qname);
|
||||
}
|
||||
|
||||
public SOAPElement setElementQName(QName newName) throws SOAPException {
|
||||
HeaderElementImpl copy =
|
||||
new HeaderElement1_2Impl((SOAPDocumentImpl)getOwnerDocument(), newName);
|
||||
return replaceElementWithSOAPElement(this,copy);
|
||||
}
|
||||
|
||||
protected NameImpl getRoleAttributeName() {
|
||||
return NameImpl.create("role", null, NameImpl.SOAP12_NAMESPACE);
|
||||
}
|
||||
|
||||
// Actor equivalent to Role in SOAP 1.2
|
||||
protected NameImpl getActorAttributeName() {
|
||||
return getRoleAttributeName();
|
||||
}
|
||||
|
||||
protected NameImpl getMustunderstandAttributeName() {
|
||||
return NameImpl.create("mustUnderstand", null, NameImpl.SOAP12_NAMESPACE);
|
||||
}
|
||||
|
||||
// mustUnderstand attribute has literal value "true" or "false"
|
||||
protected String getMustunderstandLiteralValue(boolean mustUnderstand) {
|
||||
return (mustUnderstand == true ? "true" : "false");
|
||||
}
|
||||
|
||||
protected boolean getMustunderstandAttributeValue(String mu) {
|
||||
if (mu.equals("true") || mu.equals("1"))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
protected NameImpl getRelayAttributeName() {
|
||||
return NameImpl.create("relay", null, NameImpl.SOAP12_NAMESPACE);
|
||||
}
|
||||
|
||||
//relay attribute has literal value "true" or "false"
|
||||
protected String getRelayLiteralValue(boolean relay) {
|
||||
return (relay == true ? "true" : "false");
|
||||
}
|
||||
|
||||
protected boolean getRelayAttributeValue(String relay) {
|
||||
if (relay.equals("true") || relay.equals("1"))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
protected String getActorOrRole() {
|
||||
return getRole();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author SAAJ RI Development Team
|
||||
*/
|
||||
package com.sun.xml.internal.messaging.saaj.soap.ver1_2;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.xml.soap.*;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.ContentType;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.MessageImpl;
|
||||
|
||||
public class Message1_2Impl extends MessageImpl implements SOAPConstants{
|
||||
|
||||
public Message1_2Impl() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Message1_2Impl(SOAPMessage msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public Message1_2Impl(boolean isFastInfoset, boolean acceptFastInfoset) {
|
||||
super(isFastInfoset, acceptFastInfoset);
|
||||
}
|
||||
|
||||
// unused. can we delete this? - Kohsuke
|
||||
public Message1_2Impl(MimeHeaders headers, InputStream in)
|
||||
throws IOException, SOAPExceptionImpl {
|
||||
super(headers, in);
|
||||
}
|
||||
|
||||
public Message1_2Impl(MimeHeaders headers, ContentType ct, int stat, InputStream in)
|
||||
throws SOAPExceptionImpl {
|
||||
super(headers,ct,stat,in);
|
||||
}
|
||||
|
||||
public SOAPPart getSOAPPart() {
|
||||
if (soapPartImpl == null)
|
||||
soapPartImpl = new SOAPPart1_2Impl(this);
|
||||
|
||||
return soapPartImpl;
|
||||
}
|
||||
|
||||
protected boolean isCorrectSoapVersion(int contentTypeId) {
|
||||
return (contentTypeId & SOAP1_2_FLAG) != 0;
|
||||
}
|
||||
|
||||
protected String getExpectedContentType() {
|
||||
return isFastInfoset ? "application/soap+fastinfoset" : "application/soap+xml";
|
||||
}
|
||||
|
||||
protected String getExpectedAcceptHeader() {
|
||||
String accept = "application/soap+xml, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2";
|
||||
return acceptFastInfoset ? ("application/soap+fastinfoset, " + accept) : accept;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author SAAJ RI Development Team
|
||||
*/
|
||||
package com.sun.xml.internal.messaging.saaj.soap.ver1_2;
|
||||
|
||||
import javax.xml.soap.Detail;
|
||||
import javax.xml.soap.SOAPException;
|
||||
import javax.xml.soap.SOAPFault;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.SOAPFactoryImpl;
|
||||
|
||||
public class SOAPFactory1_2Impl extends SOAPFactoryImpl {
|
||||
protected SOAPDocumentImpl createDocument() {
|
||||
return (new SOAPPart1_2Impl()).getDocument();
|
||||
}
|
||||
|
||||
public Detail createDetail() throws SOAPException {
|
||||
return new Detail1_2Impl(createDocument());
|
||||
}
|
||||
|
||||
public SOAPFault createFault(String reasonText, QName faultCode)
|
||||
throws SOAPException {
|
||||
if (faultCode == null) {
|
||||
throw new IllegalArgumentException("faultCode argument for createFault was passed NULL");
|
||||
}
|
||||
if (reasonText == null) {
|
||||
throw new IllegalArgumentException("reasonText argument for createFault was passed NULL");
|
||||
}
|
||||
Fault1_2Impl fault = new Fault1_2Impl(createDocument(), null);
|
||||
fault.setFaultCode(faultCode);
|
||||
fault.setFaultString(reasonText);
|
||||
return fault;
|
||||
}
|
||||
|
||||
public SOAPFault createFault() throws SOAPException {
|
||||
Fault1_2Impl fault = new Fault1_2Impl(createDocument(), null);
|
||||
fault.setFaultCode(fault.getDefaultFaultCode());
|
||||
fault.setFaultString("Fault string, and possibly fault code, not set");
|
||||
return fault;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JAX-RPC RI Development Team
|
||||
*/
|
||||
package com.sun.xml.internal.messaging.saaj.soap.ver1_2;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.xml.soap.*;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.MessageFactoryImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.MessageImpl;
|
||||
|
||||
public class SOAPMessageFactory1_2Impl extends MessageFactoryImpl {
|
||||
|
||||
public SOAPMessage createMessage() throws SOAPException {
|
||||
return new Message1_2Impl();
|
||||
}
|
||||
|
||||
public SOAPMessage createMessage(boolean isFastInfoset,
|
||||
boolean acceptFastInfoset) throws SOAPException
|
||||
{
|
||||
return new Message1_2Impl(isFastInfoset, acceptFastInfoset);
|
||||
}
|
||||
|
||||
public SOAPMessage createMessage(MimeHeaders headers, InputStream in) throws IOException, SOAPExceptionImpl {
|
||||
|
||||
if (headers == null) {
|
||||
headers = new MimeHeaders();
|
||||
}
|
||||
|
||||
if (getContentType(headers) == null) {
|
||||
headers.setHeader("Content-Type", SOAPConstants.SOAP_1_2_CONTENT_TYPE);
|
||||
}
|
||||
|
||||
MessageImpl msg = new Message1_2Impl(headers, in);
|
||||
msg.setLazyAttachments(lazyAttachments);
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author SAAJ RI Development Team
|
||||
*/
|
||||
package com.sun.xml.internal.messaging.saaj.soap.ver1_2;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.xml.soap.SOAPConstants;
|
||||
import javax.xml.soap.SOAPException;
|
||||
import javax.xml.transform.Source;
|
||||
|
||||
import com.sun.xml.internal.messaging.saaj.soap.*;
|
||||
import com.sun.xml.internal.messaging.saaj.soap.impl.EnvelopeImpl;
|
||||
import com.sun.xml.internal.messaging.saaj.util.XMLDeclarationParser;
|
||||
|
||||
public class SOAPPart1_2Impl extends SOAPPartImpl implements SOAPConstants{
|
||||
|
||||
protected static final Logger log =
|
||||
Logger.getLogger(SOAPPart1_2Impl.class.getName(),
|
||||
"com.sun.xml.internal.messaging.saaj.soap.ver1_2.LocalStrings");
|
||||
|
||||
public SOAPPart1_2Impl() {
|
||||
super();
|
||||
}
|
||||
|
||||
public SOAPPart1_2Impl(MessageImpl message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
protected String getContentType() {
|
||||
return "application/soap+xml";
|
||||
}
|
||||
|
||||
protected Envelope createEmptyEnvelope(String prefix) throws SOAPException {
|
||||
return new Envelope1_2Impl(getDocument(), prefix, true, true);
|
||||
}
|
||||
|
||||
protected Envelope createEnvelopeFromSource() throws SOAPException {
|
||||
XMLDeclarationParser parser = lookForXmlDecl();
|
||||
Source tmp = source;
|
||||
source = null;
|
||||
EnvelopeImpl envelope = (EnvelopeImpl)EnvelopeFactory.createEnvelope(tmp, this);
|
||||
if (!envelope.getNamespaceURI().equals(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE)) {
|
||||
log.severe("SAAJ0415.ver1_2.msg.invalid.soap1.2");
|
||||
throw new SOAPException("InputStream does not represent a valid SOAP 1.2 Message");
|
||||
}
|
||||
|
||||
if (parser != null) { //can be null if source was a DomSource and not StreamSource
|
||||
if (!omitXmlDecl) {
|
||||
envelope.setOmitXmlDecl("no");
|
||||
envelope.setXmlDecl(parser.getXmlDeclaration());
|
||||
envelope.setCharsetEncoding(parser.getEncoding());
|
||||
}
|
||||
}
|
||||
return envelope;
|
||||
|
||||
}
|
||||
|
||||
protected SOAPPartImpl duplicateType() {
|
||||
return new SOAPPart1_2Impl();
|
||||
}
|
||||
|
||||
}
|
||||
272
jdkSrc/jdk8/com/sun/xml/internal/messaging/saaj/util/Base64.java
Normal file
272
jdkSrc/jdk8/com/sun/xml/internal/messaging/saaj/util/Base64.java
Normal file
@@ -0,0 +1,272 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.util;
|
||||
|
||||
|
||||
// Cut & paste from tomcat
|
||||
|
||||
/**
|
||||
* This class provides encode/decode for RFC 2045 Base64 as
|
||||
* defined by RFC 2045, N. Freed and N. Borenstein.
|
||||
* RFC 2045: Multipurpose Internet Mail Extensions (MIME)
|
||||
* Part One: Format of Internet Message Bodies. Reference
|
||||
* 1996 Available at: http://www.ietf.org/rfc/rfc2045.txt
|
||||
* This class is used by XML Schema binary format validation
|
||||
*
|
||||
* @author Jeffrey Rodriguez
|
||||
* @version
|
||||
*/
|
||||
public final class Base64 {
|
||||
|
||||
|
||||
static private final int BASELENGTH = 255;
|
||||
static private final int LOOKUPLENGTH = 63;
|
||||
static private final int TWENTYFOURBITGROUP = 24;
|
||||
static private final int EIGHTBIT = 8;
|
||||
static private final int SIXTEENBIT = 16;
|
||||
static private final int SIXBIT = 6;
|
||||
static private final int FOURBYTE = 4;
|
||||
|
||||
|
||||
static private final byte PAD = ( byte ) '=';
|
||||
static private byte [] base64Alphabet = new byte[BASELENGTH];
|
||||
static private byte [] lookUpBase64Alphabet = new byte[LOOKUPLENGTH];
|
||||
|
||||
static {
|
||||
|
||||
for (int i = 0; i<BASELENGTH; i++ ) {
|
||||
base64Alphabet[i] = -1;
|
||||
}
|
||||
for ( int i = 'Z'; i >= 'A'; i-- ) {
|
||||
base64Alphabet[i] = (byte) (i-'A');
|
||||
}
|
||||
for ( int i = 'z'; i>= 'a'; i--) {
|
||||
base64Alphabet[i] = (byte) ( i-'a' + 26);
|
||||
}
|
||||
|
||||
for ( int i = '9'; i >= '0'; i--) {
|
||||
base64Alphabet[i] = (byte) (i-'0' + 52);
|
||||
}
|
||||
|
||||
base64Alphabet['+'] = 62;
|
||||
base64Alphabet['/'] = 63;
|
||||
|
||||
for (int i = 0; i<=25; i++ )
|
||||
lookUpBase64Alphabet[i] = (byte) ('A'+i );
|
||||
|
||||
for (int i = 26, j = 0; i<=51; i++, j++ )
|
||||
lookUpBase64Alphabet[i] = (byte) ('a'+ j );
|
||||
|
||||
for (int i = 52, j = 0; i<=61; i++, j++ )
|
||||
lookUpBase64Alphabet[i] = (byte) ('0' + j );
|
||||
|
||||
}
|
||||
|
||||
|
||||
static boolean isBase64( byte octect ) {
|
||||
//shall we ignore white space? JEFF??
|
||||
return(octect == PAD || base64Alphabet[octect] != -1 );
|
||||
}
|
||||
|
||||
|
||||
static boolean isArrayByteBase64( byte[] arrayOctect ) {
|
||||
int length = arrayOctect.length;
|
||||
if ( length == 0 )
|
||||
return false;
|
||||
for ( int i=0; i < length; i++ ) {
|
||||
if ( Base64.isBase64( arrayOctect[i] ) == false)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes hex octects into Base64
|
||||
*
|
||||
* @param binaryData Array containing binaryData
|
||||
* @return Encoded Base64 array
|
||||
*/
|
||||
public static byte[] encode( byte[] binaryData ) {
|
||||
int lengthDataBits = binaryData.length*EIGHTBIT;
|
||||
int fewerThan24bits = lengthDataBits%TWENTYFOURBITGROUP;
|
||||
int numberTriplets = lengthDataBits/TWENTYFOURBITGROUP;
|
||||
byte encodedData[] = null;
|
||||
|
||||
|
||||
if ( fewerThan24bits != 0 ) //data not divisible by 24 bit
|
||||
encodedData = new byte[ (numberTriplets + 1 )*4 ];
|
||||
else // 16 or 8 bit
|
||||
encodedData = new byte[ numberTriplets*4 ];
|
||||
|
||||
byte k=0, l=0, b1=0,b2=0,b3=0;
|
||||
|
||||
int encodedIndex = 0;
|
||||
int dataIndex = 0;
|
||||
int i = 0;
|
||||
for ( i = 0; i<numberTriplets; i++ ) {
|
||||
|
||||
dataIndex = i*3;
|
||||
b1 = binaryData[dataIndex];
|
||||
b2 = binaryData[dataIndex + 1];
|
||||
b3 = binaryData[dataIndex + 2];
|
||||
|
||||
l = (byte)(b2 & 0x0f);
|
||||
k = (byte)(b1 & 0x03);
|
||||
|
||||
encodedIndex = i*4;
|
||||
encodedData[encodedIndex] = lookUpBase64Alphabet[ b1 >>2 ];
|
||||
encodedData[encodedIndex+1] = lookUpBase64Alphabet[(b2 >>4 ) |
|
||||
( k<<4 )];
|
||||
encodedData[encodedIndex+2] = lookUpBase64Alphabet[ (l <<2 ) |
|
||||
( b3>>6)];
|
||||
encodedData[encodedIndex+3] = lookUpBase64Alphabet[ b3 & 0x3f ];
|
||||
}
|
||||
|
||||
// form integral number of 6-bit groups
|
||||
dataIndex = i*3;
|
||||
encodedIndex = i*4;
|
||||
if (fewerThan24bits == EIGHTBIT ) {
|
||||
b1 = binaryData[dataIndex];
|
||||
k = (byte) ( b1 &0x03 );
|
||||
encodedData[encodedIndex] = lookUpBase64Alphabet[ b1 >>2 ];
|
||||
encodedData[encodedIndex + 1] = lookUpBase64Alphabet[ k<<4 ];
|
||||
encodedData[encodedIndex + 2] = PAD;
|
||||
encodedData[encodedIndex + 3] = PAD;
|
||||
} else if ( fewerThan24bits == SIXTEENBIT ) {
|
||||
|
||||
b1 = binaryData[dataIndex];
|
||||
b2 = binaryData[dataIndex +1 ];
|
||||
l = ( byte ) ( b2 &0x0f );
|
||||
k = ( byte ) ( b1 &0x03 );
|
||||
encodedData[encodedIndex] = lookUpBase64Alphabet[ b1 >>2 ];
|
||||
encodedData[encodedIndex + 1] = lookUpBase64Alphabet[ (b2 >>4 )
|
||||
| ( k<<4 )];
|
||||
encodedData[encodedIndex + 2] = lookUpBase64Alphabet[ l<<2 ];
|
||||
encodedData[encodedIndex + 3] = PAD;
|
||||
}
|
||||
return encodedData;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Decodes Base64 data into octects
|
||||
*
|
||||
* @param binaryData Byte array containing Base64 data
|
||||
* @return Array containind decoded data.
|
||||
*/
|
||||
public byte[] decode( byte[] base64Data ) {
|
||||
int numberQuadruple = base64Data.length/FOURBYTE;
|
||||
byte decodedData[] = null;
|
||||
byte b1=0,b2=0,b3=0, b4=0, marker0=0, marker1=0;
|
||||
|
||||
// Throw away anything not in base64Data
|
||||
// Adjust size
|
||||
|
||||
int encodedIndex = 0;
|
||||
int dataIndex = 0;
|
||||
decodedData = new byte[ numberQuadruple*3 + 1 ];
|
||||
|
||||
for (int i = 0; i<numberQuadruple; i++ ) {
|
||||
dataIndex = i*4;
|
||||
marker0 = base64Data[dataIndex +2];
|
||||
marker1 = base64Data[dataIndex +3];
|
||||
|
||||
b1 = base64Alphabet[base64Data[dataIndex]];
|
||||
b2 = base64Alphabet[base64Data[dataIndex +1]];
|
||||
|
||||
if ( marker0 != PAD && marker1 != PAD ) { //No PAD e.g 3cQl
|
||||
b3 = base64Alphabet[ marker0 ];
|
||||
b4 = base64Alphabet[ marker1 ];
|
||||
|
||||
decodedData[encodedIndex] = (byte)( b1 <<2 | b2>>4 ) ;
|
||||
decodedData[encodedIndex+1] = (byte)(((b2 & 0xf)<<4 ) |(
|
||||
(b3>>2) & 0xf) );
|
||||
decodedData[encodedIndex+2] = (byte)( b3<<6 | b4 );
|
||||
} else if ( marker0 == PAD ) { //Two PAD e.g. 3c[Pad][Pad]
|
||||
decodedData[encodedIndex] = (byte)( b1 <<2 | b2>>4 ) ;
|
||||
decodedData[encodedIndex+1] = (byte)((b2 & 0xf)<<4 );
|
||||
decodedData[encodedIndex+2] = (byte) 0;
|
||||
} else if ( marker1 == PAD ) { //One PAD e.g. 3cQ[Pad]
|
||||
b3 = base64Alphabet[ marker0 ];
|
||||
|
||||
decodedData[encodedIndex] = (byte)( b1 <<2 | b2>>4 );
|
||||
decodedData[encodedIndex+1] = (byte)(((b2 & 0xf)<<4 ) |(
|
||||
(b3>>2) & 0xf) );
|
||||
decodedData[encodedIndex+2] = (byte)( b3<<6);
|
||||
}
|
||||
encodedIndex += 3;
|
||||
}
|
||||
return decodedData;
|
||||
|
||||
}
|
||||
|
||||
static final int base64[]= {
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63,
|
||||
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64,
|
||||
64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
|
||||
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64,
|
||||
64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
|
||||
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
|
||||
};
|
||||
|
||||
public static String base64Decode( String orig ) {
|
||||
char chars[]=orig.toCharArray();
|
||||
StringBuffer sb=new StringBuffer();
|
||||
int i=0;
|
||||
|
||||
int shift = 0; // # of excess bits stored in accum
|
||||
int acc = 0;
|
||||
|
||||
for (i=0; i<chars.length; i++) {
|
||||
int v = base64[ chars[i] & 0xFF ];
|
||||
|
||||
if ( v >= 64 ) {
|
||||
if( chars[i] != '=' )
|
||||
System.out.println("Wrong char in base64: " + chars[i]);
|
||||
} else {
|
||||
acc= ( acc << 6 ) | v;
|
||||
shift += 6;
|
||||
if ( shift >= 8 ) {
|
||||
shift -= 8;
|
||||
sb.append( (char) ((acc >> shift) & 0xff));
|
||||
}
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.util;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
// This class just gives access to the underlying buffer without copying.
|
||||
|
||||
public class ByteInputStream extends ByteArrayInputStream {
|
||||
private static final byte[] EMPTY_ARRAY = new byte[0];
|
||||
|
||||
public ByteInputStream() {
|
||||
this(EMPTY_ARRAY, 0);
|
||||
}
|
||||
|
||||
public ByteInputStream(byte buf[], int length) {
|
||||
super(buf, 0, length);
|
||||
}
|
||||
|
||||
public ByteInputStream(byte buf[], int offset, int length) {
|
||||
super(buf, offset, length);
|
||||
}
|
||||
|
||||
public byte[] getBytes() {
|
||||
return buf;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
reset();
|
||||
}
|
||||
|
||||
public void setBuf(byte[] buf) {
|
||||
this.buf = buf;
|
||||
this.pos = 0;
|
||||
this.count = buf.length;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.messaging.saaj.util;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
/**
|
||||
* Customized {@link BufferedOutputStream}.
|
||||
*
|
||||
* <p>
|
||||
* Compared to {@link BufferedOutputStream},
|
||||
* this class:
|
||||
*
|
||||
* <ol>
|
||||
* <li>doesn't do synchronization
|
||||
* <li>allows access to the raw buffer
|
||||
* <li>almost no parameter check
|
||||
*/
|
||||
public final class ByteOutputStream extends OutputStream {
|
||||
/**
|
||||
* The buffer where data is stored.
|
||||
*/
|
||||
protected byte[] buf;
|
||||
|
||||
/**
|
||||
* The number of valid bytes in the buffer.
|
||||
*/
|
||||
protected int count = 0;
|
||||
|
||||
public ByteOutputStream() {
|
||||
this(1024);
|
||||
}
|
||||
|
||||
public ByteOutputStream(int size) {
|
||||
buf = new byte[size];
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all the bytes from this input into this buffer.
|
||||
*/
|
||||
public void write(InputStream in) throws IOException {
|
||||
if (in instanceof ByteArrayInputStream) {
|
||||
int size = in.available();
|
||||
ensureCapacity(size);
|
||||
count += in.read(buf,count,size);
|
||||
return;
|
||||
}
|
||||
while(true) {
|
||||
int cap = buf.length-count;
|
||||
int sz = in.read(buf,count,cap);
|
||||
if(sz<0) return; // hit EOS
|
||||
|
||||
count += sz;
|
||||
if(cap==sz)
|
||||
// the buffer filled up. double the buffer
|
||||
ensureCapacity(count);
|
||||
}
|
||||
}
|
||||
|
||||
public void write(int b) {
|
||||
ensureCapacity(1);
|
||||
buf[count] = (byte) b;
|
||||
count++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that the buffer has at least this much space.
|
||||
*/
|
||||
private void ensureCapacity(int space) {
|
||||
int newcount = space + count;
|
||||
if (newcount > buf.length) {
|
||||
byte[] newbuf = new byte[Math.max(buf.length << 1, newcount)];
|
||||
System.arraycopy(buf, 0, newbuf, 0, count);
|
||||
buf = newbuf;
|
||||
}
|
||||
}
|
||||
|
||||
public void write(byte[] b, int off, int len) {
|
||||
ensureCapacity(len);
|
||||
System.arraycopy(b, off, buf, count, len);
|
||||
count += len;
|
||||
}
|
||||
|
||||
public void write(byte[] b) {
|
||||
write(b, 0, b.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a string as ASCII string.
|
||||
*/
|
||||
public void writeAsAscii(String s) {
|
||||
int len = s.length();
|
||||
|
||||
ensureCapacity(len);
|
||||
|
||||
int ptr = count;
|
||||
for( int i=0; i<len; i++ )
|
||||
buf[ptr++] = (byte)s.charAt(i);
|
||||
count = ptr;
|
||||
}
|
||||
|
||||
public void writeTo(OutputStream out) throws IOException {
|
||||
out.write(buf, 0, count);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
count = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Evil buffer reallocation method.
|
||||
* Don't use it unless you absolutely have to.
|
||||
*
|
||||
* @deprecated
|
||||
* because this is evil!
|
||||
*/
|
||||
public byte toByteArray()[] {
|
||||
byte[] newbuf = new byte[count];
|
||||
System.arraycopy(buf, 0, newbuf, 0, count);
|
||||
return newbuf;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public ByteInputStream newInputStream() {
|
||||
return new ByteInputStream(buf,count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the buffer's contents into a string, translating bytes into
|
||||
* characters according to the platform's default character encoding.
|
||||
*
|
||||
* @return String translated from the buffer's contents.
|
||||
* @since JDK1.1
|
||||
*/
|
||||
public String toString() {
|
||||
return new String(buf, 0, count);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
}
|
||||
|
||||
public byte[] getBytes() {
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user