| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
package org.apache.camel.component.cxf; |
| 19 |
|
|
| 20 |
|
import org.apache.camel.RuntimeCamelException; |
| 21 |
|
import org.apache.camel.Exchange; |
| 22 |
|
import org.apache.camel.impl.DefaultProducer; |
| 23 |
|
import org.apache.cxf.endpoint.Client; |
| 24 |
|
import org.apache.cxf.frontend.ClientFactoryBean; |
| 25 |
|
|
| 26 |
|
import java.util.List; |
| 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 |
|
} |
| 54 |
0 |
catch (Exception e) { |
| 55 |
0 |
throw new RuntimeCamelException(e); |
| 56 |
1 |
} |
| 57 |
|
|
| 58 |
1 |
CxfBinding binding = endpoint.getBinding(); |
| 59 |
1 |
binding.storeCxfResponse(exchange, response); |
| 60 |
1 |
} |
| 61 |
|
|
| 62 |
|
@Override |
| 63 |
|
protected void doStart() throws Exception { |
| 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 |
cfBean.setServiceClass(Class.forName(endpoint.getProperty(CxfConstants.SEI))); |
| 73 |
1 |
client = cfBean.create(); |
| 74 |
|
} |
| 75 |
1 |
} |
| 76 |
|
|
| 77 |
|
@Override |
| 78 |
|
protected void doStop() throws Exception { |
| 79 |
0 |
if (client != null) { |
| 80 |
0 |
client.getConduit().close(); |
| 81 |
0 |
client = null; |
| 82 |
|
} |
| 83 |
|
|
| 84 |
0 |
super.doStop(); |
| 85 |
0 |
} |
| 86 |
|
} |
| 87 |
|
|
| 88 |
|
|