Wed, 12 Jun 2013 14:47:09 +0100
8013021: Rebase 8005432 & 8003542 against the latest jdk8/jaxws
8003542: Improve processing of MTOM attachments
8005432: Update access to JAX-WS
Reviewed-by: mullan
ohair@286 | 1 | /* |
alanb@368 | 2 | * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
ohair@286 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ohair@286 | 4 | * |
ohair@286 | 5 | * This code is free software; you can redistribute it and/or modify it |
ohair@286 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@286 | 7 | * published by the Free Software Foundation. Oracle designates this |
ohair@286 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@286 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
ohair@286 | 10 | * |
ohair@286 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
ohair@286 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ohair@286 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ohair@286 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
ohair@286 | 15 | * accompanied this code). |
ohair@286 | 16 | * |
ohair@286 | 17 | * You should have received a copy of the GNU General Public License version |
ohair@286 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
ohair@286 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ohair@286 | 20 | * |
ohair@286 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@286 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@286 | 23 | * questions. |
ohair@286 | 24 | */ |
ohair@286 | 25 | |
ohair@286 | 26 | package com.sun.xml.internal.ws.api.message; |
ohair@286 | 27 | |
ohair@286 | 28 | import java.io.IOException; |
ohair@286 | 29 | import java.io.InputStream; |
alanb@368 | 30 | import java.util.ArrayList; |
alanb@368 | 31 | import java.util.HashMap; |
alanb@368 | 32 | import java.util.Iterator; |
alanb@368 | 33 | import java.util.List; |
alanb@368 | 34 | import java.util.Map; |
ohair@286 | 35 | |
alanb@368 | 36 | import javax.xml.soap.MimeHeader; |
alanb@368 | 37 | import javax.xml.soap.MimeHeaders; |
ohair@286 | 38 | import javax.xml.soap.SOAPMessage; |
ohair@286 | 39 | import javax.xml.transform.Source; |
ohair@286 | 40 | import javax.xml.ws.WebServiceFeature; |
alanb@368 | 41 | import javax.xml.ws.soap.MTOMFeature; |
ohair@286 | 42 | |
alanb@368 | 43 | import com.oracle.webservices.internal.api.EnvelopeStyle; |
alanb@368 | 44 | import com.oracle.webservices.internal.api.EnvelopeStyleFeature; |
alanb@368 | 45 | import com.oracle.webservices.internal.api.message.MessageContext; |
ohair@286 | 46 | import com.sun.xml.internal.ws.api.SOAPVersion; |
ohair@286 | 47 | import com.sun.xml.internal.ws.api.WSFeatureList; |
ohair@286 | 48 | import com.sun.xml.internal.ws.api.pipe.Codec; |
ohair@286 | 49 | import com.sun.xml.internal.ws.api.pipe.Codecs; |
alanb@368 | 50 | import static com.sun.xml.internal.ws.transport.http.HttpAdapter.fixQuotesAroundSoapAction; |
ohair@286 | 51 | |
ohair@286 | 52 | /** |
alanb@368 | 53 | * The MessageContextFactory implements com.oracle.webservices.internal.api.message.MessageContextFactory as |
ohair@286 | 54 | * a factory of Packet and public facade of Codec(s). |
ohair@286 | 55 | * |
ohair@286 | 56 | * @author shih-chang.chen@oracle.com |
ohair@286 | 57 | */ |
alanb@368 | 58 | public class MessageContextFactory extends com.oracle.webservices.internal.api.message.MessageContextFactory { |
ohair@286 | 59 | |
ohair@286 | 60 | private WSFeatureList features; |
ohair@286 | 61 | private Codec soapCodec; |
ohair@286 | 62 | private Codec xmlCodec; |
ohair@286 | 63 | private EnvelopeStyleFeature envelopeStyle; |
ohair@286 | 64 | private EnvelopeStyle.Style singleSoapStyle; |
ohair@286 | 65 | |
ohair@286 | 66 | public MessageContextFactory(WebServiceFeature[] wsf) { |
ohair@286 | 67 | this(new com.sun.xml.internal.ws.binding.WebServiceFeatureList(wsf)); |
ohair@286 | 68 | } |
ohair@286 | 69 | |
ohair@286 | 70 | public MessageContextFactory(WSFeatureList wsf) { |
ohair@286 | 71 | features = wsf; |
ohair@286 | 72 | envelopeStyle = features.get(EnvelopeStyleFeature.class); |
ohair@286 | 73 | if (envelopeStyle == null) {//Default to SOAP11 |
ohair@286 | 74 | envelopeStyle = new EnvelopeStyleFeature(new EnvelopeStyle.Style[]{EnvelopeStyle.Style.SOAP11}); |
ohair@286 | 75 | features.mergeFeatures(new WebServiceFeature[]{envelopeStyle}, false); |
ohair@286 | 76 | } |
ohair@286 | 77 | for (EnvelopeStyle.Style s : envelopeStyle.getStyles()) { |
ohair@286 | 78 | if (s.isXML()) { |
ohair@286 | 79 | if (xmlCodec == null) xmlCodec = Codecs.createXMLCodec(features); |
ohair@286 | 80 | } else { |
ohair@286 | 81 | if (soapCodec == null) soapCodec = Codecs.createSOAPBindingCodec(features); |
ohair@286 | 82 | singleSoapStyle = s; |
ohair@286 | 83 | } |
ohair@286 | 84 | } |
ohair@286 | 85 | } |
ohair@286 | 86 | |
alanb@368 | 87 | protected com.oracle.webservices.internal.api.message.MessageContextFactory newFactory(WebServiceFeature... f) { |
ohair@286 | 88 | return new com.sun.xml.internal.ws.api.message.MessageContextFactory(f); |
ohair@286 | 89 | } |
ohair@286 | 90 | |
alanb@368 | 91 | |
alanb@368 | 92 | public com.oracle.webservices.internal.api.message.MessageContext createContext() { |
alanb@368 | 93 | return packet(null); |
alanb@368 | 94 | } |
alanb@368 | 95 | |
alanb@368 | 96 | public com.oracle.webservices.internal.api.message.MessageContext createContext(SOAPMessage soap) { |
alanb@368 | 97 | throwIfIllegalMessageArgument(soap); |
ohair@286 | 98 | return packet(Messages.create(soap)); |
ohair@286 | 99 | } |
ohair@286 | 100 | |
alanb@368 | 101 | public MessageContext createContext(Source m, com.oracle.webservices.internal.api.EnvelopeStyle.Style envelopeStyle) { |
alanb@368 | 102 | throwIfIllegalMessageArgument(m); |
ohair@286 | 103 | return packet(Messages.create(m, SOAPVersion.from(envelopeStyle))); |
ohair@286 | 104 | } |
ohair@286 | 105 | |
alanb@368 | 106 | public com.oracle.webservices.internal.api.message.MessageContext createContext(Source m) { |
alanb@368 | 107 | throwIfIllegalMessageArgument(m); |
ohair@286 | 108 | return packet(Messages.create(m, SOAPVersion.from(singleSoapStyle))); |
ohair@286 | 109 | } |
ohair@286 | 110 | |
alanb@368 | 111 | public com.oracle.webservices.internal.api.message.MessageContext createContext(InputStream in, String contentType) throws IOException { |
alanb@368 | 112 | throwIfIllegalMessageArgument(in); |
ohair@286 | 113 | //TODO when do we use xmlCodec? |
ohair@286 | 114 | Packet p = packet(null); |
ohair@286 | 115 | soapCodec.decode(in, contentType, p); |
ohair@286 | 116 | return p; |
ohair@286 | 117 | } |
ohair@286 | 118 | |
alanb@368 | 119 | /** |
alanb@368 | 120 | * @deprecated http://java.net/jira/browse/JAX_WS-1077 |
alanb@368 | 121 | */ |
alanb@368 | 122 | @Deprecated |
alanb@368 | 123 | public com.oracle.webservices.internal.api.message.MessageContext createContext(InputStream in, MimeHeaders headers) throws IOException { |
alanb@368 | 124 | String contentType = getHeader(headers, "Content-Type"); |
alanb@368 | 125 | Packet packet = (Packet) createContext(in, contentType); |
alanb@368 | 126 | packet.acceptableMimeTypes = getHeader(headers, "Accept"); |
alanb@368 | 127 | packet.soapAction = fixQuotesAroundSoapAction(getHeader(headers, "SOAPAction")); |
alanb@368 | 128 | // packet.put(Packet.INBOUND_TRANSPORT_HEADERS, toMap(headers)); |
alanb@368 | 129 | return packet; |
alanb@368 | 130 | } |
alanb@368 | 131 | |
alanb@368 | 132 | static String getHeader(MimeHeaders headers, String name) { |
alanb@368 | 133 | String[] values = headers.getHeader(name); |
alanb@368 | 134 | return (values != null && values.length > 0) ? values[0] : null; |
alanb@368 | 135 | } |
alanb@368 | 136 | |
alanb@368 | 137 | static Map<String, List<String>> toMap(MimeHeaders headers) { |
alanb@368 | 138 | HashMap<String, List<String>> map = new HashMap<String, List<String>>(); |
alanb@368 | 139 | for (Iterator<MimeHeader> i = headers.getAllHeaders(); i.hasNext();) { |
alanb@368 | 140 | MimeHeader mh = i.next(); |
alanb@368 | 141 | List<String> values = map.get(mh.getName()); |
alanb@368 | 142 | if (values == null) { |
alanb@368 | 143 | values = new ArrayList<String>(); |
alanb@368 | 144 | map.put(mh.getName(), values); |
alanb@368 | 145 | } |
alanb@368 | 146 | values.add(mh.getValue()); |
alanb@368 | 147 | } |
alanb@368 | 148 | return map; |
alanb@368 | 149 | } |
alanb@368 | 150 | |
alanb@368 | 151 | public MessageContext createContext(Message m) { |
alanb@368 | 152 | throwIfIllegalMessageArgument(m); |
alanb@368 | 153 | return packet(m); |
alanb@368 | 154 | } |
alanb@368 | 155 | |
ohair@286 | 156 | private Packet packet(Message m) { |
ohair@286 | 157 | final Packet p = new Packet(); |
ohair@286 | 158 | //TODO when do we use xmlCodec? |
ohair@286 | 159 | p.codec = soapCodec; |
ohair@286 | 160 | if (m != null) p.setMessage(m); |
alanb@368 | 161 | MTOMFeature mf = features.get(MTOMFeature.class); |
alanb@368 | 162 | if (mf != null) { |
alanb@368 | 163 | p.setMtomFeature(mf); |
alanb@368 | 164 | } |
ohair@286 | 165 | return p; |
ohair@286 | 166 | } |
ohair@286 | 167 | |
alanb@368 | 168 | private void throwIfIllegalMessageArgument(Object message) |
alanb@368 | 169 | throws IllegalArgumentException |
alanb@368 | 170 | { |
alanb@368 | 171 | if (message == null) { |
alanb@368 | 172 | throw new IllegalArgumentException("null messages are not allowed. Consider using MessageContextFactory.createContext()"); |
alanb@368 | 173 | } |
alanb@368 | 174 | } |
ohair@286 | 175 | |
alanb@368 | 176 | @Deprecated |
alanb@368 | 177 | public com.oracle.webservices.internal.api.message.MessageContext doCreate() { |
ohair@286 | 178 | return packet(null); |
ohair@286 | 179 | } |
alanb@368 | 180 | @Deprecated |
alanb@368 | 181 | public com.oracle.webservices.internal.api.message.MessageContext doCreate(SOAPMessage m) { |
ohair@286 | 182 | return createContext(m); |
ohair@286 | 183 | } |
alanb@368 | 184 | @Deprecated |
alanb@368 | 185 | public com.oracle.webservices.internal.api.message.MessageContext doCreate(Source x, SOAPVersion soapVersion) { |
ohair@286 | 186 | return packet(Messages.create(x, soapVersion)); |
ohair@286 | 187 | } |
ohair@286 | 188 | } |