summaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/util/client
diff options
context:
space:
mode:
authorThomas Lenz <thomas.lenz@egiz.gv.at>2019-03-08 08:07:11 +0100
committerThomas Lenz <thomas.lenz@egiz.gv.at>2019-03-08 08:07:11 +0100
commitc7e92047632432346c13723925f45888461887e9 (patch)
tree3cc1e96e2d0bc59047b484bbb86f227e21aa9cb9 /src/main/java/at/gv/util/client
parente5474ef416f8d9f6cb2c3b6e900ad1eb5ac20a38 (diff)
downloadegovutils-c7e92047632432346c13723925f45888461887e9.tar.gz
egovutils-c7e92047632432346c13723925f45888461887e9.tar.bz2
egovutils-c7e92047632432346c13723925f45888461887e9.zip
add USP_v2 client implementation
Diffstat (limited to 'src/main/java/at/gv/util/client')
-rw-r--r--src/main/java/at/gv/util/client/mis/usp_v2/USPClient.java185
-rw-r--r--src/main/java/at/gv/util/client/mis/usp_v2/USPClientException.java33
2 files changed, 218 insertions, 0 deletions
diff --git a/src/main/java/at/gv/util/client/mis/usp_v2/USPClient.java b/src/main/java/at/gv/util/client/mis/usp_v2/USPClient.java
new file mode 100644
index 0000000..334df87
--- /dev/null
+++ b/src/main/java/at/gv/util/client/mis/usp_v2/USPClient.java
@@ -0,0 +1,185 @@
+package at.gv.util.client.mis.usp_v2;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Resource;
+import javax.net.ssl.SSLContext;
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.handler.Handler;
+
+import org.apache.commons.lang.RandomStringUtils;
+import org.apache.cxf.configuration.jsse.TLSClientParameters;
+import org.apache.cxf.endpoint.Client;
+import org.apache.cxf.frontend.ClientProxy;
+import org.apache.cxf.transport.http.HTTPConduit;
+import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.gv.util.LaxHostNameVerifier;
+import at.gv.util.LoggingHandler;
+import at.gv.util.MiscUtil;
+import at.gv.util.client.szr.SZRSOAPHandler;
+import at.gv.util.config.EgovUtilConfiguration;
+import at.gv.util.ex.EgovUtilException;
+import at.gv.util.wsdl.mis.usp.GetMandatesPortType;
+import at.gv.util.wsdl.mis.usp.GetMandatesService;
+import at.gv.util.wsdl.mis.usp_v2.ISyncService;
+import at.gv.util.wsdl.mis.usp_v2.ListMandatesFault;
+import at.gv.util.wsdl.mis.usp_v2.SynchronisationServiceServiceagent;
+import at.gv.util.xsd.mis.usp.GetMandatesRequest;
+import at.gv.util.xsd.mis.usp.GetMandatesRequest.MandateFilters;
+import at.gv.util.xsd.mis.usp.GetMandatesResponse;
+import at.gv.util.xsd.mis.usp.IdentificationType;
+import at.gv.util.xsd.mis.usp_v2.eai.syncmsgs.ListMandatesRequest;
+import at.gv.util.xsd.mis.usp_v2.eai.syncmsgs.ListMandatesResponseType;
+import at.gv.util.xsd.szr.pvp.PvpTokenType;
+
+public class USPClient {
+
+ @Resource
+ WebServiceContext wsContext;
+
+ private EgovUtilConfiguration config = null;
+ private Logger log = LoggerFactory.getLogger(USPClient.class);
+ private boolean logEnabled = true;
+ private ISyncService uspSuche = null;
+
+ public USPClient(EgovUtilConfiguration config, boolean logEnabled) throws EgovUtilException {
+ MiscUtil.assertNotNull(config, "config");
+ this.config = config;
+ this.logEnabled = logEnabled;
+ initialize();
+ }
+
+// public GetMandatesResponse getMandates(String bpkType, String bpkValue, List<String> mandateFilters) {
+//
+// // assemble request
+// GetMandatesRequest request = new GetMandatesRequest();
+// String requestId = createUSPRequestId();
+// log.debug("USP request id: " + requestId);
+// request.setRequestId(requestId);
+// Date date = new Date();
+// try {
+// request.setTimestamp(MiscUtil.getXMLGregorianCalendar(date));
+// } catch (DatatypeConfigurationException e) {
+// log.warn("Error initializing USP client.", e);
+// return null;
+// }
+// log.debug("USP time stamp: " + date.toString());
+// request.setApplicationId(config.getUSPApplicationId());
+// log.debug("USP application id: " + config.getUSPApplicationId());
+//
+// // set identification
+// IdentificationType idt = new IdentificationType();
+// idt.setType(bpkType);
+// idt.setValue(bpkValue);
+// request.setIdentification(idt);
+//
+// // set filters
+// if (mandateFilters != null && mandateFilters.size() > 0) {
+// MandateFilters mf = new MandateFilters();
+// mf.getMandateFilter().addAll(mandateFilters);
+// request.setMandateFilters(mf);
+// }
+//
+// return this.uspSuche.getMandatesOperation(request);
+//
+//
+// }
+
+ public void getMandates(String bpkType, String bpkValue, List<String> mandateFilters) {
+ ListMandatesRequest parameters = new ListMandatesRequest();
+
+ //request USP
+ try {
+ ListMandatesResponseType results = this.uspSuche.listMandates(parameters );
+
+ } catch (ListMandatesFault e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ private void initialize() throws EgovUtilException {
+ URL url = USPClient.class.getResource("/wsdl/mis/usp_v2/Synchronisation-1.wsdl");
+ SynchronisationServiceServiceagent uspService = null;
+ String uspURL = null;
+ uspService = new SynchronisationServiceServiceagent(url);
+ uspSuche = uspService.getISyncServiceEndpoint();
+
+ if (config.isUSPTestEnvironment()) {
+ log.trace("Initializing USP test configuration.");
+ uspURL = config.getUSPTestEnvironmentURL();
+ } else {
+ log.trace("Initializing USP productive configuration.");
+ uspURL = config.getUSPProductionEnvironmentURL();
+ }
+ log.trace("USP connection URL: " + uspURL);
+ BindingProvider bindingProvider = (BindingProvider) uspSuche;
+ Map<String, Object> requestContext = bindingProvider.getRequestContext();
+ requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, uspURL);
+
+ log.trace("Adding JAX-WS request/response trace handler.");
+ List<Handler> handlerList = bindingProvider.getBinding().getHandlerChain();
+ if (handlerList == null) {
+ handlerList = new ArrayList();
+ }
+ LoggingHandler loggingHandler = new LoggingHandler();
+ if (this.logEnabled) {
+ handlerList.add(loggingHandler);
+ }
+
+ // PV authentication
+ log.trace("Adding WS-Security Header handler.");
+ PvpTokenType pvpToken = config.getURPVPToken();
+ SZRSOAPHandler szrSOAPHandler = new SZRSOAPHandler();
+ szrSOAPHandler.configure(pvpToken);
+ handlerList.add(szrSOAPHandler);
+ bindingProvider.getBinding().setHandlerChain(handlerList);
+
+ Client client = ClientProxy.getClient(uspSuche);
+ HTTPConduit http = (HTTPConduit) client.getConduit();
+ HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
+
+ //set HTTP Client Timeout (Default Timeout 60sec)
+ httpClientPolicy.setConnectionTimeout(this.config.getHTTPRequestTimeout());
+ httpClientPolicy.setAllowChunking(false);
+ httpClientPolicy.setReceiveTimeout(32000);
+ http.setClient(httpClientPolicy);
+
+ // check for ssl
+ if (uspURL.toLowerCase().startsWith("https")) {
+ log.trace("Using ssl for SZR client request.");
+ SSLContext sslContext = this.config.getUSPsslConfiguration().getSSLContext(false);
+ if (sslContext == null) {
+ throw new EgovUtilException("SSL context from configuration is empty. Please configure an SSL context in the configuration first.");
+
+ }
+
+ TLSClientParameters tlsParams = new TLSClientParameters();
+ tlsParams.setSSLSocketFactory(sslContext.getSocketFactory());
+
+ // check for lax hostname
+ if (this.config.getUSPsslConfiguration().useLaxHostNameVerifier()) {
+ log.trace("LaxHostnameVerifier enabled. This setting is not recommended to use.");
+ tlsParams.setHostnameVerifier(new LaxHostNameVerifier());
+ }
+ http.setTlsClientParameters(tlsParams );
+ }
+ }
+
+ private String createUSPRequestId() {
+ return RandomStringUtils.randomAlphanumeric(12);
+ }
+
+}
diff --git a/src/main/java/at/gv/util/client/mis/usp_v2/USPClientException.java b/src/main/java/at/gv/util/client/mis/usp_v2/USPClientException.java
new file mode 100644
index 0000000..96ad965
--- /dev/null
+++ b/src/main/java/at/gv/util/client/mis/usp_v2/USPClientException.java
@@ -0,0 +1,33 @@
+package at.gv.util.client.mis.usp_v2;
+
+public class USPClientException extends Exception {
+
+ private static final long serialVersionUID = 5173056345209288701L;
+
+ private int code = -1;
+
+ public USPClientException(int code) {
+ super();
+ this.code = code;
+ }
+
+ public USPClientException(String message, int code, Throwable cause) {
+ super(message, cause);
+ this.code = code;
+ }
+
+ public USPClientException(String message, int code) {
+ super(message);
+ this.code = code;
+ }
+
+ public USPClientException(int code, Throwable cause) {
+ super(cause);
+ this.code = code;
+ }
+
+ public int getCode() {
+ return this.code;
+ }
+
+}