1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.module.cxf.builder; |
12 | |
|
13 | |
import org.mule.api.lifecycle.CreateException; |
14 | |
import org.mule.module.cxf.CxfConstants; |
15 | |
import org.mule.module.cxf.CxfOutboundMessageProcessor; |
16 | |
import org.mule.module.cxf.support.CopyAttachmentInInterceptor; |
17 | |
import org.mule.module.cxf.support.CopyAttachmentOutInterceptor; |
18 | |
import org.mule.module.cxf.support.CxfUtils; |
19 | |
import org.mule.module.cxf.support.OutputPayloadInterceptor; |
20 | |
import org.mule.module.cxf.support.ProxyService; |
21 | |
import org.mule.module.cxf.support.ResetStaxInterceptor; |
22 | |
import org.mule.module.cxf.support.ReversibleStaxInInterceptor; |
23 | |
import org.mule.module.cxf.support.StreamClosingInterceptor; |
24 | |
import org.mule.module.cxf.transport.MuleUniversalConduit; |
25 | |
|
26 | |
import org.apache.cxf.binding.Binding; |
27 | |
import org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor; |
28 | |
import org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor; |
29 | |
import org.apache.cxf.binding.soap.interceptor.Soap12FaultInInterceptor; |
30 | |
import org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor; |
31 | |
import org.apache.cxf.databinding.stax.StaxDataBinding; |
32 | |
import org.apache.cxf.databinding.stax.StaxDataBindingFeature; |
33 | |
import org.apache.cxf.endpoint.Client; |
34 | |
import org.apache.cxf.frontend.ClientProxy; |
35 | |
import org.apache.cxf.frontend.ClientProxyFactoryBean; |
36 | |
import org.apache.cxf.interceptor.WrappedOutInterceptor; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | 0 | public class ProxyClientMessageProcessorBuilder extends AbstractOutboundMessageProcessorBuilder |
48 | |
{ |
49 | |
private String payload; |
50 | |
|
51 | |
@Override |
52 | |
protected void configureClient(Client client) |
53 | |
{ |
54 | 0 | MuleUniversalConduit conduit = (MuleUniversalConduit)client.getConduit(); |
55 | |
|
56 | |
|
57 | 0 | client.getInInterceptors().add(new CopyAttachmentInInterceptor()); |
58 | 0 | client.getInInterceptors().add(new StreamClosingInterceptor()); |
59 | 0 | client.getOutInterceptors().add(new OutputPayloadInterceptor()); |
60 | 0 | client.getOutInterceptors().add(new CopyAttachmentOutInterceptor()); |
61 | |
|
62 | |
|
63 | 0 | conduit.setCloseInput(false); |
64 | 0 | } |
65 | |
|
66 | |
public boolean isProxyEnvelope() |
67 | |
{ |
68 | 0 | return CxfConstants.PAYLOAD_ENVELOPE.equals(payload); |
69 | |
} |
70 | |
|
71 | |
@Override |
72 | |
protected void configureMessageProcessor(CxfOutboundMessageProcessor processor) |
73 | |
{ |
74 | 0 | processor.setProxy(true); |
75 | 0 | } |
76 | |
|
77 | |
@Override |
78 | |
protected Client createClient() throws CreateException, Exception |
79 | |
{ |
80 | 0 | ClientProxyFactoryBean cpf = new ClientProxyFactoryBean(); |
81 | 0 | cpf.setServiceClass(ProxyService.class); |
82 | 0 | cpf.setDataBinding(new StaxDataBinding()); |
83 | 0 | cpf.getFeatures().add(new StaxDataBindingFeature()); |
84 | 0 | cpf.setAddress(getAddress()); |
85 | 0 | cpf.setBus(getBus()); |
86 | 0 | cpf.setProperties(properties); |
87 | |
|
88 | 0 | if (wsdlLocation != null) |
89 | |
{ |
90 | 0 | cpf.setWsdlLocation(wsdlLocation); |
91 | |
} |
92 | |
|
93 | 0 | Client client = ClientProxy.getClient(cpf.create()); |
94 | |
|
95 | 0 | Binding binding = client.getEndpoint().getBinding(); |
96 | 0 | CxfUtils.removeInterceptor(binding.getOutInterceptors(), WrappedOutInterceptor.class.getName()); |
97 | 0 | CxfUtils.removeInterceptor(binding.getInInterceptors(), Soap11FaultInInterceptor.class.getName()); |
98 | 0 | CxfUtils.removeInterceptor(binding.getInInterceptors(), Soap12FaultInInterceptor.class.getName()); |
99 | 0 | CxfUtils.removeInterceptor(binding.getInInterceptors(), CheckFaultInterceptor.class.getName()); |
100 | |
|
101 | 0 | if (isProxyEnvelope()) |
102 | |
{ |
103 | 0 | CxfUtils.removeInterceptor(binding.getOutInterceptors(), SoapOutInterceptor.class.getName()); |
104 | 0 | client.getInInterceptors().add(new ReversibleStaxInInterceptor()); |
105 | 0 | client.getInInterceptors().add(new ResetStaxInterceptor()); |
106 | |
} |
107 | |
|
108 | 0 | return client; |
109 | |
} |
110 | |
|
111 | |
public String getPayload() |
112 | |
{ |
113 | 0 | return payload; |
114 | |
} |
115 | |
|
116 | |
public void setPayload(String payload) |
117 | |
{ |
118 | 0 | this.payload = payload; |
119 | 0 | } |
120 | |
|
121 | |
} |