001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.xml.ws.client.sei;
038:
039: import com.sun.xml.ws.api.message.Message;
040: import com.sun.xml.ws.api.message.Packet;
041: import com.sun.xml.ws.client.RequestContext;
042: import com.sun.xml.ws.client.ResponseContextReceiver;
043: import com.sun.xml.ws.encoding.soap.DeserializationException;
044: import com.sun.xml.ws.fault.SOAPFaultBuilder;
045: import com.sun.xml.ws.message.jaxb.JAXBMessage;
046: import com.sun.xml.ws.model.CheckedExceptionImpl;
047: import com.sun.xml.ws.model.JavaMethodImpl;
048: import com.sun.xml.ws.model.ParameterImpl;
049: import com.sun.xml.ws.model.WrapperParameter;
050:
051: import javax.xml.bind.JAXBException;
052: import javax.xml.namespace.QName;
053: import javax.xml.stream.XMLStreamException;
054: import javax.xml.ws.Holder;
055: import java.util.ArrayList;
056: import java.util.HashMap;
057: import java.util.List;
058: import java.util.Map;
059:
060: /**
061: * {@link MethodHandler} that handles synchronous method invocations.
062: *
063: * <p>
064: * This class mainly performs the following two tasks:
065: * <ol>
066: * <li>Accepts Object[] that represents arguments for a Java method,
067: * and creates {@link JAXBMessage} that represents a request message.
068: * <li>Takes a {@link Message] that represents a response,
069: * and extracts the return value (and updates {@link Holder}s.)
070: * </ol>
071: *
072: * <h2>Creating {@link JAXBMessage}</h2>
073: * <p>
074: * At the construction time, we prepare {@link BodyBuilder} and {@link MessageFiller}s
075: * that know how to move arguments into a {@link Message}.
076: * Some arguments go to the payload, some go to headers, still others go to attachments.
077: *
078: * @author Kohsuke Kawaguchi
079: */
080: final class SyncMethodHandler extends SEIMethodHandler {
081: private final ResponseBuilder responseBuilder;
082:
083: SyncMethodHandler(SEIStub owner, JavaMethodImpl method) {
084: super (owner, method);
085: responseBuilder = buildResponseBuilder(method,
086: ValueSetterFactory.SYNC);
087: }
088:
089: Object invoke(Object proxy, Object[] args) throws Throwable {
090: return invoke(proxy, args, owner.requestContext, owner);
091: }
092:
093: /**
094: * Invokes synchronously, but with the given {@link RequestContext}
095: * and {@link ResponseContextReceiver}.
096: *
097: * @param rc
098: * This {@link RequestContext} is used for invoking this method.
099: * We take this as a separate parameter because of the async invocation
100: * handling, which requires a separate copy.
101: */
102: Object invoke(Object proxy, Object[] args, RequestContext rc,
103: ResponseContextReceiver receiver) throws Throwable {
104: Packet req = new Packet(createRequestMessage(args));
105:
106: req.soapAction = soapAction;
107: req.expectReply = !isOneWay;
108: req.getMessage().assertOneWay(isOneWay);
109:
110: // process the message
111: Packet reply = owner.doProcess(req, rc, receiver);
112:
113: Message msg = reply.getMessage();
114: if (msg == null)
115: // no reply. must have been one-way
116: return null;
117:
118: try {
119: if (msg.isFault()) {
120: SOAPFaultBuilder faultBuilder = SOAPFaultBuilder
121: .create(msg);
122: throw faultBuilder.createException(checkedExceptions);
123: } else {
124: return responseBuilder.readResponse(msg, args);
125: }
126: } catch (JAXBException e) {
127: throw new DeserializationException(
128: "failed.to.read.response", e);
129: } catch (XMLStreamException e) {
130: throw new DeserializationException(
131: "failed.to.read.response", e);
132: }
133: }
134:
135: ValueGetterFactory getValueGetterFactory() {
136: return ValueGetterFactory.SYNC;
137: }
138:
139: }
|