001: /*
002: * Portions Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025: package com.sun.xml.internal.ws.encoding.soap.server;
026:
027: import javax.xml.stream.XMLStreamWriter;
028: import javax.xml.stream.XMLStreamException;
029: import javax.xml.ws.soap.SOAPBinding;
030:
031: import com.sun.xml.internal.ws.pept.ept.MessageInfo;
032: import com.sun.xml.internal.ws.encoding.soap.message.SOAPFaultInfo;
033: import com.sun.xml.internal.ws.encoding.soap.message.SOAP12FaultInfo;
034: import com.sun.xml.internal.ws.encoding.soap.streaming.SOAP12NamespaceConstants;
035: import com.sun.xml.internal.ws.encoding.soap.streaming.SOAPNamespaceConstants;
036: import com.sun.xml.internal.ws.encoding.JAXWSAttachmentMarshaller;
037: import com.sun.xml.internal.ws.util.MessageInfoUtil;
038: import com.sun.xml.internal.ws.client.BindingProviderProperties;
039: import com.sun.xml.internal.ws.server.*;
040:
041: import static com.sun.xml.internal.ws.client.BindingProviderProperties.*;
042: import com.sun.xml.internal.ws.handler.MessageContextUtil;
043: import com.sun.xml.internal.ws.spi.runtime.WSConnection;
044: import javax.xml.ws.handler.MessageContext;
045:
046: public class SOAP12XMLEncoder extends SOAPXMLEncoder {
047: /*
048: * @see SOAPEncoder#startEnvelope(XMLStreamWriter)
049: */
050: @Override
051: protected void startEnvelope(XMLStreamWriter writer) {
052: try {
053: writer.writeStartElement(
054: SOAPNamespaceConstants.NSPREFIX_SOAP_ENVELOPE,
055: SOAPNamespaceConstants.TAG_ENVELOPE,
056: SOAP12NamespaceConstants.ENVELOPE);
057: writer.setPrefix(
058: SOAPNamespaceConstants.NSPREFIX_SOAP_ENVELOPE,
059: SOAP12NamespaceConstants.ENVELOPE);
060: writer.writeNamespace(
061: SOAPNamespaceConstants.NSPREFIX_SOAP_ENVELOPE,
062: SOAP12NamespaceConstants.ENVELOPE);
063: } catch (XMLStreamException e) {
064: throw new ServerRtException(e);
065: }
066: }
067:
068: /*
069: * @see SOAPEncoder#startBody(XMLStreamWriter)
070: */
071: @Override
072: protected void startBody(XMLStreamWriter writer) {
073: try {
074: writer.writeStartElement(
075: SOAPNamespaceConstants.NSPREFIX_SOAP_ENVELOPE,
076: SOAPNamespaceConstants.TAG_BODY,
077: SOAP12NamespaceConstants.ENVELOPE);
078: } catch (XMLStreamException e) {
079: throw new ServerRtException(e);
080: }
081: }
082:
083: /*
084: * @see SOAPEncoder#startHeader(XMLStreamWriter)
085: */
086: @Override
087: protected void startHeader(XMLStreamWriter writer) {
088: try {
089: writer.writeStartElement(
090: SOAPNamespaceConstants.NSPREFIX_SOAP_ENVELOPE,
091: SOAPNamespaceConstants.TAG_HEADER,
092: SOAP12NamespaceConstants.ENVELOPE); // <env:Header>
093: } catch (XMLStreamException e) {
094: throw new ServerRtException(e);
095: }
096: }
097:
098: /* (non-Javadoc)
099: * @see com.sun.xml.internal.ws.rt.server.SOAPXMLEncoder#writeFault(com.sun.xml.internal.ws.soap.message.SOAPFaultInfo, com.sun.pept.ept.MessageInfo, com.sun.xml.internal.ws.streaming.XMLStreamWriter)
100: */
101: @Override
102: protected void writeFault(SOAPFaultInfo faultInfo,
103: MessageInfo messageInfo, XMLStreamWriter writer) {
104: if (!(faultInfo instanceof SOAP12FaultInfo))
105: return;
106: // Set a status code for Fault
107: MessageContext ctxt = MessageInfoUtil
108: .getMessageContext(messageInfo);
109: if (MessageContextUtil.getHttpStatusCode(ctxt) == null) {
110: MessageContextUtil.setHttpStatusCode(ctxt,
111: WSConnection.INTERNAL_ERR);
112: }
113:
114: ((SOAP12FaultInfo) faultInfo).write(writer, messageInfo);
115: }
116:
117: protected String getContentType(MessageInfo messageInfo,
118: JAXWSAttachmentMarshaller marshaller) {
119: String contentNegotiation = (String) messageInfo
120: .getMetaData(BindingProviderProperties.CONTENT_NEGOTIATION_PROPERTY);
121:
122: if (marshaller == null) {
123: marshaller = getAttachmentMarshaller(messageInfo);
124: }
125:
126: if (marshaller != null && marshaller.isXopped()) {
127: return XOP_SOAP12_XML_TYPE_VALUE;
128: } else {
129: return (contentNegotiation == "optimistic") ? FAST_INFOSET_TYPE_SOAP12
130: : SOAP12_XML_CONTENT_TYPE_VALUE;
131: }
132: }
133:
134: /**
135: * This method is used to create the appropriate SOAPMessage (1.1 or 1.2 using SAAJ api).
136: * @return the BindingID associated with this encoder
137: */
138: protected String getBindingId() {
139: return SOAPBinding.SOAP12HTTP_BINDING;
140: }
141: }
|