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 public class ProxyClientMessageProcessorBuilder extends AbstractOutboundMessageProcessorBuilder
48 {
49 private String payload;
50
51 @Override
52 protected void configureClient(Client client)
53 {
54 MuleUniversalConduit conduit = (MuleUniversalConduit)client.getConduit();
55
56
57 client.getInInterceptors().add(new CopyAttachmentInInterceptor());
58 client.getInInterceptors().add(new StreamClosingInterceptor());
59 client.getOutInterceptors().add(new OutputPayloadInterceptor());
60 client.getOutInterceptors().add(new CopyAttachmentOutInterceptor());
61
62
63 conduit.setCloseInput(false);
64 }
65
66 public boolean isProxyEnvelope()
67 {
68 return CxfConstants.PAYLOAD_ENVELOPE.equals(payload);
69 }
70
71 @Override
72 protected void configureMessageProcessor(CxfOutboundMessageProcessor processor)
73 {
74 processor.setProxy(true);
75 }
76
77 @Override
78 protected Client createClient() throws CreateException, Exception
79 {
80 ClientProxyFactoryBean cpf = new ClientProxyFactoryBean();
81 cpf.setServiceClass(ProxyService.class);
82 cpf.setDataBinding(new StaxDataBinding());
83 cpf.getFeatures().add(new StaxDataBindingFeature());
84 cpf.setAddress(getAddress());
85 cpf.setBus(getBus());
86 cpf.setProperties(properties);
87
88 if (wsdlLocation != null)
89 {
90 cpf.setWsdlLocation(wsdlLocation);
91 }
92
93 Client client = ClientProxy.getClient(cpf.create());
94
95 Binding binding = client.getEndpoint().getBinding();
96 CxfUtils.removeInterceptor(binding.getOutInterceptors(), WrappedOutInterceptor.class.getName());
97 CxfUtils.removeInterceptor(binding.getInInterceptors(), Soap11FaultInInterceptor.class.getName());
98 CxfUtils.removeInterceptor(binding.getInInterceptors(), Soap12FaultInInterceptor.class.getName());
99 CxfUtils.removeInterceptor(binding.getInInterceptors(), CheckFaultInterceptor.class.getName());
100
101 if (isProxyEnvelope())
102 {
103 CxfUtils.removeInterceptor(binding.getOutInterceptors(), SoapOutInterceptor.class.getName());
104 client.getInInterceptors().add(new ReversibleStaxInInterceptor());
105 client.getInInterceptors().add(new ResetStaxInterceptor());
106 }
107
108 return client;
109 }
110
111 public String getPayload()
112 {
113 return payload;
114 }
115
116 public void setPayload(String payload)
117 {
118 this.payload = payload;
119 }
120
121 }