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

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 408
b0610cd08440
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

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

mercurial