|
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.client.dispatch; |
|
27 |
|
28 import com.sun.xml.internal.ws.api.addressing.WSEndpointReference; |
|
29 import com.sun.xml.internal.ws.api.message.Message; |
|
30 import com.sun.xml.internal.ws.api.message.Messages; |
|
31 import com.sun.xml.internal.ws.api.message.Packet; |
|
32 import com.sun.xml.internal.ws.api.pipe.Tube; |
|
33 import com.sun.xml.internal.ws.api.client.WSPortInfo; |
|
34 import com.sun.xml.internal.ws.binding.BindingImpl; |
|
35 import com.sun.xml.internal.ws.client.WSServiceDelegate; |
|
36 import com.sun.xml.internal.ws.client.PortInfo; |
|
37 import com.sun.xml.internal.ws.encoding.xml.XMLMessage; |
|
38 import com.sun.xml.internal.ws.message.source.PayloadSourceMessage; |
|
39 import static com.sun.xml.internal.ws.binding.WebServiceFeatureList.toFeatureArray; |
|
40 |
|
41 import javax.xml.namespace.QName; |
|
42 import javax.xml.transform.Source; |
|
43 import javax.xml.transform.stream.StreamSource; |
|
44 import javax.xml.ws.Dispatch; |
|
45 import javax.xml.ws.Service.Mode; |
|
46 import java.io.IOException; |
|
47 |
|
48 /** |
|
49 * {@link Dispatch} implementation for {@link Source} and XML/HTTP binding. |
|
50 * |
|
51 * @author Kathy Walsh |
|
52 * @author Kohsuke Kawaguchi |
|
53 * @see SOAPSourceDispatch |
|
54 */ |
|
55 final class RESTSourceDispatch extends DispatchImpl<Source> { |
|
56 @Deprecated |
|
57 public RESTSourceDispatch(QName port, Mode mode, WSServiceDelegate owner, Tube pipe, BindingImpl binding, WSEndpointReference epr) { |
|
58 super(port, mode, owner, pipe, binding, epr); |
|
59 assert isXMLHttp(binding); |
|
60 } |
|
61 |
|
62 public RESTSourceDispatch(WSPortInfo portInfo, Mode mode, BindingImpl binding, WSEndpointReference epr) { |
|
63 super(portInfo, mode, binding, epr); |
|
64 assert isXMLHttp(binding); |
|
65 } |
|
66 |
|
67 @Override |
|
68 Source toReturnValue(Packet response) { |
|
69 Message msg = response.getMessage(); |
|
70 try { |
|
71 return new StreamSource(XMLMessage.getDataSource(msg, binding.getFeatures()).getInputStream()); |
|
72 } catch (IOException e) { |
|
73 throw new RuntimeException(e); |
|
74 } |
|
75 } |
|
76 |
|
77 @Override |
|
78 Packet createPacket(Source msg) { |
|
79 Message message; |
|
80 |
|
81 if(msg==null) |
|
82 message = Messages.createEmpty(soapVersion); |
|
83 else |
|
84 message = new PayloadSourceMessage(null, msg, setOutboundAttachments(), soapVersion); |
|
85 |
|
86 return new Packet(message); |
|
87 } |
|
88 } |