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: package com.sun.xml.ws.server.sei;
037:
038: import com.sun.istack.NotNull;
039: import com.sun.xml.ws.api.SOAPVersion;
040: import com.sun.xml.ws.api.WSBinding;
041: import com.sun.xml.ws.api.message.Message;
042: import com.sun.xml.ws.api.message.Packet;
043: import com.sun.xml.ws.api.pipe.NextAction;
044: import com.sun.xml.ws.api.server.Invoker;
045: import com.sun.xml.ws.client.sei.MethodHandler;
046: import com.sun.xml.ws.model.AbstractSEIModelImpl;
047: import com.sun.xml.ws.server.InvokerTube;
048: import com.sun.xml.ws.resources.ServerMessages;
049: import com.sun.xml.ws.fault.SOAPFaultBuilder;
050:
051: import java.util.List;
052: import java.text.MessageFormat;
053:
054: /**
055: * This pipe is used to invoke SEI based endpoints.
056: *
057: * @author Jitendra Kotamraju
058: */
059: public class SEIInvokerTube extends InvokerTube {
060:
061: /**
062: * For each method on the port interface we have
063: * a {@link MethodHandler} that processes it.
064: */
065: private final SOAPVersion soapVersion;
066: private final WSBinding binding;
067: private final AbstractSEIModelImpl model;
068: private final List<EndpointMethodDispatcher> dispatcherList;
069:
070: public SEIInvokerTube(AbstractSEIModelImpl model, Invoker invoker,
071: WSBinding binding) {
072: super (invoker);
073: this .soapVersion = binding.getSOAPVersion();
074: this .binding = binding;
075: this .model = model;
076: EndpointMethodDispatcherGetter methodDispatcherGetter = new EndpointMethodDispatcherGetter(
077: model, binding, this );
078: dispatcherList = methodDispatcherGetter.getDispatcherList();
079: }
080:
081: /**
082: * This binds the parameters for SEI endpoints and invokes the endpoint method. The
083: * return value, and response Holder arguments are used to create a new {@link Message}
084: * that traverses through the Pipeline to transport.
085: */
086: public @NotNull
087: NextAction processRequest(@NotNull
088: Packet req) {
089: for (EndpointMethodDispatcher dispatcher : dispatcherList) {
090: EndpointMethodHandler handler;
091: try {
092: handler = dispatcher.getEndpointMethodHandler(req);
093: } catch (DispatchException e) {
094: return doReturnWith(req.createServerResponse(e.fault,
095: model.getPort(), null, binding));
096: }
097: if (handler != null) {
098: Packet res = handler.invoke(req);
099: assert res != null;
100: return doReturnWith(res);
101: }
102: }
103: String err = MessageFormat.format(
104: "Request=[SOAPAction={0},Payload='{'{1}'}'{2}]",
105: req.soapAction, req.getMessage()
106: .getPayloadNamespaceURI(), req.getMessage()
107: .getPayloadLocalPart());
108: String faultString = ServerMessages
109: .DISPATCH_CANNOT_FIND_METHOD(err);
110: Message faultMsg = SOAPFaultBuilder.createSOAPFaultMessage(
111: binding.getSOAPVersion(), faultString, binding
112: .getSOAPVersion().faultCodeClient);
113: return doReturnWith(req.createServerResponse(faultMsg, model
114: .getPort(), null, binding));
115: }
116:
117: public @NotNull
118: NextAction processResponse(@NotNull
119: Packet response) {
120: throw new IllegalStateException(
121: "InovkerPipe's processResponse shouldn't be called.");
122: }
123:
124: public @NotNull
125: NextAction processException(@NotNull
126: Throwable t) {
127: throw new IllegalStateException(
128: "InovkerPipe's processException shouldn't be called.");
129: }
130:
131: }
|