1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.client.lib.batch;
20
21 import java.io.IOException;
22 import java.net.URI;
23 import java.util.ArrayList;
24 import java.util.List;
25 import org.apache.cxf.endpoint.ConduitSelector;
26 import org.apache.cxf.endpoint.Endpoint;
27 import org.apache.cxf.endpoint.UpfrontConduitSelector;
28 import org.apache.cxf.jaxrs.client.ClientProxyImpl;
29 import org.apache.cxf.jaxrs.client.ClientState;
30 import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
31 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
32 import org.apache.syncope.common.rest.api.batch.BatchRequestItem;
33
34 public class BatchClientFactoryBean extends JAXRSClientFactoryBean {
35
36 private final List<BatchRequestItem> batchRequestItems = new ArrayList<>();
37
38 @Override
39 protected ConduitSelector getConduitSelector(final Endpoint ep) {
40 ConduitSelector cs = getConduitSelector();
41 if (cs == null) {
42 try {
43 cs = new UpfrontConduitSelector(new BatchOfflineHTTPConduit(bus, ep.getEndpointInfo()));
44 } catch (IOException e) {
45 throw new IllegalArgumentException("Could not create " + BatchOfflineHTTPConduit.class.getName(), e);
46 }
47 }
48 cs.setEndpoint(ep);
49 return cs;
50 }
51
52 @Override
53 protected ClientProxyImpl createClientProxy(
54 final ClassResourceInfo cri,
55 final boolean isRoot,
56 final ClientState actualState,
57 final Object[] varValues) {
58
59 if (actualState == null) {
60 return new BatchClientProxyImpl(
61 this, URI.create(getAddress()), proxyLoader, cri, isRoot, inheritHeaders, varValues);
62 } else {
63 return new BatchClientProxyImpl(
64 this, actualState, proxyLoader, cri, isRoot, inheritHeaders, varValues);
65 }
66 }
67
68 public boolean add(final BatchRequestItem item) {
69 return this.batchRequestItems.add(item);
70 }
71
72 public List<BatchRequestItem> getBatchRequestItems() {
73 return batchRequestItems;
74 }
75 }