src/share/jaxws_classes/com/sun/xml/internal/ws/model/JavaMethodImpl.java

Tue, 09 Apr 2013 14:51:13 +0100

author
alanb
date
Tue, 09 Apr 2013 14:51:13 +0100
changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 408
b0610cd08440
permissions
-rw-r--r--

8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com

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.model;
ohair@286 27
ohair@286 28 import com.sun.istack.internal.NotNull;
ohair@286 29 import com.sun.xml.internal.bind.api.TypeReference;
ohair@286 30 import com.sun.xml.internal.ws.api.databinding.MetadataReader;
ohair@286 31 import com.sun.xml.internal.ws.api.model.JavaMethod;
ohair@286 32 import com.sun.xml.internal.ws.api.model.MEP;
ohair@286 33 import com.sun.xml.internal.ws.api.model.SEIModel;
ohair@286 34 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
ohair@286 35 import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation;
ohair@286 36 import com.sun.xml.internal.ws.api.model.wsdl.WSDLFault;
ohair@286 37 import com.sun.xml.internal.ws.api.model.soap.SOAPBinding;
ohair@286 38 import com.sun.xml.internal.ws.model.soap.SOAPBindingImpl;
ohair@286 39 import com.sun.xml.internal.ws.spi.db.TypeInfo;
ohair@286 40 import com.sun.xml.internal.ws.wsdl.ActionBasedOperationSignature;
ohair@286 41 import com.sun.istack.internal.Nullable;
ohair@286 42
ohair@286 43 import javax.xml.namespace.QName;
ohair@286 44 import javax.xml.ws.Action;
ohair@286 45 import javax.xml.ws.WebServiceException;
ohair@286 46 import javax.jws.WebMethod;
ohair@286 47 import java.lang.reflect.Method;
ohair@286 48 import java.util.ArrayList;
ohair@286 49 import java.util.Collections;
ohair@286 50 import java.util.List;
ohair@286 51 import java.util.logging.Logger;
ohair@286 52
ohair@286 53 /**
ohair@286 54 * Build this runtime model using java SEI and annotations
ohair@286 55 *
ohair@286 56 * @author Vivek Pandey
ohair@286 57 */
ohair@286 58 public final class JavaMethodImpl implements JavaMethod {
ohair@286 59
ohair@286 60 private String inputAction = "";
ohair@286 61 private String outputAction = "";
ohair@286 62 private final List<CheckedExceptionImpl> exceptions = new ArrayList<CheckedExceptionImpl>();
ohair@286 63 private final Method method;
ohair@286 64 /*package*/ final List<ParameterImpl> requestParams = new ArrayList<ParameterImpl>();
ohair@286 65 /*package*/ final List<ParameterImpl> responseParams = new ArrayList<ParameterImpl>();
ohair@286 66 private final List<ParameterImpl> unmReqParams = Collections.unmodifiableList(requestParams);
ohair@286 67 private final List<ParameterImpl> unmResParams = Collections.unmodifiableList(responseParams);
ohair@286 68 private SOAPBinding binding;
ohair@286 69 private MEP mep;
ohair@286 70 private QName operationName;
ohair@286 71 private WSDLBoundOperation wsdlOperation;
ohair@286 72 /*package*/ final AbstractSEIModelImpl owner;
ohair@286 73 private final Method seiMethod;
ohair@286 74 private QName requestPayloadName;
ohair@286 75 private String soapAction;
ohair@286 76
ohair@286 77 /**
ohair@286 78 * @param owner
ohair@286 79 * @param method : Implementation class method
ohair@286 80 * @param seiMethod : corresponding SEI Method.
ohair@286 81 * Is there is no SEI, it should be Implementation class method
ohair@286 82 */
ohair@286 83 public JavaMethodImpl(AbstractSEIModelImpl owner, Method method, Method seiMethod, MetadataReader metadataReader) {
ohair@286 84 this.owner = owner;
ohair@286 85 this.method = method;
ohair@286 86 this.seiMethod = seiMethod;
ohair@286 87 setWsaActions(metadataReader);
ohair@286 88 }
ohair@286 89
ohair@286 90 private void setWsaActions(MetadataReader metadataReader) {
ohair@286 91 Action action = (metadataReader != null)? metadataReader.getAnnotation(Action.class, seiMethod):seiMethod.getAnnotation(Action.class);
ohair@286 92 if(action != null) {
ohair@286 93 inputAction = action.input();
ohair@286 94 outputAction = action.output();
ohair@286 95 }
ohair@286 96
ohair@286 97 //@Action(input) =="", get it from @WebMethod(action)
ohair@286 98 WebMethod webMethod = (metadataReader != null)? metadataReader.getAnnotation(WebMethod.class, seiMethod):seiMethod.getAnnotation(WebMethod.class);
ohair@286 99 soapAction = "";
ohair@286 100 if (webMethod != null )
ohair@286 101 soapAction = webMethod.action();
ohair@286 102 if(!soapAction.equals("")) {
ohair@286 103 //non-empty soapAction
ohair@286 104 if(inputAction.equals(""))
ohair@286 105 // set input action to non-empty soapAction
ohair@286 106 inputAction = soapAction;
ohair@286 107 else if(!inputAction.equals(soapAction)){
ohair@286 108 //both are explicitly set via annotations, make sure @Action == @WebMethod.action
alanb@368 109 //http://java.net/jira/browse/JAX_WS-1108
alanb@368 110 //throw new WebServiceException("@Action and @WebMethod(action=\"\" does not match on operation "+ method.getName());
ohair@286 111 }
ohair@286 112 }
ohair@286 113 }
ohair@286 114
ohair@286 115 public ActionBasedOperationSignature getOperationSignature() {
ohair@286 116 QName qname = getRequestPayloadName();
ohair@286 117 if (qname == null) qname = new QName("", "");
ohair@286 118 return new ActionBasedOperationSignature(getInputAction(), qname);
ohair@286 119 }
ohair@286 120
ohair@286 121 public SEIModel getOwner() {
ohair@286 122 return owner;
ohair@286 123 }
ohair@286 124
ohair@286 125 /**
alanb@368 126 * @see JavaMethod
ohair@286 127 *
ohair@286 128 * @return Returns the method.
ohair@286 129 */
ohair@286 130 public Method getMethod() {
ohair@286 131 return method;
ohair@286 132 }
ohair@286 133
ohair@286 134 /**
alanb@368 135 * @see JavaMethod
ohair@286 136 *
ohair@286 137 * @return Returns the SEI method where annotations are present
ohair@286 138 */
ohair@286 139 public Method getSEIMethod() {
ohair@286 140 return seiMethod;
ohair@286 141 }
ohair@286 142
ohair@286 143 /**
ohair@286 144 * @return Returns the mep.
ohair@286 145 */
ohair@286 146 public MEP getMEP() {
ohair@286 147 return mep;
ohair@286 148 }
ohair@286 149
ohair@286 150 /**
ohair@286 151 * @param mep
ohair@286 152 * The mep to set.
ohair@286 153 */
ohair@286 154 void setMEP(MEP mep) {
ohair@286 155 this.mep = mep;
ohair@286 156 }
ohair@286 157
ohair@286 158 /**
ohair@286 159 * @return the Binding object
ohair@286 160 */
ohair@286 161 public SOAPBinding getBinding() {
ohair@286 162 if (binding == null)
ohair@286 163 return new SOAPBindingImpl();
ohair@286 164 return binding;
ohair@286 165 }
ohair@286 166
ohair@286 167 /**
ohair@286 168 * @param binding
ohair@286 169 */
ohair@286 170 void setBinding(SOAPBinding binding) {
ohair@286 171 this.binding = binding;
ohair@286 172 }
ohair@286 173
ohair@286 174 /**
alanb@368 175 * Returns the {@link WSDLBoundOperation} Operation associated with {@link JavaMethodImpl}
ohair@286 176 * operation.
ohair@286 177 * @deprecated
ohair@286 178 * @return the WSDLBoundOperation for this JavaMethod
ohair@286 179 */
ohair@286 180 public WSDLBoundOperation getOperation() {
ohair@286 181 // assert wsdlOperation != null;
ohair@286 182 return wsdlOperation;
ohair@286 183 }
ohair@286 184
ohair@286 185 public void setOperationQName(QName name) {
ohair@286 186 this.operationName = name;
ohair@286 187 }
ohair@286 188
ohair@286 189 public QName getOperationQName() {
ohair@286 190 return (wsdlOperation != null)? wsdlOperation.getName(): operationName;
ohair@286 191 }
ohair@286 192
ohair@286 193 public String getSOAPAction() {
ohair@286 194 return (wsdlOperation != null)? wsdlOperation.getSOAPAction(): soapAction;
ohair@286 195 }
ohair@286 196
ohair@286 197 public String getOperationName() {
ohair@286 198 return operationName.getLocalPart();
ohair@286 199 }
ohair@286 200
ohair@286 201 public String getRequestMessageName() {
ohair@286 202 return getOperationName();
ohair@286 203 }
ohair@286 204
ohair@286 205 public String getResponseMessageName() {
ohair@286 206 if(mep.isOneWay())
ohair@286 207 return null;
ohair@286 208 return getOperationName()+"Response";
ohair@286 209 }
ohair@286 210
ohair@286 211 public void setRequestPayloadName(QName n) {
ohair@286 212 requestPayloadName = n;
ohair@286 213 }
ohair@286 214
ohair@286 215 /**
ohair@286 216 * @return soap:Body's first child name for request message.
ohair@286 217 */
ohair@286 218 public @Nullable QName getRequestPayloadName() {
ohair@286 219 return (wsdlOperation != null)? wsdlOperation.getReqPayloadName(): requestPayloadName;
ohair@286 220 }
ohair@286 221
ohair@286 222 /**
ohair@286 223 * @return soap:Body's first child name for response message.
ohair@286 224 */
ohair@286 225 public @Nullable QName getResponsePayloadName() {
ohair@286 226 return (mep == MEP.ONE_WAY) ? null : wsdlOperation.getResPayloadName();
ohair@286 227 }
ohair@286 228
ohair@286 229 /**
ohair@286 230 * @return returns unmodifiable list of request parameters
ohair@286 231 */
ohair@286 232 public List<ParameterImpl> getRequestParameters() {
ohair@286 233 return unmReqParams;
ohair@286 234 }
ohair@286 235
ohair@286 236 /**
ohair@286 237 * @return returns unmodifiable list of response parameters
ohair@286 238 */
ohair@286 239 public List<ParameterImpl> getResponseParameters() {
ohair@286 240 return unmResParams;
ohair@286 241 }
ohair@286 242
ohair@286 243 void addParameter(ParameterImpl p) {
ohair@286 244 if (p.isIN() || p.isINOUT()) {
ohair@286 245 assert !requestParams.contains(p);
ohair@286 246 requestParams.add(p);
ohair@286 247 }
ohair@286 248
ohair@286 249 if (p.isOUT() || p.isINOUT()) {
ohair@286 250 // this check is only for out parameters
ohair@286 251 assert !responseParams.contains(p);
ohair@286 252 responseParams.add(p);
ohair@286 253 }
ohair@286 254 }
ohair@286 255
ohair@286 256 void addRequestParameter(ParameterImpl p){
ohair@286 257 if (p.isIN() || p.isINOUT()) {
ohair@286 258 requestParams.add(p);
ohair@286 259 }
ohair@286 260 }
ohair@286 261
ohair@286 262 void addResponseParameter(ParameterImpl p){
ohair@286 263 if (p.isOUT() || p.isINOUT()) {
ohair@286 264 responseParams.add(p);
ohair@286 265 }
ohair@286 266 }
ohair@286 267
ohair@286 268 /**
ohair@286 269 * @return Returns number of java method parameters - that will be all the
ohair@286 270 * IN, INOUT and OUT holders
ohair@286 271 *
ohair@286 272 * @deprecated no longer use in the new architecture
ohair@286 273 */
ohair@286 274 public int getInputParametersCount() {
ohair@286 275 int count = 0;
ohair@286 276 for (ParameterImpl param : requestParams) {
ohair@286 277 if (param.isWrapperStyle()) {
ohair@286 278 count += ((WrapperParameter) param).getWrapperChildren().size();
ohair@286 279 } else {
ohair@286 280 count++;
ohair@286 281 }
ohair@286 282 }
ohair@286 283
ohair@286 284 for (ParameterImpl param : responseParams) {
ohair@286 285 if (param.isWrapperStyle()) {
ohair@286 286 for (ParameterImpl wc : ((WrapperParameter) param).getWrapperChildren()) {
ohair@286 287 if (!wc.isResponse() && wc.isOUT()) {
ohair@286 288 count++;
ohair@286 289 }
ohair@286 290 }
ohair@286 291 } else if (!param.isResponse() && param.isOUT()) {
ohair@286 292 count++;
ohair@286 293 }
ohair@286 294 }
ohair@286 295
ohair@286 296 return count;
ohair@286 297 }
ohair@286 298
ohair@286 299 /**
ohair@286 300 * @param ce
ohair@286 301 */
ohair@286 302 void addException(CheckedExceptionImpl ce) {
ohair@286 303 if (!exceptions.contains(ce))
ohair@286 304 exceptions.add(ce);
ohair@286 305 }
ohair@286 306
ohair@286 307 /**
ohair@286 308 * @param exceptionClass
ohair@286 309 * @return CheckedException corresponding to the exceptionClass. Returns
ohair@286 310 * null if not found.
ohair@286 311 */
ohair@286 312 public CheckedExceptionImpl getCheckedException(Class exceptionClass) {
ohair@286 313 for (CheckedExceptionImpl ce : exceptions) {
ohair@286 314 if (ce.getExceptionClass()==exceptionClass)
ohair@286 315 return ce;
ohair@286 316 }
ohair@286 317 return null;
ohair@286 318 }
ohair@286 319
ohair@286 320
ohair@286 321 /**
ohair@286 322 * @return a list of checked Exceptions thrown by this method
ohair@286 323 */
ohair@286 324 public List<CheckedExceptionImpl> getCheckedExceptions(){
ohair@286 325 return Collections.unmodifiableList(exceptions);
ohair@286 326 }
ohair@286 327
ohair@286 328 public String getInputAction() {
ohair@286 329 // return (wsdlOperation != null)? wsdlOperation.getOperation().getInput().getAction(): inputAction;
ohair@286 330 return inputAction;
ohair@286 331 }
ohair@286 332
ohair@286 333 public String getOutputAction() {
ohair@286 334 // return (wsdlOperation != null)? wsdlOperation.getOperation().getOutput().getAction(): outputAction;
ohair@286 335 return outputAction;
ohair@286 336 }
ohair@286 337
ohair@286 338 /**
ohair@286 339 * @deprecated
ohair@286 340 * @param detailType
ohair@286 341 * @return Gets the CheckedException corresponding to detailType. Returns
ohair@286 342 * null if no CheckedExcpetion with the detailType found.
ohair@286 343 */
ohair@286 344 public CheckedExceptionImpl getCheckedException(TypeReference detailType) {
ohair@286 345 for (CheckedExceptionImpl ce : exceptions) {
ohair@286 346 TypeInfo actual = ce.getDetailType();
ohair@286 347 if (actual.tagName.equals(detailType.tagName) && actual.type==detailType.type) {
ohair@286 348 return ce;
ohair@286 349 }
ohair@286 350 }
ohair@286 351 return null;
ohair@286 352 }
ohair@286 353
ohair@286 354
ohair@286 355
ohair@286 356 /**
ohair@286 357 * Returns if the java method is async
ohair@286 358 * @return if this is an Asynch
ohair@286 359 */
ohair@286 360 public boolean isAsync(){
ohair@286 361 return mep.isAsync;
ohair@286 362 }
ohair@286 363
ohair@286 364 /*package*/ void freeze(WSDLPort portType) {
ohair@286 365 this.wsdlOperation = portType.getBinding().get(new QName(portType.getBinding().getPortType().getName().getNamespaceURI(),getOperationName()));
ohair@286 366 // TODO: replace this with proper error handling
ohair@286 367 if(wsdlOperation ==null)
ohair@286 368 throw new WebServiceException("Method "+seiMethod.getName()+" is exposed as WebMethod, but there is no corresponding wsdl operation with name "+operationName+" in the wsdl:portType" + portType.getBinding().getPortType().getName());
ohair@286 369
ohair@286 370 //so far, the inputAction, outputAction and fault actions are set from the @Action and @FaultAction
ohair@286 371 //set the values from WSDLModel, if such annotations are not present or defaulted
ohair@286 372 if(inputAction.equals("")) {
ohair@286 373 inputAction = wsdlOperation.getOperation().getInput().getAction();
ohair@286 374 } else if(!inputAction.equals(wsdlOperation.getOperation().getInput().getAction()))
ohair@286 375 //TODO input action might be from @Action or WebMethod(action)
ohair@286 376 LOGGER.warning("Input Action on WSDL operation "+wsdlOperation.getName().getLocalPart() + " and @Action on its associated Web Method " + seiMethod.getName() +" did not match and will cause problems in dispatching the requests");
ohair@286 377
ohair@286 378 if (!mep.isOneWay()) {
ohair@286 379 if (outputAction.equals(""))
ohair@286 380 outputAction = wsdlOperation.getOperation().getOutput().getAction();
ohair@286 381
ohair@286 382 for (CheckedExceptionImpl ce : exceptions) {
ohair@286 383 if (ce.getFaultAction().equals("")) {
ohair@286 384 QName detailQName = ce.getDetailType().tagName;
ohair@286 385 WSDLFault wsdlfault = wsdlOperation.getOperation().getFault(detailQName);
ohair@286 386 if(wsdlfault == null) {
ohair@286 387 // mismatch between wsdl model and SEI model, log a warning and use SEI model for Action determination
ohair@286 388 LOGGER.warning("Mismatch between Java model and WSDL model found, For wsdl operation " +
ohair@286 389 wsdlOperation.getName() + ",There is no matching wsdl fault with detail QName " +
ohair@286 390 ce.getDetailType().tagName);
ohair@286 391 ce.setFaultAction(ce.getDefaultFaultAction());
ohair@286 392 } else {
ohair@286 393 ce.setFaultAction(wsdlfault.getAction());
ohair@286 394 }
ohair@286 395 }
ohair@286 396 }
ohair@286 397 }
ohair@286 398 }
ohair@286 399
ohair@286 400 final void fillTypes(List<TypeInfo> types) {
ohair@286 401 fillTypes(requestParams, types);
ohair@286 402 fillTypes(responseParams, types);
ohair@286 403
ohair@286 404 for (CheckedExceptionImpl ce : exceptions) {
ohair@286 405 types.add(ce.getDetailType());
ohair@286 406 }
ohair@286 407 }
ohair@286 408
ohair@286 409 private void fillTypes(List<ParameterImpl> params, List<TypeInfo> types) {
ohair@286 410 for (ParameterImpl p : params) {
ohair@286 411 p.fillTypes(types);
ohair@286 412 }
ohair@286 413 }
ohair@286 414
ohair@286 415 private static final Logger LOGGER = Logger.getLogger(com.sun.xml.internal.ws.model.JavaMethodImpl.class.getName());
ohair@286 416
ohair@286 417 }

mercurial