feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
@@ -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;
|
||||
Reference in New Issue
Block a user