aboutsummaryrefslogtreecommitdiff
path: root/spss.handbook/clients/webservice/src/at
diff options
context:
space:
mode:
authorgregor <gregor@d688527b-c9ab-4aba-bd8d-4036d912da1d>2004-08-05 12:05:45 +0000
committergregor <gregor@d688527b-c9ab-4aba-bd8d-4036d912da1d>2004-08-05 12:05:45 +0000
commit2baad7fa9e23016a7d40977c8c4e6aa1aebc6ffd (patch)
treee8a69d27f282b810d288d45d0e43db5ec5b03b84 /spss.handbook/clients/webservice/src/at
parent0e1015514b0e02436a6863d7afe930008e9b6f26 (diff)
downloadmoa-id-spss-2baad7fa9e23016a7d40977c8c4e6aa1aebc6ffd.tar.gz
moa-id-spss-2baad7fa9e23016a7d40977c8c4e6aa1aebc6ffd.tar.bz2
moa-id-spss-2baad7fa9e23016a7d40977c8c4e6aa1aebc6ffd.zip
Neuorganisation des Handbuchs. Auslagerung in ein eigenes Projekt.
git-svn-id: https://joinup.ec.europa.eu/svn/moa-idspss/trunk@163 d688527b-c9ab-4aba-bd8d-4036d912da1d
Diffstat (limited to 'spss.handbook/clients/webservice/src/at')
-rw-r--r--spss.handbook/clients/webservice/src/at/gv/egovernment/moa/spss/handbook/clients/webservice/HTTP.java114
-rw-r--r--spss.handbook/clients/webservice/src/at/gv/egovernment/moa/spss/handbook/clients/webservice/HTTPSClientAuth.java154
-rw-r--r--spss.handbook/clients/webservice/src/at/gv/egovernment/moa/spss/handbook/clients/webservice/HTTPSServerAuth.java142
3 files changed, 410 insertions, 0 deletions
diff --git a/spss.handbook/clients/webservice/src/at/gv/egovernment/moa/spss/handbook/clients/webservice/HTTP.java b/spss.handbook/clients/webservice/src/at/gv/egovernment/moa/spss/handbook/clients/webservice/HTTP.java
new file mode 100644
index 000000000..646c53947
--- /dev/null
+++ b/spss.handbook/clients/webservice/src/at/gv/egovernment/moa/spss/handbook/clients/webservice/HTTP.java
@@ -0,0 +1,114 @@
+package at.gv.egovernment.moa.spss.handbook.clients.webservice;
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.util.Vector;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.rpc.Call;
+import javax.xml.rpc.Service;
+import javax.xml.rpc.ServiceFactory;
+
+import org.apache.axis.message.SOAPBodyElement;
+import org.apache.xml.serialize.OutputFormat;
+import org.apache.xml.serialize.XMLSerializer;
+import org.w3c.dom.Document;
+
+/**
+ * Diese Klasse implementiert einen einfachen Client f�r das MOA SP/SS Webservice mittels Apache Axis. Die
+ * Verbindung erfolgt ungesichert �ber HTTP.
+ */
+public class HTTP
+{
+ // Zugangspunkt f�r Signaturerstellung (SS)
+ private static final QName SERVICE_QNAME_ = new QName("SignatureCreation");
+ private static final String ENDPOINT_ = "http://localhost:8080/moa-spss/services/SignatureCreation";
+
+ // Zugangspunkt f�r Signaturpr�fung (SP)
+// private static final QName SERVICE_QNAME_ = new QName("SignatureVerification");
+// private static final String ENDPOINT_ ="http://localhost:8080/moa-spss/services/SignatureVerification";
+
+ // Datei mit dem zu sendenden XML-Request
+ private static final String XML_REQUEST_FILENAME_ =
+ "clients/common/resources/requests/CreateXMLSignatureRequest1.xml";
+// "clients/common/resources/requests/CreateXMLSignatureRequest2.xml";
+// "clients/common/resources/requests/VerifyCMSSignatureRequest.xml";
+// "clients/common/resources/requests/VerifyXMLSignatureRequest1.xml";
+// "clients/common/resources/requests/VerifyXMLSignatureRequest2.xml";
+
+ /**
+ * Methode main.
+ *
+ * Enth�lt den Beispielcode der n�tig ist um von Java aus auf MOA-SPSS zugreifen zu k�nnen. Der Zugriff
+ * passiert �ber das AXIS-Framework. Die Verbindung erfolgt ungesichert �ber HTTP.
+ *
+ * @param args Wird nicht verwendet.
+ */
+ public static void main(String[] args)
+ {
+ try
+ {
+ // Datei mit Request einlesen
+ FileInputStream inputStream = new FileInputStream(XML_REQUEST_FILENAME_);
+
+ // Parser/DOMBuilder instanzieren
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+
+ // XML Datei in einen DOM-Baum umwandeln
+ Document xmlRequest = builder.parse(inputStream);
+
+ // AXIS-Server instanzieren
+ Service service = ServiceFactory.newInstance().createService(SERVICE_QNAME_);
+
+ // Call �ffnen
+ Call call = service.createCall();
+
+ // Neues BodyElement anlegen und mit dem DOM-Baum f�llen
+ SOAPBodyElement body = new SOAPBodyElement(xmlRequest.getDocumentElement());
+ SOAPBodyElement[] params = new SOAPBodyElement[]
+ {
+ body
+ };
+
+ // Call mit Endpoint verkn�pfen
+ call.setTargetEndpointAddress(ENDPOINT_);
+
+ // Call ausl�sen und die Antworten speichern
+ System.out.println("Calling ...");
+ Vector responses = (Vector) call.invoke(params);
+
+ // Erstes Body Element auslesen
+ SOAPBodyElement response = (SOAPBodyElement) responses.get(0);
+
+ // Aus der Response den DOM-Baum lesen
+ Document root_response = response.getAsDocument();
+ System.out.println("Return ...");
+
+ // XML-Formatierung konfiguieren
+ OutputFormat format = new OutputFormat((Document) root_response);
+ format.setLineSeparator("\n");
+ format.setIndenting(false);
+ format.setPreserveSpace(true);
+ format.setOmitXMLDeclaration(false);
+ format.setEncoding("UTF-8");
+
+ // Ausgabe der Webservice-Antwort auf die Konsole
+ XMLSerializer conSerializer = new XMLSerializer(System.out, format);
+ conSerializer.serialize(root_response);
+
+ // Ausgabe der Webservice-Antwort in Datei
+ String responseFile = XML_REQUEST_FILENAME_.substring(0, XML_REQUEST_FILENAME_.lastIndexOf('.'))
+ + ".response.xml";
+ XMLSerializer fileSerializer = new XMLSerializer(new FileOutputStream(responseFile), format);
+ fileSerializer.serialize(root_response);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+} \ No newline at end of file
diff --git a/spss.handbook/clients/webservice/src/at/gv/egovernment/moa/spss/handbook/clients/webservice/HTTPSClientAuth.java b/spss.handbook/clients/webservice/src/at/gv/egovernment/moa/spss/handbook/clients/webservice/HTTPSClientAuth.java
new file mode 100644
index 000000000..4d3b6641d
--- /dev/null
+++ b/spss.handbook/clients/webservice/src/at/gv/egovernment/moa/spss/handbook/clients/webservice/HTTPSClientAuth.java
@@ -0,0 +1,154 @@
+package at.gv.egovernment.moa.spss.handbook.clients.webservice;
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.security.Security;
+import java.util.Vector;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.rpc.Call;
+import javax.xml.rpc.Service;
+import javax.xml.rpc.ServiceFactory;
+
+import org.apache.axis.message.SOAPBodyElement;
+import org.apache.xml.serialize.OutputFormat;
+import org.apache.xml.serialize.XMLSerializer;
+import org.w3c.dom.Document;
+
+import com.sun.net.ssl.internal.ssl.Provider;
+
+/**
+ * Diese Klasse implementiert einen einfachen Client f�r das MOA SP/SS Webservice mittels Apache Axis. Die
+ * Verbindung erfolgt gesichert �ber SSL, und zwar sowohl mit Server- und Clientauthentisierung.
+ */
+public class HTTPSClientAuth
+{
+ // Zugangspunkt f�r Signaturerstellung (SS)
+ private static final QName SERVICE_QNAME_ = new QName("SignatureCreation");
+ private static final String SECURE_ENDPOINT_ = "https://localhost:8443/moa-spss/services/SignatureCreation";
+
+ // Zugangspunkt f�r Signaturpr�fung (SP)
+// private static final QName SERVICE_QNAME_ = new QName("SignatureVerification");
+// private static final String SECURE_ENDPOINT_ = "https://localhost:8443/moa-spss/services/SignatureVerification";
+
+ // Datei mit dem zu sendenden XML-Request
+ private static final String XML_REQUEST_FILENAME_ =
+ "clients/common/resources/requests/CreateXMLSignatureRequest1.xml";
+// "clients/common/resources/requests/CreateXMLSignatureRequest2.xml";
+// "clients/common/resources/requests/VerifyCMSSignatureRequest.xml";
+// "clients/common/resources/requests/VerifyXMLSignatureRequest1.xml";
+// "clients/common/resources/requests/VerifyXMLSignatureRequest2.xml";
+
+ // SSL Konstanten
+ public static final String HANDLER = "java.protocol.handler.pkgs";
+
+ public static final String KEYSTORE = "javax.net.ssl.keyStore";
+ public static final String KEYSTOREPASSWORD = "javax.net.ssl.keyStorePassword";
+ public static final String KEYSTORETYPE = "javax.net.ssl.keyStoreType";
+
+ public static final String TRUSTSTORE = "javax.net.ssl.trustStore";
+ public static final String TRUSTSTOREPASSWORD = "javax.net.ssl.trustStorePassword";
+ public static final String TRUSTSTORETYPE = "javax.net.ssl.trustStoreType";
+
+ /**
+ * Methode main.
+ *
+ * Enth�lt den Beispielcode der n�tig ist um von Java aus auf MOA-SPSS zugreifen zu k�nnen. Der Zugriff
+ * passiert �ber das AXIS-Framework. Die Verbindung ist eine SSL Verbindung mit Clientauthentisierung.
+ *
+ * @param args Wird nicht verwendet.
+ */
+ public static void main(String[] args)
+ {
+ try
+ {
+ configureSSL();
+
+ // Datei mit Request einlesen
+ FileInputStream inputStream = new FileInputStream(XML_REQUEST_FILENAME_);
+
+ // Parser/DOMBuilder instanzieren
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+
+ // XML Datei in einen DOM-Baum umwandeln
+ Document root_request = builder.parse(inputStream);
+
+ // AXIS-Server instanzieren
+ Service service = ServiceFactory.newInstance().createService(SERVICE_QNAME_);
+
+ // Call �ffnen
+ Call call = service.createCall();
+
+ // Neues BodyElement anlegen und mit dem DOM-Baum f�llen
+ SOAPBodyElement body = new SOAPBodyElement(root_request.getDocumentElement());
+ SOAPBodyElement[] params = new SOAPBodyElement[]
+ {
+ body
+ };
+
+ // Call mit Endpoint verkn�pfen
+ call.setTargetEndpointAddress(SECURE_ENDPOINT_);
+
+ // Call ausl�sen und die Antworten speichern
+ System.out.println("Calling ...");
+ Vector responses = (Vector) call.invoke(params);
+
+ // Erstes BodyElement auslesen
+ SOAPBodyElement response = (SOAPBodyElement) responses.get(0);
+
+ // Aus der Response den DOM-Baum lesen
+ Document root_response = response.getAsDocument();
+ System.out.println("Return ...");
+
+ // XML-Formatierung konfiguieren
+ OutputFormat format = new OutputFormat((Document) root_response);
+ format.setLineSeparator("\n");
+ format.setIndenting(false);
+ format.setPreserveSpace(true);
+ format.setOmitXMLDeclaration(false);
+ format.setEncoding("UTF-8");
+
+ // Ausgabe der Webservice-Antwort auf die Konsole
+ XMLSerializer conSerializer = new XMLSerializer(System.out, format);
+ conSerializer.serialize(root_response);
+
+ // Ausgabe der Webservice-Antwort in Datei
+ String responseFile = XML_REQUEST_FILENAME_.substring(0, XML_REQUEST_FILENAME_.lastIndexOf('.'))
+ + ".response.xml";
+ XMLSerializer fileSerializer = new XMLSerializer(new FileOutputStream(responseFile), format);
+ fileSerializer.serialize(root_response);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Konfiguriert JSSE f�r eine SSL-Verbindung mit Client- und Serverauthentisierung.
+ */
+ private static void configureSSL()
+ {
+ Security.addProvider(new Provider());
+ System.setProperty(HANDLER, "com.sun.net.ssl.internal.www.protocol");
+
+ // Konfiguriere Key-Store (enth�lt privaten Schluessel und Zertifikat des Clients
+ System.setProperty(KEYSTORETYPE, "PKCS12");
+ System.setProperty(KEYSTORE,
+ "clients/webservice/resources/sslKeys/customer1/moa-ssl-kunde1(pwd=kunde1).p12");
+// "clients/webservice/resources/sslKeys/customer2/moa-ssl-kunde2(pwd=kunde2).p12");
+ System.setProperty(KEYSTOREPASSWORD, "kunde1");
+// System.setProperty(KEYSTOREPASSWORD, "kunde2");
+
+ // Konfiguriere Trust-Store (enth�lt SSL-Zertifikat des MOA Services, dem vertraut wird)
+ System.setProperty(TRUSTSTORETYPE, "JKS");
+ System.setProperty(TRUSTSTORE,
+ "clients/webservice/resources/sslKeys/customer1/trustedServers(pwd=servers).keystore");
+// "clients/webservice/resources/sslKeys/customer2/trustedServers(pwd=servers).keystore");
+ System.setProperty(TRUSTSTOREPASSWORD, "servers");
+ }
+} \ No newline at end of file
diff --git a/spss.handbook/clients/webservice/src/at/gv/egovernment/moa/spss/handbook/clients/webservice/HTTPSServerAuth.java b/spss.handbook/clients/webservice/src/at/gv/egovernment/moa/spss/handbook/clients/webservice/HTTPSServerAuth.java
new file mode 100644
index 000000000..cd5036b7d
--- /dev/null
+++ b/spss.handbook/clients/webservice/src/at/gv/egovernment/moa/spss/handbook/clients/webservice/HTTPSServerAuth.java
@@ -0,0 +1,142 @@
+package at.gv.egovernment.moa.spss.handbook.clients.webservice;
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.security.Security;
+import java.util.Vector;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.rpc.Call;
+import javax.xml.rpc.Service;
+import javax.xml.rpc.ServiceFactory;
+
+import org.apache.axis.message.SOAPBodyElement;
+import org.apache.xml.serialize.OutputFormat;
+import org.apache.xml.serialize.XMLSerializer;
+import org.w3c.dom.Document;
+
+import com.sun.net.ssl.internal.ssl.Provider;
+
+/**
+ * Diese Klasse implementiert einen einfachen Client f�r das MOA SP/SS Webservice mittels Apache Axis. Die
+ * Verbindung erfolgt gesichert �ber SSL, und zwar nur mit Serverauthentisierung.
+ */
+public class HTTPSServerAuth
+{
+ // Zugangspunkt f�r Signaturerstellung (SS)
+ private static final QName SERVICE_QNAME_ = new QName("SignatureCreation");
+ private static final String SECURE_ENDPOINT_ = "https://localhost:8443/moa-spss/services/SignatureCreation";
+
+ // Zugangspunkt f�r Signaturpr�fung (SP)
+// private static final QName SERVICE_QNAME_ = new QName("SignatureVerification");
+// private static final String SECURE_ENDPOINT_ = "https://localhost:8443/moa-spss/services/SignatureVerification";
+
+ // Datei mit dem zu sendenden XML-Request
+ private static final String XML_REQUEST_FILENAME_ =
+ "clients/common/resources/requests/CreateXMLSignatureRequest1.xml";
+// "clients/common/resources/requests/CreateXMLSignatureRequest2.xml";
+// "clients/common/resources/requests/VerifyCMSSignatureRequest.xml";
+// "clients/common/resources/requests/VerifyXMLSignatureRequest1.xml";
+// "clients/common/resources/requests/VerifyXMLSignatureRequest2.xml";
+
+ // SSL Konstanten
+ public static final String HANDLER = "java.protocol.handler.pkgs";
+
+ public static final String TRUSTSTORE = "javax.net.ssl.trustStore";
+ public static final String TRUSTSTOREPASSWORD = "javax.net.ssl.trustStorePassword";
+ public static final String TRUSTSTORETYPE = "javax.net.ssl.trustStoreType";
+
+ /**
+ * Methode main.
+ *
+ * Enth�lt den Beispielcode der n�tig ist um von Java aus auf MOA-SPSS zugreifen zu k�nnen. Der Zugriff
+ * passiert �ber das AXIS-Framework. Die Verbindung ist eine SSL Verbindung mit Serverauthentisierung.
+ *
+ * @param args Wird nicht verwendet.
+ */
+ public static void main(String[] args)
+ {
+ try
+ {
+ configureSSL();
+
+ // Datei mit Request einlesen
+ FileInputStream inputStream = new FileInputStream(XML_REQUEST_FILENAME_);
+
+ // Parser/DOMBuilder instanzieren
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+
+ // XML Datei in einen DOM-Baum umwandeln
+ Document root_request = builder.parse(inputStream);
+
+ // AXIS-Server instanzieren
+ Service service = ServiceFactory.newInstance().createService(SERVICE_QNAME_);
+
+ // Call �ffnen
+ Call call = service.createCall();
+
+ // Neues BodyElement anlegen und mit dem DOM-Baum f�llen
+ SOAPBodyElement body = new SOAPBodyElement(root_request.getDocumentElement());
+ SOAPBodyElement[] params = new SOAPBodyElement[]
+ {
+ body
+ };
+
+ // Call mit Endpoint verkn�pfen
+ call.setTargetEndpointAddress(SECURE_ENDPOINT_);
+
+ // Call ausl�sen und die Antworten speichern
+ System.out.println("Calling ...");
+ Vector responses = (Vector) call.invoke(params);
+
+ // Erstes BodyElement auslesen
+ SOAPBodyElement response = (SOAPBodyElement) responses.get(0);
+
+ // Aus der Response den DOM-Baum lesen
+ Document root_response = response.getAsDocument();
+ System.out.println("Return ...");
+
+ // XML-Formatierung konfiguieren
+ OutputFormat format = new OutputFormat((Document) root_response);
+ format.setLineSeparator("\n");
+ format.setIndenting(false);
+ format.setPreserveSpace(true);
+ format.setOmitXMLDeclaration(false);
+ format.setEncoding("UTF-8");
+
+ // Ausgabe der Webservice-Antwort auf die Konsole
+ XMLSerializer conSerializer = new XMLSerializer(System.out, format);
+ conSerializer.serialize(root_response);
+
+ // Ausgabe der Webservice-Antwort in Datei
+ String responseFile = XML_REQUEST_FILENAME_.substring(0, XML_REQUEST_FILENAME_.lastIndexOf('.'))
+ + ".response.xml";
+ XMLSerializer fileSerializer = new XMLSerializer(new FileOutputStream(responseFile), format);
+ fileSerializer.serialize(root_response);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Konfiguriert JSSE f�r eine SSL-Verbindung mit Serverauthentisierung.
+ */
+ private static void configureSSL()
+ {
+ Security.addProvider(new Provider());
+ System.setProperty(HANDLER, "com.sun.net.ssl.internal.www.protocol");
+
+ // Konfiguriere Trust-Store (enth�lt SSL-Zertifikat des MOA Services, dem vertraut wird)
+ System.setProperty(TRUSTSTORETYPE, "JKS");
+ System.setProperty(TRUSTSTORE,
+ "clients/webservice/resources/sslKeys/customer1/trustedServers(pwd=servers).keystore");
+// "clients/webservice/resources/sslKeys/customer2/trustedServers(pwd=servers).keystore");
+ System.setProperty(TRUSTSTOREPASSWORD, "servers");
+ }
+} \ No newline at end of file