Sat, 07 Nov 2020 10:30:02 +0800
Added tag mips-jdk8u275-b01 for changeset fdbe50121f48
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.client.sei; |
aoqi@0 | 27 | |
aoqi@0 | 28 | //import com.sun.tools.internal.ws.wsdl.document.soap.SOAPBinding; |
aoqi@0 | 29 | |
aoqi@0 | 30 | import com.oracle.webservices.internal.api.databinding.JavaCallInfo; |
aoqi@0 | 31 | import com.sun.istack.internal.NotNull; |
aoqi@0 | 32 | import com.sun.xml.internal.ws.api.message.Message; |
aoqi@0 | 33 | import com.sun.xml.internal.ws.api.message.Packet; |
aoqi@0 | 34 | import com.sun.xml.internal.ws.api.pipe.Fiber; |
aoqi@0 | 35 | import com.sun.xml.internal.ws.client.AsyncInvoker; |
aoqi@0 | 36 | import com.sun.xml.internal.ws.client.AsyncResponseImpl; |
aoqi@0 | 37 | import com.sun.xml.internal.ws.client.RequestContext; |
aoqi@0 | 38 | import com.sun.xml.internal.ws.client.ResponseContext; |
aoqi@0 | 39 | |
aoqi@0 | 40 | import javax.xml.ws.AsyncHandler; |
aoqi@0 | 41 | import javax.xml.ws.Response; |
aoqi@0 | 42 | import javax.xml.ws.WebServiceException; |
aoqi@0 | 43 | |
aoqi@0 | 44 | import java.lang.reflect.Method; |
aoqi@0 | 45 | |
aoqi@0 | 46 | /** |
aoqi@0 | 47 | * Common part between {@link CallbackMethodHandler} and {@link PollingMethodHandler}. |
aoqi@0 | 48 | * |
aoqi@0 | 49 | * @author Kohsuke Kawaguchi |
aoqi@0 | 50 | * @author Jitendra Kotamraju |
aoqi@0 | 51 | */ |
aoqi@0 | 52 | abstract class AsyncMethodHandler extends MethodHandler { |
aoqi@0 | 53 | |
aoqi@0 | 54 | AsyncMethodHandler(SEIStub owner, Method m) { |
aoqi@0 | 55 | super(owner, m); |
aoqi@0 | 56 | } |
aoqi@0 | 57 | |
aoqi@0 | 58 | // private final ResponseBuilder responseBuilder; |
aoqi@0 | 59 | // /** |
aoqi@0 | 60 | // * Async bean class that has setters for all out parameters |
aoqi@0 | 61 | // */ |
aoqi@0 | 62 | // private final @Nullable Class asyncBeanClass; |
aoqi@0 | 63 | // |
aoqi@0 | 64 | // AsyncMethodHandler(SEIStub owner, JavaMethodImpl jm, JavaMethodImpl sync) { |
aoqi@0 | 65 | // super(owner, sync); |
aoqi@0 | 66 | // |
aoqi@0 | 67 | // List<ParameterImpl> rp = sync.getResponseParameters(); |
aoqi@0 | 68 | // int size = 0; |
aoqi@0 | 69 | // for( ParameterImpl param : rp ) { |
aoqi@0 | 70 | // if (param.isWrapperStyle()) { |
aoqi@0 | 71 | // WrapperParameter wrapParam = (WrapperParameter)param; |
aoqi@0 | 72 | // size += wrapParam.getWrapperChildren().size(); |
aoqi@0 | 73 | // if (sync.getBinding().getStyle() == Style.DOCUMENT) { |
aoqi@0 | 74 | // // doc/asyncBeanClass - asyncBeanClass bean is in async signature |
aoqi@0 | 75 | // // Add 2 or more so that it is considered as async bean case |
aoqi@0 | 76 | // size += 2; |
aoqi@0 | 77 | // } |
aoqi@0 | 78 | // } else { |
aoqi@0 | 79 | // ++size; |
aoqi@0 | 80 | // } |
aoqi@0 | 81 | // } |
aoqi@0 | 82 | // |
aoqi@0 | 83 | // Class tempWrap = null; |
aoqi@0 | 84 | // if (size > 1) { |
aoqi@0 | 85 | // rp = jm.getResponseParameters(); |
aoqi@0 | 86 | // for(ParameterImpl param : rp) { |
aoqi@0 | 87 | // if (param.isWrapperStyle()) { |
aoqi@0 | 88 | // WrapperParameter wrapParam = (WrapperParameter)param; |
aoqi@0 | 89 | // if (sync.getBinding().getStyle() == Style.DOCUMENT) { |
aoqi@0 | 90 | // // doc/asyncBeanClass style |
aoqi@0 | 91 | // tempWrap = (Class)wrapParam.getTypeReference().type; |
aoqi@0 | 92 | // break; |
aoqi@0 | 93 | // } |
aoqi@0 | 94 | // for(ParameterImpl p : wrapParam.getWrapperChildren()) { |
aoqi@0 | 95 | // if (p.getIndex() == -1) { |
aoqi@0 | 96 | // tempWrap = (Class)p.getTypeReference().type; |
aoqi@0 | 97 | // break; |
aoqi@0 | 98 | // } |
aoqi@0 | 99 | // } |
aoqi@0 | 100 | // if (tempWrap != null) { |
aoqi@0 | 101 | // break; |
aoqi@0 | 102 | // } |
aoqi@0 | 103 | // } else { |
aoqi@0 | 104 | // if (param.getIndex() == -1) { |
aoqi@0 | 105 | // tempWrap = (Class)param.getTypeReference().type; |
aoqi@0 | 106 | // break; |
aoqi@0 | 107 | // } |
aoqi@0 | 108 | // } |
aoqi@0 | 109 | // } |
aoqi@0 | 110 | // } |
aoqi@0 | 111 | // asyncBeanClass = tempWrap; |
aoqi@0 | 112 | // |
aoqi@0 | 113 | // switch(size) { |
aoqi@0 | 114 | // case 0 : |
aoqi@0 | 115 | // responseBuilder = buildResponseBuilder(sync, ValueSetterFactory.NONE); |
aoqi@0 | 116 | // break; |
aoqi@0 | 117 | // case 1 : |
aoqi@0 | 118 | // responseBuilder = buildResponseBuilder(sync, ValueSetterFactory.SINGLE); |
aoqi@0 | 119 | // break; |
aoqi@0 | 120 | // default : |
aoqi@0 | 121 | // responseBuilder = buildResponseBuilder(sync, new ValueSetterFactory.AsyncBeanValueSetterFactory(asyncBeanClass)); |
aoqi@0 | 122 | // } |
aoqi@0 | 123 | // |
aoqi@0 | 124 | // } |
aoqi@0 | 125 | |
aoqi@0 | 126 | protected final Response<Object> doInvoke(Object proxy, Object[] args, AsyncHandler handler) { |
aoqi@0 | 127 | |
aoqi@0 | 128 | AsyncInvoker invoker = new SEIAsyncInvoker(proxy, args); |
aoqi@0 | 129 | invoker.setNonNullAsyncHandlerGiven(handler != null); |
aoqi@0 | 130 | AsyncResponseImpl<Object> ft = new AsyncResponseImpl<Object>(invoker,handler); |
aoqi@0 | 131 | invoker.setReceiver(ft); |
aoqi@0 | 132 | ft.run(); |
aoqi@0 | 133 | return ft; |
aoqi@0 | 134 | } |
aoqi@0 | 135 | |
aoqi@0 | 136 | private class SEIAsyncInvoker extends AsyncInvoker { |
aoqi@0 | 137 | // snapshot the context now. this is necessary to avoid concurrency issue, |
aoqi@0 | 138 | // and is required by the spec |
aoqi@0 | 139 | private final RequestContext rc = owner.requestContext.copy(); |
aoqi@0 | 140 | private final Object[] args; |
aoqi@0 | 141 | |
aoqi@0 | 142 | SEIAsyncInvoker(Object proxy, Object[] args) { |
aoqi@0 | 143 | this.args = args; |
aoqi@0 | 144 | } |
aoqi@0 | 145 | |
aoqi@0 | 146 | public void do_run () { |
aoqi@0 | 147 | JavaCallInfo call = owner.databinding.createJavaCallInfo(method, args); |
aoqi@0 | 148 | Packet req = (Packet)owner.databinding.serializeRequest(call); |
aoqi@0 | 149 | |
aoqi@0 | 150 | Fiber.CompletionCallback callback = new Fiber.CompletionCallback() { |
aoqi@0 | 151 | |
aoqi@0 | 152 | public void onCompletion(@NotNull Packet response) { |
aoqi@0 | 153 | responseImpl.setResponseContext(new ResponseContext(response)); |
aoqi@0 | 154 | Message msg = response.getMessage(); |
aoqi@0 | 155 | if (msg == null) { |
aoqi@0 | 156 | return; |
aoqi@0 | 157 | } |
aoqi@0 | 158 | try { |
aoqi@0 | 159 | Object[] rargs = new Object[1]; |
aoqi@0 | 160 | JavaCallInfo call = owner.databinding.createJavaCallInfo(method, rargs); |
aoqi@0 | 161 | call = owner.databinding.deserializeResponse(response, call); |
aoqi@0 | 162 | if (call.getException() != null) { |
aoqi@0 | 163 | throw call.getException(); |
aoqi@0 | 164 | } else { |
aoqi@0 | 165 | responseImpl.set(rargs[0], null); |
aoqi@0 | 166 | } |
aoqi@0 | 167 | // dbHandler.readResponse(response, call); |
aoqi@0 | 168 | // responseImpl.set(rargs[0], null); |
aoqi@0 | 169 | // if(msg.isFault()) { |
aoqi@0 | 170 | // SOAPFaultBuilder faultBuilder = SOAPFaultBuilder.create(msg); |
aoqi@0 | 171 | // throw faultBuilder.createException(checkedExceptions); |
aoqi@0 | 172 | // } else { |
aoqi@0 | 173 | // Object[] rargs = new Object[1]; |
aoqi@0 | 174 | // if (asyncBeanClass != null) { |
aoqi@0 | 175 | // rargs[0] = asyncBeanClass.newInstance(); |
aoqi@0 | 176 | // } |
aoqi@0 | 177 | // responseBuilder.readResponse(msg, rargs); |
aoqi@0 | 178 | // responseImpl.set(rargs[0], null); |
aoqi@0 | 179 | // } |
aoqi@0 | 180 | } catch (Throwable t) { |
aoqi@0 | 181 | if (t instanceof RuntimeException) { |
aoqi@0 | 182 | if (t instanceof WebServiceException) { |
aoqi@0 | 183 | responseImpl.set(null, t); |
aoqi@0 | 184 | return; |
aoqi@0 | 185 | } |
aoqi@0 | 186 | } else if (t instanceof Exception) { |
aoqi@0 | 187 | responseImpl.set(null, t); |
aoqi@0 | 188 | return; |
aoqi@0 | 189 | } |
aoqi@0 | 190 | //its RuntimeException or some other exception resulting from user error, wrap it in |
aoqi@0 | 191 | // WebServiceException |
aoqi@0 | 192 | responseImpl.set(null, new WebServiceException(t)); |
aoqi@0 | 193 | } |
aoqi@0 | 194 | } |
aoqi@0 | 195 | |
aoqi@0 | 196 | |
aoqi@0 | 197 | public void onCompletion(@NotNull Throwable error) { |
aoqi@0 | 198 | if (error instanceof WebServiceException) { |
aoqi@0 | 199 | responseImpl.set(null, error); |
aoqi@0 | 200 | } else { |
aoqi@0 | 201 | //its RuntimeException or some other exception resulting from user error, wrap it in |
aoqi@0 | 202 | // WebServiceException |
aoqi@0 | 203 | responseImpl.set(null, new WebServiceException(error)); |
aoqi@0 | 204 | } |
aoqi@0 | 205 | } |
aoqi@0 | 206 | }; |
aoqi@0 | 207 | owner.doProcessAsync(responseImpl, req, rc, callback); |
aoqi@0 | 208 | } |
aoqi@0 | 209 | } |
aoqi@0 | 210 | |
aoqi@0 | 211 | ValueGetterFactory getValueGetterFactory() { |
aoqi@0 | 212 | return ValueGetterFactory.ASYNC; |
aoqi@0 | 213 | } |
aoqi@0 | 214 | |
aoqi@0 | 215 | } |