1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.camel.component.cxf; |
18 |
|
|
19 |
|
import java.util.List; |
20 |
|
|
21 |
|
import org.apache.camel.Exchange; |
22 |
|
import org.apache.camel.RuntimeCamelException; |
23 |
|
import org.apache.camel.impl.DefaultProducer; |
24 |
|
import org.apache.camel.util.ObjectHelper; |
25 |
|
import org.apache.cxf.endpoint.Client; |
26 |
|
import org.apache.cxf.frontend.ClientFactoryBean; |
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
public class CxfInvokeProducer extends DefaultProducer { |
34 |
|
private CxfInvokeEndpoint endpoint; |
35 |
|
private Client client; |
36 |
|
|
37 |
|
public CxfInvokeProducer(CxfInvokeEndpoint endpoint) { |
38 |
1 |
super(endpoint); |
39 |
1 |
this.endpoint = endpoint; |
40 |
1 |
} |
41 |
|
|
42 |
|
public void process(Exchange exchange) { |
43 |
1 |
CxfExchange cxfExchange = endpoint.toExchangeType(exchange); |
44 |
1 |
process(cxfExchange); |
45 |
1 |
exchange.copyFrom(cxfExchange); |
46 |
1 |
} |
47 |
|
|
48 |
|
public void process(CxfExchange exchange) { |
49 |
1 |
List params = exchange.getIn().getBody(List.class); |
50 |
1 |
Object[] response = null; |
51 |
|
try { |
52 |
1 |
response = client.invoke(endpoint.getProperty(CxfConstants.METHOD), params.toArray()); |
53 |
0 |
} catch (Exception e) { |
54 |
0 |
throw new RuntimeCamelException(e); |
55 |
1 |
} |
56 |
|
|
57 |
1 |
CxfBinding binding = endpoint.getBinding(); |
58 |
1 |
binding.storeCxfResponse(exchange, response); |
59 |
1 |
} |
60 |
|
|
61 |
|
@Override |
62 |
|
protected void doStart() throws Exception { |
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
1 |
if (client == null) { |
69 |
1 |
ClientFactoryBean cfBean = new ClientFactoryBean(); |
70 |
1 |
cfBean.setAddress(getEndpoint().getEndpointUri()); |
71 |
1 |
cfBean.setBus(endpoint.getBus()); |
72 |
1 |
String className = endpoint.getProperty(CxfConstants.SEI); |
73 |
1 |
Class type = ObjectHelper.loadClass(className); |
74 |
1 |
cfBean.setServiceClass(type); |
75 |
1 |
client = cfBean.create(); |
76 |
|
} |
77 |
1 |
} |
78 |
|
|
79 |
|
@Override |
80 |
|
protected void doStop() throws Exception { |
81 |
0 |
if (client != null) { |
82 |
0 |
client.getConduit().close(); |
83 |
0 |
client = null; |
84 |
|
} |
85 |
|
|
86 |
0 |
super.doStop(); |
87 |
0 |
} |
88 |
|
} |