1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.module.cxf.transport; |
12 | |
|
13 | |
import org.mule.module.cxf.support.DelegatingOutputStream; |
14 | |
|
15 | |
import java.io.ByteArrayOutputStream; |
16 | |
import java.io.IOException; |
17 | |
import java.io.OutputStream; |
18 | |
import java.net.HttpURLConnection; |
19 | |
import java.util.logging.Logger; |
20 | |
|
21 | |
import org.apache.cxf.message.Message; |
22 | |
import org.apache.cxf.service.model.EndpointInfo; |
23 | |
import org.apache.cxf.transport.AbstractConduit; |
24 | |
import org.apache.cxf.transport.AbstractDestination; |
25 | |
import org.apache.cxf.transport.Conduit; |
26 | |
import org.apache.cxf.transport.ConduitInitiator; |
27 | |
import org.apache.cxf.ws.addressing.EndpointReferenceType; |
28 | |
|
29 | 0 | public class MuleUniversalDestination extends AbstractDestination |
30 | |
{ |
31 | |
public static final String RESPONSE_OBSERVER = "mule.destination.response.observer"; |
32 | |
|
33 | 0 | private static final Logger LOGGER = Logger.getLogger(MuleUniversalDestination.class.getName()); |
34 | |
private MuleUniversalTransport transport; |
35 | |
|
36 | |
public MuleUniversalDestination(MuleUniversalTransport transport, |
37 | |
EndpointReferenceType ref, |
38 | |
EndpointInfo ei) |
39 | |
{ |
40 | 0 | super(ref, ei); |
41 | 0 | this.transport = transport; |
42 | 0 | } |
43 | |
|
44 | |
@Override |
45 | |
protected Conduit getInbuiltBackChannel(Message inMessage) |
46 | |
{ |
47 | 0 | return new ResponseConduit(null); |
48 | |
} |
49 | |
|
50 | |
@Override |
51 | |
protected Logger getLogger() |
52 | |
{ |
53 | 0 | return LOGGER; |
54 | |
} |
55 | |
|
56 | |
@Override |
57 | |
public void shutdown() |
58 | |
{ |
59 | 0 | transport.remove(this); |
60 | |
|
61 | 0 | super.shutdown(); |
62 | 0 | } |
63 | |
|
64 | |
@Override |
65 | |
protected boolean markPartialResponse(Message partialResponse, EndpointReferenceType decoupledTarget) |
66 | |
{ |
67 | |
|
68 | 0 | partialResponse.put(Message.RESPONSE_CODE, HttpURLConnection.HTTP_ACCEPTED); |
69 | 0 | partialResponse.getExchange().put(EndpointReferenceType.class, decoupledTarget); |
70 | 0 | return true; |
71 | |
} |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
@Override |
78 | |
protected ConduitInitiator getConduitInitiator() |
79 | |
{ |
80 | 0 | return transport; |
81 | |
} |
82 | |
|
83 | |
public class ResponseConduit extends AbstractConduit |
84 | |
{ |
85 | |
|
86 | |
public ResponseConduit(EndpointReferenceType arg0) |
87 | 0 | { |
88 | 0 | super(arg0); |
89 | 0 | } |
90 | |
|
91 | |
public void prepare(Message message) throws IOException { |
92 | |
|
93 | |
|
94 | 0 | DelegatingOutputStream stream = new DelegatingOutputStream(new ByteArrayOutputStream()); |
95 | 0 | message.setContent(OutputStream.class, stream); |
96 | 0 | message.setContent(DelegatingOutputStream.class, stream); |
97 | 0 | } |
98 | |
|
99 | |
@Override |
100 | |
public void close(Message message) throws IOException |
101 | |
{ |
102 | 0 | message.getContent(OutputStream.class).close(); |
103 | 0 | } |
104 | |
|
105 | |
@Override |
106 | |
protected Logger getLogger() |
107 | |
{ |
108 | 0 | return LOGGER; |
109 | |
} |
110 | |
|
111 | |
} |
112 | |
} |