1
2
3
4
5
6
7
8
9
10
11 package org.mule.module.cxf.builder;
12
13 import org.mule.module.cxf.CxfConstants;
14 import org.mule.module.cxf.support.CopyAttachmentInInterceptor;
15 import org.mule.module.cxf.support.CopyAttachmentOutInterceptor;
16 import org.mule.module.cxf.support.CxfUtils;
17 import org.mule.module.cxf.support.OutputPayloadInterceptor;
18 import org.mule.module.cxf.support.ProxySchemaValidationInInterceptor;
19 import org.mule.module.cxf.support.ProxyService;
20 import org.mule.module.cxf.support.ProxyServiceFactoryBean;
21 import org.mule.module.cxf.support.ResetStaxInterceptor;
22 import org.mule.module.cxf.support.ReversibleStaxInInterceptor;
23
24 import org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor;
25 import org.apache.cxf.databinding.stax.StaxDataBinding;
26 import org.apache.cxf.databinding.stax.StaxDataBindingFeature;
27 import org.apache.cxf.endpoint.Server;
28 import org.apache.cxf.frontend.ServerFactoryBean;
29
30
31
32
33
34
35
36
37
38
39 public class ProxyServiceMessageProcessorBuilder extends AbstractInboundMessageProcessorBuilder
40 {
41 private String payload;
42
43 @Override
44 protected ServerFactoryBean createServerFactory() throws Exception
45 {
46 ServerFactoryBean sfb = new ServerFactoryBean();
47 sfb.setDataBinding(new StaxDataBinding());
48 sfb.getFeatures().add(new StaxDataBindingFeature());
49 sfb.setServiceFactory(new ProxyServiceFactoryBean());
50 sfb.setServiceClass(ProxyService.class);
51
52 addProxyInterceptors(sfb);
53
54 return sfb;
55 }
56
57 @Override
58 protected Class<?> getServiceClass()
59 {
60 return ProxyService.class;
61 }
62
63 @Override
64 protected void configureServer(Server server)
65 {
66 if (isProxyEnvelope())
67 {
68 CxfUtils.removeInterceptor(server.getEndpoint().getBinding().getOutInterceptors(), SoapOutInterceptor.class.getName());
69 }
70
71 if (isValidationEnabled())
72 {
73 server.getEndpoint().getInInterceptors().add(new ProxySchemaValidationInInterceptor(getConfiguration().getCxfBus(),
74 server.getEndpoint().getService().getServiceInfos().get(0)));
75 }
76 }
77
78 @Override
79 public boolean isProxy()
80 {
81 return true;
82 }
83
84 protected void addProxyInterceptors(ServerFactoryBean sfb)
85 {
86 sfb.getOutInterceptors().add(new OutputPayloadInterceptor());
87 sfb.getInInterceptors().add(new CopyAttachmentInInterceptor());
88 sfb.getOutInterceptors().add(new CopyAttachmentOutInterceptor());
89
90 if (isProxyEnvelope())
91 {
92 sfb.getInInterceptors().add(new ReversibleStaxInInterceptor());
93 sfb.getInInterceptors().add(new ResetStaxInterceptor());
94 }
95 }
96
97 public boolean isProxyEnvelope()
98 {
99 return CxfConstants.PAYLOAD_ENVELOPE.equals(payload);
100 }
101
102 public String getPayload()
103 {
104 return payload;
105 }
106
107 public void setPayload(String payload)
108 {
109 this.payload = payload;
110 }
111
112 }