src/share/jaxws_classes/com/sun/xml/internal/ws/client/sei/AsyncMethodHandler.java

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

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

merge

     1 /*
     2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.xml.internal.ws.client.sei;
    28 //import com.sun.tools.internal.ws.wsdl.document.soap.SOAPBinding;
    30 import com.oracle.webservices.internal.api.databinding.JavaCallInfo;
    31 import com.sun.istack.internal.NotNull;
    32 import com.sun.xml.internal.ws.api.message.Message;
    33 import com.sun.xml.internal.ws.api.message.Packet;
    34 import com.sun.xml.internal.ws.api.pipe.Fiber;
    35 import com.sun.xml.internal.ws.client.AsyncInvoker;
    36 import com.sun.xml.internal.ws.client.AsyncResponseImpl;
    37 import com.sun.xml.internal.ws.client.RequestContext;
    38 import com.sun.xml.internal.ws.client.ResponseContext;
    40 import javax.xml.ws.AsyncHandler;
    41 import javax.xml.ws.Response;
    42 import javax.xml.ws.WebServiceException;
    44 import java.lang.reflect.Method;
    46 /**
    47  * Common part between {@link CallbackMethodHandler} and {@link PollingMethodHandler}.
    48  *
    49  * @author Kohsuke Kawaguchi
    50  * @author Jitendra Kotamraju
    51  */
    52 abstract class AsyncMethodHandler extends MethodHandler {
    54     AsyncMethodHandler(SEIStub owner, Method m) {
    55         super(owner, m);
    56     }
    58 //    private final ResponseBuilder responseBuilder;
    59 //    /**
    60 //     * Async bean class that has setters for all out parameters
    61 //     */
    62 //    private final @Nullable Class asyncBeanClass;
    63 //
    64 //    AsyncMethodHandler(SEIStub owner, JavaMethodImpl jm, JavaMethodImpl sync) {
    65 //        super(owner, sync);
    66 //
    67 //        List<ParameterImpl> rp = sync.getResponseParameters();
    68 //        int size = 0;
    69 //        for( ParameterImpl param : rp ) {
    70 //            if (param.isWrapperStyle()) {
    71 //                WrapperParameter wrapParam = (WrapperParameter)param;
    72 //                size += wrapParam.getWrapperChildren().size();
    73 //                if (sync.getBinding().getStyle() == Style.DOCUMENT) {
    74 //                    // doc/asyncBeanClass - asyncBeanClass bean is in async signature
    75 //                    // Add 2 or more so that it is considered as async bean case
    76 //                    size += 2;
    77 //                }
    78 //            } else {
    79 //                ++size;
    80 //            }
    81 //        }
    82 //
    83 //        Class tempWrap = null;
    84 //        if (size > 1) {
    85 //            rp = jm.getResponseParameters();
    86 //            for(ParameterImpl param : rp) {
    87 //                if (param.isWrapperStyle()) {
    88 //                    WrapperParameter wrapParam = (WrapperParameter)param;
    89 //                    if (sync.getBinding().getStyle() == Style.DOCUMENT) {
    90 //                        // doc/asyncBeanClass style
    91 //                        tempWrap = (Class)wrapParam.getTypeReference().type;
    92 //                        break;
    93 //                    }
    94 //                    for(ParameterImpl p : wrapParam.getWrapperChildren()) {
    95 //                        if (p.getIndex() == -1) {
    96 //                            tempWrap = (Class)p.getTypeReference().type;
    97 //                            break;
    98 //                        }
    99 //                    }
   100 //                    if (tempWrap != null) {
   101 //                        break;
   102 //                    }
   103 //                } else {
   104 //                    if (param.getIndex() == -1) {
   105 //                        tempWrap = (Class)param.getTypeReference().type;
   106 //                        break;
   107 //                    }
   108 //                }
   109 //            }
   110 //        }
   111 //        asyncBeanClass = tempWrap;
   112 //
   113 //        switch(size) {
   114 //            case 0 :
   115 //                responseBuilder = buildResponseBuilder(sync, ValueSetterFactory.NONE);
   116 //                break;
   117 //            case 1 :
   118 //                responseBuilder = buildResponseBuilder(sync, ValueSetterFactory.SINGLE);
   119 //                break;
   120 //            default :
   121 //                responseBuilder = buildResponseBuilder(sync, new ValueSetterFactory.AsyncBeanValueSetterFactory(asyncBeanClass));
   122 //        }
   123 //
   124 //    }
   126     protected final Response<Object> doInvoke(Object proxy, Object[] args, AsyncHandler handler) {
   128         AsyncInvoker invoker = new SEIAsyncInvoker(proxy, args);
   129         invoker.setNonNullAsyncHandlerGiven(handler != null);
   130         AsyncResponseImpl<Object> ft = new AsyncResponseImpl<Object>(invoker,handler);
   131         invoker.setReceiver(ft);
   132         ft.run();
   133         return ft;
   134     }
   136     private class SEIAsyncInvoker extends AsyncInvoker {
   137         // snapshot the context now. this is necessary to avoid concurrency issue,
   138         // and is required by the spec
   139         private final RequestContext rc = owner.requestContext.copy();
   140         private final Object[] args;
   142         SEIAsyncInvoker(Object proxy, Object[] args) {
   143             this.args = args;
   144         }
   146         public void do_run () {
   147                 JavaCallInfo call = owner.databinding.createJavaCallInfo(method, args);
   148             Packet req = (Packet)owner.databinding.serializeRequest(call);
   150             Fiber.CompletionCallback callback = new Fiber.CompletionCallback() {
   152                 public void onCompletion(@NotNull Packet response) {
   153                     responseImpl.setResponseContext(new ResponseContext(response));
   154                     Message msg = response.getMessage();
   155                     if (msg == null) {
   156                         return;
   157                     }
   158                     try {
   159                         Object[] rargs = new Object[1];
   160                         JavaCallInfo call = owner.databinding.createJavaCallInfo(method, rargs);
   161                         call = owner.databinding.deserializeResponse(response, call);
   162                         if (call.getException() != null) {
   163                             throw call.getException();
   164                         } else {
   165                             responseImpl.set(rargs[0], null);
   166                         }
   167 //                      dbHandler.readResponse(response, call);
   168 //                      responseImpl.set(rargs[0], null);
   169 //                        if(msg.isFault()) {
   170 //                            SOAPFaultBuilder faultBuilder = SOAPFaultBuilder.create(msg);
   171 //                            throw faultBuilder.createException(checkedExceptions);
   172 //                        } else {
   173 //                            Object[] rargs = new Object[1];
   174 //                            if (asyncBeanClass != null) {
   175 //                                rargs[0] = asyncBeanClass.newInstance();
   176 //                            }
   177 //                            responseBuilder.readResponse(msg, rargs);
   178 //                            responseImpl.set(rargs[0], null);
   179 //                        }
   180                    } catch (Throwable t) {
   181                         if (t instanceof RuntimeException) {
   182                             if (t instanceof WebServiceException) {
   183                                 responseImpl.set(null, t);
   184                                 return;
   185                             }
   186                         }  else if (t instanceof Exception) {
   187                             responseImpl.set(null, t);
   188                             return;
   189                         }
   190                         //its RuntimeException or some other exception resulting from user error, wrap it in
   191                         // WebServiceException
   192                         responseImpl.set(null, new WebServiceException(t));
   193                     }
   194                 }
   197                 public void onCompletion(@NotNull Throwable error) {
   198                     if (error instanceof WebServiceException) {
   199                         responseImpl.set(null, error);
   200                     } else {
   201                         //its RuntimeException or some other exception resulting from user error, wrap it in
   202                         // WebServiceException
   203                         responseImpl.set(null, new WebServiceException(error));
   204                     }
   205                 }
   206             };
   207             owner.doProcessAsync(responseImpl, req, rc, callback);
   208         }
   209     }
   211     ValueGetterFactory getValueGetterFactory() {
   212         return ValueGetterFactory.ASYNC;
   213     }
   215 }

mercurial