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