feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* 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.ws.message;
|
||||
|
||||
import com.sun.istack.internal.NotNull;
|
||||
import com.sun.xml.internal.bind.api.Bridge;
|
||||
import com.sun.xml.internal.bind.api.BridgeContext;
|
||||
import com.sun.xml.internal.ws.api.SOAPVersion;
|
||||
import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
|
||||
import com.sun.xml.internal.ws.api.addressing.WSEndpointReference;
|
||||
import com.sun.xml.internal.ws.api.message.Header;
|
||||
import com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory;
|
||||
import com.sun.xml.internal.ws.spi.db.XMLBridge;
|
||||
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Partial default implementation of {@link Header}.
|
||||
*
|
||||
* <p>
|
||||
* This is meant to be a convenient base class
|
||||
* for {@link Header}-derived classes.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public abstract class AbstractHeaderImpl implements Header {
|
||||
|
||||
protected AbstractHeaderImpl() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
public final <T> T readAsJAXB(Bridge<T> bridge, BridgeContext context) throws JAXBException {
|
||||
return readAsJAXB(bridge);
|
||||
}
|
||||
|
||||
public <T> T readAsJAXB(Unmarshaller unmarshaller) throws JAXBException {
|
||||
try {
|
||||
return (T)unmarshaller.unmarshal(readHeader());
|
||||
} catch (Exception e) {
|
||||
throw new JAXBException(e);
|
||||
}
|
||||
}
|
||||
/** @deprecated */
|
||||
public <T> T readAsJAXB(Bridge<T> bridge) throws JAXBException {
|
||||
try {
|
||||
return bridge.unmarshal(readHeader());
|
||||
} catch (XMLStreamException e) {
|
||||
throw new JAXBException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public <T> T readAsJAXB(XMLBridge<T> bridge) throws JAXBException {
|
||||
try {
|
||||
return bridge.unmarshal(readHeader(), null);
|
||||
} catch (XMLStreamException e) {
|
||||
throw new JAXBException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Default implementation that copies the infoset. Not terribly efficient.
|
||||
*/
|
||||
public WSEndpointReference readAsEPR(AddressingVersion expected) throws XMLStreamException {
|
||||
XMLStreamReader xsr = readHeader();
|
||||
WSEndpointReference epr = new WSEndpointReference(xsr, expected);
|
||||
XMLStreamReaderFactory.recycle(xsr);
|
||||
return epr;
|
||||
}
|
||||
|
||||
public boolean isIgnorable(@NotNull SOAPVersion soapVersion, @NotNull Set<String> roles) {
|
||||
// check mustUnderstand
|
||||
String v = getAttribute(soapVersion.nsUri, "mustUnderstand");
|
||||
if(v==null || !parseBool(v)) return true;
|
||||
|
||||
if (roles == null) return true;
|
||||
|
||||
// now role
|
||||
return !roles.contains(getRole(soapVersion));
|
||||
}
|
||||
|
||||
public @NotNull String getRole(@NotNull SOAPVersion soapVersion) {
|
||||
String v = getAttribute(soapVersion.nsUri, soapVersion.roleAttributeName);
|
||||
if(v==null)
|
||||
v = soapVersion.implicitRole;
|
||||
return v;
|
||||
}
|
||||
|
||||
public boolean isRelay() {
|
||||
String v = getAttribute(SOAPVersion.SOAP_12.nsUri,"relay");
|
||||
if(v==null) return false; // on SOAP 1.1 message there shouldn't be such an attribute, so this works fine
|
||||
return parseBool(v);
|
||||
}
|
||||
|
||||
public String getAttribute(QName name) {
|
||||
return getAttribute(name.getNamespaceURI(),name.getLocalPart());
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a string that looks like <tt>xs:boolean</tt> into boolean.
|
||||
*
|
||||
* This method assumes that the whilespace normalization has already taken place.
|
||||
*/
|
||||
protected final boolean parseBool(String value) {
|
||||
if(value.length()==0)
|
||||
return false;
|
||||
|
||||
char ch = value.charAt(0);
|
||||
return ch=='t' || ch=='1';
|
||||
}
|
||||
|
||||
public String getStringContent() {
|
||||
try {
|
||||
XMLStreamReader xsr = readHeader();
|
||||
xsr.nextTag();
|
||||
return xsr.getElementText();
|
||||
} catch (XMLStreamException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected static final AttributesImpl EMPTY_ATTS = new AttributesImpl();
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
/*
|
||||
* 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.ws.message;
|
||||
|
||||
import com.sun.istack.internal.NotNull;
|
||||
import com.sun.xml.internal.bind.api.Bridge;
|
||||
import com.sun.xml.internal.ws.api.SOAPVersion;
|
||||
import com.sun.xml.internal.ws.api.message.Header;
|
||||
import com.sun.xml.internal.ws.api.message.Message;
|
||||
import com.sun.xml.internal.ws.api.message.MessageHeaders;
|
||||
import com.sun.xml.internal.ws.api.message.MessageWritable;
|
||||
import com.sun.xml.internal.ws.api.message.Packet;
|
||||
import com.sun.xml.internal.ws.api.message.saaj.SAAJFactory;
|
||||
import com.sun.xml.internal.ws.encoding.TagInfoset;
|
||||
import com.sun.xml.internal.ws.message.saaj.SAAJMessage;
|
||||
import com.sun.xml.internal.ws.spi.db.XMLBridge;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
import org.xml.sax.helpers.LocatorImpl;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.soap.SOAPException;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.sax.SAXSource;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Partial {@link Message} implementation.
|
||||
*
|
||||
* <p>
|
||||
* This class implements some of the {@link Message} methods.
|
||||
* The idea is that those implementations may be non-optimal but
|
||||
* it may save effort in implementing {@link Message} and reduce
|
||||
* the code size.
|
||||
*
|
||||
* <p>
|
||||
* {@link Message} classes that are used more commonly should
|
||||
* examine carefully which method can be implemented faster,
|
||||
* and override them accordingly.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public abstract class AbstractMessageImpl extends Message {
|
||||
/**
|
||||
* SOAP version of this message.
|
||||
* Used to implement some of the methods, but nothing more than that.
|
||||
*
|
||||
* <p>
|
||||
* So if you aren't using those methods that use this field,
|
||||
* this can be null.
|
||||
*/
|
||||
protected final SOAPVersion soapVersion;
|
||||
|
||||
protected @NotNull TagInfoset envelopeTag;
|
||||
protected @NotNull TagInfoset headerTag;
|
||||
protected @NotNull TagInfoset bodyTag;
|
||||
|
||||
protected static final AttributesImpl EMPTY_ATTS;
|
||||
protected static final LocatorImpl NULL_LOCATOR = new LocatorImpl();
|
||||
protected static final List<TagInfoset> DEFAULT_TAGS;
|
||||
|
||||
static void create(SOAPVersion v, List c) {
|
||||
int base = v.ordinal()*3;
|
||||
c.add(base, new TagInfoset(v.nsUri, "Envelope", "S", EMPTY_ATTS,"S", v.nsUri));
|
||||
c.add(base+1, new TagInfoset(v.nsUri, "Header", "S", EMPTY_ATTS));
|
||||
c.add(base+2, new TagInfoset(v.nsUri, "Body", "S", EMPTY_ATTS));
|
||||
}
|
||||
|
||||
static {
|
||||
EMPTY_ATTS = new AttributesImpl();
|
||||
List<TagInfoset> tagList = new ArrayList<TagInfoset>();
|
||||
create(SOAPVersion.SOAP_11, tagList);
|
||||
create(SOAPVersion.SOAP_12, tagList);
|
||||
DEFAULT_TAGS = Collections.unmodifiableList(tagList);
|
||||
}
|
||||
|
||||
protected AbstractMessageImpl(SOAPVersion soapVersion) {
|
||||
this.soapVersion = soapVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SOAPVersion getSOAPVersion() {
|
||||
return soapVersion;
|
||||
}
|
||||
/**
|
||||
* Copy constructor.
|
||||
*/
|
||||
protected AbstractMessageImpl(AbstractMessageImpl that) {
|
||||
this.soapVersion = that.soapVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Source readEnvelopeAsSource() {
|
||||
return new SAXSource(new XMLReaderImpl(this), XMLReaderImpl.THE_SOURCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T readPayloadAsJAXB(Unmarshaller unmarshaller) throws JAXBException {
|
||||
if(hasAttachments())
|
||||
unmarshaller.setAttachmentUnmarshaller(new AttachmentUnmarshallerImpl(getAttachments()));
|
||||
try {
|
||||
return (T) unmarshaller.unmarshal(readPayloadAsSource());
|
||||
} finally{
|
||||
unmarshaller.setAttachmentUnmarshaller(null);
|
||||
}
|
||||
}
|
||||
/** @deprecated */
|
||||
@Override
|
||||
public <T> T readPayloadAsJAXB(Bridge<T> bridge) throws JAXBException {
|
||||
return bridge.unmarshal(readPayloadAsSource(),
|
||||
hasAttachments()? new AttachmentUnmarshallerImpl(getAttachments()) : null );
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T readPayloadAsJAXB(XMLBridge<T> bridge) throws JAXBException {
|
||||
return bridge.unmarshal(readPayloadAsSource(),
|
||||
hasAttachments()? new AttachmentUnmarshallerImpl(getAttachments()) : null );
|
||||
}
|
||||
|
||||
/**
|
||||
* Default implementation that relies on {@link #writePayloadTo(XMLStreamWriter)}
|
||||
*/
|
||||
@Override
|
||||
public void writeTo(XMLStreamWriter w) throws XMLStreamException {
|
||||
String soapNsUri = soapVersion.nsUri;
|
||||
w.writeStartDocument();
|
||||
w.writeStartElement("S","Envelope",soapNsUri);
|
||||
w.writeNamespace("S",soapNsUri);
|
||||
if(hasHeaders()) {
|
||||
w.writeStartElement("S","Header",soapNsUri);
|
||||
MessageHeaders headers = getHeaders();
|
||||
for (Header h : headers.asList()) {
|
||||
h.writeTo(w);
|
||||
}
|
||||
w.writeEndElement();
|
||||
}
|
||||
// write the body
|
||||
w.writeStartElement("S","Body",soapNsUri);
|
||||
|
||||
writePayloadTo(w);
|
||||
|
||||
w.writeEndElement();
|
||||
w.writeEndElement();
|
||||
w.writeEndDocument();
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the whole envelope as SAX events.
|
||||
*/
|
||||
@Override
|
||||
public void writeTo( ContentHandler contentHandler, ErrorHandler errorHandler ) throws SAXException {
|
||||
String soapNsUri = soapVersion.nsUri;
|
||||
|
||||
contentHandler.setDocumentLocator(NULL_LOCATOR);
|
||||
contentHandler.startDocument();
|
||||
contentHandler.startPrefixMapping("S",soapNsUri);
|
||||
contentHandler.startElement(soapNsUri,"Envelope","S:Envelope",EMPTY_ATTS);
|
||||
if(hasHeaders()) {
|
||||
contentHandler.startElement(soapNsUri,"Header","S:Header",EMPTY_ATTS);
|
||||
MessageHeaders headers = getHeaders();
|
||||
for (Header h : headers.asList()) {
|
||||
h.writeTo(contentHandler,errorHandler);
|
||||
}
|
||||
contentHandler.endElement(soapNsUri,"Header","S:Header");
|
||||
}
|
||||
// write the body
|
||||
contentHandler.startElement(soapNsUri,"Body","S:Body",EMPTY_ATTS);
|
||||
writePayloadTo(contentHandler,errorHandler, true);
|
||||
contentHandler.endElement(soapNsUri,"Body","S:Body");
|
||||
contentHandler.endElement(soapNsUri,"Envelope","S:Envelope");
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the payload to SAX events.
|
||||
*
|
||||
* @param fragment
|
||||
* if true, this method will fire SAX events without start/endDocument events,
|
||||
* suitable for embedding this into a bigger SAX event sequence.
|
||||
* if false, this method generaets a completely SAX event sequence on its own.
|
||||
*/
|
||||
protected abstract void writePayloadTo(ContentHandler contentHandler, ErrorHandler errorHandler, boolean fragment) throws SAXException;
|
||||
|
||||
public Message toSAAJ(Packet p, Boolean inbound) throws SOAPException {
|
||||
SAAJMessage message = SAAJFactory.read(p);
|
||||
if (message instanceof MessageWritable)
|
||||
((MessageWritable) message)
|
||||
.setMTOMConfiguration(p.getMtomFeature());
|
||||
if (inbound != null) transportHeaders(p, inbound, message.readAsSOAPMessage());
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default implementation that uses {@link #writeTo(ContentHandler, ErrorHandler)}
|
||||
*/
|
||||
@Override
|
||||
public SOAPMessage readAsSOAPMessage() throws SOAPException {
|
||||
return SAAJFactory.read(soapVersion, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SOAPMessage readAsSOAPMessage(Packet packet, boolean inbound) throws SOAPException {
|
||||
SOAPMessage msg = SAAJFactory.read(soapVersion, this, packet);
|
||||
transportHeaders(packet, inbound, msg);
|
||||
return msg;
|
||||
}
|
||||
|
||||
private void transportHeaders(Packet packet, boolean inbound, SOAPMessage msg) throws SOAPException {
|
||||
Map<String, List<String>> headers = getTransportHeaders(packet, inbound);
|
||||
if (headers != null) {
|
||||
addSOAPMimeHeaders(msg.getMimeHeaders(), headers);
|
||||
}
|
||||
if (msg.saveRequired()) msg.saveChanges();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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.ws.message;
|
||||
|
||||
import com.sun.xml.internal.ws.api.message.AttachmentSet;
|
||||
import com.sun.xml.internal.ws.api.message.Attachment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Default dumb {@link AttachmentSet} implementation backed by {@link ArrayList}.
|
||||
*
|
||||
* <p>
|
||||
* The assumption here is that the number of attachments are small enough to
|
||||
* justify linear search in {@link #get(String)}.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public final class AttachmentSetImpl implements AttachmentSet {
|
||||
|
||||
private final ArrayList<Attachment> attList = new ArrayList<Attachment>();
|
||||
|
||||
/**
|
||||
* Creates an empty {@link AttachmentSet}.
|
||||
*/
|
||||
public AttachmentSetImpl() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an {@link AttachmentSet} by copying contents from another.
|
||||
*/
|
||||
public AttachmentSetImpl(Iterable<Attachment> base) {
|
||||
for (Attachment a : base)
|
||||
add(a);
|
||||
}
|
||||
|
||||
public Attachment get(String contentId) {
|
||||
for( int i=attList.size()-1; i>=0; i-- ) {
|
||||
Attachment a = attList.get(i);
|
||||
if(a.getContentId().equals(contentId))
|
||||
return a;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return attList.isEmpty();
|
||||
}
|
||||
|
||||
public void add(Attachment att) {
|
||||
attList.add(att);
|
||||
}
|
||||
|
||||
public Iterator<Attachment> iterator() {
|
||||
return attList.iterator();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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.ws.message;
|
||||
|
||||
import com.sun.xml.internal.ws.api.message.Attachment;
|
||||
import com.sun.xml.internal.ws.api.message.AttachmentSet;
|
||||
import com.sun.xml.internal.ws.encoding.MimeMultipartParser;
|
||||
import com.sun.xml.internal.ws.resources.EncodingMessages;
|
||||
|
||||
import javax.activation.DataHandler;
|
||||
import javax.xml.bind.attachment.AttachmentUnmarshaller;
|
||||
import javax.xml.ws.WebServiceException;
|
||||
|
||||
/**
|
||||
* Implementation of {@link AttachmentUnmarshaller} that uses
|
||||
* loads attachments from {@link AttachmentSet} directly.
|
||||
*
|
||||
* @author Vivek Pandey
|
||||
* @see MimeMultipartParser
|
||||
*/
|
||||
public final class AttachmentUnmarshallerImpl extends AttachmentUnmarshaller {
|
||||
|
||||
private final AttachmentSet attachments;
|
||||
|
||||
public AttachmentUnmarshallerImpl(AttachmentSet attachments) {
|
||||
this.attachments = attachments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataHandler getAttachmentAsDataHandler(String cid) {
|
||||
Attachment a = attachments.get(stripScheme(cid));
|
||||
if(a==null)
|
||||
throw new WebServiceException(EncodingMessages.NO_SUCH_CONTENT_ID(cid));
|
||||
return a.asDataHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getAttachmentAsByteArray(String cid) {
|
||||
Attachment a = attachments.get(stripScheme(cid));
|
||||
if(a==null)
|
||||
throw new WebServiceException(EncodingMessages.NO_SUCH_CONTENT_ID(cid));
|
||||
return a.asByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* The CID reference has 'cid:' prefix, so get rid of it.
|
||||
*/
|
||||
private String stripScheme(String cid) {
|
||||
if(cid.startsWith("cid:")) // work defensively, in case the input is wrong
|
||||
cid = cid.substring(4);
|
||||
return cid;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* 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.ws.message;
|
||||
|
||||
import com.sun.istack.internal.NotNull;
|
||||
import com.sun.xml.internal.ws.api.message.Attachment;
|
||||
import com.sun.xml.internal.ws.util.ByteArrayDataSource;
|
||||
import com.sun.xml.internal.ws.encoding.DataSourceStreamingDataHandler;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
import javax.activation.DataHandler;
|
||||
import javax.xml.soap.AttachmentPart;
|
||||
import javax.xml.soap.SOAPException;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* @author Jitendra Kotamraju
|
||||
*/
|
||||
public final class ByteArrayAttachment implements Attachment {
|
||||
|
||||
private final String contentId;
|
||||
private byte[] data;
|
||||
private int start;
|
||||
private final int len;
|
||||
private final String mimeType;
|
||||
|
||||
public ByteArrayAttachment(@NotNull String contentId, byte[] data, int start, int len, String mimeType) {
|
||||
this.contentId = contentId;
|
||||
this.data = data;
|
||||
this.start = start;
|
||||
this.len = len;
|
||||
this.mimeType = mimeType;
|
||||
}
|
||||
|
||||
public ByteArrayAttachment(@NotNull String contentId, byte[] data, String mimeType) {
|
||||
this(contentId, data, 0, data.length, mimeType);
|
||||
}
|
||||
|
||||
public String getContentId() {
|
||||
return contentId;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return mimeType;
|
||||
}
|
||||
|
||||
public byte[] asByteArray() {
|
||||
if(start!=0 || len!=data.length) {
|
||||
// if our buffer isn't exact, switch to the exact one
|
||||
byte[] exact = new byte[len];
|
||||
System.arraycopy(data,start,exact,0,len);
|
||||
start = 0;
|
||||
data = exact;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public DataHandler asDataHandler() {
|
||||
return new DataSourceStreamingDataHandler(new ByteArrayDataSource(data,start,len,getContentType()));
|
||||
}
|
||||
|
||||
public Source asSource() {
|
||||
return new StreamSource(asInputStream());
|
||||
}
|
||||
|
||||
public InputStream asInputStream() {
|
||||
return new ByteArrayInputStream(data,start,len);
|
||||
}
|
||||
|
||||
public void writeTo(OutputStream os) throws IOException {
|
||||
os.write(asByteArray());
|
||||
}
|
||||
|
||||
public void writeTo(SOAPMessage saaj) throws SOAPException {
|
||||
AttachmentPart part = saaj.createAttachmentPart();
|
||||
part.setDataHandler(asDataHandler());
|
||||
part.setContentId(contentId);
|
||||
saaj.addAttachmentPart(part);
|
||||
}
|
||||
|
||||
}
|
||||
143
jdkSrc/jdk8/com/sun/xml/internal/ws/message/DOMHeader.java
Normal file
143
jdkSrc/jdk8/com/sun/xml/internal/ws/message/DOMHeader.java
Normal file
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* 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.ws.message;
|
||||
|
||||
import com.sun.xml.internal.bind.api.Bridge;
|
||||
import com.sun.xml.internal.bind.unmarshaller.DOMScanner;
|
||||
import com.sun.xml.internal.ws.streaming.DOMStreamReader;
|
||||
import com.sun.xml.internal.ws.util.DOMUtil;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.soap.SOAPException;
|
||||
import javax.xml.soap.SOAPHeader;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
|
||||
/**
|
||||
* {@link com.sun.xml.internal.ws.api.message.Header} implementation for a DOM.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public class DOMHeader<N extends Element> extends AbstractHeaderImpl {
|
||||
protected final N node;
|
||||
|
||||
private final String nsUri;
|
||||
private final String localName;
|
||||
|
||||
public DOMHeader(N node) {
|
||||
assert node!=null;
|
||||
this.node = node;
|
||||
|
||||
this.nsUri = fixNull(node.getNamespaceURI());
|
||||
this.localName = node.getLocalName();
|
||||
}
|
||||
|
||||
|
||||
public String getNamespaceURI() {
|
||||
return nsUri;
|
||||
}
|
||||
|
||||
public String getLocalPart() {
|
||||
return localName;
|
||||
}
|
||||
|
||||
public XMLStreamReader readHeader() throws XMLStreamException {
|
||||
DOMStreamReader r = new DOMStreamReader(node);
|
||||
r.nextTag(); // move ahead to the start tag
|
||||
return r;
|
||||
}
|
||||
|
||||
public <T> T readAsJAXB(Unmarshaller unmarshaller) throws JAXBException {
|
||||
return (T) unmarshaller.unmarshal(node);
|
||||
}
|
||||
/** @deprecated */
|
||||
public <T> T readAsJAXB(Bridge<T> bridge) throws JAXBException {
|
||||
return bridge.unmarshal(node);
|
||||
}
|
||||
|
||||
public void writeTo(XMLStreamWriter w) throws XMLStreamException {
|
||||
DOMUtil.serializeNode(node, w);
|
||||
}
|
||||
|
||||
private static String fixNull(String s) {
|
||||
if(s!=null) return s;
|
||||
else return "";
|
||||
}
|
||||
|
||||
public void writeTo(ContentHandler contentHandler, ErrorHandler errorHandler) throws SAXException {
|
||||
DOMScanner ds = new DOMScanner();
|
||||
ds.setContentHandler(contentHandler);
|
||||
ds.scan(node);
|
||||
}
|
||||
|
||||
public String getAttribute(String nsUri, String localName) {
|
||||
if(nsUri.length()==0) nsUri=null; // DOM wants null, not "".
|
||||
return node.getAttributeNS(nsUri,localName);
|
||||
}
|
||||
|
||||
public void writeTo(SOAPMessage saaj) throws SOAPException {
|
||||
SOAPHeader header = saaj.getSOAPHeader();
|
||||
if(header == null)
|
||||
header = saaj.getSOAPPart().getEnvelope().addHeader();
|
||||
Node clone = header.getOwnerDocument().importNode(node,true);
|
||||
header.appendChild(clone);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStringContent() {
|
||||
return node.getTextContent();
|
||||
}
|
||||
|
||||
public N getWrappedNode() {
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getWrappedNode().hashCode();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof DOMHeader) {
|
||||
return getWrappedNode().equals(((DOMHeader) obj).getWrappedNode());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
156
jdkSrc/jdk8/com/sun/xml/internal/ws/message/DOMMessage.java
Normal file
156
jdkSrc/jdk8/com/sun/xml/internal/ws/message/DOMMessage.java
Normal file
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* 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.ws.message;
|
||||
|
||||
import com.sun.istack.internal.FragmentContentHandler;
|
||||
import com.sun.xml.internal.bind.api.Bridge;
|
||||
import com.sun.xml.internal.bind.unmarshaller.DOMScanner;
|
||||
import com.sun.xml.internal.ws.api.SOAPVersion;
|
||||
import com.sun.xml.internal.ws.api.message.HeaderList;
|
||||
import com.sun.xml.internal.ws.api.message.Message;
|
||||
import com.sun.xml.internal.ws.api.message.AttachmentSet;
|
||||
import com.sun.xml.internal.ws.api.message.MessageHeaders;
|
||||
import com.sun.xml.internal.ws.streaming.DOMStreamReader;
|
||||
import com.sun.xml.internal.ws.util.DOMUtil;
|
||||
import org.w3c.dom.Element;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.ws.WebServiceException;
|
||||
|
||||
/**
|
||||
* {@link Message} backed by a DOM {@link Element} that represents the payload.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public final class DOMMessage extends AbstractMessageImpl {
|
||||
private MessageHeaders headers;
|
||||
private final Element payload;
|
||||
|
||||
public DOMMessage(SOAPVersion ver, Element payload) {
|
||||
this(ver,null,payload);
|
||||
}
|
||||
|
||||
public DOMMessage(SOAPVersion ver, MessageHeaders headers, Element payload) {
|
||||
this(ver,headers,payload,null);
|
||||
}
|
||||
|
||||
public DOMMessage(SOAPVersion ver, MessageHeaders headers, Element payload, AttachmentSet attachments) {
|
||||
super(ver);
|
||||
this.headers = headers;
|
||||
this.payload = payload;
|
||||
this.attachmentSet = attachments;
|
||||
assert payload!=null;
|
||||
}
|
||||
/**
|
||||
* This constructor is a convenience and called by the {@link #copy}
|
||||
*/
|
||||
private DOMMessage(DOMMessage that) {
|
||||
super(that);
|
||||
this.headers = HeaderList.copy(that.headers);
|
||||
this.payload = that.payload;
|
||||
}
|
||||
|
||||
public boolean hasHeaders() {
|
||||
return getHeaders().hasHeaders();
|
||||
}
|
||||
|
||||
public MessageHeaders getHeaders() {
|
||||
if (headers == null)
|
||||
headers = new HeaderList(getSOAPVersion());
|
||||
|
||||
return headers;
|
||||
}
|
||||
|
||||
public String getPayloadLocalPart() {
|
||||
return payload.getLocalName();
|
||||
}
|
||||
|
||||
public String getPayloadNamespaceURI() {
|
||||
return payload.getNamespaceURI();
|
||||
}
|
||||
|
||||
public boolean hasPayload() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Source readPayloadAsSource() {
|
||||
return new DOMSource(payload);
|
||||
}
|
||||
|
||||
public <T> T readPayloadAsJAXB(Unmarshaller unmarshaller) throws JAXBException {
|
||||
if(hasAttachments())
|
||||
unmarshaller.setAttachmentUnmarshaller(new AttachmentUnmarshallerImpl(getAttachments()));
|
||||
try {
|
||||
return (T)unmarshaller.unmarshal(payload);
|
||||
} finally{
|
||||
unmarshaller.setAttachmentUnmarshaller(null);
|
||||
}
|
||||
}
|
||||
/** @deprecated */
|
||||
public <T> T readPayloadAsJAXB(Bridge<T> bridge) throws JAXBException {
|
||||
return bridge.unmarshal(payload,
|
||||
hasAttachments()? new AttachmentUnmarshallerImpl(getAttachments()) : null);
|
||||
}
|
||||
|
||||
public XMLStreamReader readPayload() throws XMLStreamException {
|
||||
DOMStreamReader dss = new DOMStreamReader();
|
||||
dss.setCurrentNode(payload);
|
||||
dss.nextTag();
|
||||
assert dss.getEventType()==XMLStreamReader.START_ELEMENT;
|
||||
return dss;
|
||||
}
|
||||
|
||||
public void writePayloadTo(XMLStreamWriter sw) {
|
||||
try {
|
||||
if (payload != null)
|
||||
DOMUtil.serializeNode(payload, sw);
|
||||
} catch (XMLStreamException e) {
|
||||
throw new WebServiceException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void writePayloadTo(ContentHandler contentHandler, ErrorHandler errorHandler, boolean fragment) throws SAXException {
|
||||
if(fragment)
|
||||
contentHandler = new FragmentContentHandler(contentHandler);
|
||||
DOMScanner ds = new DOMScanner();
|
||||
ds.setContentHandler(contentHandler);
|
||||
ds.scan(payload);
|
||||
}
|
||||
|
||||
public Message copy() {
|
||||
return new DOMMessage(this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* 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.ws.message;
|
||||
|
||||
import com.sun.istack.internal.NotNull;
|
||||
import com.sun.xml.internal.ws.api.message.Attachment;
|
||||
import com.sun.xml.internal.ws.util.ByteArrayBuffer;
|
||||
|
||||
import javax.activation.DataHandler;
|
||||
import javax.xml.soap.AttachmentPart;
|
||||
import javax.xml.soap.SOAPException;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
import javax.xml.ws.WebServiceException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
/**
|
||||
* @author Jitendra Kotamraju
|
||||
*/
|
||||
public final class DataHandlerAttachment implements Attachment {
|
||||
|
||||
private final DataHandler dh;
|
||||
private final String contentId;
|
||||
String contentIdNoAngleBracket;
|
||||
|
||||
/**
|
||||
* This will be constructed by {@link com.sun.xml.internal.ws.message.jaxb.AttachmentMarshallerImpl}
|
||||
*/
|
||||
public DataHandlerAttachment(@NotNull String contentId, @NotNull DataHandler dh) {
|
||||
this.dh = dh;
|
||||
this.contentId = contentId;
|
||||
}
|
||||
|
||||
public String getContentId() {
|
||||
// return contentId;
|
||||
if (contentIdNoAngleBracket == null) {
|
||||
contentIdNoAngleBracket = contentId;
|
||||
if (contentIdNoAngleBracket != null && contentIdNoAngleBracket.charAt(0) == '<')
|
||||
contentIdNoAngleBracket = contentIdNoAngleBracket.substring(1, contentIdNoAngleBracket.length()-1);
|
||||
}
|
||||
return contentIdNoAngleBracket;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return dh.getContentType();
|
||||
}
|
||||
|
||||
public byte[] asByteArray() {
|
||||
try {
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
dh.writeTo(os);
|
||||
return os.toByteArray();
|
||||
} catch (IOException e) {
|
||||
throw new WebServiceException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public DataHandler asDataHandler() {
|
||||
return dh;
|
||||
}
|
||||
|
||||
public Source asSource() {
|
||||
try {
|
||||
return new StreamSource(dh.getInputStream());
|
||||
} catch (IOException e) {
|
||||
throw new WebServiceException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public InputStream asInputStream() {
|
||||
try {
|
||||
return dh.getInputStream();
|
||||
} catch (IOException e) {
|
||||
throw new WebServiceException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeTo(OutputStream os) throws IOException {
|
||||
dh.writeTo(os);
|
||||
}
|
||||
|
||||
public void writeTo(SOAPMessage saaj) throws SOAPException {
|
||||
AttachmentPart part = saaj.createAttachmentPart();
|
||||
part.setDataHandler(dh);
|
||||
part.setContentId(contentId);
|
||||
saaj.addAttachmentPart(part);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* 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.ws.message;
|
||||
|
||||
import com.sun.istack.internal.NotNull;
|
||||
import com.sun.xml.internal.ws.api.SOAPVersion;
|
||||
import com.sun.xml.internal.ws.api.message.AttachmentSet;
|
||||
import com.sun.xml.internal.ws.api.message.HeaderList;
|
||||
import com.sun.xml.internal.ws.api.message.Message;
|
||||
import com.sun.xml.internal.ws.api.message.MessageHeaders;
|
||||
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
import javax.xml.transform.Source;
|
||||
|
||||
/**
|
||||
* {@link Message} that has no body.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public class EmptyMessageImpl extends AbstractMessageImpl {
|
||||
|
||||
/**
|
||||
* If a message has no payload, it's more likely to have
|
||||
* some header, so we create it eagerly here.
|
||||
*/
|
||||
private final MessageHeaders headers;
|
||||
private final AttachmentSet attachmentSet;
|
||||
|
||||
public EmptyMessageImpl(SOAPVersion version) {
|
||||
super(version);
|
||||
this.headers = new HeaderList(version);
|
||||
this.attachmentSet = new AttachmentSetImpl();
|
||||
}
|
||||
|
||||
public EmptyMessageImpl(MessageHeaders headers, @NotNull AttachmentSet attachmentSet, SOAPVersion version){
|
||||
super(version);
|
||||
if(headers==null)
|
||||
headers = new HeaderList(version);
|
||||
this.attachmentSet = attachmentSet;
|
||||
this.headers = headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*/
|
||||
private EmptyMessageImpl(EmptyMessageImpl that) {
|
||||
super(that);
|
||||
this.headers = new HeaderList(that.headers);
|
||||
this.attachmentSet = that.attachmentSet;
|
||||
}
|
||||
|
||||
public boolean hasHeaders() {
|
||||
return headers.hasHeaders();
|
||||
}
|
||||
|
||||
public MessageHeaders getHeaders() {
|
||||
return headers;
|
||||
}
|
||||
|
||||
public String getPayloadLocalPart() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getPayloadNamespaceURI() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean hasPayload() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Source readPayloadAsSource() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public XMLStreamReader readPayload() throws XMLStreamException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void writePayloadTo(XMLStreamWriter sw) throws XMLStreamException {
|
||||
// noop
|
||||
}
|
||||
|
||||
public void writePayloadTo(ContentHandler contentHandler, ErrorHandler errorHandler, boolean fragment) throws SAXException {
|
||||
// noop
|
||||
}
|
||||
|
||||
public Message copy() {
|
||||
return new EmptyMessageImpl(this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* 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.ws.message;
|
||||
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
import javax.xml.soap.SOAPException;
|
||||
import javax.xml.soap.SOAPHeader;
|
||||
import javax.xml.soap.SOAPHeaderElement;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import com.sun.istack.internal.Nullable;
|
||||
import com.sun.istack.internal.NotNull;
|
||||
import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
|
||||
import com.sun.xml.internal.stream.buffer.MutableXMLStreamBuffer;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* @author Arun Gupta
|
||||
*/
|
||||
public class FaultDetailHeader extends AbstractHeaderImpl {
|
||||
|
||||
private AddressingVersion av;
|
||||
private String wrapper;
|
||||
private String problemValue = null;
|
||||
|
||||
public FaultDetailHeader(AddressingVersion av, String wrapper, QName problemHeader) {
|
||||
this.av = av;
|
||||
this.wrapper = wrapper;
|
||||
this.problemValue = problemHeader.toString();
|
||||
}
|
||||
|
||||
public FaultDetailHeader(AddressingVersion av, String wrapper, String problemValue) {
|
||||
this.av = av;
|
||||
this.wrapper = wrapper;
|
||||
this.problemValue = problemValue;
|
||||
}
|
||||
|
||||
public
|
||||
@NotNull
|
||||
String getNamespaceURI() {
|
||||
return av.nsUri;
|
||||
}
|
||||
|
||||
public
|
||||
@NotNull
|
||||
String getLocalPart() {
|
||||
return av.faultDetailTag.getLocalPart();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getAttribute(@NotNull String nsUri, @NotNull String localName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public XMLStreamReader readHeader() throws XMLStreamException {
|
||||
MutableXMLStreamBuffer buf = new MutableXMLStreamBuffer();
|
||||
XMLStreamWriter w = buf.createFromXMLStreamWriter();
|
||||
writeTo(w);
|
||||
return buf.readAsXMLStreamReader();
|
||||
}
|
||||
|
||||
public void writeTo(XMLStreamWriter w) throws XMLStreamException {
|
||||
w.writeStartElement("", av.faultDetailTag.getLocalPart(), av.faultDetailTag.getNamespaceURI());
|
||||
w.writeDefaultNamespace(av.nsUri);
|
||||
w.writeStartElement("", wrapper, av.nsUri);
|
||||
w.writeCharacters(problemValue);
|
||||
w.writeEndElement();
|
||||
w.writeEndElement();
|
||||
}
|
||||
|
||||
public void writeTo(SOAPMessage saaj) throws SOAPException {
|
||||
SOAPHeader header = saaj.getSOAPHeader();
|
||||
if (header == null)
|
||||
header = saaj.getSOAPPart().getEnvelope().addHeader();
|
||||
SOAPHeaderElement she = header.addHeaderElement(av.faultDetailTag);
|
||||
she = header.addHeaderElement(new QName(av.nsUri, wrapper));
|
||||
she.addTextNode(problemValue);
|
||||
}
|
||||
|
||||
public void writeTo(ContentHandler h, ErrorHandler errorHandler) throws SAXException {
|
||||
String nsUri = av.nsUri;
|
||||
String ln = av.faultDetailTag.getLocalPart();
|
||||
|
||||
h.startPrefixMapping("",nsUri);
|
||||
h.startElement(nsUri,ln,ln,EMPTY_ATTS);
|
||||
h.startElement(nsUri,wrapper,wrapper,EMPTY_ATTS);
|
||||
h.characters(problemValue.toCharArray(),0,problemValue.length());
|
||||
h.endElement(nsUri,wrapper,wrapper);
|
||||
h.endElement(nsUri,ln,ln);
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.ws.message;
|
||||
|
||||
import com.sun.istack.internal.Nullable;
|
||||
import com.sun.xml.internal.ws.api.message.Message;
|
||||
import com.sun.xml.internal.ws.api.message.FilterMessageImpl;
|
||||
import com.sun.xml.internal.ws.api.model.wsdl.WSDLFault;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
/**
|
||||
* SOAP Fault message. It has optimized implementation to get
|
||||
* first detail entry's name. This is useful to identify the
|
||||
* corresponding {@link WSDLFault}
|
||||
*
|
||||
* @author Jitendra Kotamraju
|
||||
*/
|
||||
public class FaultMessage extends FilterMessageImpl {
|
||||
|
||||
private final @Nullable QName detailEntryName;
|
||||
|
||||
public FaultMessage(Message delegate, @Nullable QName detailEntryName) {
|
||||
super(delegate);
|
||||
this.detailEntryName = detailEntryName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable QName getFirstDetailEntryName() {
|
||||
return detailEntryName;
|
||||
}
|
||||
|
||||
}
|
||||
138
jdkSrc/jdk8/com/sun/xml/internal/ws/message/JAXBAttachment.java
Normal file
138
jdkSrc/jdk8/com/sun/xml/internal/ws/message/JAXBAttachment.java
Normal file
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* 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.ws.message;
|
||||
|
||||
import com.sun.istack.internal.NotNull;
|
||||
import com.sun.xml.internal.ws.api.message.Attachment;
|
||||
import com.sun.xml.internal.ws.spi.db.XMLBridge;
|
||||
import com.sun.xml.internal.ws.util.ByteArrayBuffer;
|
||||
import com.sun.xml.internal.ws.encoding.DataSourceStreamingDataHandler;
|
||||
|
||||
import javax.activation.DataHandler;
|
||||
import javax.activation.DataSource;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.soap.AttachmentPart;
|
||||
import javax.xml.soap.SOAPException;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
import javax.xml.ws.WebServiceException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* @author Jitendra Kotamraju
|
||||
*/
|
||||
public final class JAXBAttachment implements Attachment, DataSource {
|
||||
|
||||
private final String contentId;
|
||||
private final String mimeType;
|
||||
private final Object jaxbObject;
|
||||
private final XMLBridge bridge;
|
||||
|
||||
public JAXBAttachment(@NotNull String contentId, Object jaxbObject, XMLBridge bridge, String mimeType) {
|
||||
this.contentId = contentId;
|
||||
this.jaxbObject = jaxbObject;
|
||||
this.bridge = bridge;
|
||||
this.mimeType = mimeType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContentId() {
|
||||
return contentId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContentType() {
|
||||
return mimeType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] asByteArray() {
|
||||
ByteArrayBuffer bab = new ByteArrayBuffer();
|
||||
try {
|
||||
writeTo(bab);
|
||||
} catch (IOException e) {
|
||||
throw new WebServiceException(e);
|
||||
}
|
||||
return bab.getRawData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataHandler asDataHandler() {
|
||||
return new DataSourceStreamingDataHandler(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Source asSource() {
|
||||
return new StreamSource(asInputStream());
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream asInputStream() {
|
||||
ByteArrayBuffer bab = new ByteArrayBuffer();
|
||||
try {
|
||||
writeTo(bab);
|
||||
} catch (IOException e) {
|
||||
throw new WebServiceException(e);
|
||||
}
|
||||
return bab.newInputStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(OutputStream os) throws IOException {
|
||||
try {
|
||||
bridge.marshal(jaxbObject, os, null, null);
|
||||
} catch (JAXBException e) {
|
||||
throw new WebServiceException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(SOAPMessage saaj) throws SOAPException {
|
||||
AttachmentPart part = saaj.createAttachmentPart();
|
||||
part.setDataHandler(asDataHandler());
|
||||
part.setContentId(contentId);
|
||||
saaj.addAttachmentPart(part);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() throws IOException {
|
||||
return asInputStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputStream getOutputStream() throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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.ws.message;
|
||||
|
||||
import com.sun.xml.internal.ws.api.message.AttachmentSet;
|
||||
import com.sun.xml.internal.ws.api.message.Attachment;
|
||||
import com.sun.xml.internal.ws.encoding.MimeMultipartParser;
|
||||
import com.sun.xml.internal.ws.resources.EncodingMessages;
|
||||
import com.sun.istack.internal.Nullable;
|
||||
|
||||
import javax.xml.ws.WebServiceException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* {@link AttachmentSet} backed by {@link com.sun.xml.internal.ws.encoding.MimeMultipartParser}
|
||||
*
|
||||
* @author Vivek Pandey
|
||||
*/
|
||||
public final class MimeAttachmentSet implements AttachmentSet {
|
||||
private final MimeMultipartParser mpp;
|
||||
private Map<String, Attachment> atts = new HashMap<String, Attachment>();
|
||||
|
||||
|
||||
public MimeAttachmentSet(MimeMultipartParser mpp) {
|
||||
this.mpp = mpp;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Attachment get(String contentId) {
|
||||
Attachment att;
|
||||
/**
|
||||
* First try to get the Attachment from internal map, maybe this attachment
|
||||
* is added by the user.
|
||||
*/
|
||||
att = atts.get(contentId);
|
||||
if(att != null)
|
||||
return att;
|
||||
try {
|
||||
/**
|
||||
* Attachment is not found in the internal map, now do look in
|
||||
* the mpp, if found add to the internal Attachment map.
|
||||
*/
|
||||
att = mpp.getAttachmentPart(contentId);
|
||||
if(att != null){
|
||||
atts.put(contentId, att);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new WebServiceException(EncodingMessages.NO_SUCH_CONTENT_ID(contentId), e);
|
||||
}
|
||||
return att;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is expensive operation, its going to to read all the underlying
|
||||
* attachments in {@link MimeMultipartParser}.
|
||||
*/
|
||||
public boolean isEmpty() {
|
||||
return atts.size() <= 0 && mpp.getAttachmentParts().isEmpty();
|
||||
}
|
||||
|
||||
public void add(Attachment att) {
|
||||
atts.put(att.getContentId(), att);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expensive operation.
|
||||
*/
|
||||
public Iterator<Attachment> iterator() {
|
||||
/**
|
||||
* Browse thru all the attachments in the mpp, add them to #atts,
|
||||
* then return whether its empty.
|
||||
*/
|
||||
Map<String, Attachment> attachments = mpp.getAttachmentParts();
|
||||
for(Map.Entry<String, Attachment> att : attachments.entrySet()) {
|
||||
if(atts.get(att.getKey()) == null){
|
||||
atts.put(att.getKey(), att.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
return atts.values().iterator();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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.ws.message;
|
||||
|
||||
import com.sun.xml.internal.ws.encoding.soap.SOAP12Constants;
|
||||
import com.sun.xml.internal.ws.encoding.soap.SOAPConstants;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
/**
|
||||
* Parses the SOAP message in order to get {@link QName} of a payload element.
|
||||
* It parses message until it
|
||||
*
|
||||
* @author Miroslav Kos (miroslav.kos at oracle.com)
|
||||
*/
|
||||
public class PayloadElementSniffer extends DefaultHandler {
|
||||
|
||||
// flag if the last element was SOAP body
|
||||
private boolean bodyStarted;
|
||||
|
||||
// payloadQName used as a return value
|
||||
private QName payloadQName;
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
||||
|
||||
if (bodyStarted) {
|
||||
payloadQName = new QName(uri, localName);
|
||||
// we have what we wanted - let's skip rest of parsing ...
|
||||
throw new SAXException("Payload element found, interrupting the parsing process.");
|
||||
}
|
||||
|
||||
// check for both SOAP 1.1/1.2
|
||||
if (equalsQName(uri, localName, SOAPConstants.QNAME_SOAP_BODY) ||
|
||||
equalsQName(uri, localName, SOAP12Constants.QNAME_SOAP_BODY)) {
|
||||
bodyStarted = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean equalsQName(String uri, String localName, QName qname) {
|
||||
return qname.getLocalPart().equals(localName) &&
|
||||
qname.getNamespaceURI().equals(uri);
|
||||
}
|
||||
|
||||
public QName getPayloadQName() {
|
||||
return payloadQName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* 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.ws.message;
|
||||
|
||||
import com.sun.istack.internal.NotNull;
|
||||
import com.sun.istack.internal.Nullable;
|
||||
import com.sun.xml.internal.stream.buffer.MutableXMLStreamBuffer;
|
||||
import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
|
||||
import com.sun.xml.internal.ws.api.message.Header;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.SOAPException;
|
||||
import javax.xml.soap.SOAPHeader;
|
||||
import javax.xml.soap.SOAPHeaderElement;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
|
||||
/**
|
||||
* {@link Header} that represents <wsa:ProblemAction>
|
||||
* @author Arun Gupta
|
||||
*/
|
||||
public class ProblemActionHeader extends AbstractHeaderImpl {
|
||||
protected @NotNull String action;
|
||||
protected String soapAction;
|
||||
protected @NotNull AddressingVersion av;
|
||||
|
||||
private static final String actionLocalName = "Action";
|
||||
private static final String soapActionLocalName = "SoapAction";
|
||||
|
||||
public ProblemActionHeader(@NotNull String action, @NotNull AddressingVersion av) {
|
||||
this(action,null,av);
|
||||
}
|
||||
|
||||
public ProblemActionHeader(@NotNull String action, String soapAction, @NotNull AddressingVersion av) {
|
||||
assert action!=null;
|
||||
assert av!=null;
|
||||
this.action = action;
|
||||
this.soapAction = soapAction;
|
||||
this.av = av;
|
||||
}
|
||||
|
||||
public
|
||||
@NotNull
|
||||
String getNamespaceURI() {
|
||||
return av.nsUri;
|
||||
}
|
||||
|
||||
public
|
||||
@NotNull
|
||||
String getLocalPart() {
|
||||
return "ProblemAction";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getAttribute(@NotNull String nsUri, @NotNull String localName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public XMLStreamReader readHeader() throws XMLStreamException {
|
||||
MutableXMLStreamBuffer buf = new MutableXMLStreamBuffer();
|
||||
XMLStreamWriter w = buf.createFromXMLStreamWriter();
|
||||
writeTo(w);
|
||||
return buf.readAsXMLStreamReader();
|
||||
}
|
||||
|
||||
public void writeTo(XMLStreamWriter w) throws XMLStreamException {
|
||||
w.writeStartElement("", getLocalPart(), getNamespaceURI());
|
||||
w.writeDefaultNamespace(getNamespaceURI());
|
||||
w.writeStartElement(actionLocalName);
|
||||
w.writeCharacters(action);
|
||||
w.writeEndElement();
|
||||
if (soapAction != null) {
|
||||
w.writeStartElement(soapActionLocalName);
|
||||
w.writeCharacters(soapAction);
|
||||
w.writeEndElement();
|
||||
}
|
||||
w.writeEndElement();
|
||||
}
|
||||
|
||||
public void writeTo(SOAPMessage saaj) throws SOAPException {
|
||||
SOAPHeader header = saaj.getSOAPHeader();
|
||||
if(header == null)
|
||||
header = saaj.getSOAPPart().getEnvelope().addHeader();
|
||||
SOAPHeaderElement she = header.addHeaderElement(new QName(getNamespaceURI(), getLocalPart()));
|
||||
she.addChildElement(actionLocalName);
|
||||
she.addTextNode(action);
|
||||
if (soapAction != null) {
|
||||
she.addChildElement(soapActionLocalName);
|
||||
she.addTextNode(soapAction);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeTo(ContentHandler h, ErrorHandler errorHandler) throws SAXException {
|
||||
String nsUri = getNamespaceURI();
|
||||
String ln = getLocalPart();
|
||||
|
||||
h.startPrefixMapping("",nsUri);
|
||||
h.startElement(nsUri,ln,ln,EMPTY_ATTS);
|
||||
h.startElement(nsUri,actionLocalName,actionLocalName,EMPTY_ATTS);
|
||||
h.characters(action.toCharArray(),0,action.length());
|
||||
h.endElement(nsUri,actionLocalName,actionLocalName);
|
||||
if (soapAction != null) {
|
||||
h.startElement(nsUri,soapActionLocalName,soapActionLocalName,EMPTY_ATTS);
|
||||
h.characters(soapAction.toCharArray(),0,soapAction.length());
|
||||
h.endElement(nsUri,soapActionLocalName,soapActionLocalName);
|
||||
}
|
||||
h.endElement(nsUri,ln,ln);
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.ws.message;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.SOAPException;
|
||||
import javax.xml.soap.SOAPHeader;
|
||||
import javax.xml.soap.SOAPHeaderElement;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
|
||||
/**
|
||||
* WS-Addressing <RelatesTo> header.
|
||||
*
|
||||
* Used for outbound only.
|
||||
*
|
||||
* @author Arun Gupta
|
||||
*/
|
||||
public final class RelatesToHeader extends StringHeader {
|
||||
protected String type;
|
||||
private final QName typeAttributeName;
|
||||
|
||||
public RelatesToHeader(QName name, String messageId, String type) {
|
||||
super(name, messageId);
|
||||
this.type = type;
|
||||
this.typeAttributeName = new QName(name.getNamespaceURI(), "type");
|
||||
}
|
||||
|
||||
public RelatesToHeader(QName name, String mid) {
|
||||
super(name, mid);
|
||||
this.typeAttributeName = new QName(name.getNamespaceURI(), "type");
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(XMLStreamWriter w) throws XMLStreamException {
|
||||
w.writeStartElement("", name.getLocalPart(), name.getNamespaceURI());
|
||||
w.writeDefaultNamespace(name.getNamespaceURI());
|
||||
if (type != null)
|
||||
w.writeAttribute("type", type);
|
||||
w.writeCharacters(value);
|
||||
w.writeEndElement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(SOAPMessage saaj) throws SOAPException {
|
||||
SOAPHeader header = saaj.getSOAPHeader();
|
||||
if (header == null)
|
||||
header = saaj.getSOAPPart().getEnvelope().addHeader();
|
||||
SOAPHeaderElement she = header.addHeaderElement(name);
|
||||
|
||||
if (type != null)
|
||||
she.addAttribute(typeAttributeName, type);
|
||||
she.addTextNode(value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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.ws.message;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
/**
|
||||
* Sniffs the root element name and its attributes from SAX events.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public final class RootElementSniffer extends DefaultHandler {
|
||||
private String nsUri = "##error";
|
||||
private String localName = "##error";
|
||||
private Attributes atts;
|
||||
|
||||
private final boolean parseAttributes;
|
||||
|
||||
public RootElementSniffer(boolean parseAttributes) {
|
||||
this.parseAttributes = parseAttributes;
|
||||
}
|
||||
|
||||
public RootElementSniffer() {
|
||||
this(true);
|
||||
}
|
||||
|
||||
public void startElement(String uri, String localName, String qName, Attributes a) throws SAXException {
|
||||
this.nsUri = uri;
|
||||
this.localName = localName;
|
||||
|
||||
if(parseAttributes) {
|
||||
if(a.getLength()==0) // often there's no attribute
|
||||
this.atts = EMPTY_ATTRIBUTES;
|
||||
else
|
||||
this.atts = new AttributesImpl(a);
|
||||
}
|
||||
|
||||
// no need to parse any further.
|
||||
throw aSAXException;
|
||||
}
|
||||
|
||||
public String getNsUri() {
|
||||
return nsUri;
|
||||
}
|
||||
|
||||
public String getLocalName() {
|
||||
return localName;
|
||||
}
|
||||
|
||||
public Attributes getAttributes() {
|
||||
return atts;
|
||||
}
|
||||
|
||||
private static final SAXException aSAXException = new SAXException();
|
||||
private static final Attributes EMPTY_ATTRIBUTES = new AttributesImpl();
|
||||
}
|
||||
161
jdkSrc/jdk8/com/sun/xml/internal/ws/message/StringHeader.java
Normal file
161
jdkSrc/jdk8/com/sun/xml/internal/ws/message/StringHeader.java
Normal file
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* 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.ws.message;
|
||||
|
||||
import com.sun.istack.internal.NotNull;
|
||||
import com.sun.istack.internal.Nullable;
|
||||
import com.sun.xml.internal.stream.buffer.MutableXMLStreamBuffer;
|
||||
import com.sun.xml.internal.ws.api.SOAPVersion;
|
||||
import com.sun.xml.internal.ws.api.message.Header;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.SOAPException;
|
||||
import javax.xml.soap.SOAPHeader;
|
||||
import javax.xml.soap.SOAPHeaderElement;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
|
||||
/**
|
||||
* {@link Header} that has a single text value in it
|
||||
* (IOW, of the form <foo>text</foo>.)
|
||||
*
|
||||
* @author Rama Pulavarthi
|
||||
* @author Arun Gupta
|
||||
*/
|
||||
public class StringHeader extends AbstractHeaderImpl {
|
||||
/**
|
||||
* Tag name.
|
||||
*/
|
||||
protected final QName name;
|
||||
/**
|
||||
* Header value.
|
||||
*/
|
||||
protected final String value;
|
||||
|
||||
protected boolean mustUnderstand = false;
|
||||
protected SOAPVersion soapVersion;
|
||||
|
||||
public StringHeader(@NotNull QName name, @NotNull String value) {
|
||||
assert name != null;
|
||||
assert value != null;
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public StringHeader(@NotNull QName name, @NotNull String value, @NotNull SOAPVersion soapVersion, boolean mustUnderstand ) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.soapVersion = soapVersion;
|
||||
this.mustUnderstand = mustUnderstand;
|
||||
}
|
||||
|
||||
public @NotNull String getNamespaceURI() {
|
||||
return name.getNamespaceURI();
|
||||
}
|
||||
|
||||
public @NotNull String getLocalPart() {
|
||||
return name.getLocalPart();
|
||||
}
|
||||
|
||||
@Nullable public String getAttribute(@NotNull String nsUri, @NotNull String localName) {
|
||||
if(mustUnderstand && soapVersion.nsUri.equals(nsUri) && MUST_UNDERSTAND.equals(localName)) {
|
||||
return getMustUnderstandLiteral(soapVersion);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public XMLStreamReader readHeader() throws XMLStreamException {
|
||||
MutableXMLStreamBuffer buf = new MutableXMLStreamBuffer();
|
||||
XMLStreamWriter w = buf.createFromXMLStreamWriter();
|
||||
writeTo(w);
|
||||
return buf.readAsXMLStreamReader();
|
||||
}
|
||||
|
||||
public void writeTo(XMLStreamWriter w) throws XMLStreamException {
|
||||
w.writeStartElement("", name.getLocalPart(), name.getNamespaceURI());
|
||||
w.writeDefaultNamespace(name.getNamespaceURI());
|
||||
if (mustUnderstand) {
|
||||
//Writing the ns declaration conditionally checking in the NSContext breaks XWSS. as readHeader() adds ns declaration,
|
||||
// where as writing alonf with the soap envelope does n't add it.
|
||||
//Looks like they expect the readHeader() and writeTo() produce the same infoset, Need to understand their usage
|
||||
|
||||
//if(w.getNamespaceContext().getPrefix(soapVersion.nsUri) == null) {
|
||||
w.writeNamespace("S", soapVersion.nsUri);
|
||||
w.writeAttribute("S", soapVersion.nsUri, MUST_UNDERSTAND, getMustUnderstandLiteral(soapVersion));
|
||||
// } else {
|
||||
// w.writeAttribute(soapVersion.nsUri,MUST_UNDERSTAND, getMustUnderstandLiteral(soapVersion));
|
||||
// }
|
||||
}
|
||||
w.writeCharacters(value);
|
||||
w.writeEndElement();
|
||||
}
|
||||
|
||||
public void writeTo(SOAPMessage saaj) throws SOAPException {
|
||||
SOAPHeader header = saaj.getSOAPHeader();
|
||||
if(header == null)
|
||||
header = saaj.getSOAPPart().getEnvelope().addHeader();
|
||||
SOAPHeaderElement she = header.addHeaderElement(name);
|
||||
if(mustUnderstand) {
|
||||
she.setMustUnderstand(true);
|
||||
}
|
||||
she.addTextNode(value);
|
||||
}
|
||||
|
||||
public void writeTo(ContentHandler h, ErrorHandler errorHandler) throws SAXException {
|
||||
String nsUri = name.getNamespaceURI();
|
||||
String ln = name.getLocalPart();
|
||||
|
||||
h.startPrefixMapping("",nsUri);
|
||||
if(mustUnderstand) {
|
||||
AttributesImpl attributes = new AttributesImpl();
|
||||
attributes.addAttribute(soapVersion.nsUri,MUST_UNDERSTAND,"S:"+MUST_UNDERSTAND,"CDATA", getMustUnderstandLiteral(soapVersion));
|
||||
h.startElement(nsUri,ln,ln,attributes);
|
||||
} else {
|
||||
h.startElement(nsUri,ln,ln,EMPTY_ATTS);
|
||||
}
|
||||
h.characters(value.toCharArray(),0,value.length());
|
||||
h.endElement(nsUri,ln,ln);
|
||||
}
|
||||
|
||||
private static String getMustUnderstandLiteral(SOAPVersion sv) {
|
||||
if(sv == SOAPVersion.SOAP_12) {
|
||||
return S12_MUST_UNDERSTAND_TRUE;
|
||||
} else {
|
||||
return S11_MUST_UNDERSTAND_TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected static final String MUST_UNDERSTAND = "mustUnderstand";
|
||||
protected static final String S12_MUST_UNDERSTAND_TRUE ="true";
|
||||
protected static final String S11_MUST_UNDERSTAND_TRUE ="1";
|
||||
}
|
||||
48
jdkSrc/jdk8/com/sun/xml/internal/ws/message/Util.java
Normal file
48
jdkSrc/jdk8/com/sun/xml/internal/ws/message/Util.java
Normal file
@@ -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.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.ws.message;
|
||||
|
||||
import com.sun.xml.internal.ws.api.message.Message;
|
||||
|
||||
/**
|
||||
* Utility code for the {@link Message} implementation.
|
||||
*/
|
||||
public abstract class Util {
|
||||
/**
|
||||
* Parses a stringthat represents a boolean into boolean.
|
||||
* This method assumes that the whilespace normalization has already taken place.
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
public static boolean parseBool(String value) {
|
||||
if(value.length()==0)
|
||||
return false;
|
||||
|
||||
char ch = value.charAt(0);
|
||||
return ch=='t' || ch=='1';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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.ws.message;
|
||||
|
||||
import com.sun.xml.internal.ws.api.message.Message;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
import org.xml.sax.helpers.XMLFilterImpl;
|
||||
|
||||
import javax.xml.transform.sax.SAXSource;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
final class XMLReaderImpl extends XMLFilterImpl {
|
||||
|
||||
private final Message msg;
|
||||
|
||||
XMLReaderImpl(Message msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public void parse(String systemId) {
|
||||
reportError();
|
||||
}
|
||||
|
||||
private void reportError() {
|
||||
// TODO: i18n
|
||||
throw new IllegalStateException(
|
||||
"This is a special XMLReader implementation that only works with the InputSource given in SAXSource.");
|
||||
}
|
||||
|
||||
public void parse(InputSource input) throws SAXException {
|
||||
if(input!=THE_SOURCE)
|
||||
reportError();
|
||||
msg.writeTo(this,this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContentHandler getContentHandler() {
|
||||
if(super.getContentHandler()==DUMMY) return null;
|
||||
return super.getContentHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentHandler(ContentHandler contentHandler) {
|
||||
if(contentHandler==null) contentHandler = DUMMY;
|
||||
super.setContentHandler(contentHandler);
|
||||
}
|
||||
|
||||
private static final ContentHandler DUMMY = new DefaultHandler();
|
||||
|
||||
/**
|
||||
* Special {@link InputSource} instance that we use to pass to {@link SAXSource}.
|
||||
*/
|
||||
protected static final InputSource THE_SOURCE = new InputSource();
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* 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.ws.message.jaxb;
|
||||
|
||||
import com.sun.istack.internal.logging.Logger;
|
||||
import com.sun.xml.internal.ws.api.message.Attachment;
|
||||
import com.sun.xml.internal.ws.api.message.AttachmentSet;
|
||||
import com.sun.xml.internal.ws.message.DataHandlerAttachment;
|
||||
|
||||
import javax.activation.DataHandler;
|
||||
import javax.xml.bind.attachment.AttachmentMarshaller;
|
||||
import javax.xml.ws.WebServiceException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Implementation of {@link AttachmentMarshaller}, its used from JAXBMessage to marshall swaref type
|
||||
*
|
||||
* @author Vivek Pandey
|
||||
* @see JAXBMessage
|
||||
*/
|
||||
final class AttachmentMarshallerImpl extends AttachmentMarshaller {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(AttachmentMarshallerImpl.class);
|
||||
|
||||
private AttachmentSet attachments;
|
||||
|
||||
public AttachmentMarshallerImpl(AttachmentSet attachemnts) {
|
||||
this.attachments = attachemnts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Release a reference to user objects to avoid keeping it in memory.
|
||||
*/
|
||||
void cleanup() {
|
||||
attachments = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String addMtomAttachment(DataHandler data, String elementNamespace, String elementLocalName) {
|
||||
// We don't use JAXB for handling XOP
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String addMtomAttachment(byte[] data, int offset, int length, String mimeType, String elementNamespace, String elementLocalName) {
|
||||
// We don't use JAXB for handling XOP
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String addSwaRefAttachment(DataHandler data) {
|
||||
String cid = encodeCid(null);
|
||||
Attachment att = new DataHandlerAttachment(cid, data);
|
||||
attachments.add(att);
|
||||
cid = "cid:" + cid;
|
||||
return cid;
|
||||
}
|
||||
|
||||
private String encodeCid(String ns) {
|
||||
String cid = "example.jaxws.sun.com";
|
||||
String name = UUID.randomUUID() + "@";
|
||||
if (ns != null && (ns.length() > 0)) {
|
||||
try {
|
||||
URI uri = new URI(ns);
|
||||
cid = uri.toURL().getHost();
|
||||
} catch (URISyntaxException e) {
|
||||
if (LOGGER.isLoggable(Level.INFO)) {
|
||||
LOGGER.log(Level.INFO, null, e);
|
||||
}
|
||||
return null;
|
||||
} catch (MalformedURLException e) {
|
||||
try {
|
||||
cid = URLEncoder.encode(ns, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e1) {
|
||||
throw new WebServiceException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return name + cid;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* 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.ws.message.jaxb;
|
||||
|
||||
import com.sun.xml.internal.ws.spi.db.XMLBridge;
|
||||
|
||||
import org.xml.sax.*;
|
||||
import org.xml.sax.ext.LexicalHandler;
|
||||
import org.xml.sax.helpers.XMLFilterImpl;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.sax.SAXSource;
|
||||
|
||||
/**
|
||||
* Wraps a bridge and JAXB object into a pseudo-{@link Source}.
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
final class JAXBBridgeSource extends SAXSource {
|
||||
|
||||
public JAXBBridgeSource( XMLBridge bridge, Object contentObject ) {
|
||||
this.bridge = bridge;
|
||||
this.contentObject = contentObject;
|
||||
|
||||
super.setXMLReader(pseudoParser);
|
||||
// pass a dummy InputSource. We don't care
|
||||
super.setInputSource(new InputSource());
|
||||
}
|
||||
|
||||
private final XMLBridge bridge;
|
||||
private final Object contentObject;
|
||||
|
||||
// this object will pretend as an XMLReader.
|
||||
// no matter what parameter is specified to the parse method,
|
||||
// it just parse the contentObject.
|
||||
private final XMLReader pseudoParser = new XMLFilterImpl() {
|
||||
public boolean getFeature(String name) throws SAXNotRecognizedException {
|
||||
if(name.equals("http://xml.org/sax/features/namespaces"))
|
||||
return true;
|
||||
if(name.equals("http://xml.org/sax/features/namespace-prefixes"))
|
||||
return false;
|
||||
throw new SAXNotRecognizedException(name);
|
||||
}
|
||||
|
||||
public void setFeature(String name, boolean value) throws SAXNotRecognizedException {
|
||||
if(name.equals("http://xml.org/sax/features/namespaces") && value)
|
||||
return;
|
||||
if(name.equals("http://xml.org/sax/features/namespace-prefixes") && !value)
|
||||
return;
|
||||
throw new SAXNotRecognizedException(name);
|
||||
}
|
||||
|
||||
public Object getProperty(String name) throws SAXNotRecognizedException {
|
||||
if( "http://xml.org/sax/properties/lexical-handler".equals(name) ) {
|
||||
return lexicalHandler;
|
||||
}
|
||||
throw new SAXNotRecognizedException(name);
|
||||
}
|
||||
|
||||
public void setProperty(String name, Object value) throws SAXNotRecognizedException {
|
||||
if( "http://xml.org/sax/properties/lexical-handler".equals(name) ) {
|
||||
this.lexicalHandler = (LexicalHandler)value;
|
||||
return;
|
||||
}
|
||||
throw new SAXNotRecognizedException(name);
|
||||
}
|
||||
|
||||
private LexicalHandler lexicalHandler;
|
||||
|
||||
public void parse(InputSource input) throws SAXException {
|
||||
parse();
|
||||
}
|
||||
|
||||
public void parse(String systemId) throws SAXException {
|
||||
parse();
|
||||
}
|
||||
|
||||
public void parse() throws SAXException {
|
||||
// parses a content object by using the given bridge
|
||||
// SAX events will be sent to the repeater, and the repeater
|
||||
// will further forward it to an appropriate component.
|
||||
try {
|
||||
startDocument();
|
||||
// this method only writes a fragment, so need start/end document
|
||||
bridge.marshal( contentObject, this, null );
|
||||
endDocument();
|
||||
} catch( JAXBException e ) {
|
||||
// wrap it to a SAXException
|
||||
SAXParseException se =
|
||||
new SAXParseException( e.getMessage(),
|
||||
null, null, -1, -1, e );
|
||||
|
||||
// if the consumer sets an error handler, it is our responsibility
|
||||
// to notify it.
|
||||
fatalError(se);
|
||||
|
||||
// this is a fatal error. Even if the error handler
|
||||
// returns, we will abort anyway.
|
||||
throw se;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
* 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.ws.message.jaxb;
|
||||
|
||||
import com.sun.xml.internal.ws.api.SOAPVersion;
|
||||
import com.sun.xml.internal.ws.api.message.Message;
|
||||
import com.sun.xml.internal.ws.api.message.MessageHeaders;
|
||||
import com.sun.xml.internal.ws.encoding.SOAPBindingCodec;
|
||||
import com.sun.xml.internal.ws.message.AbstractMessageImpl;
|
||||
import com.sun.xml.internal.ws.message.PayloadElementSniffer;
|
||||
import com.sun.xml.internal.ws.spi.db.BindingContext;
|
||||
import com.sun.xml.internal.ws.spi.db.XMLBridge;
|
||||
import com.sun.xml.internal.ws.streaming.MtomStreamWriter;
|
||||
import com.sun.xml.internal.ws.streaming.XMLStreamWriterUtil;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.attachment.AttachmentMarshaller;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.ws.WebServiceException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* {@link Message} backed by a JAXB bean; this implementation is used when client uses
|
||||
* Dispatch mechanism in JAXB/MESSAGE mode; difference from {@link JAXBMessage} is
|
||||
* that {@code jaxbObject} holds whole SOAP message including SOAP envelope;
|
||||
* it's the client who is responsible for preparing message content.
|
||||
*
|
||||
* @author Miroslav Kos (miroslav.kos at oracle.com)
|
||||
*/
|
||||
public class JAXBDispatchMessage extends AbstractMessageImpl {
|
||||
|
||||
private final Object jaxbObject;
|
||||
|
||||
private final XMLBridge bridge;
|
||||
|
||||
/**
|
||||
* For the use case of a user-supplied JAXB context that is not
|
||||
* a known JAXB type, as when creating a Disaptch object with a
|
||||
* JAXB object parameter, we will marshal and unmarshal directly with
|
||||
* the context object, as there is no Bond available. In this case,
|
||||
* swaRef is not supported.
|
||||
*/
|
||||
private final JAXBContext rawContext;
|
||||
|
||||
/**
|
||||
* Lazily sniffed payload element name
|
||||
*/
|
||||
private QName payloadQName;
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*/
|
||||
private JAXBDispatchMessage(JAXBDispatchMessage that) {
|
||||
super(that);
|
||||
jaxbObject = that.jaxbObject;
|
||||
rawContext = that.rawContext;
|
||||
bridge = that.bridge;
|
||||
}
|
||||
|
||||
public JAXBDispatchMessage(JAXBContext rawContext, Object jaxbObject, SOAPVersion soapVersion) {
|
||||
super(soapVersion);
|
||||
this.bridge = null;
|
||||
this.rawContext = rawContext;
|
||||
this.jaxbObject = jaxbObject;
|
||||
}
|
||||
|
||||
public JAXBDispatchMessage(BindingContext context, Object jaxbObject, SOAPVersion soapVersion) {
|
||||
super(soapVersion);
|
||||
this.bridge = context.createFragmentBridge();
|
||||
this.rawContext = null;
|
||||
this.jaxbObject = jaxbObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writePayloadTo(ContentHandler contentHandler, ErrorHandler errorHandler, boolean fragment) throws SAXException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasHeaders() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageHeaders getHeaders() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPayloadLocalPart() {
|
||||
if (payloadQName == null) {
|
||||
readPayloadElement();
|
||||
}
|
||||
return payloadQName.getLocalPart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPayloadNamespaceURI() {
|
||||
if (payloadQName == null) {
|
||||
readPayloadElement();
|
||||
}
|
||||
return payloadQName.getNamespaceURI();
|
||||
}
|
||||
|
||||
private void readPayloadElement() {
|
||||
PayloadElementSniffer sniffer = new PayloadElementSniffer();
|
||||
try {
|
||||
if (rawContext != null) {
|
||||
Marshaller m = rawContext.createMarshaller();
|
||||
m.setProperty("jaxb.fragment", Boolean.FALSE);
|
||||
m.marshal(jaxbObject, sniffer);
|
||||
} else {
|
||||
bridge.marshal(jaxbObject, sniffer, null);
|
||||
}
|
||||
|
||||
} catch (JAXBException e) {
|
||||
// if it's due to us aborting the processing after the first element,
|
||||
// we can safely ignore this exception.
|
||||
//
|
||||
// if it's due to error in the object, the same error will be reported
|
||||
// when the readHeader() method is used, so we don't have to report
|
||||
// an error right now.
|
||||
payloadQName = sniffer.getPayloadQName();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPayload() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Source readPayloadAsSource() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public XMLStreamReader readPayload() throws XMLStreamException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writePayloadTo(XMLStreamWriter sw) throws XMLStreamException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message copy() {
|
||||
return new JAXBDispatchMessage(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void writeTo(XMLStreamWriter sw) throws XMLStreamException {
|
||||
try {
|
||||
// MtomCodec sets its own AttachmentMarshaller
|
||||
AttachmentMarshaller am = (sw instanceof MtomStreamWriter)
|
||||
? ((MtomStreamWriter) sw).getAttachmentMarshaller()
|
||||
: new AttachmentMarshallerImpl(attachmentSet);
|
||||
|
||||
// Get the encoding of the writer
|
||||
String encoding = XMLStreamWriterUtil.getEncoding(sw);
|
||||
|
||||
// Get output stream and use JAXB UTF-8 writer
|
||||
OutputStream os = bridge.supportOutputStream() ? XMLStreamWriterUtil.getOutputStream(sw) : null;
|
||||
if (rawContext != null) {
|
||||
Marshaller m = rawContext.createMarshaller();
|
||||
m.setProperty("jaxb.fragment", Boolean.FALSE);
|
||||
m.setAttachmentMarshaller(am);
|
||||
if (os != null) {
|
||||
m.marshal(jaxbObject, os);
|
||||
} else {
|
||||
m.marshal(jaxbObject, sw);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (os != null && encoding != null && encoding.equalsIgnoreCase(SOAPBindingCodec.UTF8_ENCODING)) {
|
||||
bridge.marshal(jaxbObject, os, sw.getNamespaceContext(), am);
|
||||
} else {
|
||||
bridge.marshal(jaxbObject, sw, am);
|
||||
}
|
||||
}
|
||||
//cleanup() is not needed since JAXB doesn't keep ref to AttachmentMarshaller
|
||||
} catch (JAXBException e) {
|
||||
// bug 6449684, spec 4.3.4
|
||||
throw new WebServiceException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
212
jdkSrc/jdk8/com/sun/xml/internal/ws/message/jaxb/JAXBHeader.java
Normal file
212
jdkSrc/jdk8/com/sun/xml/internal/ws/message/jaxb/JAXBHeader.java
Normal file
@@ -0,0 +1,212 @@
|
||||
/*
|
||||
* 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.ws.message.jaxb;
|
||||
|
||||
import com.sun.istack.internal.NotNull;
|
||||
import com.sun.istack.internal.XMLStreamException2;
|
||||
import com.sun.xml.internal.bind.api.Bridge;
|
||||
import com.sun.xml.internal.stream.buffer.MutableXMLStreamBuffer;
|
||||
import com.sun.xml.internal.stream.buffer.XMLStreamBuffer;
|
||||
import com.sun.xml.internal.stream.buffer.XMLStreamBufferResult;
|
||||
import com.sun.xml.internal.ws.api.message.Header;
|
||||
import com.sun.xml.internal.ws.encoding.SOAPBindingCodec;
|
||||
import com.sun.xml.internal.ws.message.AbstractHeaderImpl;
|
||||
import com.sun.xml.internal.ws.message.RootElementSniffer;
|
||||
import com.sun.xml.internal.ws.spi.db.BindingContext;
|
||||
import com.sun.xml.internal.ws.spi.db.XMLBridge;
|
||||
import com.sun.xml.internal.ws.streaming.XMLStreamWriterUtil;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
import javax.xml.bind.JAXBElement;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.bind.util.JAXBResult;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.soap.SOAPException;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
import javax.xml.soap.SOAPHeader;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* {@link Header} whose physical data representation is a JAXB bean.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public final class JAXBHeader extends AbstractHeaderImpl {
|
||||
|
||||
/**
|
||||
* The JAXB object that represents the header.
|
||||
*/
|
||||
private final Object jaxbObject;
|
||||
|
||||
private final XMLBridge bridge;
|
||||
|
||||
// information about this header. lazily obtained.
|
||||
private String nsUri;
|
||||
private String localName;
|
||||
private Attributes atts;
|
||||
|
||||
/**
|
||||
* Once the header is turned into infoset,
|
||||
* this buffer keeps it.
|
||||
*/
|
||||
private XMLStreamBuffer infoset;
|
||||
|
||||
public JAXBHeader(BindingContext context, Object jaxbObject) {
|
||||
this.jaxbObject = jaxbObject;
|
||||
// this.bridge = new MarshallerBridge(context);
|
||||
this.bridge = context.createFragmentBridge();
|
||||
|
||||
if (jaxbObject instanceof JAXBElement) {
|
||||
JAXBElement e = (JAXBElement) jaxbObject;
|
||||
this.nsUri = e.getName().getNamespaceURI();
|
||||
this.localName = e.getName().getLocalPart();
|
||||
}
|
||||
}
|
||||
|
||||
public JAXBHeader(XMLBridge bridge, Object jaxbObject) {
|
||||
this.jaxbObject = jaxbObject;
|
||||
this.bridge = bridge;
|
||||
|
||||
QName tagName = bridge.getTypeInfo().tagName;
|
||||
this.nsUri = tagName.getNamespaceURI();
|
||||
this.localName = tagName.getLocalPart();
|
||||
}
|
||||
|
||||
/**
|
||||
* Lazily parse the first element to obtain attribute values on it.
|
||||
*/
|
||||
private void parse() {
|
||||
RootElementSniffer sniffer = new RootElementSniffer();
|
||||
try {
|
||||
bridge.marshal(jaxbObject,sniffer,null);
|
||||
} catch (JAXBException e) {
|
||||
// if it's due to us aborting the processing after the first element,
|
||||
// we can safely ignore this exception.
|
||||
//
|
||||
// if it's due to error in the object, the same error will be reported
|
||||
// when the readHeader() method is used, so we don't have to report
|
||||
// an error right now.
|
||||
nsUri = sniffer.getNsUri();
|
||||
localName = sniffer.getLocalName();
|
||||
atts = sniffer.getAttributes();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public @NotNull String getNamespaceURI() {
|
||||
if(nsUri==null)
|
||||
parse();
|
||||
return nsUri;
|
||||
}
|
||||
|
||||
public @NotNull String getLocalPart() {
|
||||
if(localName==null)
|
||||
parse();
|
||||
return localName;
|
||||
}
|
||||
|
||||
public String getAttribute(String nsUri, String localName) {
|
||||
if(atts==null)
|
||||
parse();
|
||||
return atts.getValue(nsUri,localName);
|
||||
}
|
||||
|
||||
public XMLStreamReader readHeader() throws XMLStreamException {
|
||||
if(infoset==null) {
|
||||
MutableXMLStreamBuffer buffer = new MutableXMLStreamBuffer();
|
||||
writeTo(buffer.createFromXMLStreamWriter());
|
||||
infoset = buffer;
|
||||
}
|
||||
return infoset.readAsXMLStreamReader();
|
||||
}
|
||||
|
||||
public <T> T readAsJAXB(Unmarshaller unmarshaller) throws JAXBException {
|
||||
try {
|
||||
JAXBResult r = new JAXBResult(unmarshaller);
|
||||
// bridge marshals a fragment, so we need to add start/endDocument by ourselves
|
||||
r.getHandler().startDocument();
|
||||
bridge.marshal(jaxbObject,r);
|
||||
r.getHandler().endDocument();
|
||||
return (T)r.getResult();
|
||||
} catch (SAXException e) {
|
||||
throw new JAXBException(e);
|
||||
}
|
||||
}
|
||||
/** @deprecated */
|
||||
public <T> T readAsJAXB(Bridge<T> bridge) throws JAXBException {
|
||||
return bridge.unmarshal(new JAXBBridgeSource(this.bridge,jaxbObject));
|
||||
}
|
||||
|
||||
public <T> T readAsJAXB(XMLBridge<T> bond) throws JAXBException {
|
||||
return bond.unmarshal(new JAXBBridgeSource(this.bridge,jaxbObject),null);
|
||||
}
|
||||
|
||||
public void writeTo(XMLStreamWriter sw) throws XMLStreamException {
|
||||
try {
|
||||
// Get the encoding of the writer
|
||||
String encoding = XMLStreamWriterUtil.getEncoding(sw);
|
||||
|
||||
// Get output stream and use JAXB UTF-8 writer
|
||||
OutputStream os = bridge.supportOutputStream() ? XMLStreamWriterUtil.getOutputStream(sw) : null;
|
||||
if (os != null && encoding != null && encoding.equalsIgnoreCase(SOAPBindingCodec.UTF8_ENCODING)) {
|
||||
bridge.marshal(jaxbObject, os, sw.getNamespaceContext(), null);
|
||||
} else {
|
||||
bridge.marshal(jaxbObject,sw, null);
|
||||
}
|
||||
} catch (JAXBException e) {
|
||||
throw new XMLStreamException2(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeTo(SOAPMessage saaj) throws SOAPException {
|
||||
try {
|
||||
SOAPHeader header = saaj.getSOAPHeader();
|
||||
if (header == null)
|
||||
header = saaj.getSOAPPart().getEnvelope().addHeader();
|
||||
bridge.marshal(jaxbObject,header);
|
||||
} catch (JAXBException e) {
|
||||
throw new SOAPException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeTo(ContentHandler contentHandler, ErrorHandler errorHandler) throws SAXException {
|
||||
try {
|
||||
bridge.marshal(jaxbObject,contentHandler,null);
|
||||
} catch (JAXBException e) {
|
||||
SAXParseException x = new SAXParseException(e.getMessage(),null,null,-1,-1,e);
|
||||
errorHandler.fatalError(x);
|
||||
throw x;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,446 @@
|
||||
/*
|
||||
* 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.ws.message.jaxb;
|
||||
|
||||
import com.sun.istack.internal.FragmentContentHandler;
|
||||
import com.sun.xml.internal.stream.buffer.MutableXMLStreamBuffer;
|
||||
import com.sun.xml.internal.stream.buffer.XMLStreamBuffer;
|
||||
import com.sun.xml.internal.stream.buffer.XMLStreamBufferResult;
|
||||
import com.sun.xml.internal.ws.api.SOAPVersion;
|
||||
import com.sun.xml.internal.ws.api.message.AttachmentSet;
|
||||
import com.sun.xml.internal.ws.api.message.Header;
|
||||
import com.sun.xml.internal.ws.api.message.HeaderList;
|
||||
import com.sun.xml.internal.ws.api.message.Message;
|
||||
import com.sun.xml.internal.ws.api.message.MessageHeaders;
|
||||
import com.sun.xml.internal.ws.api.message.StreamingSOAP;
|
||||
import com.sun.xml.internal.ws.encoding.SOAPBindingCodec;
|
||||
import com.sun.xml.internal.ws.message.AbstractMessageImpl;
|
||||
import com.sun.xml.internal.ws.message.AttachmentSetImpl;
|
||||
import com.sun.xml.internal.ws.message.RootElementSniffer;
|
||||
import com.sun.xml.internal.ws.message.stream.StreamMessage;
|
||||
import com.sun.xml.internal.ws.spi.db.BindingContext;
|
||||
import com.sun.xml.internal.ws.spi.db.BindingContextFactory;
|
||||
import com.sun.xml.internal.ws.spi.db.XMLBridge;
|
||||
import com.sun.xml.internal.ws.streaming.XMLStreamWriterUtil;
|
||||
import com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil;
|
||||
import com.sun.xml.internal.ws.streaming.MtomStreamWriter;
|
||||
import com.sun.xml.internal.ws.util.xml.XMLReaderComposite;
|
||||
import com.sun.xml.internal.ws.util.xml.XMLReaderComposite.ElemInfo;
|
||||
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBElement;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.bind.attachment.AttachmentMarshaller;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.util.JAXBResult;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
import static javax.xml.stream.XMLStreamConstants.START_DOCUMENT;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.ws.WebServiceException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* {@link Message} backed by a JAXB bean.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public final class JAXBMessage extends AbstractMessageImpl implements StreamingSOAP {
|
||||
private MessageHeaders headers;
|
||||
|
||||
/**
|
||||
* The JAXB object that represents the payload.
|
||||
*/
|
||||
private final Object jaxbObject;
|
||||
|
||||
private final XMLBridge bridge;
|
||||
|
||||
/**
|
||||
* For the use case of a user-supplied JAXB context that is not
|
||||
* a known JAXB type, as when creating a Disaptch object with a
|
||||
* JAXB object parameter, we will marshal and unmarshal directly with
|
||||
* the context object, as there is no Bond available. In this case,
|
||||
* swaRef is not supported.
|
||||
*/
|
||||
private final JAXBContext rawContext;
|
||||
|
||||
/**
|
||||
* Lazily sniffed payload element name
|
||||
*/
|
||||
private String nsUri,localName;
|
||||
|
||||
/**
|
||||
* If we have the infoset representation for the payload, this field is non-null.
|
||||
*/
|
||||
private XMLStreamBuffer infoset;
|
||||
|
||||
public static Message create(BindingContext context, Object jaxbObject, SOAPVersion soapVersion, MessageHeaders headers, AttachmentSet attachments) {
|
||||
if(!context.hasSwaRef()) {
|
||||
return new JAXBMessage(context,jaxbObject,soapVersion,headers,attachments);
|
||||
}
|
||||
|
||||
// If we have swaRef, then that means we might have attachments.
|
||||
// to comply with the packet API, we need to eagerly turn the JAXB object into infoset
|
||||
// to correctly find out about attachments.
|
||||
|
||||
try {
|
||||
MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();
|
||||
|
||||
Marshaller m = context.createMarshaller();
|
||||
AttachmentMarshallerImpl am = new AttachmentMarshallerImpl(attachments);
|
||||
m.setAttachmentMarshaller(am);
|
||||
am.cleanup();
|
||||
m.marshal(jaxbObject,xsb.createFromXMLStreamWriter());
|
||||
|
||||
// any way to reuse this XMLStreamBuffer in StreamMessage?
|
||||
return new StreamMessage(headers,attachments,xsb.readAsXMLStreamReader(),soapVersion);
|
||||
} catch (JAXBException e) {
|
||||
throw new WebServiceException(e);
|
||||
} catch (XMLStreamException e) {
|
||||
throw new WebServiceException(e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Creates a {@link Message} backed by a JAXB bean.
|
||||
*
|
||||
* @param context
|
||||
* The JAXBContext to be used for marshalling.
|
||||
* @param jaxbObject
|
||||
* The JAXB object that represents the payload. must not be null. This object
|
||||
* must be bound to an element (which means it either is a {@link JAXBElement} or
|
||||
* an instanceof a class with {@link XmlRootElement}).
|
||||
* @param soapVersion
|
||||
* The SOAP version of the message. Must not be null.
|
||||
*/
|
||||
public static Message create(BindingContext context, Object jaxbObject, SOAPVersion soapVersion) {
|
||||
return create(context,jaxbObject,soapVersion,null,null);
|
||||
}
|
||||
/** @deprecated */
|
||||
public static Message create(JAXBContext context, Object jaxbObject, SOAPVersion soapVersion) {
|
||||
return create(BindingContextFactory.create(context),jaxbObject,soapVersion,null,null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* For use when creating a Dispatch object with an unknown JAXB implementation
|
||||
* for he JAXBContext parameter.
|
||||
*
|
||||
*/
|
||||
public static Message createRaw(JAXBContext context, Object jaxbObject, SOAPVersion soapVersion) {
|
||||
return new JAXBMessage(context,jaxbObject,soapVersion,null,null);
|
||||
}
|
||||
|
||||
private JAXBMessage( BindingContext context, Object jaxbObject, SOAPVersion soapVer, MessageHeaders headers, AttachmentSet attachments ) {
|
||||
super(soapVer);
|
||||
// this.bridge = new MarshallerBridge(context);
|
||||
this.bridge = context.createFragmentBridge();
|
||||
this.rawContext = null;
|
||||
this.jaxbObject = jaxbObject;
|
||||
this.headers = headers;
|
||||
this.attachmentSet = attachments;
|
||||
}
|
||||
|
||||
private JAXBMessage( JAXBContext rawContext, Object jaxbObject, SOAPVersion soapVer, MessageHeaders headers, AttachmentSet attachments ) {
|
||||
super(soapVer);
|
||||
// this.bridge = new MarshallerBridge(context);
|
||||
this.rawContext = rawContext;
|
||||
this.bridge = null;
|
||||
this.jaxbObject = jaxbObject;
|
||||
this.headers = headers;
|
||||
this.attachmentSet = attachments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link Message} backed by a JAXB bean.
|
||||
*
|
||||
* @param bridge
|
||||
* Specify the payload tag name and how <tt>jaxbObject</tt> is bound.
|
||||
* @param jaxbObject
|
||||
*/
|
||||
public static Message create(XMLBridge bridge, Object jaxbObject, SOAPVersion soapVer) {
|
||||
if(!bridge.context().hasSwaRef()) {
|
||||
return new JAXBMessage(bridge,jaxbObject,soapVer);
|
||||
}
|
||||
|
||||
// If we have swaRef, then that means we might have attachments.
|
||||
// to comply with the packet API, we need to eagerly turn the JAXB object into infoset
|
||||
// to correctly find out about attachments.
|
||||
|
||||
try {
|
||||
MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();
|
||||
|
||||
AttachmentSetImpl attachments = new AttachmentSetImpl();
|
||||
AttachmentMarshallerImpl am = new AttachmentMarshallerImpl(attachments);
|
||||
bridge.marshal(jaxbObject,xsb.createFromXMLStreamWriter(), am);
|
||||
am.cleanup();
|
||||
|
||||
// any way to reuse this XMLStreamBuffer in StreamMessage?
|
||||
return new StreamMessage(null,attachments,xsb.readAsXMLStreamReader(),soapVer);
|
||||
} catch (JAXBException e) {
|
||||
throw new WebServiceException(e);
|
||||
} catch (XMLStreamException e) {
|
||||
throw new WebServiceException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private JAXBMessage(XMLBridge bridge, Object jaxbObject, SOAPVersion soapVer) {
|
||||
super(soapVer);
|
||||
// TODO: think about a better way to handle BridgeContext
|
||||
this.bridge = bridge;
|
||||
this.rawContext = null;
|
||||
this.jaxbObject = jaxbObject;
|
||||
QName tagName = bridge.getTypeInfo().tagName;
|
||||
this.nsUri = tagName.getNamespaceURI();
|
||||
this.localName = tagName.getLocalPart();
|
||||
this.attachmentSet = new AttachmentSetImpl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*/
|
||||
public JAXBMessage(JAXBMessage that) {
|
||||
super(that);
|
||||
this.headers = that.headers;
|
||||
if(this.headers!=null)
|
||||
this.headers = new HeaderList(this.headers);
|
||||
this.attachmentSet = that.attachmentSet;
|
||||
|
||||
this.jaxbObject = that.jaxbObject;
|
||||
this.bridge = that.bridge;
|
||||
this.rawContext = that.rawContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasHeaders() {
|
||||
return headers!=null && headers.hasHeaders();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageHeaders getHeaders() {
|
||||
if(headers==null)
|
||||
headers = new HeaderList(getSOAPVersion());
|
||||
return headers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPayloadLocalPart() {
|
||||
if(localName==null)
|
||||
sniff();
|
||||
return localName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPayloadNamespaceURI() {
|
||||
if(nsUri==null)
|
||||
sniff();
|
||||
return nsUri;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPayload() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the tag name of the root element.
|
||||
*/
|
||||
private void sniff() {
|
||||
RootElementSniffer sniffer = new RootElementSniffer(false);
|
||||
try {
|
||||
if (rawContext != null) {
|
||||
Marshaller m = rawContext.createMarshaller();
|
||||
m.setProperty("jaxb.fragment", Boolean.TRUE);
|
||||
m.marshal(jaxbObject,sniffer);
|
||||
} else
|
||||
bridge.marshal(jaxbObject,sniffer,null);
|
||||
} catch (JAXBException e) {
|
||||
// if it's due to us aborting the processing after the first element,
|
||||
// we can safely ignore this exception.
|
||||
//
|
||||
// if it's due to error in the object, the same error will be reported
|
||||
// when the readHeader() method is used, so we don't have to report
|
||||
// an error right now.
|
||||
nsUri = sniffer.getNsUri();
|
||||
localName = sniffer.getLocalName();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Source readPayloadAsSource() {
|
||||
return new JAXBBridgeSource(bridge,jaxbObject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T readPayloadAsJAXB(Unmarshaller unmarshaller) throws JAXBException {
|
||||
JAXBResult out = new JAXBResult(unmarshaller);
|
||||
// since the bridge only produces fragments, we need to fire start/end document.
|
||||
try {
|
||||
out.getHandler().startDocument();
|
||||
if (rawContext != null) {
|
||||
Marshaller m = rawContext.createMarshaller();
|
||||
m.setProperty("jaxb.fragment", Boolean.TRUE);
|
||||
m.marshal(jaxbObject,out);
|
||||
} else
|
||||
bridge.marshal(jaxbObject,out);
|
||||
out.getHandler().endDocument();
|
||||
} catch (SAXException e) {
|
||||
throw new JAXBException(e);
|
||||
}
|
||||
return (T)out.getResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public XMLStreamReader readPayload() throws XMLStreamException {
|
||||
try {
|
||||
if(infoset==null) {
|
||||
if (rawContext != null) {
|
||||
XMLStreamBufferResult sbr = new XMLStreamBufferResult();
|
||||
Marshaller m = rawContext.createMarshaller();
|
||||
m.setProperty("jaxb.fragment", Boolean.TRUE);
|
||||
m.marshal(jaxbObject, sbr);
|
||||
infoset = sbr.getXMLStreamBuffer();
|
||||
} else {
|
||||
MutableXMLStreamBuffer buffer = new MutableXMLStreamBuffer();
|
||||
writePayloadTo(buffer.createFromXMLStreamWriter());
|
||||
infoset = buffer;
|
||||
}
|
||||
}
|
||||
XMLStreamReader reader = infoset.readAsXMLStreamReader();
|
||||
if(reader.getEventType()== START_DOCUMENT)
|
||||
XMLStreamReaderUtil.nextElementContent(reader);
|
||||
return reader;
|
||||
} catch (JAXBException e) {
|
||||
// bug 6449684, spec 4.3.4
|
||||
throw new WebServiceException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the payload as SAX events.
|
||||
*/
|
||||
@Override
|
||||
protected void writePayloadTo(ContentHandler contentHandler, ErrorHandler errorHandler, boolean fragment) throws SAXException {
|
||||
try {
|
||||
if(fragment)
|
||||
contentHandler = new FragmentContentHandler(contentHandler);
|
||||
AttachmentMarshallerImpl am = new AttachmentMarshallerImpl(attachmentSet);
|
||||
if (rawContext != null) {
|
||||
Marshaller m = rawContext.createMarshaller();
|
||||
m.setProperty("jaxb.fragment", Boolean.TRUE);
|
||||
m.setAttachmentMarshaller(am);
|
||||
m.marshal(jaxbObject,contentHandler);
|
||||
} else
|
||||
bridge.marshal(jaxbObject,contentHandler, am);
|
||||
am.cleanup();
|
||||
} catch (JAXBException e) {
|
||||
// this is really more helpful but spec compliance
|
||||
// errorHandler.fatalError(new SAXParseException(e.getMessage(),NULL_LOCATOR,e));
|
||||
// bug 6449684, spec 4.3.4
|
||||
throw new WebServiceException(e.getMessage(),e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writePayloadTo(XMLStreamWriter sw) throws XMLStreamException {
|
||||
try {
|
||||
// MtomCodec sets its own AttachmentMarshaller
|
||||
AttachmentMarshaller am = (sw instanceof MtomStreamWriter)
|
||||
? ((MtomStreamWriter)sw).getAttachmentMarshaller()
|
||||
: new AttachmentMarshallerImpl(attachmentSet);
|
||||
|
||||
// Get the encoding of the writer
|
||||
String encoding = XMLStreamWriterUtil.getEncoding(sw);
|
||||
|
||||
// Get output stream and use JAXB UTF-8 writer
|
||||
OutputStream os = bridge.supportOutputStream() ? XMLStreamWriterUtil.getOutputStream(sw) : null;
|
||||
if (rawContext != null) {
|
||||
Marshaller m = rawContext.createMarshaller();
|
||||
m.setProperty("jaxb.fragment", Boolean.TRUE);
|
||||
m.setAttachmentMarshaller(am);
|
||||
if (os != null) {
|
||||
m.marshal(jaxbObject, os);
|
||||
} else {
|
||||
m.marshal(jaxbObject, sw);
|
||||
}
|
||||
} else {
|
||||
if (os != null && encoding != null && encoding.equalsIgnoreCase(SOAPBindingCodec.UTF8_ENCODING)) {
|
||||
bridge.marshal(jaxbObject, os, sw.getNamespaceContext(), am);
|
||||
} else {
|
||||
bridge.marshal(jaxbObject, sw, am);
|
||||
}
|
||||
}
|
||||
//cleanup() is not needed since JAXB doesn't keep ref to AttachmentMarshaller
|
||||
//am.cleanup();
|
||||
} catch (JAXBException e) {
|
||||
// bug 6449684, spec 4.3.4
|
||||
throw new WebServiceException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message copy() {
|
||||
return new JAXBMessage(this);
|
||||
}
|
||||
|
||||
public XMLStreamReader readEnvelope() {
|
||||
int base = soapVersion.ordinal()*3;
|
||||
this.envelopeTag = DEFAULT_TAGS.get(base);
|
||||
this.bodyTag = DEFAULT_TAGS.get(base+2);
|
||||
List<XMLStreamReader> hReaders = new java.util.ArrayList<XMLStreamReader>();
|
||||
ElemInfo envElem = new ElemInfo(envelopeTag, null);
|
||||
ElemInfo bdyElem = new ElemInfo(bodyTag, envElem);
|
||||
for (Header h : getHeaders().asList()) {
|
||||
try {
|
||||
hReaders.add(h.readHeader());
|
||||
} catch (XMLStreamException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
XMLStreamReader soapHeader = null;
|
||||
if(hReaders.size()>0) {
|
||||
headerTag = DEFAULT_TAGS.get(base+1);
|
||||
ElemInfo hdrElem = new ElemInfo(headerTag, envElem);
|
||||
soapHeader = new XMLReaderComposite(hdrElem, hReaders.toArray(new XMLStreamReader[hReaders.size()]));
|
||||
}
|
||||
try {
|
||||
XMLStreamReader payload= readPayload();
|
||||
XMLStreamReader soapBody = new XMLReaderComposite(bdyElem, new XMLStreamReader[]{payload});
|
||||
XMLStreamReader[] soapContent = (soapHeader != null) ? new XMLStreamReader[]{soapHeader, soapBody} : new XMLStreamReader[]{soapBody};
|
||||
return new XMLReaderComposite(envElem, soapContent);
|
||||
} catch (XMLStreamException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.ws.message.jaxb;
|
||||
|
||||
import com.sun.xml.internal.bind.api.Bridge;
|
||||
import com.sun.xml.internal.bind.api.JAXBRIContext;
|
||||
import com.sun.xml.internal.bind.api.TypeReference;
|
||||
import com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl;
|
||||
import com.sun.xml.internal.bind.v2.runtime.MarshallerImpl;
|
||||
import org.w3c.dom.Node;
|
||||
import org.xml.sax.ContentHandler;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.namespace.NamespaceContext;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.Source;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* Used to adapt {@link Marshaller} into a {@link Bridge}.
|
||||
* @deprecated
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
final class MarshallerBridge extends Bridge {
|
||||
public MarshallerBridge(JAXBRIContext context) {
|
||||
super((JAXBContextImpl)context);
|
||||
}
|
||||
|
||||
public void marshal(Marshaller m, Object object, XMLStreamWriter output) throws JAXBException {
|
||||
m.setProperty(Marshaller.JAXB_FRAGMENT,true);
|
||||
try {
|
||||
m.marshal(object,output);
|
||||
} finally {
|
||||
m.setProperty(Marshaller.JAXB_FRAGMENT,false);
|
||||
}
|
||||
}
|
||||
|
||||
public void marshal(Marshaller m, Object object, OutputStream output, NamespaceContext nsContext) throws JAXBException {
|
||||
m.setProperty(Marshaller.JAXB_FRAGMENT,true);
|
||||
try {
|
||||
((MarshallerImpl)m).marshal(object,output,nsContext);
|
||||
} finally {
|
||||
m.setProperty(Marshaller.JAXB_FRAGMENT,false);
|
||||
}
|
||||
}
|
||||
|
||||
public void marshal(Marshaller m, Object object, Node output) throws JAXBException {
|
||||
m.setProperty(Marshaller.JAXB_FRAGMENT,true);
|
||||
try {
|
||||
m.marshal(object,output);
|
||||
} finally {
|
||||
m.setProperty(Marshaller.JAXB_FRAGMENT,false);
|
||||
}
|
||||
}
|
||||
|
||||
public void marshal(Marshaller m, Object object, ContentHandler contentHandler) throws JAXBException {
|
||||
m.setProperty(Marshaller.JAXB_FRAGMENT,true);
|
||||
try {
|
||||
m.marshal(object,contentHandler);
|
||||
} finally {
|
||||
m.setProperty(Marshaller.JAXB_FRAGMENT,false);
|
||||
}
|
||||
}
|
||||
|
||||
public void marshal(Marshaller m, Object object, Result result) throws JAXBException {
|
||||
m.setProperty(Marshaller.JAXB_FRAGMENT,true);
|
||||
try {
|
||||
m.marshal(object,result);
|
||||
} finally {
|
||||
m.setProperty(Marshaller.JAXB_FRAGMENT,false);
|
||||
}
|
||||
}
|
||||
|
||||
public Object unmarshal(Unmarshaller u, XMLStreamReader in) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Object unmarshal(Unmarshaller u, Source in) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Object unmarshal(Unmarshaller u, InputStream in) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Object unmarshal(Unmarshaller u, Node n) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public TypeReference getTypeReference() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* {@link com.sun.xml.internal.ws.api.message.Message} implementation for JAXB.
|
||||
*
|
||||
* <pre>
|
||||
* TODO:
|
||||
* Because a producer of a message doesn't generally know
|
||||
* when a message is consumed, it's difficult for
|
||||
* the caller to do a proper instance caching. Perhaps
|
||||
* there should be a layer around JAXBContext that does that?
|
||||
* </pre>
|
||||
*/
|
||||
package com.sun.xml.internal.ws.message.jaxb;
|
||||
|
||||
import com.sun.xml.internal.ws.api.message.Message;
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* {@link com.sun.xml.internal.ws.api.message.Message} implementations.
|
||||
*/
|
||||
package com.sun.xml.internal.ws.message;
|
||||
|
||||
import com.sun.xml.internal.ws.api.message.Message;
|
||||
@@ -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.ws.message.saaj;
|
||||
|
||||
import com.sun.xml.internal.ws.api.message.Header;
|
||||
import com.sun.xml.internal.ws.api.SOAPVersion;
|
||||
import com.sun.xml.internal.ws.message.DOMHeader;
|
||||
import com.sun.istack.internal.NotNull;
|
||||
|
||||
import javax.xml.soap.SOAPHeaderElement;
|
||||
|
||||
/**
|
||||
* {@link Header} for {@link SOAPHeaderElement}.
|
||||
*
|
||||
* @author Vivek Pandey
|
||||
*/
|
||||
public final class SAAJHeader extends DOMHeader<SOAPHeaderElement> {
|
||||
public SAAJHeader(SOAPHeaderElement header) {
|
||||
// we won't rely on any of the super class method that uses SOAPVersion,
|
||||
// so we can just pass in a dummy version
|
||||
super(header);
|
||||
}
|
||||
|
||||
public
|
||||
@NotNull
|
||||
String getRole(@NotNull SOAPVersion soapVersion) {
|
||||
String v = getAttribute(soapVersion.nsUri, soapVersion.roleAttributeName);
|
||||
if(v==null || v.equals(""))
|
||||
v = soapVersion.implicitRole;
|
||||
return v;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,778 @@
|
||||
/*
|
||||
* 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.ws.message.saaj;
|
||||
|
||||
import com.sun.istack.internal.FragmentContentHandler;
|
||||
import com.sun.istack.internal.NotNull;
|
||||
import com.sun.istack.internal.Nullable;
|
||||
import com.sun.istack.internal.XMLStreamException2;
|
||||
import com.sun.xml.internal.bind.api.Bridge;
|
||||
import com.sun.xml.internal.bind.unmarshaller.DOMScanner;
|
||||
import com.sun.xml.internal.ws.api.SOAPVersion;
|
||||
import com.sun.xml.internal.ws.api.message.*;
|
||||
import com.sun.xml.internal.ws.message.AttachmentUnmarshallerImpl;
|
||||
import com.sun.xml.internal.ws.spi.db.XMLBridge;
|
||||
import com.sun.xml.internal.ws.streaming.DOMStreamReader;
|
||||
import com.sun.xml.internal.ws.util.ASCIIUtility;
|
||||
import com.sun.xml.internal.ws.util.DOMUtil;
|
||||
import org.w3c.dom.Attr;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
import org.xml.sax.helpers.LocatorImpl;
|
||||
|
||||
import javax.activation.DataHandler;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.soap.*;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
import javax.xml.ws.WebServiceException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* {@link Message} implementation backed by {@link SOAPMessage}.
|
||||
*
|
||||
* @author Vivek Pandey
|
||||
* @author Rama Pulavarthi
|
||||
*/
|
||||
public class SAAJMessage extends Message {
|
||||
// flag to switch between representations
|
||||
private boolean parsedMessage;
|
||||
// flag to check if Message API is exercised;
|
||||
private boolean accessedMessage;
|
||||
private final SOAPMessage sm;
|
||||
|
||||
private MessageHeaders headers;
|
||||
private List<Element> bodyParts;
|
||||
private Element payload;
|
||||
|
||||
private String payloadLocalName;
|
||||
private String payloadNamespace;
|
||||
private SOAPVersion soapVersion;
|
||||
|
||||
//Collect the attrbutes on the enclosing elements so that the same message can be reproduced without loss of any
|
||||
// valuable info
|
||||
private NamedNodeMap bodyAttrs, headerAttrs, envelopeAttrs;
|
||||
|
||||
public SAAJMessage(SOAPMessage sm) {
|
||||
this.sm = sm;
|
||||
}
|
||||
|
||||
/**
|
||||
* This constructor is a convenience and called by the {@link #copy}
|
||||
*
|
||||
* @param headers
|
||||
* @param sm
|
||||
*/
|
||||
private SAAJMessage(MessageHeaders headers, AttachmentSet as, SOAPMessage sm, SOAPVersion version) {
|
||||
this.sm = sm;
|
||||
this.parse();
|
||||
if(headers == null)
|
||||
headers = new HeaderList(version);
|
||||
this.headers = headers;
|
||||
this.attachmentSet = as;
|
||||
}
|
||||
|
||||
private void parse() {
|
||||
if (!parsedMessage) {
|
||||
try {
|
||||
access();
|
||||
if (headers == null)
|
||||
headers = new HeaderList(getSOAPVersion());
|
||||
SOAPHeader header = sm.getSOAPHeader();
|
||||
if (header != null) {
|
||||
headerAttrs = header.getAttributes();
|
||||
Iterator iter = header.examineAllHeaderElements();
|
||||
while (iter.hasNext()) {
|
||||
headers.add(new SAAJHeader((SOAPHeaderElement) iter.next()));
|
||||
}
|
||||
}
|
||||
attachmentSet = new SAAJAttachmentSet(sm);
|
||||
|
||||
parsedMessage = true;
|
||||
} catch (SOAPException e) {
|
||||
throw new WebServiceException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void access() {
|
||||
if (!accessedMessage) {
|
||||
try {
|
||||
envelopeAttrs = sm.getSOAPPart().getEnvelope().getAttributes();
|
||||
Node body = sm.getSOAPBody();
|
||||
bodyAttrs = body.getAttributes();
|
||||
soapVersion = SOAPVersion.fromNsUri(body.getNamespaceURI());
|
||||
//cature all the body elements
|
||||
bodyParts = DOMUtil.getChildElements(body);
|
||||
//we treat payload as the first body part
|
||||
payload = bodyParts.size() > 0 ? bodyParts.get(0) : null;
|
||||
// hope this is correct. Caching the localname and namespace of the payload should be fine
|
||||
// but what about if a Handler replaces the payload with something else? Weel, may be it
|
||||
// will be error condition anyway
|
||||
if (payload != null) {
|
||||
payloadLocalName = payload.getLocalName();
|
||||
payloadNamespace = payload.getNamespaceURI();
|
||||
}
|
||||
accessedMessage = true;
|
||||
} catch (SOAPException e) {
|
||||
throw new WebServiceException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasHeaders() {
|
||||
parse();
|
||||
return headers.hasHeaders();
|
||||
}
|
||||
|
||||
public @NotNull MessageHeaders getHeaders() {
|
||||
parse();
|
||||
return headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the attachments of this message
|
||||
* (attachments live outside a message.)
|
||||
*/
|
||||
@Override
|
||||
public @NotNull AttachmentSet getAttachments() {
|
||||
if (attachmentSet == null) attachmentSet = new SAAJAttachmentSet(sm);
|
||||
return attachmentSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optimization hint for the derived class to check
|
||||
* if we may have some attachments.
|
||||
*/
|
||||
@Override
|
||||
protected boolean hasAttachments() {
|
||||
return !getAttachments().isEmpty();
|
||||
}
|
||||
|
||||
public @Nullable String getPayloadLocalPart() {
|
||||
soapBodyFirstChild();
|
||||
return payloadLocalName;
|
||||
}
|
||||
|
||||
public String getPayloadNamespaceURI() {
|
||||
soapBodyFirstChild();
|
||||
return payloadNamespace;
|
||||
}
|
||||
|
||||
public boolean hasPayload() {
|
||||
return soapBodyFirstChild() != null;
|
||||
}
|
||||
|
||||
private void addAttributes(Element e, NamedNodeMap attrs) {
|
||||
if(attrs == null)
|
||||
return;
|
||||
String elPrefix = e.getPrefix();
|
||||
for(int i=0; i < attrs.getLength();i++) {
|
||||
Attr a = (Attr)attrs.item(i);
|
||||
//check if attr is ns declaration
|
||||
if("xmlns".equals(a.getPrefix()) || "xmlns".equals(a.getLocalName())) {
|
||||
if(elPrefix == null && a.getLocalName().equals("xmlns")) {
|
||||
// the target element has already default ns declaration, dont' override it
|
||||
continue;
|
||||
} else if(elPrefix != null && "xmlns".equals(a.getPrefix()) && elPrefix.equals(a.getLocalName())) {
|
||||
//dont bind the prefix to ns again, its already in the target element.
|
||||
continue;
|
||||
}
|
||||
e.setAttributeNS(a.getNamespaceURI(),a.getName(),a.getValue());
|
||||
continue;
|
||||
}
|
||||
e.setAttributeNS(a.getNamespaceURI(),a.getName(),a.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public Source readEnvelopeAsSource() {
|
||||
try {
|
||||
if (!parsedMessage) {
|
||||
SOAPEnvelope se = sm.getSOAPPart().getEnvelope();
|
||||
return new DOMSource(se);
|
||||
|
||||
} else {
|
||||
SOAPMessage msg = soapVersion.getMessageFactory().createMessage();
|
||||
addAttributes(msg.getSOAPPart().getEnvelope(),envelopeAttrs);
|
||||
|
||||
SOAPBody newBody = msg.getSOAPPart().getEnvelope().getBody();
|
||||
addAttributes(newBody, bodyAttrs);
|
||||
for (Element part : bodyParts) {
|
||||
Node n = newBody.getOwnerDocument().importNode(part, true);
|
||||
newBody.appendChild(n);
|
||||
}
|
||||
addAttributes(msg.getSOAPHeader(),headerAttrs);
|
||||
for (Header header : headers.asList()) {
|
||||
header.writeTo(msg);
|
||||
}
|
||||
SOAPEnvelope se = msg.getSOAPPart().getEnvelope();
|
||||
return new DOMSource(se);
|
||||
}
|
||||
} catch (SOAPException e) {
|
||||
throw new WebServiceException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public SOAPMessage readAsSOAPMessage() throws SOAPException {
|
||||
if (!parsedMessage) {
|
||||
return sm;
|
||||
} else {
|
||||
SOAPMessage msg = soapVersion.getMessageFactory().createMessage();
|
||||
addAttributes(msg.getSOAPPart().getEnvelope(),envelopeAttrs);
|
||||
SOAPBody newBody = msg.getSOAPPart().getEnvelope().getBody();
|
||||
addAttributes(newBody, bodyAttrs);
|
||||
for (Element part : bodyParts) {
|
||||
Node n = newBody.getOwnerDocument().importNode(part, true);
|
||||
newBody.appendChild(n);
|
||||
}
|
||||
addAttributes(msg.getSOAPHeader(),headerAttrs);
|
||||
for (Header header : headers.asList()) {
|
||||
header.writeTo(msg);
|
||||
}
|
||||
for (Attachment att : getAttachments()) {
|
||||
AttachmentPart part = msg.createAttachmentPart();
|
||||
part.setDataHandler(att.asDataHandler());
|
||||
part.setContentId('<' + att.getContentId() + '>');
|
||||
addCustomMimeHeaders(att, part);
|
||||
msg.addAttachmentPart(part);
|
||||
}
|
||||
msg.saveChanges();
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
||||
private void addCustomMimeHeaders(Attachment att, AttachmentPart part) {
|
||||
if (att instanceof AttachmentEx) {
|
||||
Iterator<AttachmentEx.MimeHeader> allMimeHeaders = ((AttachmentEx) att).getMimeHeaders();
|
||||
while (allMimeHeaders.hasNext()) {
|
||||
AttachmentEx.MimeHeader mh = allMimeHeaders.next();
|
||||
String name = mh.getName();
|
||||
if (!"Content-Type".equalsIgnoreCase(name)
|
||||
&& !"Content-Id".equalsIgnoreCase(name)) {
|
||||
part.addMimeHeader(name, mh.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Source readPayloadAsSource() {
|
||||
access();
|
||||
return (payload != null) ? new DOMSource(payload) : null;
|
||||
}
|
||||
|
||||
public <T> T readPayloadAsJAXB(Unmarshaller unmarshaller) throws JAXBException {
|
||||
access();
|
||||
if (payload != null) {
|
||||
if(hasAttachments())
|
||||
unmarshaller.setAttachmentUnmarshaller(new AttachmentUnmarshallerImpl(getAttachments()));
|
||||
return (T) unmarshaller.unmarshal(payload);
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
public <T> T readPayloadAsJAXB(Bridge<T> bridge) throws JAXBException {
|
||||
access();
|
||||
if (payload != null)
|
||||
return bridge.unmarshal(payload,hasAttachments()? new AttachmentUnmarshallerImpl(getAttachments()) : null);
|
||||
return null;
|
||||
}
|
||||
public <T> T readPayloadAsJAXB(XMLBridge<T> bridge) throws JAXBException {
|
||||
access();
|
||||
if (payload != null)
|
||||
return bridge.unmarshal(payload,hasAttachments()? new AttachmentUnmarshallerImpl(getAttachments()) : null);
|
||||
return null;
|
||||
}
|
||||
|
||||
public XMLStreamReader readPayload() throws XMLStreamException {
|
||||
return soapBodyFirstChildReader();
|
||||
}
|
||||
|
||||
public void writePayloadTo(XMLStreamWriter sw) throws XMLStreamException {
|
||||
access();
|
||||
try {
|
||||
for (Element part : bodyParts)
|
||||
DOMUtil.serializeNode(part, sw);
|
||||
} catch (XMLStreamException e) {
|
||||
throw new WebServiceException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeTo(XMLStreamWriter writer) throws XMLStreamException {
|
||||
try {
|
||||
writer.writeStartDocument();
|
||||
if (!parsedMessage) {
|
||||
DOMUtil.serializeNode(sm.getSOAPPart().getEnvelope(), writer);
|
||||
} else {
|
||||
SOAPEnvelope env = sm.getSOAPPart().getEnvelope();
|
||||
DOMUtil.writeTagWithAttributes(env, writer);
|
||||
if (hasHeaders()) {
|
||||
if(env.getHeader() != null) {
|
||||
DOMUtil.writeTagWithAttributes(env.getHeader(), writer);
|
||||
} else {
|
||||
writer.writeStartElement(env.getPrefix(), "Header", env.getNamespaceURI());
|
||||
}
|
||||
for (Header h : headers.asList()) {
|
||||
h.writeTo(writer);
|
||||
}
|
||||
writer.writeEndElement();
|
||||
}
|
||||
|
||||
DOMUtil.serializeNode(sm.getSOAPBody(), writer);
|
||||
writer.writeEndElement();
|
||||
}
|
||||
writer.writeEndDocument();
|
||||
writer.flush();
|
||||
} catch (SOAPException ex) {
|
||||
throw new XMLStreamException2(ex);
|
||||
//for now. ask jaxws team what to do.
|
||||
}
|
||||
}
|
||||
|
||||
public void writeTo(ContentHandler contentHandler, ErrorHandler errorHandler) throws SAXException {
|
||||
String soapNsUri = soapVersion.nsUri;
|
||||
if (!parsedMessage) {
|
||||
DOMScanner ds = new DOMScanner();
|
||||
ds.setContentHandler(contentHandler);
|
||||
ds.scan(sm.getSOAPPart());
|
||||
} else {
|
||||
contentHandler.setDocumentLocator(NULL_LOCATOR);
|
||||
contentHandler.startDocument();
|
||||
contentHandler.startPrefixMapping("S", soapNsUri);
|
||||
startPrefixMapping(contentHandler, envelopeAttrs,"S");
|
||||
contentHandler.startElement(soapNsUri, "Envelope", "S:Envelope", getAttributes(envelopeAttrs));
|
||||
if (hasHeaders()) {
|
||||
startPrefixMapping(contentHandler, headerAttrs,"S");
|
||||
contentHandler.startElement(soapNsUri, "Header", "S:Header", getAttributes(headerAttrs));
|
||||
MessageHeaders headers = getHeaders();
|
||||
for (Header h : headers.asList()) {
|
||||
h.writeTo(contentHandler, errorHandler);
|
||||
}
|
||||
endPrefixMapping(contentHandler, headerAttrs,"S");
|
||||
contentHandler.endElement(soapNsUri, "Header", "S:Header");
|
||||
|
||||
}
|
||||
startPrefixMapping(contentHandler, bodyAttrs,"S");
|
||||
// write the body
|
||||
contentHandler.startElement(soapNsUri, "Body", "S:Body", getAttributes(bodyAttrs));
|
||||
writePayloadTo(contentHandler, errorHandler, true);
|
||||
endPrefixMapping(contentHandler, bodyAttrs,"S");
|
||||
contentHandler.endElement(soapNsUri, "Body", "S:Body");
|
||||
endPrefixMapping(contentHandler, envelopeAttrs,"S");
|
||||
contentHandler.endElement(soapNsUri, "Envelope", "S:Envelope");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Gets the Attributes that are not namesapce declarations
|
||||
* @param attrs
|
||||
* @return
|
||||
*/
|
||||
private AttributesImpl getAttributes(NamedNodeMap attrs) {
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
if(attrs == null)
|
||||
return EMPTY_ATTS;
|
||||
for(int i=0; i < attrs.getLength();i++) {
|
||||
Attr a = (Attr)attrs.item(i);
|
||||
//check if attr is ns declaration
|
||||
if("xmlns".equals(a.getPrefix()) || "xmlns".equals(a.getLocalName())) {
|
||||
continue;
|
||||
}
|
||||
atts.addAttribute(fixNull(a.getNamespaceURI()),a.getLocalName(),a.getName(),a.getSchemaTypeInfo().getTypeName(),a.getValue());
|
||||
}
|
||||
return atts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects the ns declarations and starts the prefix mapping, consequently the associated endPrefixMapping needs to be called.
|
||||
* @param contentHandler
|
||||
* @param attrs
|
||||
* @param excludePrefix , this is to excldue the global prefix mapping "S" used at the start
|
||||
* @throws SAXException
|
||||
*/
|
||||
private void startPrefixMapping(ContentHandler contentHandler, NamedNodeMap attrs, String excludePrefix) throws SAXException {
|
||||
if(attrs == null)
|
||||
return;
|
||||
for(int i=0; i < attrs.getLength();i++) {
|
||||
Attr a = (Attr)attrs.item(i);
|
||||
//check if attr is ns declaration
|
||||
if("xmlns".equals(a.getPrefix()) || "xmlns".equals(a.getLocalName())) {
|
||||
if(!fixNull(a.getPrefix()).equals(excludePrefix)) {
|
||||
contentHandler.startPrefixMapping(fixNull(a.getPrefix()), a.getNamespaceURI());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void endPrefixMapping(ContentHandler contentHandler, NamedNodeMap attrs, String excludePrefix) throws SAXException {
|
||||
if(attrs == null)
|
||||
return;
|
||||
for(int i=0; i < attrs.getLength();i++) {
|
||||
Attr a = (Attr)attrs.item(i);
|
||||
//check if attr is ns declaration
|
||||
if("xmlns".equals(a.getPrefix()) || "xmlns".equals(a.getLocalName())) {
|
||||
if(!fixNull(a.getPrefix()).equals(excludePrefix)) {
|
||||
contentHandler.endPrefixMapping(fixNull(a.getPrefix()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String fixNull(String s) {
|
||||
if(s==null) return "";
|
||||
else return s;
|
||||
}
|
||||
|
||||
private void writePayloadTo(ContentHandler contentHandler, ErrorHandler errorHandler, boolean fragment) throws SAXException {
|
||||
if(fragment)
|
||||
contentHandler = new FragmentContentHandler(contentHandler);
|
||||
DOMScanner ds = new DOMScanner();
|
||||
ds.setContentHandler(contentHandler);
|
||||
ds.scan(payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a copy of a {@link com.sun.xml.internal.ws.api.message.Message}.
|
||||
* <p/>
|
||||
* <p/>
|
||||
* This method creates a new {@link com.sun.xml.internal.ws.api.message.Message} whose header/payload/attachments/properties
|
||||
* are identical to this {@link com.sun.xml.internal.ws.api.message.Message}. Once created, the created {@link com.sun.xml.internal.ws.api.message.Message}
|
||||
* and the original {@link com.sun.xml.internal.ws.api.message.Message} behaves independently --- adding header/
|
||||
* attachment to one {@link com.sun.xml.internal.ws.api.message.Message} doesn't affect another {@link com.sun.xml.internal.ws.api.message.Message}
|
||||
* at all.
|
||||
* <p/>
|
||||
* <h3>Design Rationale</h3>
|
||||
* <p/>
|
||||
* Since a {@link com.sun.xml.internal.ws.api.message.Message} body is read-once, sometimes
|
||||
* (such as when you do fail-over, or WS-RM) you need to
|
||||
* create an idential copy of a {@link com.sun.xml.internal.ws.api.message.Message}.
|
||||
* <p/>
|
||||
* <p/>
|
||||
* The actual copy operation depends on the layout
|
||||
* of the data in memory, hence it's best to be done by
|
||||
* the {@link com.sun.xml.internal.ws.api.message.Message} implementation itself.
|
||||
*/
|
||||
public Message copy() {
|
||||
try {
|
||||
if (!parsedMessage) {
|
||||
return new SAAJMessage(readAsSOAPMessage());
|
||||
} else {
|
||||
SOAPMessage msg = soapVersion.getMessageFactory().createMessage();
|
||||
SOAPBody newBody = msg.getSOAPPart().getEnvelope().getBody();
|
||||
for (Element part : bodyParts) {
|
||||
Node n = newBody.getOwnerDocument().importNode(part, true);
|
||||
newBody.appendChild(n);
|
||||
}
|
||||
addAttributes(newBody, bodyAttrs);
|
||||
return new SAAJMessage(getHeaders(), getAttachments(), msg, soapVersion);
|
||||
}
|
||||
} catch (SOAPException e) {
|
||||
throw new WebServiceException(e);
|
||||
}
|
||||
}
|
||||
private static final AttributesImpl EMPTY_ATTS = new AttributesImpl();
|
||||
private static final LocatorImpl NULL_LOCATOR = new LocatorImpl();
|
||||
|
||||
protected static class SAAJAttachment implements AttachmentEx {
|
||||
|
||||
final AttachmentPart ap;
|
||||
|
||||
String contentIdNoAngleBracket;
|
||||
|
||||
public SAAJAttachment(AttachmentPart part) {
|
||||
this.ap = part;
|
||||
}
|
||||
|
||||
/**
|
||||
* Content ID of the attachment. Uniquely identifies an attachment.
|
||||
*/
|
||||
public String getContentId() {
|
||||
if (contentIdNoAngleBracket == null) {
|
||||
contentIdNoAngleBracket = ap.getContentId();
|
||||
if (contentIdNoAngleBracket != null && contentIdNoAngleBracket.charAt(0) == '<')
|
||||
contentIdNoAngleBracket = contentIdNoAngleBracket.substring(1, contentIdNoAngleBracket.length()-1);
|
||||
}
|
||||
return contentIdNoAngleBracket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the MIME content-type of this attachment.
|
||||
*/
|
||||
public String getContentType() {
|
||||
return ap.getContentType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the attachment as an exact-length byte array.
|
||||
*/
|
||||
public byte[] asByteArray() {
|
||||
try {
|
||||
return ap.getRawContentBytes();
|
||||
} catch (SOAPException e) {
|
||||
throw new WebServiceException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the attachment as a {@link javax.activation.DataHandler}.
|
||||
*/
|
||||
public DataHandler asDataHandler() {
|
||||
try {
|
||||
return ap.getDataHandler();
|
||||
} catch (SOAPException e) {
|
||||
throw new WebServiceException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the attachment as a {@link javax.xml.transform.Source}.
|
||||
* Note that there's no guarantee that the attachment is actually an XML.
|
||||
*/
|
||||
public Source asSource() {
|
||||
try {
|
||||
return new StreamSource(ap.getRawContent());
|
||||
} catch (SOAPException e) {
|
||||
throw new WebServiceException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains this attachment as an {@link java.io.InputStream}.
|
||||
*/
|
||||
public InputStream asInputStream() {
|
||||
try {
|
||||
return ap.getRawContent();
|
||||
} catch (SOAPException e) {
|
||||
throw new WebServiceException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the contents of the attachment into the given stream.
|
||||
*/
|
||||
public void writeTo(OutputStream os) throws IOException {
|
||||
try {
|
||||
ASCIIUtility.copyStream(ap.getRawContent(), os);
|
||||
} catch (SOAPException e) {
|
||||
throw new WebServiceException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes this attachment to the given {@link javax.xml.soap.SOAPMessage}.
|
||||
*/
|
||||
public void writeTo(SOAPMessage saaj) {
|
||||
saaj.addAttachmentPart(ap);
|
||||
}
|
||||
|
||||
AttachmentPart asAttachmentPart(){
|
||||
return ap;
|
||||
}
|
||||
|
||||
public Iterator<MimeHeader> getMimeHeaders() {
|
||||
final Iterator it = ap.getAllMimeHeaders();
|
||||
return new Iterator<MimeHeader>() {
|
||||
public boolean hasNext() {
|
||||
return it.hasNext();
|
||||
}
|
||||
|
||||
public MimeHeader next() {
|
||||
final javax.xml.soap.MimeHeader mh = (javax.xml.soap.MimeHeader) it.next();
|
||||
return new MimeHeader() {
|
||||
public String getName() {
|
||||
return mh.getName();
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return mh.getValue();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link AttachmentSet} for SAAJ.
|
||||
*
|
||||
* SAAJ wants '<' and '>' for the content ID, but {@link AttachmentSet}
|
||||
* doesn't. S this class also does the conversion between them.
|
||||
*/
|
||||
protected static class SAAJAttachmentSet implements AttachmentSet {
|
||||
|
||||
private Map<String, Attachment> attMap;
|
||||
private Iterator attIter;
|
||||
|
||||
public SAAJAttachmentSet(SOAPMessage sm) {
|
||||
attIter = sm.getAttachments();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the attachment by the content ID.
|
||||
*
|
||||
* @return null
|
||||
* if no such attachment exist.
|
||||
*/
|
||||
public Attachment get(String contentId) {
|
||||
// if this is the first time then create the attachment Map
|
||||
if (attMap == null) {
|
||||
if (!attIter.hasNext())
|
||||
return null;
|
||||
attMap = createAttachmentMap();
|
||||
}
|
||||
if(contentId.charAt(0) != '<'){
|
||||
return attMap.get('<'+contentId+'>');
|
||||
}
|
||||
return attMap.get(contentId);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
if(attMap!=null)
|
||||
return attMap.isEmpty();
|
||||
else
|
||||
return !attIter.hasNext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator over a set of elements of type T.
|
||||
*
|
||||
* @return an Iterator.
|
||||
*/
|
||||
public Iterator<Attachment> iterator() {
|
||||
if (attMap == null) {
|
||||
attMap = createAttachmentMap();
|
||||
}
|
||||
return attMap.values().iterator();
|
||||
}
|
||||
|
||||
private Map<String, Attachment> createAttachmentMap() {
|
||||
HashMap<String, Attachment> map = new HashMap<String, Attachment>();
|
||||
while (attIter.hasNext()) {
|
||||
AttachmentPart ap = (AttachmentPart) attIter.next();
|
||||
map.put(ap.getContentId(), new SAAJAttachment(ap));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public void add(Attachment att) {
|
||||
attMap.put('<'+att.getContentId()+'>', att);
|
||||
}
|
||||
}
|
||||
|
||||
public SOAPVersion getSOAPVersion() {
|
||||
return soapVersion;
|
||||
}
|
||||
|
||||
private XMLStreamReader soapBodyFirstChildReader;
|
||||
|
||||
/**
|
||||
* This allow the subclass to retain the XMLStreamReader.
|
||||
*/
|
||||
protected XMLStreamReader getXMLStreamReader(SOAPElement soapElement) {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected XMLStreamReader createXMLStreamReader(SOAPElement soapElement) {
|
||||
DOMStreamReader dss = new DOMStreamReader();
|
||||
dss.setCurrentNode(soapElement);
|
||||
return dss;
|
||||
}
|
||||
|
||||
protected XMLStreamReader soapBodyFirstChildReader() {
|
||||
if (soapBodyFirstChildReader != null) return soapBodyFirstChildReader;
|
||||
soapBodyFirstChild();
|
||||
if (soapBodyFirstChild != null) {
|
||||
soapBodyFirstChildReader = getXMLStreamReader(soapBodyFirstChild);
|
||||
if (soapBodyFirstChildReader == null) soapBodyFirstChildReader =
|
||||
createXMLStreamReader(soapBodyFirstChild);
|
||||
if (soapBodyFirstChildReader.getEventType() == XMLStreamReader.START_DOCUMENT) {
|
||||
try {
|
||||
while(soapBodyFirstChildReader.getEventType() != XMLStreamReader.START_ELEMENT)
|
||||
soapBodyFirstChildReader.next();
|
||||
} catch (XMLStreamException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return soapBodyFirstChildReader;
|
||||
} else {
|
||||
payloadLocalName = null;
|
||||
payloadNamespace = null;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private SOAPElement soapBodyFirstChild;
|
||||
|
||||
SOAPElement soapBodyFirstChild() {
|
||||
if (soapBodyFirstChild != null) return soapBodyFirstChild;
|
||||
try {
|
||||
boolean foundElement = false;
|
||||
for (Node n = sm.getSOAPBody().getFirstChild(); n != null && !foundElement; n = n.getNextSibling()) {
|
||||
if (n.getNodeType() == Node.ELEMENT_NODE) {
|
||||
foundElement = true;
|
||||
if (n instanceof SOAPElement) {
|
||||
soapBodyFirstChild = (SOAPElement) n;
|
||||
payloadLocalName = soapBodyFirstChild.getLocalName();
|
||||
payloadNamespace = soapBodyFirstChild.getNamespaceURI();
|
||||
return soapBodyFirstChild;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(foundElement) for(Iterator i = sm.getSOAPBody().getChildElements(); i.hasNext();){
|
||||
Object o = i.next();
|
||||
if (o instanceof SOAPElement) {
|
||||
soapBodyFirstChild = (SOAPElement)o;
|
||||
payloadLocalName = soapBodyFirstChild.getLocalName();
|
||||
payloadNamespace = soapBodyFirstChild.getNamespaceURI();
|
||||
return soapBodyFirstChild;
|
||||
}
|
||||
}
|
||||
} catch (SOAPException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return soapBodyFirstChild;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.ws.message.source;
|
||||
|
||||
import com.sun.istack.internal.NotNull;
|
||||
import com.sun.istack.internal.Nullable;
|
||||
import com.sun.xml.internal.ws.api.SOAPVersion;
|
||||
import com.sun.xml.internal.ws.api.message.AttachmentSet;
|
||||
import com.sun.xml.internal.ws.api.message.HeaderList;
|
||||
import com.sun.xml.internal.ws.api.message.Message;
|
||||
import com.sun.xml.internal.ws.api.message.MessageHeaders;
|
||||
import com.sun.xml.internal.ws.message.AttachmentSetImpl;
|
||||
import com.sun.xml.internal.ws.message.stream.PayloadStreamReaderMessage;
|
||||
import com.sun.xml.internal.ws.streaming.SourceReaderFactory;
|
||||
|
||||
import javax.xml.transform.Source;
|
||||
|
||||
/**
|
||||
* {@link Message} backed by {@link Source} as payload
|
||||
*
|
||||
* @author Vivek Pandey
|
||||
*/
|
||||
public class PayloadSourceMessage extends PayloadStreamReaderMessage {
|
||||
|
||||
public PayloadSourceMessage(@Nullable MessageHeaders headers,
|
||||
@NotNull Source payload, @NotNull AttachmentSet attSet,
|
||||
@NotNull SOAPVersion soapVersion) {
|
||||
|
||||
super(headers, SourceReaderFactory.createSourceReader(payload, true),
|
||||
attSet, soapVersion);
|
||||
}
|
||||
|
||||
public PayloadSourceMessage(Source s, SOAPVersion soapVer) {
|
||||
this(null, s, new AttachmentSetImpl(), soapVer);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* 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.ws.message.source;
|
||||
|
||||
import com.sun.xml.internal.bind.api.Bridge;
|
||||
import com.sun.xml.internal.ws.api.SOAPVersion;
|
||||
import com.sun.xml.internal.ws.api.pipe.Codecs;
|
||||
import com.sun.xml.internal.ws.api.pipe.StreamSOAPCodec;
|
||||
import com.sun.xml.internal.ws.api.message.Message;
|
||||
import com.sun.xml.internal.ws.api.message.MessageHeaders;
|
||||
import com.sun.xml.internal.ws.api.message.Packet;
|
||||
import com.sun.xml.internal.ws.spi.db.XMLBridge;
|
||||
import com.sun.xml.internal.ws.streaming.SourceReaderFactory;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.soap.SOAPException;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
import javax.xml.transform.Source;
|
||||
|
||||
/**
|
||||
* Implementation of {@link Message} backed by {@link Source} where the Source
|
||||
* represents the complete message such as a SOAP envelope. It uses
|
||||
* {@link StreamSOAPCodec} to create a {@link Message} and uses it as a
|
||||
* delegate for all the methods.
|
||||
*
|
||||
* @author Vivek Pandey
|
||||
* @author Jitendra Kotamraju
|
||||
*/
|
||||
public class ProtocolSourceMessage extends Message {
|
||||
private final Message sm;
|
||||
|
||||
public ProtocolSourceMessage(Source source, SOAPVersion soapVersion) {
|
||||
XMLStreamReader reader = SourceReaderFactory.createSourceReader(source, true);
|
||||
com.sun.xml.internal.ws.api.pipe.StreamSOAPCodec codec = Codecs.createSOAPEnvelopeXmlCodec(soapVersion);
|
||||
sm = codec.decode(reader);
|
||||
}
|
||||
|
||||
public boolean hasHeaders() {
|
||||
return sm.hasHeaders();
|
||||
}
|
||||
|
||||
public String getPayloadLocalPart() {
|
||||
return sm.getPayloadLocalPart();
|
||||
}
|
||||
|
||||
public String getPayloadNamespaceURI() {
|
||||
return sm.getPayloadNamespaceURI();
|
||||
}
|
||||
|
||||
public boolean hasPayload() {
|
||||
return sm.hasPayload();
|
||||
}
|
||||
|
||||
public Source readPayloadAsSource() {
|
||||
return sm.readPayloadAsSource();
|
||||
}
|
||||
|
||||
public XMLStreamReader readPayload() throws XMLStreamException {
|
||||
return sm.readPayload();
|
||||
}
|
||||
|
||||
public void writePayloadTo(XMLStreamWriter sw) throws XMLStreamException {
|
||||
sm.writePayloadTo(sw);
|
||||
}
|
||||
|
||||
public void writeTo(XMLStreamWriter sw) throws XMLStreamException {
|
||||
sm.writeTo(sw);
|
||||
}
|
||||
|
||||
public Message copy() {
|
||||
return sm.copy();
|
||||
}
|
||||
|
||||
public Source readEnvelopeAsSource() {
|
||||
return sm.readEnvelopeAsSource();
|
||||
}
|
||||
|
||||
public SOAPMessage readAsSOAPMessage() throws SOAPException {
|
||||
return sm.readAsSOAPMessage();
|
||||
}
|
||||
|
||||
public SOAPMessage readAsSOAPMessage(Packet packet, boolean inbound) throws SOAPException {
|
||||
return sm.readAsSOAPMessage(packet, inbound);
|
||||
}
|
||||
|
||||
public <T> T readPayloadAsJAXB(Unmarshaller unmarshaller) throws JAXBException {
|
||||
return (T)sm.readPayloadAsJAXB(unmarshaller);
|
||||
}
|
||||
/** @deprecated */
|
||||
public <T> T readPayloadAsJAXB(Bridge<T> bridge) throws JAXBException {
|
||||
return sm.readPayloadAsJAXB(bridge);
|
||||
}
|
||||
public <T> T readPayloadAsJAXB(XMLBridge<T> bridge) throws JAXBException {
|
||||
return sm.readPayloadAsJAXB(bridge);
|
||||
}
|
||||
|
||||
public void writeTo(ContentHandler contentHandler, ErrorHandler errorHandler) throws SAXException {
|
||||
sm.writeTo(contentHandler, errorHandler);
|
||||
}
|
||||
|
||||
public SOAPVersion getSOAPVersion() {
|
||||
return sm.getSOAPVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageHeaders getHeaders() {
|
||||
return sm.getHeaders();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,262 @@
|
||||
/*
|
||||
* 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.ws.message.source;
|
||||
|
||||
import com.sun.xml.internal.ws.message.RootElementSniffer;
|
||||
import com.sun.xml.internal.ws.streaming.SourceReaderFactory;
|
||||
import com.sun.xml.internal.ws.util.xml.XmlUtil;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.stream.XMLStreamConstants;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerConfigurationException;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.sax.SAXResult;
|
||||
import javax.xml.transform.sax.SAXSource;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
import javax.xml.ws.WebServiceException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Vivek Pandey
|
||||
*/
|
||||
final class SourceUtils {
|
||||
|
||||
int srcType;
|
||||
|
||||
private static final int domSource = 1;
|
||||
private static final int streamSource = 2;
|
||||
private static final int saxSource=4;
|
||||
|
||||
public SourceUtils(Source src) {
|
||||
if(src instanceof StreamSource){
|
||||
srcType = streamSource;
|
||||
}else if(src instanceof DOMSource){
|
||||
srcType = domSource;
|
||||
}else if(src instanceof SAXSource){
|
||||
srcType = saxSource;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDOMSource(){
|
||||
return (srcType&domSource) == domSource;
|
||||
}
|
||||
|
||||
public boolean isStreamSource(){
|
||||
return (srcType&streamSource) == streamSource;
|
||||
}
|
||||
|
||||
public boolean isSaxSource(){
|
||||
return (srcType&saxSource) == saxSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* This would peek into the Source (DOMSource and SAXSource) for the localName and NamespaceURI
|
||||
* of the top-level element.
|
||||
* @param src
|
||||
* @return QName of the payload
|
||||
*/
|
||||
public QName sniff(Source src) {
|
||||
return sniff(src, new RootElementSniffer());
|
||||
}
|
||||
|
||||
public QName sniff(Source src, RootElementSniffer sniffer){
|
||||
String localName = null;
|
||||
String namespaceUri = null;
|
||||
|
||||
if(isDOMSource()){
|
||||
DOMSource domSrc = (DOMSource)src;
|
||||
Node n = domSrc.getNode();
|
||||
if(n.getNodeType()== Node.DOCUMENT_NODE) {
|
||||
n = ((Document)n).getDocumentElement();
|
||||
}
|
||||
localName = n.getLocalName();
|
||||
namespaceUri = n.getNamespaceURI();
|
||||
}else if(isSaxSource()){
|
||||
SAXSource saxSrc = (SAXSource)src;
|
||||
SAXResult saxResult = new SAXResult(sniffer);
|
||||
try {
|
||||
Transformer tr = XmlUtil.newTransformer();
|
||||
tr.transform(saxSrc, saxResult);
|
||||
} catch (TransformerConfigurationException e) {
|
||||
throw new WebServiceException(e);
|
||||
} catch (TransformerException e) {
|
||||
// if it's due to aborting the processing after the first element,
|
||||
// we can safely ignore this exception.
|
||||
//
|
||||
// if it's due to error in the object, the same error will be reported
|
||||
// when the readHeader() method is used, so we don't have to report
|
||||
// an error right now.
|
||||
localName = sniffer.getLocalName();
|
||||
namespaceUri = sniffer.getNsUri();
|
||||
}
|
||||
}
|
||||
return new QName(namespaceUri, localName);
|
||||
}
|
||||
|
||||
public static void serializeSource(Source src, XMLStreamWriter writer) throws XMLStreamException {
|
||||
XMLStreamReader reader = SourceReaderFactory.createSourceReader(src, true);
|
||||
int state;
|
||||
do {
|
||||
state = reader.next();
|
||||
switch (state) {
|
||||
case XMLStreamConstants.START_ELEMENT:
|
||||
/*
|
||||
* TODO: Is this necessary, shouldn't zephyr return "" instead of
|
||||
* null for getNamespaceURI() and getPrefix()?
|
||||
*/
|
||||
String uri = reader.getNamespaceURI();
|
||||
String prefix = reader.getPrefix();
|
||||
String localName = reader.getLocalName();
|
||||
|
||||
if (prefix == null) {
|
||||
if (uri == null) {
|
||||
writer.writeStartElement(localName);
|
||||
} else {
|
||||
writer.writeStartElement(uri, localName);
|
||||
}
|
||||
} else {
|
||||
// assert uri != null;
|
||||
|
||||
if(prefix.length() > 0){
|
||||
/**
|
||||
* Before we write the
|
||||
*/
|
||||
String writerURI = null;
|
||||
if (writer.getNamespaceContext() != null) {
|
||||
writerURI = writer.getNamespaceContext().getNamespaceURI(prefix);
|
||||
}
|
||||
String writerPrefix = writer.getPrefix(uri);
|
||||
if(declarePrefix(prefix, uri, writerPrefix, writerURI)){
|
||||
writer.writeStartElement(prefix, localName, uri);
|
||||
writer.setPrefix(prefix, uri != null ? uri : "");
|
||||
writer.writeNamespace(prefix, uri);
|
||||
}else{
|
||||
writer.writeStartElement(prefix, localName, uri);
|
||||
}
|
||||
}else{
|
||||
writer.writeStartElement(prefix, localName, uri);
|
||||
}
|
||||
}
|
||||
|
||||
int n = reader.getNamespaceCount();
|
||||
// Write namespace declarations
|
||||
for (int i = 0; i < n; i++) {
|
||||
String nsPrefix = reader.getNamespacePrefix(i);
|
||||
if (nsPrefix == null) {
|
||||
nsPrefix = "";
|
||||
}
|
||||
// StAX returns null for default ns
|
||||
String writerURI = null;
|
||||
if (writer.getNamespaceContext() != null) {
|
||||
writerURI = writer.getNamespaceContext().getNamespaceURI(nsPrefix);
|
||||
}
|
||||
|
||||
// Zephyr: Why is this returning null?
|
||||
// Compare nsPrefix with prefix because of [1] (above)
|
||||
String readerURI = reader.getNamespaceURI(i);
|
||||
|
||||
/**
|
||||
* write the namespace in 3 conditions
|
||||
* - when the namespace URI is not bound to the prefix in writer(writerURI == 0)
|
||||
* - when the readerPrefix and writerPrefix are ""
|
||||
* - when readerPrefix and writerPrefix are not equal and the URI bound to them
|
||||
* are different
|
||||
*/
|
||||
if (writerURI == null || ((nsPrefix.length() == 0) || (prefix.length() == 0)) ||
|
||||
(!nsPrefix.equals(prefix) && !writerURI.equals(readerURI))) {
|
||||
writer.setPrefix(nsPrefix, readerURI != null ? readerURI : "");
|
||||
writer.writeNamespace(nsPrefix, readerURI != null ? readerURI : "");
|
||||
}
|
||||
}
|
||||
|
||||
// Write attributes
|
||||
n = reader.getAttributeCount();
|
||||
for (int i = 0; i < n; i++) {
|
||||
String attrPrefix = reader.getAttributePrefix(i);
|
||||
String attrURI = reader.getAttributeNamespace(i);
|
||||
|
||||
writer.writeAttribute(attrPrefix != null ? attrPrefix : "",
|
||||
attrURI != null ? attrURI : "",
|
||||
reader.getAttributeLocalName(i),
|
||||
reader.getAttributeValue(i));
|
||||
// if the attribute prefix is undeclared in current writer scope then declare it
|
||||
setUndeclaredPrefix(attrPrefix, attrURI, writer);
|
||||
}
|
||||
break;
|
||||
case XMLStreamConstants.END_ELEMENT:
|
||||
writer.writeEndElement();
|
||||
break;
|
||||
case XMLStreamConstants.CHARACTERS:
|
||||
writer.writeCharacters(reader.getText());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} while (state != XMLStreamConstants.END_DOCUMENT);
|
||||
reader.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* sets undeclared prefixes on the writer
|
||||
* @param prefix
|
||||
* @param writer
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
private static void setUndeclaredPrefix(String prefix, String readerURI, XMLStreamWriter writer) throws XMLStreamException {
|
||||
String writerURI = null;
|
||||
if (writer.getNamespaceContext() != null) {
|
||||
writerURI = writer.getNamespaceContext().getNamespaceURI(prefix);
|
||||
}
|
||||
|
||||
if (writerURI == null) {
|
||||
writer.setPrefix(prefix, readerURI != null ? readerURI : "");
|
||||
writer.writeNamespace(prefix, readerURI != null ? readerURI : "");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* check if we need to declare
|
||||
* @param rPrefix
|
||||
* @param rUri
|
||||
* @param wPrefix
|
||||
* @param wUri
|
||||
*/
|
||||
private static boolean declarePrefix(String rPrefix, String rUri, String wPrefix, String wUri){
|
||||
if (wUri == null ||((wPrefix != null) && !rPrefix.equals(wPrefix))||
|
||||
(rUri != null && !wUri.equals(rUri))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -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.ws.message.stream;
|
||||
|
||||
import com.sun.istack.internal.FinalArrayList;
|
||||
import com.sun.istack.internal.NotNull;
|
||||
import com.sun.xml.internal.stream.buffer.XMLStreamBuffer;
|
||||
import com.sun.xml.internal.stream.buffer.XMLStreamBufferException;
|
||||
import com.sun.xml.internal.ws.api.message.Header;
|
||||
import com.sun.xml.internal.ws.message.AbstractHeaderImpl;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.soap.SOAPException;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
import javax.xml.soap.SOAPHeader;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
import javax.xml.ws.WebServiceException;
|
||||
|
||||
/**
|
||||
* Used to represent outbound header created from {@link XMLStreamBuffer}.
|
||||
*
|
||||
* <p>
|
||||
* This is optimized for outbound use, so it implements some of the methods lazily,
|
||||
* in a slow way.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public final class OutboundStreamHeader extends AbstractHeaderImpl {
|
||||
private final XMLStreamBuffer infoset;
|
||||
private final String nsUri,localName;
|
||||
|
||||
/**
|
||||
* The attributes on the header element.
|
||||
* Lazily parsed.
|
||||
* Null if not parsed yet.
|
||||
*/
|
||||
private FinalArrayList<Attribute> attributes;
|
||||
|
||||
public OutboundStreamHeader(XMLStreamBuffer infoset, String nsUri, String localName) {
|
||||
this.infoset = infoset;
|
||||
this.nsUri = nsUri;
|
||||
this.localName = localName;
|
||||
}
|
||||
|
||||
public @NotNull String getNamespaceURI() {
|
||||
return nsUri;
|
||||
}
|
||||
|
||||
public @NotNull String getLocalPart() {
|
||||
return localName;
|
||||
}
|
||||
|
||||
public String getAttribute(String nsUri, String localName) {
|
||||
if(attributes==null)
|
||||
parseAttributes();
|
||||
for(int i=attributes.size()-1; i>=0; i-- ) {
|
||||
Attribute a = attributes.get(i);
|
||||
if(a.localName.equals(localName) && a.nsUri.equals(nsUri))
|
||||
return a.value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* We don't really expect this to be used, but just to satisfy
|
||||
* the {@link Header} contract.
|
||||
*
|
||||
* So this is rather slow.
|
||||
*/
|
||||
private void parseAttributes() {
|
||||
try {
|
||||
XMLStreamReader reader = readHeader();
|
||||
|
||||
attributes = new FinalArrayList<Attribute>();
|
||||
|
||||
for (int i = 0; i < reader.getAttributeCount(); i++) {
|
||||
final String localName = reader.getAttributeLocalName(i);
|
||||
final String namespaceURI = reader.getAttributeNamespace(i);
|
||||
final String value = reader.getAttributeValue(i);
|
||||
|
||||
attributes.add(new Attribute(namespaceURI,localName,value));
|
||||
}
|
||||
} catch (XMLStreamException e) {
|
||||
throw new WebServiceException("Unable to read the attributes for {"+nsUri+"}"+localName+" header",e);
|
||||
}
|
||||
}
|
||||
|
||||
public XMLStreamReader readHeader() throws XMLStreamException {
|
||||
return infoset.readAsXMLStreamReader();
|
||||
}
|
||||
|
||||
public void writeTo(XMLStreamWriter w) throws XMLStreamException {
|
||||
infoset.writeToXMLStreamWriter(w,true);
|
||||
}
|
||||
|
||||
public void writeTo(SOAPMessage saaj) throws SOAPException {
|
||||
try {
|
||||
SOAPHeader header = saaj.getSOAPHeader();
|
||||
if (header == null)
|
||||
header = saaj.getSOAPPart().getEnvelope().addHeader();
|
||||
infoset.writeTo(header);
|
||||
} catch (XMLStreamBufferException e) {
|
||||
throw new SOAPException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeTo(ContentHandler contentHandler, ErrorHandler errorHandler) throws SAXException {
|
||||
infoset.writeTo(contentHandler,errorHandler);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Keep the information about an attribute on the header element.
|
||||
*/
|
||||
static final class Attribute {
|
||||
/**
|
||||
* Can be empty but never null.
|
||||
*/
|
||||
final String nsUri;
|
||||
final String localName;
|
||||
final String value;
|
||||
|
||||
public Attribute(String nsUri, String localName, String value) {
|
||||
this.nsUri = fixNull(nsUri);
|
||||
this.localName = localName;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert null to "".
|
||||
*/
|
||||
private static String fixNull(String s) {
|
||||
if(s==null) return "";
|
||||
else return s;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* We the performance paranoid people in the JAX-WS RI thinks
|
||||
* saving three bytes is worth while...
|
||||
*/
|
||||
private static final String TRUE_VALUE = "1";
|
||||
private static final String IS_REFERENCE_PARAMETER = "IsReferenceParameter";
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* 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.ws.message.stream;
|
||||
|
||||
import com.sun.xml.internal.ws.api.SOAPVersion;
|
||||
import com.sun.xml.internal.ws.api.message.AttachmentSet;
|
||||
import com.sun.xml.internal.ws.api.message.Message;
|
||||
import com.sun.xml.internal.ws.api.message.MessageHeaders;
|
||||
import com.sun.xml.internal.ws.message.AbstractMessageImpl;
|
||||
import com.sun.xml.internal.ws.message.AttachmentSetImpl;
|
||||
import com.sun.istack.internal.Nullable;
|
||||
import com.sun.istack.internal.NotNull;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
import javax.xml.transform.Source;
|
||||
|
||||
/**
|
||||
* {@link Message} backed by {@link XMLStreamReader} as payload
|
||||
*
|
||||
* @author Jitendra Kotamraju
|
||||
*/
|
||||
public class PayloadStreamReaderMessage extends AbstractMessageImpl {
|
||||
private final StreamMessage message;
|
||||
|
||||
public PayloadStreamReaderMessage(XMLStreamReader reader, SOAPVersion soapVer) {
|
||||
this(null, reader,new AttachmentSetImpl(), soapVer);
|
||||
}
|
||||
|
||||
public PayloadStreamReaderMessage(@Nullable MessageHeaders headers, @NotNull XMLStreamReader reader,
|
||||
@NotNull AttachmentSet attSet, @NotNull SOAPVersion soapVersion) {
|
||||
super(soapVersion);
|
||||
message = new StreamMessage(headers, attSet, reader, soapVersion);
|
||||
}
|
||||
|
||||
public boolean hasHeaders() {
|
||||
return message.hasHeaders();
|
||||
}
|
||||
|
||||
public AttachmentSet getAttachments() {
|
||||
return message.getAttachments();
|
||||
}
|
||||
|
||||
public String getPayloadLocalPart() {
|
||||
return message.getPayloadLocalPart();
|
||||
}
|
||||
|
||||
public String getPayloadNamespaceURI() {
|
||||
return message.getPayloadNamespaceURI();
|
||||
}
|
||||
|
||||
public boolean hasPayload() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Source readPayloadAsSource() {
|
||||
return message.readPayloadAsSource();
|
||||
}
|
||||
|
||||
public XMLStreamReader readPayload() throws XMLStreamException {
|
||||
return message.readPayload();
|
||||
}
|
||||
|
||||
public void writePayloadTo(XMLStreamWriter sw) throws XMLStreamException {
|
||||
message.writePayloadTo(sw);
|
||||
}
|
||||
|
||||
public <T> T readPayloadAsJAXB(Unmarshaller unmarshaller) throws JAXBException {
|
||||
return (T) message.readPayloadAsJAXB(unmarshaller);
|
||||
}
|
||||
|
||||
public void writeTo(ContentHandler contentHandler, ErrorHandler errorHandler) throws SAXException {
|
||||
message.writeTo(contentHandler, errorHandler);
|
||||
}
|
||||
|
||||
protected void writePayloadTo(ContentHandler contentHandler, ErrorHandler errorHandler, boolean fragment) throws SAXException {
|
||||
message.writePayloadTo(contentHandler, errorHandler, fragment);
|
||||
}
|
||||
|
||||
public Message copy() {
|
||||
return message.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull MessageHeaders getHeaders() {
|
||||
return message.getHeaders();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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.ws.message.stream;
|
||||
|
||||
import com.sun.xml.internal.ws.api.message.Attachment;
|
||||
import com.sun.xml.internal.ws.util.ByteArrayDataSource;
|
||||
import com.sun.xml.internal.ws.util.ByteArrayBuffer;
|
||||
import com.sun.xml.internal.ws.encoding.DataSourceStreamingDataHandler;
|
||||
|
||||
import javax.activation.DataHandler;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
import javax.xml.soap.AttachmentPart;
|
||||
import javax.xml.soap.SOAPException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
import com.sun.xml.internal.org.jvnet.staxex.Base64Data;
|
||||
|
||||
/**
|
||||
* Attachment created from raw bytes.
|
||||
*
|
||||
* @author Vivek Pandey
|
||||
*/
|
||||
public class StreamAttachment implements Attachment {
|
||||
private final String contentId;
|
||||
private final String contentType;
|
||||
private final ByteArrayBuffer byteArrayBuffer;
|
||||
private final byte[] data;
|
||||
private final int len;
|
||||
|
||||
public StreamAttachment(ByteArrayBuffer buffer, String contentId, String contentType) {
|
||||
this.contentId = contentId;
|
||||
this.contentType = contentType;
|
||||
this.byteArrayBuffer = buffer;
|
||||
this.data = byteArrayBuffer.getRawData();
|
||||
this.len = byteArrayBuffer.size();
|
||||
}
|
||||
|
||||
public String getContentId() {
|
||||
return contentId;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
|
||||
public byte[] asByteArray() {
|
||||
//we got to reallocate and give the exact byte[]
|
||||
return byteArrayBuffer.toByteArray();
|
||||
}
|
||||
|
||||
public DataHandler asDataHandler() {
|
||||
return new DataSourceStreamingDataHandler(new ByteArrayDataSource(data,0,len,getContentType()));
|
||||
}
|
||||
|
||||
public Source asSource() {
|
||||
return new StreamSource(new ByteArrayInputStream(data,0,len));
|
||||
}
|
||||
|
||||
public InputStream asInputStream() {
|
||||
return byteArrayBuffer.newInputStream();
|
||||
}
|
||||
|
||||
public Base64Data asBase64Data(){
|
||||
Base64Data base64Data = new Base64Data();
|
||||
base64Data.set(data, len, contentType);
|
||||
return base64Data;
|
||||
}
|
||||
|
||||
public void writeTo(OutputStream os) throws IOException {
|
||||
byteArrayBuffer.writeTo(os);
|
||||
}
|
||||
|
||||
public void writeTo(SOAPMessage saaj) throws SOAPException {
|
||||
AttachmentPart part = saaj.createAttachmentPart();
|
||||
part.setRawContentBytes(data,0,len,getContentType());
|
||||
part.setContentId(contentId);
|
||||
saaj.addAttachmentPart(part);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,239 @@
|
||||
/*
|
||||
* 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.ws.message.stream;
|
||||
|
||||
import com.sun.istack.internal.FinalArrayList;
|
||||
import com.sun.istack.internal.NotNull;
|
||||
import com.sun.xml.internal.stream.buffer.XMLStreamBuffer;
|
||||
import com.sun.xml.internal.stream.buffer.XMLStreamBufferSource;
|
||||
import com.sun.xml.internal.ws.api.SOAPVersion;
|
||||
import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
|
||||
import com.sun.xml.internal.ws.api.addressing.WSEndpointReference;
|
||||
import com.sun.xml.internal.ws.api.message.Header;
|
||||
import com.sun.xml.internal.ws.message.AbstractHeaderImpl;
|
||||
import com.sun.xml.internal.ws.util.xml.XmlUtil;
|
||||
import org.w3c.dom.Node;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.soap.SOAPException;
|
||||
import javax.xml.soap.SOAPHeader;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* {@link Header} whose physical data representation is an XMLStreamBuffer.
|
||||
*
|
||||
* @author Paul.Sandoz@Sun.Com
|
||||
*/
|
||||
public abstract class StreamHeader extends AbstractHeaderImpl {
|
||||
protected final XMLStreamBuffer _mark;
|
||||
|
||||
protected boolean _isMustUnderstand;
|
||||
|
||||
/**
|
||||
* Role or actor value.
|
||||
*/
|
||||
protected @NotNull String _role;
|
||||
|
||||
protected boolean _isRelay;
|
||||
|
||||
protected String _localName;
|
||||
|
||||
protected String _namespaceURI;
|
||||
|
||||
/**
|
||||
* Keep the information about an attribute on the header element.
|
||||
*
|
||||
* TODO: this whole attribute handling could be done better, I think.
|
||||
*/
|
||||
protected static final class Attribute {
|
||||
/**
|
||||
* Can be empty but never null.
|
||||
*/
|
||||
final String nsUri;
|
||||
final String localName;
|
||||
final String value;
|
||||
|
||||
public Attribute(String nsUri, String localName, String value) {
|
||||
this.nsUri = fixNull(nsUri);
|
||||
this.localName = localName;
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The attributes on the header element.
|
||||
* We expect there to be only a small number of them,
|
||||
* so the use of {@link List} would be justified.
|
||||
*
|
||||
* Null if no attribute is present.
|
||||
*/
|
||||
private final FinalArrayList<Attribute> attributes;
|
||||
|
||||
/**
|
||||
* Creates a {@link StreamHeader}.
|
||||
*
|
||||
* @param reader
|
||||
* The parser pointing at the start of the mark.
|
||||
* Technically this information is redundant,
|
||||
* but it achieves a better performance.
|
||||
* @param mark
|
||||
* The start of the buffered header content.
|
||||
*/
|
||||
protected StreamHeader(XMLStreamReader reader, XMLStreamBuffer mark) {
|
||||
assert reader!=null && mark!=null;
|
||||
_mark = mark;
|
||||
_localName = reader.getLocalName();
|
||||
_namespaceURI = reader.getNamespaceURI();
|
||||
attributes = processHeaderAttributes(reader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link StreamHeader}.
|
||||
*
|
||||
* @param reader
|
||||
* The parser that points to the start tag of the header.
|
||||
* By the end of this method, the parser will point at
|
||||
* the end tag of this element.
|
||||
*/
|
||||
protected StreamHeader(XMLStreamReader reader) throws XMLStreamException {
|
||||
_localName = reader.getLocalName();
|
||||
_namespaceURI = reader.getNamespaceURI();
|
||||
attributes = processHeaderAttributes(reader);
|
||||
// cache the body
|
||||
_mark = XMLStreamBuffer.createNewBufferFromXMLStreamReader(reader);
|
||||
}
|
||||
|
||||
public final boolean isIgnorable(@NotNull SOAPVersion soapVersion, @NotNull Set<String> roles) {
|
||||
// check mustUnderstand
|
||||
if(!_isMustUnderstand) return true;
|
||||
|
||||
if (roles == null)
|
||||
return true;
|
||||
|
||||
// now role
|
||||
return !roles.contains(_role);
|
||||
}
|
||||
|
||||
public @NotNull String getRole(@NotNull SOAPVersion soapVersion) {
|
||||
assert _role!=null;
|
||||
return _role;
|
||||
}
|
||||
|
||||
public boolean isRelay() {
|
||||
return _isRelay;
|
||||
}
|
||||
|
||||
public @NotNull String getNamespaceURI() {
|
||||
return _namespaceURI;
|
||||
}
|
||||
|
||||
public @NotNull String getLocalPart() {
|
||||
return _localName;
|
||||
}
|
||||
|
||||
public String getAttribute(String nsUri, String localName) {
|
||||
if(attributes!=null) {
|
||||
for(int i=attributes.size()-1; i>=0; i-- ) {
|
||||
Attribute a = attributes.get(i);
|
||||
if(a.localName.equals(localName) && a.nsUri.equals(nsUri))
|
||||
return a.value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the header as a {@link XMLStreamReader}
|
||||
*/
|
||||
public XMLStreamReader readHeader() throws XMLStreamException {
|
||||
return _mark.readAsXMLStreamReader();
|
||||
}
|
||||
|
||||
public void writeTo(XMLStreamWriter w) throws XMLStreamException {
|
||||
if(_mark.getInscopeNamespaces().size() > 0)
|
||||
_mark.writeToXMLStreamWriter(w,true);
|
||||
else
|
||||
_mark.writeToXMLStreamWriter(w);
|
||||
}
|
||||
|
||||
public void writeTo(SOAPMessage saaj) throws SOAPException {
|
||||
try {
|
||||
// TODO what about in-scope namespaces
|
||||
// Not very efficient consider implementing a stream buffer
|
||||
// processor that produces a DOM node from the buffer.
|
||||
TransformerFactory tf = XmlUtil.newTransformerFactory();
|
||||
Transformer t = tf.newTransformer();
|
||||
XMLStreamBufferSource source = new XMLStreamBufferSource(_mark);
|
||||
DOMResult result = new DOMResult();
|
||||
t.transform(source, result);
|
||||
Node d = result.getNode();
|
||||
if(d.getNodeType() == Node.DOCUMENT_NODE)
|
||||
d = d.getFirstChild();
|
||||
SOAPHeader header = saaj.getSOAPHeader();
|
||||
if(header == null)
|
||||
header = saaj.getSOAPPart().getEnvelope().addHeader();
|
||||
Node node = header.getOwnerDocument().importNode(d, true);
|
||||
header.appendChild(node);
|
||||
} catch (Exception e) {
|
||||
throw new SOAPException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeTo(ContentHandler contentHandler, ErrorHandler errorHandler) throws SAXException {
|
||||
_mark.writeTo(contentHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an EPR without copying infoset.
|
||||
*
|
||||
* This is the most common implementation on which {@link Header#readAsEPR(AddressingVersion)}
|
||||
* is invoked on.
|
||||
*/
|
||||
@Override @NotNull
|
||||
public WSEndpointReference readAsEPR(AddressingVersion expected) throws XMLStreamException {
|
||||
return new WSEndpointReference(_mark,expected);
|
||||
}
|
||||
|
||||
protected abstract FinalArrayList<Attribute> processHeaderAttributes(XMLStreamReader reader);
|
||||
|
||||
/**
|
||||
* Convert null to "".
|
||||
*/
|
||||
private static String fixNull(String s) {
|
||||
if(s==null) return "";
|
||||
else return s;
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.ws.message.stream;
|
||||
|
||||
import com.sun.istack.internal.FinalArrayList;
|
||||
import com.sun.xml.internal.stream.buffer.XMLStreamBuffer;
|
||||
import com.sun.xml.internal.ws.message.Util;
|
||||
|
||||
import javax.xml.soap.SOAPConstants;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
|
||||
/**
|
||||
* {@link StreamHeader} for SOAP 1.1.
|
||||
*
|
||||
* @author Paul.Sandoz@Sun.Com
|
||||
*/
|
||||
@SuppressWarnings({"StringEquality"})
|
||||
public class StreamHeader11 extends StreamHeader {
|
||||
protected static final String SOAP_1_1_MUST_UNDERSTAND = "mustUnderstand";
|
||||
|
||||
protected static final String SOAP_1_1_ROLE = "actor";
|
||||
|
||||
public StreamHeader11(XMLStreamReader reader, XMLStreamBuffer mark) {
|
||||
super(reader, mark);
|
||||
}
|
||||
|
||||
public StreamHeader11(XMLStreamReader reader) throws XMLStreamException {
|
||||
super(reader);
|
||||
}
|
||||
|
||||
protected final FinalArrayList<Attribute> processHeaderAttributes(XMLStreamReader reader) {
|
||||
FinalArrayList<Attribute> atts = null;
|
||||
|
||||
_role = SOAPConstants.URI_SOAP_ACTOR_NEXT;
|
||||
|
||||
for (int i = 0; i < reader.getAttributeCount(); i++) {
|
||||
final String localName = reader.getAttributeLocalName(i);
|
||||
final String namespaceURI = reader.getAttributeNamespace(i);
|
||||
final String value = reader.getAttributeValue(i);
|
||||
|
||||
if (SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE.equals(namespaceURI)) {
|
||||
if (SOAP_1_1_MUST_UNDERSTAND.equals(localName)) {
|
||||
_isMustUnderstand = Util.parseBool(value);
|
||||
} else if (SOAP_1_1_ROLE.equals(localName)) {
|
||||
if (value != null && value.length() > 0) {
|
||||
_role = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(atts==null) {
|
||||
atts = new FinalArrayList<Attribute>();
|
||||
}
|
||||
atts.add(new Attribute(namespaceURI,localName,value));
|
||||
}
|
||||
|
||||
return atts;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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.ws.message.stream;
|
||||
|
||||
import com.sun.xml.internal.stream.buffer.XMLStreamBuffer;
|
||||
import com.sun.xml.internal.ws.message.Util;
|
||||
import com.sun.istack.internal.FinalArrayList;
|
||||
|
||||
import javax.xml.soap.SOAPConstants;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
|
||||
/**
|
||||
* {@link StreamHeader} for SOAP 1.2.
|
||||
*
|
||||
* @author Paul.Sandoz@Sun.Com
|
||||
*/
|
||||
@SuppressWarnings({"StringEquality"})
|
||||
public class StreamHeader12 extends StreamHeader {
|
||||
protected static final String SOAP_1_2_MUST_UNDERSTAND = "mustUnderstand";
|
||||
|
||||
protected static final String SOAP_1_2_ROLE = "role";
|
||||
|
||||
protected static final String SOAP_1_2_RELAY = "relay";
|
||||
|
||||
public StreamHeader12(XMLStreamReader reader, XMLStreamBuffer mark) {
|
||||
super(reader, mark);
|
||||
}
|
||||
|
||||
public StreamHeader12(XMLStreamReader reader) throws XMLStreamException {
|
||||
super(reader);
|
||||
}
|
||||
|
||||
protected final FinalArrayList<Attribute> processHeaderAttributes(XMLStreamReader reader) {
|
||||
FinalArrayList<Attribute> atts = null;
|
||||
|
||||
_role = SOAPConstants.URI_SOAP_1_2_ROLE_ULTIMATE_RECEIVER;
|
||||
|
||||
for (int i = 0; i < reader.getAttributeCount(); i++) {
|
||||
final String localName = reader.getAttributeLocalName(i);
|
||||
final String namespaceURI = reader.getAttributeNamespace(i);
|
||||
final String value = reader.getAttributeValue(i);
|
||||
|
||||
if (SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE.equals(namespaceURI)) {
|
||||
if (SOAP_1_2_MUST_UNDERSTAND.equals(localName)) {
|
||||
_isMustUnderstand = Util.parseBool(value);
|
||||
} else if (SOAP_1_2_ROLE.equals(localName)) {
|
||||
if (value != null && value.length() > 0) {
|
||||
_role = value;
|
||||
}
|
||||
} else if (SOAP_1_2_RELAY.equals(localName)) {
|
||||
_isRelay = Util.parseBool(value);
|
||||
}
|
||||
}
|
||||
|
||||
if(atts==null) {
|
||||
atts = new FinalArrayList<Attribute>();
|
||||
}
|
||||
atts.add(new Attribute(namespaceURI,localName,value));
|
||||
}
|
||||
|
||||
return atts;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,766 @@
|
||||
/*
|
||||
* 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.ws.message.stream;
|
||||
|
||||
import com.sun.istack.internal.NotNull;
|
||||
import com.sun.istack.internal.Nullable;
|
||||
import com.sun.istack.internal.XMLStreamReaderToContentHandler;
|
||||
import com.sun.xml.internal.bind.api.Bridge;
|
||||
import com.sun.xml.internal.stream.buffer.MutableXMLStreamBuffer;
|
||||
import com.sun.xml.internal.stream.buffer.XMLStreamBuffer;
|
||||
import com.sun.xml.internal.stream.buffer.XMLStreamBufferMark;
|
||||
import com.sun.xml.internal.stream.buffer.stax.StreamReaderBufferCreator;
|
||||
import com.sun.xml.internal.ws.api.SOAPVersion;
|
||||
import com.sun.xml.internal.ws.api.message.AttachmentSet;
|
||||
import com.sun.xml.internal.ws.api.message.Header;
|
||||
import com.sun.xml.internal.ws.api.message.HeaderList;
|
||||
import com.sun.xml.internal.ws.api.message.Message;
|
||||
import com.sun.xml.internal.ws.api.message.MessageHeaders;
|
||||
import com.sun.xml.internal.ws.api.message.StreamingSOAP;
|
||||
import com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory;
|
||||
import com.sun.xml.internal.ws.encoding.TagInfoset;
|
||||
import com.sun.xml.internal.ws.message.AbstractMessageImpl;
|
||||
import com.sun.xml.internal.ws.message.AttachmentUnmarshallerImpl;
|
||||
import com.sun.xml.internal.ws.protocol.soap.VersionMismatchException;
|
||||
import com.sun.xml.internal.ws.spi.db.XMLBridge;
|
||||
import com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil;
|
||||
import com.sun.xml.internal.ws.util.xml.DummyLocation;
|
||||
import com.sun.xml.internal.ws.util.xml.StAXSource;
|
||||
import com.sun.xml.internal.ws.util.xml.XMLReaderComposite;
|
||||
import com.sun.xml.internal.ws.util.xml.XMLStreamReaderToXMLStreamWriter;
|
||||
import com.sun.xml.internal.ws.util.xml.XMLReaderComposite.ElemInfo;
|
||||
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXParseException;
|
||||
import org.xml.sax.helpers.NamespaceSupport;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.stream.*;
|
||||
|
||||
import static javax.xml.stream.XMLStreamConstants.START_DOCUMENT;
|
||||
import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
|
||||
import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.ws.WebServiceException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* {@link Message} implementation backed by {@link XMLStreamReader}.
|
||||
*
|
||||
* TODO: we need another message class that keeps {@link XMLStreamReader} that points
|
||||
* at the start of the envelope element.
|
||||
*/
|
||||
public class StreamMessage extends AbstractMessageImpl implements StreamingSOAP {
|
||||
/**
|
||||
* The reader will be positioned at
|
||||
* the first child of the SOAP body
|
||||
*/
|
||||
private @NotNull XMLStreamReader reader;
|
||||
|
||||
// lazily created
|
||||
private @Nullable MessageHeaders headers;
|
||||
|
||||
/**
|
||||
* Because the StreamMessage leaves out the white spaces around payload
|
||||
* when being instantiated the space characters between soap:Body opening and
|
||||
* payload is stored in this field to be reused later (necessary for message security);
|
||||
* Instantiated after StreamMessage creation
|
||||
*/
|
||||
private String bodyPrologue = null;
|
||||
|
||||
/**
|
||||
* instantiated after writing message to XMLStreamWriter
|
||||
*/
|
||||
private String bodyEpilogue = null;
|
||||
|
||||
private String payloadLocalName;
|
||||
|
||||
private String payloadNamespaceURI;
|
||||
|
||||
/**
|
||||
* Used only for debugging. This records where the message was consumed.
|
||||
*/
|
||||
private Throwable consumedAt;
|
||||
|
||||
private XMLStreamReader envelopeReader;
|
||||
|
||||
public StreamMessage(SOAPVersion v) {
|
||||
super(v);
|
||||
payloadLocalName = null;
|
||||
payloadNamespaceURI = null;
|
||||
}
|
||||
|
||||
public StreamMessage(SOAPVersion v, @NotNull XMLStreamReader envelope, @NotNull AttachmentSet attachments) {
|
||||
super(v);
|
||||
envelopeReader = envelope;
|
||||
attachmentSet = attachments;
|
||||
}
|
||||
|
||||
public XMLStreamReader readEnvelope() {
|
||||
if (envelopeReader == null) {
|
||||
List<XMLStreamReader> hReaders = new java.util.ArrayList<XMLStreamReader>();
|
||||
ElemInfo envElem = new ElemInfo(envelopeTag, null);
|
||||
ElemInfo hdrElem = (headerTag != null) ? new ElemInfo(headerTag, envElem) : null;
|
||||
ElemInfo bdyElem = new ElemInfo(bodyTag, envElem);
|
||||
for (Header h : getHeaders().asList()) {
|
||||
try {
|
||||
hReaders.add(h.readHeader());
|
||||
} catch (XMLStreamException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
XMLStreamReader soapHeader = (hdrElem != null) ? new XMLReaderComposite(hdrElem, hReaders.toArray(new XMLStreamReader[hReaders.size()])) : null;
|
||||
XMLStreamReader[] payload = {readPayload()};
|
||||
XMLStreamReader soapBody = new XMLReaderComposite(bdyElem, payload);
|
||||
XMLStreamReader[] soapContent = (soapHeader != null) ? new XMLStreamReader[]{soapHeader, soapBody} : new XMLStreamReader[]{soapBody};
|
||||
return new XMLReaderComposite(envElem, soapContent);
|
||||
}
|
||||
return envelopeReader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link StreamMessage} from a {@link XMLStreamReader}
|
||||
* that points at the start element of the payload, and headers.
|
||||
*
|
||||
* <p>
|
||||
* This method creates a {@link Message} from a payload.
|
||||
*
|
||||
* @param headers
|
||||
* if null, it means no headers. if non-null,
|
||||
* it will be owned by this message.
|
||||
* @param reader
|
||||
* points at the start element/document of the payload (or the end element of the <s:Body>
|
||||
* if there's no payload)
|
||||
*/
|
||||
public StreamMessage(@Nullable MessageHeaders headers, @NotNull AttachmentSet attachmentSet, @NotNull XMLStreamReader reader, @NotNull SOAPVersion soapVersion) {
|
||||
super(soapVersion);
|
||||
init(headers, attachmentSet, reader, soapVersion);
|
||||
}
|
||||
|
||||
private void init(@Nullable MessageHeaders headers, @NotNull AttachmentSet attachmentSet, @NotNull XMLStreamReader reader, @NotNull SOAPVersion soapVersion) {
|
||||
this.headers = headers;
|
||||
this.attachmentSet = attachmentSet;
|
||||
this.reader = reader;
|
||||
|
||||
if(reader.getEventType()== START_DOCUMENT)
|
||||
XMLStreamReaderUtil.nextElementContent(reader);
|
||||
|
||||
//if the reader is pointing to the end element </soapenv:Body> then its empty message
|
||||
// or no payload
|
||||
if(reader.getEventType() == XMLStreamConstants.END_ELEMENT){
|
||||
String body = reader.getLocalName();
|
||||
String nsUri = reader.getNamespaceURI();
|
||||
assert body != null;
|
||||
assert nsUri != null;
|
||||
//if its not soapenv:Body then throw exception, we received malformed stream
|
||||
if(body.equals("Body") && nsUri.equals(soapVersion.nsUri)){
|
||||
this.payloadLocalName = null;
|
||||
this.payloadNamespaceURI = null;
|
||||
}else{ //TODO: i18n and also we should be throwing better message that this
|
||||
throw new WebServiceException("Malformed stream: {"+nsUri+"}"+body);
|
||||
}
|
||||
}else{
|
||||
this.payloadLocalName = reader.getLocalName();
|
||||
this.payloadNamespaceURI = reader.getNamespaceURI();
|
||||
}
|
||||
|
||||
// use the default infoset representation for headers
|
||||
int base = soapVersion.ordinal()*3;
|
||||
this.envelopeTag = DEFAULT_TAGS.get(base);
|
||||
this.headerTag = DEFAULT_TAGS.get(base+1);
|
||||
this.bodyTag = DEFAULT_TAGS.get(base+2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link StreamMessage} from a {@link XMLStreamReader}
|
||||
* and the complete infoset of the SOAP envelope.
|
||||
*
|
||||
* <p>
|
||||
* See {@link #StreamMessage(MessageHeaders, AttachmentSet, XMLStreamReader, SOAPVersion)} for
|
||||
* the description of the basic parameters.
|
||||
*
|
||||
* @param headerTag
|
||||
* Null if the message didn't have a header tag.
|
||||
*
|
||||
*/
|
||||
public StreamMessage(@NotNull TagInfoset envelopeTag, @Nullable TagInfoset headerTag, @NotNull AttachmentSet attachmentSet, @Nullable MessageHeaders headers, @NotNull TagInfoset bodyTag, @NotNull XMLStreamReader reader, @NotNull SOAPVersion soapVersion) {
|
||||
this(envelopeTag, headerTag, attachmentSet, headers, null, bodyTag, null, reader, soapVersion);
|
||||
}
|
||||
|
||||
public StreamMessage(@NotNull TagInfoset envelopeTag, @Nullable TagInfoset headerTag, @NotNull AttachmentSet attachmentSet, @Nullable MessageHeaders headers, @Nullable String bodyPrologue, @NotNull TagInfoset bodyTag, @Nullable String bodyEpilogue, @NotNull XMLStreamReader reader, @NotNull SOAPVersion soapVersion) {
|
||||
super(soapVersion);
|
||||
init(envelopeTag, headerTag, attachmentSet, headers, bodyPrologue, bodyTag, bodyEpilogue, reader, soapVersion);
|
||||
}
|
||||
|
||||
private void init(@NotNull TagInfoset envelopeTag, @Nullable TagInfoset headerTag, @NotNull AttachmentSet attachmentSet, @Nullable MessageHeaders headers, @Nullable String bodyPrologue, @NotNull TagInfoset bodyTag, @Nullable String bodyEpilogue, @NotNull XMLStreamReader reader, @NotNull SOAPVersion soapVersion) {
|
||||
init(headers,attachmentSet,reader,soapVersion);
|
||||
if(envelopeTag == null ) {
|
||||
throw new IllegalArgumentException("EnvelopeTag TagInfoset cannot be null");
|
||||
}
|
||||
if(bodyTag == null ) {
|
||||
throw new IllegalArgumentException("BodyTag TagInfoset cannot be null");
|
||||
}
|
||||
this.envelopeTag = envelopeTag;
|
||||
this.headerTag = headerTag;
|
||||
this.bodyTag = bodyTag;
|
||||
this.bodyPrologue = bodyPrologue;
|
||||
this.bodyEpilogue = bodyEpilogue;
|
||||
}
|
||||
|
||||
public boolean hasHeaders() {
|
||||
if ( envelopeReader != null ) readEnvelope(this);
|
||||
return headers!=null && headers.hasHeaders();
|
||||
}
|
||||
|
||||
public MessageHeaders getHeaders() {
|
||||
if ( envelopeReader != null ) readEnvelope(this);
|
||||
if (headers == null) {
|
||||
headers = new HeaderList(getSOAPVersion());
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
|
||||
public String getPayloadLocalPart() {
|
||||
if ( envelopeReader != null ) readEnvelope(this);
|
||||
return payloadLocalName;
|
||||
}
|
||||
|
||||
public String getPayloadNamespaceURI() {
|
||||
if ( envelopeReader != null ) readEnvelope(this);
|
||||
return payloadNamespaceURI;
|
||||
}
|
||||
|
||||
public boolean hasPayload() {
|
||||
if ( envelopeReader != null ) readEnvelope(this);
|
||||
return payloadLocalName!=null;
|
||||
}
|
||||
|
||||
public Source readPayloadAsSource() {
|
||||
if(hasPayload()) {
|
||||
assert unconsumed();
|
||||
return new StAXSource(reader, true, getInscopeNamespaces());
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* There is no way to enumerate inscope namespaces for XMLStreamReader. That means
|
||||
* namespaces declared in envelope, and body tags need to be computed using their
|
||||
* {@link TagInfoset}s.
|
||||
*
|
||||
* @return array of the even length of the form { prefix0, uri0, prefix1, uri1, ... }
|
||||
*/
|
||||
private String[] getInscopeNamespaces() {
|
||||
NamespaceSupport nss = new NamespaceSupport();
|
||||
|
||||
nss.pushContext();
|
||||
for(int i=0; i < envelopeTag.ns.length; i+=2) {
|
||||
nss.declarePrefix(envelopeTag.ns[i], envelopeTag.ns[i+1]);
|
||||
}
|
||||
|
||||
nss.pushContext();
|
||||
for(int i=0; i < bodyTag.ns.length; i+=2) {
|
||||
nss.declarePrefix(bodyTag.ns[i], bodyTag.ns[i+1]);
|
||||
}
|
||||
|
||||
List<String> inscope = new ArrayList<String>();
|
||||
for( Enumeration en = nss.getPrefixes(); en.hasMoreElements(); ) {
|
||||
String prefix = (String)en.nextElement();
|
||||
inscope.add(prefix);
|
||||
inscope.add(nss.getURI(prefix));
|
||||
}
|
||||
return inscope.toArray(new String[inscope.size()]);
|
||||
}
|
||||
|
||||
public Object readPayloadAsJAXB(Unmarshaller unmarshaller) throws JAXBException {
|
||||
if(!hasPayload())
|
||||
return null;
|
||||
assert unconsumed();
|
||||
// TODO: How can the unmarshaller process this as a fragment?
|
||||
if(hasAttachments())
|
||||
unmarshaller.setAttachmentUnmarshaller(new AttachmentUnmarshallerImpl(getAttachments()));
|
||||
try {
|
||||
return unmarshaller.unmarshal(reader);
|
||||
} finally{
|
||||
unmarshaller.setAttachmentUnmarshaller(null);
|
||||
XMLStreamReaderUtil.readRest(reader);
|
||||
XMLStreamReaderUtil.close(reader);
|
||||
XMLStreamReaderFactory.recycle(reader);
|
||||
}
|
||||
}
|
||||
/** @deprecated */
|
||||
public <T> T readPayloadAsJAXB(Bridge<T> bridge) throws JAXBException {
|
||||
if(!hasPayload())
|
||||
return null;
|
||||
assert unconsumed();
|
||||
T r = bridge.unmarshal(reader,
|
||||
hasAttachments() ? new AttachmentUnmarshallerImpl(getAttachments()) : null);
|
||||
XMLStreamReaderUtil.readRest(reader);
|
||||
XMLStreamReaderUtil.close(reader);
|
||||
XMLStreamReaderFactory.recycle(reader);
|
||||
return r;
|
||||
}
|
||||
|
||||
public <T> T readPayloadAsJAXB(XMLBridge<T> bridge) throws JAXBException {
|
||||
if(!hasPayload())
|
||||
return null;
|
||||
assert unconsumed();
|
||||
T r = bridge.unmarshal(reader,
|
||||
hasAttachments() ? new AttachmentUnmarshallerImpl(getAttachments()) : null);
|
||||
XMLStreamReaderUtil.readRest(reader);
|
||||
XMLStreamReaderUtil.close(reader);
|
||||
XMLStreamReaderFactory.recycle(reader);
|
||||
return r;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void consume() {
|
||||
assert unconsumed();
|
||||
XMLStreamReaderUtil.readRest(reader);
|
||||
XMLStreamReaderUtil.close(reader);
|
||||
XMLStreamReaderFactory.recycle(reader);
|
||||
}
|
||||
|
||||
public XMLStreamReader readPayload() {
|
||||
if(!hasPayload())
|
||||
return null;
|
||||
// TODO: What about access at and beyond </soap:Body>
|
||||
assert unconsumed();
|
||||
return this.reader;
|
||||
}
|
||||
|
||||
public void writePayloadTo(XMLStreamWriter writer)throws XMLStreamException {
|
||||
if ( envelopeReader != null ) readEnvelope(this);
|
||||
assert unconsumed();
|
||||
|
||||
if(payloadLocalName==null) {
|
||||
return; // no body
|
||||
}
|
||||
|
||||
if (bodyPrologue != null) {
|
||||
writer.writeCharacters(bodyPrologue);
|
||||
}
|
||||
|
||||
XMLStreamReaderToXMLStreamWriter conv = new XMLStreamReaderToXMLStreamWriter();
|
||||
|
||||
while(reader.getEventType() != XMLStreamConstants.END_DOCUMENT){
|
||||
String name = reader.getLocalName();
|
||||
String nsUri = reader.getNamespaceURI();
|
||||
|
||||
// After previous conv.bridge() call the cursor will be at END_ELEMENT.
|
||||
// Check if its not soapenv:Body then move to next ELEMENT
|
||||
if(reader.getEventType() == XMLStreamConstants.END_ELEMENT){
|
||||
|
||||
if (!isBodyElement(name, nsUri)){
|
||||
// closing payload element: store epilogue for further signing, if applicable
|
||||
// however if there more than one payloads exist - the last one is stored
|
||||
String whiteSpaces = XMLStreamReaderUtil.nextWhiteSpaceContent(reader);
|
||||
if (whiteSpaces != null) {
|
||||
this.bodyEpilogue = whiteSpaces;
|
||||
// write it to the message too
|
||||
writer.writeCharacters(whiteSpaces);
|
||||
}
|
||||
} else {
|
||||
// body closed > exit
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
// payload opening element: copy payload to writer
|
||||
conv.bridge(reader,writer);
|
||||
}
|
||||
}
|
||||
|
||||
XMLStreamReaderUtil.readRest(reader);
|
||||
XMLStreamReaderUtil.close(reader);
|
||||
XMLStreamReaderFactory.recycle(reader);
|
||||
}
|
||||
|
||||
private boolean isBodyElement(String name, String nsUri) {
|
||||
return name.equals("Body") && nsUri.equals(soapVersion.nsUri);
|
||||
}
|
||||
|
||||
public void writeTo(XMLStreamWriter sw) throws XMLStreamException{
|
||||
if ( envelopeReader != null ) readEnvelope(this);
|
||||
writeEnvelope(sw);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method should be called when the StreamMessage is created with a payload
|
||||
* @param writer
|
||||
*/
|
||||
private void writeEnvelope(XMLStreamWriter writer) throws XMLStreamException {
|
||||
if ( envelopeReader != null ) readEnvelope(this);
|
||||
writer.writeStartDocument();
|
||||
envelopeTag.writeStart(writer);
|
||||
|
||||
//write headers
|
||||
MessageHeaders hl = getHeaders();
|
||||
if (hl.hasHeaders() && headerTag == null) headerTag = new TagInfoset(envelopeTag.nsUri,"Header",envelopeTag.prefix,EMPTY_ATTS);
|
||||
if (headerTag != null) {
|
||||
headerTag.writeStart(writer);
|
||||
if (hl.hasHeaders()){
|
||||
for(Header h : hl.asList()){
|
||||
h.writeTo(writer);
|
||||
}
|
||||
}
|
||||
writer.writeEndElement();
|
||||
}
|
||||
bodyTag.writeStart(writer);
|
||||
if(hasPayload())
|
||||
writePayloadTo(writer);
|
||||
writer.writeEndElement();
|
||||
writer.writeEndElement();
|
||||
writer.writeEndDocument();
|
||||
}
|
||||
|
||||
public void writePayloadTo(ContentHandler contentHandler, ErrorHandler errorHandler, boolean fragment) throws SAXException {
|
||||
if ( envelopeReader != null ) readEnvelope(this);
|
||||
assert unconsumed();
|
||||
|
||||
try {
|
||||
if(payloadLocalName==null)
|
||||
return; // no body
|
||||
|
||||
if (bodyPrologue != null) {
|
||||
char[] chars = bodyPrologue.toCharArray();
|
||||
contentHandler.characters(chars, 0, chars.length);
|
||||
}
|
||||
|
||||
XMLStreamReaderToContentHandler conv = new XMLStreamReaderToContentHandler(reader,contentHandler,true,fragment,getInscopeNamespaces());
|
||||
|
||||
while(reader.getEventType() != XMLStreamConstants.END_DOCUMENT){
|
||||
String name = reader.getLocalName();
|
||||
String nsUri = reader.getNamespaceURI();
|
||||
|
||||
// After previous conv.bridge() call the cursor will be at END_ELEMENT.
|
||||
// Check if its not soapenv:Body then move to next ELEMENT
|
||||
if(reader.getEventType() == XMLStreamConstants.END_ELEMENT){
|
||||
|
||||
if (!isBodyElement(name, nsUri)){
|
||||
// closing payload element: store epilogue for further signing, if applicable
|
||||
// however if there more than one payloads exist - the last one is stored
|
||||
String whiteSpaces = XMLStreamReaderUtil.nextWhiteSpaceContent(reader);
|
||||
if (whiteSpaces != null) {
|
||||
this.bodyEpilogue = whiteSpaces;
|
||||
// write it to the message too
|
||||
char[] chars = whiteSpaces.toCharArray();
|
||||
contentHandler.characters(chars, 0, chars.length);
|
||||
}
|
||||
} else {
|
||||
// body closed > exit
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
// payload opening element: copy payload to writer
|
||||
conv.bridge();
|
||||
}
|
||||
}
|
||||
XMLStreamReaderUtil.readRest(reader);
|
||||
XMLStreamReaderUtil.close(reader);
|
||||
XMLStreamReaderFactory.recycle(reader);
|
||||
} catch (XMLStreamException e) {
|
||||
Location loc = e.getLocation();
|
||||
if(loc==null) loc = DummyLocation.INSTANCE;
|
||||
|
||||
SAXParseException x = new SAXParseException(
|
||||
e.getMessage(),loc.getPublicId(),loc.getSystemId(),loc.getLineNumber(),loc.getColumnNumber(),e);
|
||||
errorHandler.error(x);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: this method should be probably rewritten to respect spaces between elements; is it used at all?
|
||||
@Override
|
||||
public Message copy() {
|
||||
if ( envelopeReader != null ) readEnvelope(this);
|
||||
try {
|
||||
assert unconsumed();
|
||||
consumedAt = null; // but we don't want to mark it as consumed
|
||||
MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();
|
||||
StreamReaderBufferCreator c = new StreamReaderBufferCreator(xsb);
|
||||
|
||||
// preserving inscope namespaces from envelope, and body. Other option
|
||||
// would be to create a filtering XMLStreamReader from reader+envelopeTag+bodyTag
|
||||
c.storeElement(envelopeTag.nsUri, envelopeTag.localName, envelopeTag.prefix, envelopeTag.ns);
|
||||
c.storeElement(bodyTag.nsUri, bodyTag.localName, bodyTag.prefix, bodyTag.ns);
|
||||
|
||||
if (hasPayload()) {
|
||||
// Loop all the way for multi payload case
|
||||
while(reader.getEventType() != XMLStreamConstants.END_DOCUMENT){
|
||||
String name = reader.getLocalName();
|
||||
String nsUri = reader.getNamespaceURI();
|
||||
if(isBodyElement(name, nsUri) || (reader.getEventType() == XMLStreamConstants.END_DOCUMENT))
|
||||
break;
|
||||
c.create(reader);
|
||||
|
||||
// Skip whitespaces in between payload and </Body> or between elements
|
||||
// those won't be in the message itself, but we store them in field bodyEpilogue
|
||||
if (reader.isWhiteSpace()) {
|
||||
bodyEpilogue = XMLStreamReaderUtil.currentWhiteSpaceContent(reader);
|
||||
} else {
|
||||
// clear it in case the existing was not the last one
|
||||
// (we are interested only in the last one?)
|
||||
bodyEpilogue = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
c.storeEndElement(); // create structure element for </Body>
|
||||
c.storeEndElement(); // create structure element for </Envelope>
|
||||
c.storeEndElement(); // create structure element for END_DOCUMENT
|
||||
|
||||
XMLStreamReaderUtil.readRest(reader);
|
||||
XMLStreamReaderUtil.close(reader);
|
||||
XMLStreamReaderFactory.recycle(reader);
|
||||
|
||||
reader = xsb.readAsXMLStreamReader();
|
||||
XMLStreamReader clone = xsb.readAsXMLStreamReader();
|
||||
|
||||
// advance to the start tag of the <Body> first child element
|
||||
proceedToRootElement(reader);
|
||||
proceedToRootElement(clone);
|
||||
|
||||
return new StreamMessage(envelopeTag, headerTag, attachmentSet, HeaderList.copy(headers), bodyPrologue, bodyTag, bodyEpilogue, clone, soapVersion);
|
||||
} catch (XMLStreamException e) {
|
||||
throw new WebServiceException("Failed to copy a message",e);
|
||||
}
|
||||
}
|
||||
|
||||
private void proceedToRootElement(XMLStreamReader xsr) throws XMLStreamException {
|
||||
assert xsr.getEventType()==START_DOCUMENT;
|
||||
xsr.nextTag();
|
||||
xsr.nextTag();
|
||||
xsr.nextTag();
|
||||
assert xsr.getEventType()==START_ELEMENT || xsr.getEventType()==END_ELEMENT;
|
||||
}
|
||||
|
||||
public void writeTo(ContentHandler contentHandler, ErrorHandler errorHandler ) throws SAXException {
|
||||
if ( envelopeReader != null ) readEnvelope(this);
|
||||
contentHandler.setDocumentLocator(NULL_LOCATOR);
|
||||
contentHandler.startDocument();
|
||||
envelopeTag.writeStart(contentHandler);
|
||||
if (hasHeaders() && headerTag == null) headerTag = new TagInfoset(envelopeTag.nsUri,"Header",envelopeTag.prefix,EMPTY_ATTS);
|
||||
if (headerTag != null) {
|
||||
headerTag.writeStart(contentHandler);
|
||||
if (hasHeaders()) {
|
||||
MessageHeaders headers = getHeaders();
|
||||
for (Header h : headers.asList()) {
|
||||
// shouldn't JDK be smart enough to use array-style indexing for this foreach!?
|
||||
h.writeTo(contentHandler,errorHandler);
|
||||
}
|
||||
}
|
||||
headerTag.writeEnd(contentHandler);
|
||||
}
|
||||
bodyTag.writeStart(contentHandler);
|
||||
writePayloadTo(contentHandler,errorHandler, true);
|
||||
bodyTag.writeEnd(contentHandler);
|
||||
envelopeTag.writeEnd(contentHandler);
|
||||
contentHandler.endDocument();
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for an assertion. Returns true when the message is unconsumed,
|
||||
* or otherwise throw an exception.
|
||||
*
|
||||
* <p>
|
||||
* Calling this method also marks the stream as 'consumed'
|
||||
*/
|
||||
private boolean unconsumed() {
|
||||
if(payloadLocalName==null)
|
||||
return true; // no payload. can be consumed multiple times.
|
||||
|
||||
if(reader.getEventType()!=XMLStreamReader.START_ELEMENT) {
|
||||
AssertionError error = new AssertionError("StreamMessage has been already consumed. See the nested exception for where it's consumed");
|
||||
error.initCause(consumedAt);
|
||||
throw error;
|
||||
}
|
||||
consumedAt = new Exception().fillInStackTrace();
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getBodyPrologue() {
|
||||
if ( envelopeReader != null ) readEnvelope(this);
|
||||
return bodyPrologue;
|
||||
}
|
||||
|
||||
public String getBodyEpilogue() {
|
||||
if ( envelopeReader != null ) readEnvelope(this);
|
||||
return bodyEpilogue;
|
||||
}
|
||||
|
||||
public XMLStreamReader getReader() {
|
||||
if ( envelopeReader != null ) readEnvelope(this);
|
||||
assert unconsumed();
|
||||
return reader;
|
||||
}
|
||||
|
||||
|
||||
private static final String SOAP_ENVELOPE = "Envelope";
|
||||
private static final String SOAP_HEADER = "Header";
|
||||
private static final String SOAP_BODY = "Body";
|
||||
|
||||
protected interface StreamHeaderDecoder {
|
||||
public Header decodeHeader(XMLStreamReader reader, XMLStreamBuffer mark);
|
||||
}
|
||||
|
||||
static final StreamHeaderDecoder SOAP12StreamHeaderDecoder = new StreamHeaderDecoder() {
|
||||
@Override
|
||||
public Header decodeHeader(XMLStreamReader reader, XMLStreamBuffer mark) {
|
||||
return new StreamHeader12(reader, mark);
|
||||
}
|
||||
};
|
||||
|
||||
static final StreamHeaderDecoder SOAP11StreamHeaderDecoder = new StreamHeaderDecoder() {
|
||||
@Override
|
||||
public Header decodeHeader(XMLStreamReader reader, XMLStreamBuffer mark) {
|
||||
return new StreamHeader11(reader, mark);
|
||||
}
|
||||
};
|
||||
|
||||
static private void readEnvelope(StreamMessage message) {
|
||||
if ( message.envelopeReader == null ) return;
|
||||
XMLStreamReader reader = message.envelopeReader;
|
||||
message.envelopeReader = null;
|
||||
SOAPVersion soapVersion = message.soapVersion;
|
||||
// Move to soap:Envelope and verify
|
||||
if(reader.getEventType()!=XMLStreamConstants.START_ELEMENT)
|
||||
XMLStreamReaderUtil.nextElementContent(reader);
|
||||
XMLStreamReaderUtil.verifyReaderState(reader,XMLStreamConstants.START_ELEMENT);
|
||||
if (SOAP_ENVELOPE.equals(reader.getLocalName()) && !soapVersion.nsUri.equals(reader.getNamespaceURI())) {
|
||||
throw new VersionMismatchException(soapVersion, soapVersion.nsUri, reader.getNamespaceURI());
|
||||
}
|
||||
XMLStreamReaderUtil.verifyTag(reader, soapVersion.nsUri, SOAP_ENVELOPE);
|
||||
|
||||
TagInfoset envelopeTag = new TagInfoset(reader);
|
||||
|
||||
// Collect namespaces on soap:Envelope
|
||||
Map<String,String> namespaces = new HashMap<String,String>();
|
||||
for(int i=0; i< reader.getNamespaceCount();i++){
|
||||
namespaces.put(reader.getNamespacePrefix(i), reader.getNamespaceURI(i));
|
||||
}
|
||||
|
||||
// Move to next element
|
||||
XMLStreamReaderUtil.nextElementContent(reader);
|
||||
XMLStreamReaderUtil.verifyReaderState(reader,
|
||||
javax.xml.stream.XMLStreamConstants.START_ELEMENT);
|
||||
|
||||
HeaderList headers = null;
|
||||
TagInfoset headerTag = null;
|
||||
|
||||
if (reader.getLocalName().equals(SOAP_HEADER)
|
||||
&& reader.getNamespaceURI().equals(soapVersion.nsUri)) {
|
||||
headerTag = new TagInfoset(reader);
|
||||
|
||||
// Collect namespaces on soap:Header
|
||||
for(int i=0; i< reader.getNamespaceCount();i++){
|
||||
namespaces.put(reader.getNamespacePrefix(i), reader.getNamespaceURI(i));
|
||||
}
|
||||
// skip <soap:Header>
|
||||
XMLStreamReaderUtil.nextElementContent(reader);
|
||||
|
||||
// If SOAP header blocks are present (i.e. not <soap:Header/>)
|
||||
if (reader.getEventType() == XMLStreamConstants.START_ELEMENT) {
|
||||
headers = new HeaderList(soapVersion);
|
||||
|
||||
try {
|
||||
// Cache SOAP header blocks
|
||||
StreamHeaderDecoder headerDecoder = SOAPVersion.SOAP_11.equals(soapVersion) ? SOAP11StreamHeaderDecoder : SOAP12StreamHeaderDecoder;
|
||||
cacheHeaders(reader, namespaces, headers, headerDecoder);
|
||||
} catch (XMLStreamException e) {
|
||||
// TODO need to throw more meaningful exception
|
||||
throw new WebServiceException(e);
|
||||
}
|
||||
}
|
||||
|
||||
// Move to soap:Body
|
||||
XMLStreamReaderUtil.nextElementContent(reader);
|
||||
}
|
||||
|
||||
// Verify that <soap:Body> is present
|
||||
XMLStreamReaderUtil.verifyTag(reader, soapVersion.nsUri, SOAP_BODY);
|
||||
TagInfoset bodyTag = new TagInfoset(reader);
|
||||
|
||||
String bodyPrologue = XMLStreamReaderUtil.nextWhiteSpaceContent(reader);
|
||||
message.init(envelopeTag,headerTag,message.attachmentSet,headers,bodyPrologue,bodyTag,null,reader,soapVersion);
|
||||
// when there's no payload,
|
||||
// it's tempting to use EmptyMessageImpl, but it doesn't preserve the infoset
|
||||
// of <envelope>,<header>, and <body>, so we need to stick to StreamMessage.
|
||||
}
|
||||
|
||||
|
||||
private static XMLStreamBuffer cacheHeaders(XMLStreamReader reader,
|
||||
Map<String, String> namespaces, HeaderList headers,
|
||||
StreamHeaderDecoder headerDecoder) throws XMLStreamException {
|
||||
MutableXMLStreamBuffer buffer = createXMLStreamBuffer();
|
||||
StreamReaderBufferCreator creator = new StreamReaderBufferCreator();
|
||||
creator.setXMLStreamBuffer(buffer);
|
||||
|
||||
// Reader is positioned at the first header block
|
||||
while(reader.getEventType() == javax.xml.stream.XMLStreamConstants.START_ELEMENT) {
|
||||
Map<String,String> headerBlockNamespaces = namespaces;
|
||||
|
||||
// Collect namespaces on SOAP header block
|
||||
if (reader.getNamespaceCount() > 0) {
|
||||
headerBlockNamespaces = new HashMap<String,String>(namespaces);
|
||||
for (int i = 0; i < reader.getNamespaceCount(); i++) {
|
||||
headerBlockNamespaces.put(reader.getNamespacePrefix(i), reader.getNamespaceURI(i));
|
||||
}
|
||||
}
|
||||
|
||||
// Mark
|
||||
XMLStreamBuffer mark = new XMLStreamBufferMark(headerBlockNamespaces, creator);
|
||||
// Create Header
|
||||
headers.add(headerDecoder.decodeHeader(reader, mark));
|
||||
|
||||
|
||||
// Cache the header block
|
||||
// After caching Reader will be positioned at next header block or
|
||||
// the end of the </soap:header>
|
||||
creator.createElementFragment(reader, false);
|
||||
if (reader.getEventType() != XMLStreamConstants.START_ELEMENT &&
|
||||
reader.getEventType() != XMLStreamConstants.END_ELEMENT) {
|
||||
XMLStreamReaderUtil.nextElementContent(reader);
|
||||
}
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
private static MutableXMLStreamBuffer createXMLStreamBuffer() {
|
||||
// TODO: Decode should own one MutableXMLStreamBuffer for reuse
|
||||
// since it is more efficient. ISSUE: possible issue with
|
||||
// lifetime of information in the buffer if accessed beyond
|
||||
// the pipe line.
|
||||
return new MutableXMLStreamBuffer();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user