1/*
2 * Copyright (c) 1997, 2013, 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
26package com.sun.xml.internal.ws.server.sei;
27
28import com.oracle.webservices.internal.api.databinding.JavaCallInfo;
29import com.sun.istack.internal.NotNull;
30import com.sun.xml.internal.ws.api.WSBinding;
31import com.sun.xml.internal.ws.api.message.Message;
32import com.sun.xml.internal.ws.api.message.Packet;
33import com.sun.xml.internal.ws.api.pipe.NextAction;
34import com.sun.xml.internal.ws.api.server.Invoker;
35import com.sun.xml.internal.ws.client.sei.MethodHandler;
36import com.sun.xml.internal.ws.model.AbstractSEIModelImpl;
37import com.sun.xml.internal.ws.server.InvokerTube;
38import com.sun.xml.internal.ws.wsdl.DispatchException;
39import java.lang.reflect.InvocationTargetException;
40
41/**
42 * This pipe is used to invoke SEI based endpoints.
43 *
44 * @author Jitendra Kotamraju
45 */
46public class SEIInvokerTube extends InvokerTube {
47
48    /**
49     * For each method on the port interface we have
50     * a {@link MethodHandler} that processes it.
51     */
52    private final WSBinding binding;
53    private final AbstractSEIModelImpl model;
54
55    public SEIInvokerTube(AbstractSEIModelImpl model,Invoker invoker, WSBinding binding) {
56        super(invoker);
57        this.binding = binding;
58        this.model = model;
59    }
60
61    /**
62     * This binds the parameters for SEI endpoints and invokes the endpoint method. The
63     * return value, and response Holder arguments are used to create a new {@link Message}
64     * that traverses through the Pipeline to transport.
65     */
66    public @NotNull NextAction processRequest(@NotNull Packet req) {
67                JavaCallInfo call = model.getDatabinding().deserializeRequest(req);
68                if (call.getException() == null) {
69                        try {
70                                if (req.getMessage().isOneWay(model.getPort()) && req.transportBackChannel != null) {
71                                        req.transportBackChannel.close();
72                                }
73                                Object ret = getInvoker(req).invoke(req, call.getMethod(), call.getParameters());
74                                call.setReturnValue(ret);
75                                } catch (InvocationTargetException e) {
76                                        call.setException(e);
77                                } catch (Exception e) {
78                                        call.setException(e);
79                                }
80                        } else if (call.getException() instanceof DispatchException) {
81                            DispatchException e = (DispatchException)call.getException();
82                            return doReturnWith(req.createServerResponse(e.fault, model.getPort(), null, binding));
83                        }
84                        Packet res = (Packet) model.getDatabinding().serializeResponse(call);
85                        res = req.relateServerResponse(res, req.endpoint.getPort(), model, req.endpoint.getBinding());
86            assert res != null;
87            return doReturnWith(res);
88    }
89
90    public @NotNull NextAction processResponse(@NotNull Packet response) {
91        return doReturnWith(response);
92    }
93
94    public @NotNull NextAction processException(@NotNull Throwable t) {
95        return doThrow(t);
96    }
97
98}
99