Thu, 31 Aug 2017 15:18:52 +0800
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.client.sei; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import com.oracle.webservices.internal.api.databinding.JavaCallInfo; |
aoqi@0 | 29 | import com.sun.xml.internal.ws.api.message.Message; |
aoqi@0 | 30 | import com.sun.xml.internal.ws.api.message.Packet; |
aoqi@0 | 31 | import com.sun.xml.internal.ws.client.RequestContext; |
aoqi@0 | 32 | import com.sun.xml.internal.ws.client.ResponseContextReceiver; |
aoqi@0 | 33 | import com.sun.xml.internal.ws.encoding.soap.DeserializationException; |
aoqi@0 | 34 | import com.sun.xml.internal.ws.message.jaxb.JAXBMessage; |
aoqi@0 | 35 | import com.sun.xml.internal.ws.model.JavaMethodImpl; |
aoqi@0 | 36 | import com.sun.xml.internal.ws.resources.DispatchMessages; |
aoqi@0 | 37 | |
aoqi@0 | 38 | import javax.xml.bind.JAXBException; |
aoqi@0 | 39 | import javax.xml.stream.XMLStreamException; |
aoqi@0 | 40 | import javax.xml.ws.Holder; |
aoqi@0 | 41 | import javax.xml.ws.WebServiceException; |
aoqi@0 | 42 | |
aoqi@0 | 43 | import java.lang.reflect.Method; |
aoqi@0 | 44 | |
aoqi@0 | 45 | /** |
aoqi@0 | 46 | * {@link MethodHandler} that handles synchronous method invocations. |
aoqi@0 | 47 | * |
aoqi@0 | 48 | * <p> |
aoqi@0 | 49 | * This class mainly performs the following two tasks: |
aoqi@0 | 50 | * <ol> |
aoqi@0 | 51 | * <li>Accepts Object[] that represents arguments for a Java method, |
aoqi@0 | 52 | * and creates {@link JAXBMessage} that represents a request message. |
aoqi@0 | 53 | * <li>Takes a {@link Message] that represents a response, |
aoqi@0 | 54 | * and extracts the return value (and updates {@link Holder}s.) |
aoqi@0 | 55 | * </ol> |
aoqi@0 | 56 | * |
aoqi@0 | 57 | * <h2>Creating {@link JAXBMessage}</h2> |
aoqi@0 | 58 | * <p> |
aoqi@0 | 59 | * At the construction time, we prepare {@link BodyBuilder} and {@link MessageFiller}s |
aoqi@0 | 60 | * that know how to move arguments into a {@link Message}. |
aoqi@0 | 61 | * Some arguments go to the payload, some go to headers, still others go to attachments. |
aoqi@0 | 62 | * |
aoqi@0 | 63 | * @author Kohsuke Kawaguchi |
aoqi@0 | 64 | */ |
aoqi@0 | 65 | final class SyncMethodHandler extends MethodHandler { |
aoqi@0 | 66 | final boolean isVoid; |
aoqi@0 | 67 | final boolean isOneway; |
aoqi@0 | 68 | final JavaMethodImpl javaMethod; |
aoqi@0 | 69 | SyncMethodHandler(SEIStub owner, JavaMethodImpl jm) { |
aoqi@0 | 70 | super(owner, jm.getMethod()); |
aoqi@0 | 71 | javaMethod = jm; |
aoqi@0 | 72 | isVoid = void.class.equals(jm.getMethod().getReturnType()); |
aoqi@0 | 73 | isOneway = jm.getMEP().isOneWay(); |
aoqi@0 | 74 | } |
aoqi@0 | 75 | |
aoqi@0 | 76 | Object invoke(Object proxy, Object[] args) throws Throwable { |
aoqi@0 | 77 | return invoke(proxy,args,owner.requestContext,owner); |
aoqi@0 | 78 | } |
aoqi@0 | 79 | |
aoqi@0 | 80 | /** |
aoqi@0 | 81 | * Invokes synchronously, but with the given {@link RequestContext} |
aoqi@0 | 82 | * and {@link ResponseContextReceiver}. |
aoqi@0 | 83 | * |
aoqi@0 | 84 | * @param rc |
aoqi@0 | 85 | * This {@link RequestContext} is used for invoking this method. |
aoqi@0 | 86 | * We take this as a separate parameter because of the async invocation |
aoqi@0 | 87 | * handling, which requires a separate copy. |
aoqi@0 | 88 | */ |
aoqi@0 | 89 | Object invoke(Object proxy, Object[] args, RequestContext rc, ResponseContextReceiver receiver) throws Throwable { |
aoqi@0 | 90 | JavaCallInfo call = owner.databinding.createJavaCallInfo(method, args); |
aoqi@0 | 91 | Packet req = (Packet) owner.databinding.serializeRequest(call); |
aoqi@0 | 92 | // process the message |
aoqi@0 | 93 | Packet reply = owner.doProcess(req,rc,receiver); |
aoqi@0 | 94 | |
aoqi@0 | 95 | Message msg = reply.getMessage(); |
aoqi@0 | 96 | if(msg == null) { |
aoqi@0 | 97 | if (!isOneway || !isVoid) { |
aoqi@0 | 98 | throw new WebServiceException(DispatchMessages.INVALID_RESPONSE()); |
aoqi@0 | 99 | } |
aoqi@0 | 100 | return null; |
aoqi@0 | 101 | } |
aoqi@0 | 102 | |
aoqi@0 | 103 | try { |
aoqi@0 | 104 | call = owner.databinding.deserializeResponse(reply, call); |
aoqi@0 | 105 | if (call.getException() != null) { |
aoqi@0 | 106 | throw call.getException(); |
aoqi@0 | 107 | } else { |
aoqi@0 | 108 | return call.getReturnValue(); |
aoqi@0 | 109 | } |
aoqi@0 | 110 | } catch (JAXBException e) { |
aoqi@0 | 111 | throw new DeserializationException(DispatchMessages.INVALID_RESPONSE_DESERIALIZATION(), e); |
aoqi@0 | 112 | } catch (XMLStreamException e) { |
aoqi@0 | 113 | throw new DeserializationException(DispatchMessages.INVALID_RESPONSE_DESERIALIZATION(),e); |
aoqi@0 | 114 | } finally { |
aoqi@0 | 115 | if (reply.transportBackChannel != null) |
aoqi@0 | 116 | reply.transportBackChannel.close(); |
aoqi@0 | 117 | } |
aoqi@0 | 118 | } |
aoqi@0 | 119 | |
aoqi@0 | 120 | ValueGetterFactory getValueGetterFactory() { |
aoqi@0 | 121 | return ValueGetterFactory.SYNC; |
aoqi@0 | 122 | } |
aoqi@0 | 123 | |
aoqi@0 | 124 | } |