|
1 /* |
|
2 * Copyright (c) 1997, 2012, 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.server.provider; |
|
27 |
|
28 import com.sun.istack.internal.Nullable; |
|
29 import com.sun.xml.internal.ws.api.SOAPVersion; |
|
30 import com.sun.xml.internal.ws.api.WSBinding; |
|
31 import com.sun.xml.internal.ws.api.message.Message; |
|
32 import com.sun.xml.internal.ws.api.message.Packet; |
|
33 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort; |
|
34 import com.sun.xml.internal.ws.fault.SOAPFaultBuilder; |
|
35 |
|
36 import javax.xml.ws.soap.SOAPBinding; |
|
37 |
|
38 /** |
|
39 * @author Jitendra Kotamraju |
|
40 */ |
|
41 |
|
42 public // TODO need this in the factory |
|
43 abstract class ProviderArgumentsBuilder<T> { |
|
44 |
|
45 /** |
|
46 * Creates a fault {@link Message} from method invocation's exception |
|
47 */ |
|
48 protected abstract Message getResponseMessage(Exception e); |
|
49 |
|
50 /** |
|
51 * Creates {@link Message} from method invocation's return value |
|
52 */ |
|
53 protected Packet getResponse(Packet request, Exception e, WSDLPort port, WSBinding binding) { |
|
54 Message message = getResponseMessage(e); |
|
55 Packet response = request.createServerResponse(message,port,null,binding); |
|
56 return response; |
|
57 } |
|
58 |
|
59 /** |
|
60 * Binds {@link com.sun.xml.internal.ws.api.message.Message} to method invocation parameter |
|
61 * @param packet |
|
62 */ |
|
63 /*protected*/ public abstract T getParameter(Packet packet); // TODO public for DISI pluggable Provider |
|
64 |
|
65 protected abstract Message getResponseMessage(T returnValue); |
|
66 |
|
67 /** |
|
68 * Creates {@link Packet} from method invocation's return value |
|
69 */ |
|
70 protected Packet getResponse(Packet request, @Nullable T returnValue, WSDLPort port, WSBinding binding) { |
|
71 Message message = null; |
|
72 if (returnValue != null) { |
|
73 message = getResponseMessage(returnValue); |
|
74 } |
|
75 Packet response = request.createServerResponse(message,port,null,binding); |
|
76 return response; |
|
77 } |
|
78 |
|
79 public static ProviderArgumentsBuilder<?> create(ProviderEndpointModel model, WSBinding binding) { |
|
80 if (model.datatype == Packet.class) |
|
81 return new PacketProviderArgumentsBuilder(binding.getSOAPVersion()); |
|
82 return (binding instanceof SOAPBinding) ? SOAPProviderArgumentBuilder.create(model, binding.getSOAPVersion()) |
|
83 : XMLProviderArgumentBuilder.createBuilder(model, binding); |
|
84 } |
|
85 |
|
86 private static class PacketProviderArgumentsBuilder extends ProviderArgumentsBuilder<Packet> { |
|
87 private final SOAPVersion soapVersion; |
|
88 |
|
89 public PacketProviderArgumentsBuilder(SOAPVersion soapVersion) { |
|
90 this.soapVersion = soapVersion; |
|
91 } |
|
92 |
|
93 @Override |
|
94 protected Message getResponseMessage(Exception e) { |
|
95 // Will be called by AsyncProviderCallbackImpl.sendError |
|
96 return SOAPFaultBuilder.createSOAPFaultMessage(soapVersion, null, e); |
|
97 } |
|
98 |
|
99 @Override |
|
100 /*protected*/ public Packet getParameter(Packet packet) { |
|
101 return packet; |
|
102 } |
|
103 |
|
104 @Override |
|
105 protected Message getResponseMessage(Packet returnValue) { |
|
106 // Should never be called |
|
107 throw new IllegalStateException(); |
|
108 } |
|
109 |
|
110 @Override |
|
111 protected Packet getResponse(Packet request, @Nullable Packet returnValue, WSDLPort port, WSBinding binding) { |
|
112 return returnValue; |
|
113 } |
|
114 } |
|
115 } |