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

changeset 286
f50545b5e2f1
child 368
0989ad8c0860
equal deleted inserted replaced
284:88b85470e72c 286:f50545b5e2f1
1 /*
2 * Copyright (c) 1997, 2011, 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 */
25
26 package com.sun.xml.internal.ws.client.sei;
27
28 import com.sun.xml.internal.ws.api.databinding.ClientCallBridge;
29 import com.sun.xml.internal.ws.api.message.Message;
30 import com.sun.xml.internal.ws.api.message.Packet;
31 import com.sun.xml.internal.ws.client.RequestContext;
32 import com.sun.xml.internal.ws.client.ResponseContextReceiver;
33 import com.sun.xml.internal.ws.encoding.soap.DeserializationException;
34 import com.sun.xml.internal.ws.fault.SOAPFaultBuilder;
35 import com.sun.xml.internal.ws.message.jaxb.JAXBMessage;
36 import com.sun.xml.internal.ws.model.CheckedExceptionImpl;
37 import com.sun.xml.internal.ws.model.JavaMethodImpl;
38 import com.sun.xml.internal.ws.model.ParameterImpl;
39 import com.sun.xml.internal.ws.model.WrapperParameter;
40 import com.sun.xml.internal.org.jvnet.ws.databinding.JavaCallInfo;
41
42 import javax.xml.bind.JAXBException;
43 import javax.xml.namespace.QName;
44 import javax.xml.stream.XMLStreamException;
45 import javax.xml.ws.Holder;
46
47 import java.lang.reflect.Method;
48 import java.util.ArrayList;
49 import java.util.HashMap;
50 import java.util.List;
51 import java.util.Map;
52
53 /**
54 * {@link MethodHandler} that handles synchronous method invocations.
55 *
56 * <p>
57 * This class mainly performs the following two tasks:
58 * <ol>
59 * <li>Accepts Object[] that represents arguments for a Java method,
60 * and creates {@link JAXBMessage} that represents a request message.
61 * <li>Takes a {@link Message] that represents a response,
62 * and extracts the return value (and updates {@link Holder}s.)
63 * </ol>
64 *
65 * <h2>Creating {@link JAXBMessage}</h2>
66 * <p>
67 * At the construction time, we prepare {@link BodyBuilder} and {@link MessageFiller}s
68 * that know how to move arguments into a {@link Message}.
69 * Some arguments go to the payload, some go to headers, still others go to attachments.
70 *
71 * @author Kohsuke Kawaguchi
72 */
73 final class SyncMethodHandler extends MethodHandler {
74 // private ResponseBuilder responseBuilder;
75
76 SyncMethodHandler(SEIStub owner, Method m) {
77 super(owner, m);
78 // responseBuilder = buildResponseBuilder(method, ValueSetterFactory.SYNC);
79 }
80
81 // SyncMethodHandler(SEIStub owner, JavaMethodImpl method) {
82 // super(owner, method);
83 // responseBuilder = buildResponseBuilder(method, ValueSetterFactory.SYNC);
84 // }
85
86 Object invoke(Object proxy, Object[] args) throws Throwable {
87 return invoke(proxy,args,owner.requestContext,owner);
88 }
89
90 /**
91 * Invokes synchronously, but with the given {@link RequestContext}
92 * and {@link ResponseContextReceiver}.
93 *
94 * @param rc
95 * This {@link RequestContext} is used for invoking this method.
96 * We take this as a separate parameter because of the async invocation
97 * handling, which requires a separate copy.
98 */
99 Object invoke(Object proxy, Object[] args, RequestContext rc, ResponseContextReceiver receiver) throws Throwable {
100 JavaCallInfo call = owner.databinding.createJavaCallInfo(method, args);
101 // Packet req = new Packet(createRequestMessage(args));
102 Packet req = (Packet) owner.databinding.serializeRequest(call);
103 // process the message
104 Packet reply = owner.doProcess(req,rc,receiver);
105
106 Message msg = reply.getMessage();
107 if(msg ==null)
108 // no reply. must have been one-way
109 return null;
110
111 try {
112 // return dbHandler.readResponse(reply, call).getReturnValue();
113 call = owner.databinding.deserializeResponse(reply, call);
114 if (call.getException() != null) {
115 throw call.getException();
116 } else {
117 return call.getReturnValue();
118 }
119 // if(msg.isFault()) {
120 // SOAPFaultBuilder faultBuilder = SOAPFaultBuilder.create(msg);
121 // throw faultBuilder.createException(checkedExceptions);
122 // } else {
123 // return responseBuilder.readResponse(msg,args);
124 // }
125 } catch (JAXBException e) {
126 throw new DeserializationException("failed.to.read.response",e);
127 } catch (XMLStreamException e) {
128 throw new DeserializationException("failed.to.read.response",e);
129 } finally {
130 if (reply.transportBackChannel != null)
131 reply.transportBackChannel.close();
132 }
133 }
134
135 ValueGetterFactory getValueGetterFactory() {
136 return ValueGetterFactory.SYNC;
137 }
138
139 }

mercurial