Wed, 27 Apr 2016 01:27:09 +0800
Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/jaxws/
changeset: 657:d47a47f961ee
tag: jdk8u25-b17
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package com.sun.xml.internal.ws.server.sei; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import com.sun.xml.internal.ws.api.SOAPVersion; |
aoqi@0 | 29 | import com.sun.xml.internal.ws.api.message.Message; |
aoqi@0 | 30 | import com.sun.xml.internal.ws.api.message.Messages; |
aoqi@0 | 31 | import com.sun.xml.internal.ws.message.jaxb.JAXBMessage; |
aoqi@0 | 32 | import com.sun.xml.internal.ws.model.ParameterImpl; |
aoqi@0 | 33 | import com.sun.xml.internal.ws.model.WrapperParameter; |
aoqi@0 | 34 | import com.sun.xml.internal.ws.spi.db.BindingContext; |
aoqi@0 | 35 | import com.sun.xml.internal.ws.spi.db.XMLBridge; |
aoqi@0 | 36 | import com.sun.xml.internal.ws.spi.db.PropertyAccessor; |
aoqi@0 | 37 | import com.sun.xml.internal.ws.spi.db.WrapperComposite; |
aoqi@0 | 38 | |
aoqi@0 | 39 | import javax.xml.bind.JAXBException; |
aoqi@0 | 40 | import javax.xml.namespace.QName; |
aoqi@0 | 41 | import javax.xml.ws.Holder; |
aoqi@0 | 42 | import javax.xml.ws.WebServiceException; |
aoqi@0 | 43 | import java.util.List; |
aoqi@0 | 44 | |
aoqi@0 | 45 | /** |
aoqi@0 | 46 | * Builds a JAXB object that represents the payload. |
aoqi@0 | 47 | * |
aoqi@0 | 48 | * @see MessageFiller |
aoqi@0 | 49 | * @author Jitendra Kotamraju |
aoqi@0 | 50 | */ |
aoqi@0 | 51 | public abstract class EndpointResponseMessageBuilder { |
aoqi@0 | 52 | public abstract Message createMessage(Object[] methodArgs, Object returnValue); |
aoqi@0 | 53 | |
aoqi@0 | 54 | public static final EndpointResponseMessageBuilder EMPTY_SOAP11 = new Empty(SOAPVersion.SOAP_11); |
aoqi@0 | 55 | public static final EndpointResponseMessageBuilder EMPTY_SOAP12 = new Empty(SOAPVersion.SOAP_12); |
aoqi@0 | 56 | |
aoqi@0 | 57 | private static final class Empty extends EndpointResponseMessageBuilder { |
aoqi@0 | 58 | private final SOAPVersion soapVersion; |
aoqi@0 | 59 | |
aoqi@0 | 60 | public Empty(SOAPVersion soapVersion) { |
aoqi@0 | 61 | this.soapVersion = soapVersion; |
aoqi@0 | 62 | } |
aoqi@0 | 63 | |
aoqi@0 | 64 | public Message createMessage(Object[] methodArgs, Object returnValue) { |
aoqi@0 | 65 | return Messages.createEmpty(soapVersion); |
aoqi@0 | 66 | } |
aoqi@0 | 67 | } |
aoqi@0 | 68 | |
aoqi@0 | 69 | /** |
aoqi@0 | 70 | * Base class for those {@link EndpointResponseMessageBuilder}s that build a {@link Message} |
aoqi@0 | 71 | * from JAXB objects. |
aoqi@0 | 72 | */ |
aoqi@0 | 73 | private static abstract class JAXB extends EndpointResponseMessageBuilder { |
aoqi@0 | 74 | /** |
aoqi@0 | 75 | * This object determines the binding of the object returned |
aoqi@0 | 76 | * from {@link #createMessage(Object[], Object)} |
aoqi@0 | 77 | */ |
aoqi@0 | 78 | private final XMLBridge bridge; |
aoqi@0 | 79 | private final SOAPVersion soapVersion; |
aoqi@0 | 80 | |
aoqi@0 | 81 | protected JAXB(XMLBridge bridge, SOAPVersion soapVersion) { |
aoqi@0 | 82 | assert bridge!=null; |
aoqi@0 | 83 | this.bridge = bridge; |
aoqi@0 | 84 | this.soapVersion = soapVersion; |
aoqi@0 | 85 | } |
aoqi@0 | 86 | |
aoqi@0 | 87 | public final Message createMessage(Object[] methodArgs, Object returnValue) { |
aoqi@0 | 88 | return JAXBMessage.create( bridge, build(methodArgs, returnValue), soapVersion ); |
aoqi@0 | 89 | } |
aoqi@0 | 90 | |
aoqi@0 | 91 | /** |
aoqi@0 | 92 | * Builds a JAXB object that becomes the payload. |
aoqi@0 | 93 | */ |
aoqi@0 | 94 | abstract Object build(Object[] methodArgs, Object returnValue); |
aoqi@0 | 95 | } |
aoqi@0 | 96 | |
aoqi@0 | 97 | /** |
aoqi@0 | 98 | * Used to create a payload JAXB object just by taking |
aoqi@0 | 99 | * one of the parameters. |
aoqi@0 | 100 | */ |
aoqi@0 | 101 | public final static class Bare extends JAXB { |
aoqi@0 | 102 | /** |
aoqi@0 | 103 | * The index of the method invocation parameters that goes into the payload. |
aoqi@0 | 104 | */ |
aoqi@0 | 105 | private final int methodPos; |
aoqi@0 | 106 | |
aoqi@0 | 107 | private final ValueGetter getter; |
aoqi@0 | 108 | |
aoqi@0 | 109 | /** |
aoqi@0 | 110 | * Creates a {@link EndpointResponseMessageBuilder} from a bare parameter. |
aoqi@0 | 111 | */ |
aoqi@0 | 112 | public Bare(ParameterImpl p, SOAPVersion soapVersion) { |
aoqi@0 | 113 | super(p.getXMLBridge(), soapVersion); |
aoqi@0 | 114 | this.methodPos = p.getIndex(); |
aoqi@0 | 115 | this.getter = ValueGetter.get(p); |
aoqi@0 | 116 | } |
aoqi@0 | 117 | |
aoqi@0 | 118 | /** |
aoqi@0 | 119 | * Picks up an object from the method arguments and uses it. |
aoqi@0 | 120 | */ |
aoqi@0 | 121 | Object build(Object[] methodArgs, Object returnValue) { |
aoqi@0 | 122 | if (methodPos == -1) { |
aoqi@0 | 123 | return returnValue; |
aoqi@0 | 124 | } |
aoqi@0 | 125 | return getter.get(methodArgs[methodPos]); |
aoqi@0 | 126 | } |
aoqi@0 | 127 | } |
aoqi@0 | 128 | |
aoqi@0 | 129 | |
aoqi@0 | 130 | /** |
aoqi@0 | 131 | * Used to handle a 'wrapper' style request. |
aoqi@0 | 132 | * Common part of rpc/lit and doc/lit. |
aoqi@0 | 133 | */ |
aoqi@0 | 134 | abstract static class Wrapped extends JAXB { |
aoqi@0 | 135 | |
aoqi@0 | 136 | /** |
aoqi@0 | 137 | * Where in the method argument list do they come from? |
aoqi@0 | 138 | */ |
aoqi@0 | 139 | protected final int[] indices; |
aoqi@0 | 140 | |
aoqi@0 | 141 | /** |
aoqi@0 | 142 | * Abstracts away the {@link Holder} handling when touching method arguments. |
aoqi@0 | 143 | */ |
aoqi@0 | 144 | protected final ValueGetter[] getters; |
aoqi@0 | 145 | |
aoqi@0 | 146 | /** |
aoqi@0 | 147 | * How does each wrapped parameter binds to XML? |
aoqi@0 | 148 | */ |
aoqi@0 | 149 | protected XMLBridge[] parameterBridges; |
aoqi@0 | 150 | |
aoqi@0 | 151 | /** |
aoqi@0 | 152 | * Used for error diagnostics. |
aoqi@0 | 153 | */ |
aoqi@0 | 154 | protected List<ParameterImpl> children; |
aoqi@0 | 155 | |
aoqi@0 | 156 | protected Wrapped(WrapperParameter wp, SOAPVersion soapVersion) { |
aoqi@0 | 157 | super(wp.getXMLBridge(), soapVersion); |
aoqi@0 | 158 | |
aoqi@0 | 159 | children = wp.getWrapperChildren(); |
aoqi@0 | 160 | |
aoqi@0 | 161 | indices = new int[children.size()]; |
aoqi@0 | 162 | getters = new ValueGetter[children.size()]; |
aoqi@0 | 163 | for( int i=0; i<indices.length; i++ ) { |
aoqi@0 | 164 | ParameterImpl p = children.get(i); |
aoqi@0 | 165 | indices[i] = p.getIndex(); |
aoqi@0 | 166 | getters[i] = ValueGetter.get(p); |
aoqi@0 | 167 | } |
aoqi@0 | 168 | } |
aoqi@0 | 169 | |
aoqi@0 | 170 | /** |
aoqi@0 | 171 | * Packs a bunch of arguments intoa {@link WrapperComposite}. |
aoqi@0 | 172 | */ |
aoqi@0 | 173 | WrapperComposite buildWrapperComposite(Object[] methodArgs, Object returnValue) { |
aoqi@0 | 174 | WrapperComposite cs = new WrapperComposite(); |
aoqi@0 | 175 | cs.bridges = parameterBridges; |
aoqi@0 | 176 | cs.values = new Object[parameterBridges.length]; |
aoqi@0 | 177 | |
aoqi@0 | 178 | // fill in wrapped parameters from methodArgs |
aoqi@0 | 179 | for( int i=indices.length-1; i>=0; i-- ) { |
aoqi@0 | 180 | Object v; |
aoqi@0 | 181 | if (indices[i] == -1) { |
aoqi@0 | 182 | v = getters[i].get(returnValue); |
aoqi@0 | 183 | } else { |
aoqi@0 | 184 | v = getters[i].get(methodArgs[indices[i]]); |
aoqi@0 | 185 | } |
aoqi@0 | 186 | if(v==null) { |
aoqi@0 | 187 | throw new WebServiceException("Method Parameter: "+ |
aoqi@0 | 188 | children.get(i).getName() +" cannot be null. This is BP 1.1 R2211 violation."); |
aoqi@0 | 189 | } |
aoqi@0 | 190 | cs.values[i] = v; |
aoqi@0 | 191 | } |
aoqi@0 | 192 | |
aoqi@0 | 193 | return cs; |
aoqi@0 | 194 | } |
aoqi@0 | 195 | } |
aoqi@0 | 196 | |
aoqi@0 | 197 | /** |
aoqi@0 | 198 | * Used to create a payload JAXB object by wrapping |
aoqi@0 | 199 | * multiple parameters into one "wrapper bean". |
aoqi@0 | 200 | */ |
aoqi@0 | 201 | public final static class DocLit extends Wrapped { |
aoqi@0 | 202 | /** |
aoqi@0 | 203 | * How does each wrapped parameter binds to XML? |
aoqi@0 | 204 | */ |
aoqi@0 | 205 | private final PropertyAccessor[] accessors; |
aoqi@0 | 206 | |
aoqi@0 | 207 | //private final RawAccessor retAccessor; |
aoqi@0 | 208 | |
aoqi@0 | 209 | /** |
aoqi@0 | 210 | * Wrapper bean. |
aoqi@0 | 211 | */ |
aoqi@0 | 212 | private final Class wrapper; |
aoqi@0 | 213 | private boolean dynamicWrapper; |
aoqi@0 | 214 | |
aoqi@0 | 215 | /** |
aoqi@0 | 216 | * Needed to get wrapper instantiation method. |
aoqi@0 | 217 | */ |
aoqi@0 | 218 | private BindingContext bindingContext; |
aoqi@0 | 219 | |
aoqi@0 | 220 | /** |
aoqi@0 | 221 | * Creates a {@link EndpointResponseMessageBuilder} from a {@link WrapperParameter}. |
aoqi@0 | 222 | */ |
aoqi@0 | 223 | public DocLit(WrapperParameter wp, SOAPVersion soapVersion) { |
aoqi@0 | 224 | super(wp, soapVersion); |
aoqi@0 | 225 | bindingContext = wp.getOwner().getBindingContext(); |
aoqi@0 | 226 | wrapper = (Class)wp.getXMLBridge().getTypeInfo().type; |
aoqi@0 | 227 | dynamicWrapper = WrapperComposite.class.equals(wrapper); |
aoqi@0 | 228 | children = wp.getWrapperChildren(); |
aoqi@0 | 229 | parameterBridges = new XMLBridge[children.size()]; |
aoqi@0 | 230 | accessors = new PropertyAccessor[children.size()]; |
aoqi@0 | 231 | for( int i=0; i<accessors.length; i++ ) { |
aoqi@0 | 232 | ParameterImpl p = children.get(i); |
aoqi@0 | 233 | QName name = p.getName(); |
aoqi@0 | 234 | if (dynamicWrapper) { |
aoqi@0 | 235 | parameterBridges[i] = children.get(i).getInlinedRepeatedElementBridge(); |
aoqi@0 | 236 | if (parameterBridges[i] == null) parameterBridges[i] = children.get(i).getXMLBridge(); |
aoqi@0 | 237 | } else { |
aoqi@0 | 238 | try { |
aoqi@0 | 239 | accessors[i] = (dynamicWrapper) ? null : |
aoqi@0 | 240 | p.getOwner().getBindingContext().getElementPropertyAccessor( |
aoqi@0 | 241 | wrapper, name.getNamespaceURI(), name.getLocalPart() ); |
aoqi@0 | 242 | } catch (JAXBException e) { |
aoqi@0 | 243 | throw new WebServiceException( // TODO: i18n |
aoqi@0 | 244 | wrapper+" do not have a property of the name "+name,e); |
aoqi@0 | 245 | } |
aoqi@0 | 246 | } |
aoqi@0 | 247 | } |
aoqi@0 | 248 | |
aoqi@0 | 249 | } |
aoqi@0 | 250 | |
aoqi@0 | 251 | /** |
aoqi@0 | 252 | * Packs a bunch of arguments into a {@link WrapperComposite}. |
aoqi@0 | 253 | */ |
aoqi@0 | 254 | Object build(Object[] methodArgs, Object returnValue) { |
aoqi@0 | 255 | if (dynamicWrapper) return buildWrapperComposite(methodArgs, returnValue); |
aoqi@0 | 256 | try { |
aoqi@0 | 257 | //Object bean = wrapper.newInstance(); |
aoqi@0 | 258 | Object bean = bindingContext.newWrapperInstace(wrapper); |
aoqi@0 | 259 | |
aoqi@0 | 260 | // fill in wrapped parameters from methodArgs |
aoqi@0 | 261 | for( int i=indices.length-1; i>=0; i-- ) { |
aoqi@0 | 262 | if (indices[i] == -1) { |
aoqi@0 | 263 | accessors[i].set(bean, returnValue); |
aoqi@0 | 264 | } else { |
aoqi@0 | 265 | accessors[i].set(bean,getters[i].get(methodArgs[indices[i]])); |
aoqi@0 | 266 | } |
aoqi@0 | 267 | } |
aoqi@0 | 268 | |
aoqi@0 | 269 | return bean; |
aoqi@0 | 270 | } catch (InstantiationException e) { |
aoqi@0 | 271 | // this is irrecoverable |
aoqi@0 | 272 | Error x = new InstantiationError(e.getMessage()); |
aoqi@0 | 273 | x.initCause(e); |
aoqi@0 | 274 | throw x; |
aoqi@0 | 275 | } catch (IllegalAccessException e) { |
aoqi@0 | 276 | // this is irrecoverable |
aoqi@0 | 277 | Error x = new IllegalAccessError(e.getMessage()); |
aoqi@0 | 278 | x.initCause(e); |
aoqi@0 | 279 | throw x; |
aoqi@0 | 280 | } catch (com.sun.xml.internal.ws.spi.db.DatabindingException e) { |
aoqi@0 | 281 | // this can happen when the set method throw a checked exception or something like that |
aoqi@0 | 282 | throw new WebServiceException(e); // TODO:i18n |
aoqi@0 | 283 | } |
aoqi@0 | 284 | } |
aoqi@0 | 285 | } |
aoqi@0 | 286 | |
aoqi@0 | 287 | |
aoqi@0 | 288 | /** |
aoqi@0 | 289 | * Used to create a payload JAXB object by wrapping |
aoqi@0 | 290 | * multiple parameters into a {@link WrapperComposite}. |
aoqi@0 | 291 | * |
aoqi@0 | 292 | * <p> |
aoqi@0 | 293 | * This is used for rpc/lit, as we don't have a wrapper bean for it. |
aoqi@0 | 294 | * (TODO: Why don't we have a wrapper bean for this, when doc/lit does!?) |
aoqi@0 | 295 | */ |
aoqi@0 | 296 | public final static class RpcLit extends Wrapped { |
aoqi@0 | 297 | |
aoqi@0 | 298 | /** |
aoqi@0 | 299 | * Creates a {@link EndpointResponseMessageBuilder} from a {@link WrapperParameter}. |
aoqi@0 | 300 | */ |
aoqi@0 | 301 | public RpcLit(WrapperParameter wp, SOAPVersion soapVersion) { |
aoqi@0 | 302 | super(wp, soapVersion); |
aoqi@0 | 303 | // we'll use CompositeStructure to pack requests |
aoqi@0 | 304 | assert wp.getTypeInfo().type==WrapperComposite.class; |
aoqi@0 | 305 | |
aoqi@0 | 306 | parameterBridges = new XMLBridge[children.size()]; |
aoqi@0 | 307 | for( int i=0; i<parameterBridges.length; i++ ) |
aoqi@0 | 308 | parameterBridges[i] = children.get(i).getXMLBridge(); |
aoqi@0 | 309 | } |
aoqi@0 | 310 | |
aoqi@0 | 311 | /** |
aoqi@0 | 312 | * Packs a bunch of arguments intoa {@link WrapperComposite}. |
aoqi@0 | 313 | */ |
aoqi@0 | 314 | Object build(Object[] methodArgs, Object returnValue) { |
aoqi@0 | 315 | return buildWrapperComposite(methodArgs, returnValue); |
aoqi@0 | 316 | } |
aoqi@0 | 317 | } |
aoqi@0 | 318 | } |