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

Fri, 04 Oct 2013 16:21:34 +0100

author
mkos
date
Fri, 04 Oct 2013 16:21:34 +0100
changeset 408
b0610cd08440
parent 368
0989ad8c0860
child 637
9c07ef4934dd
permissions
-rw-r--r--

8025054: Update JAX-WS RI integration to 2.2.9-b130926.1035
Reviewed-by: chegar

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

mercurial