From ece7d18cf35374bf4e26d041799cda8f791c89f8 Mon Sep 17 00:00:00 2001 From: gregor Date: Mon, 7 Jul 2003 10:58:37 +0000 Subject: Initial commit git-svn-id: https://joinup.ec.europa.eu/svn/moa-idspss/trunk@2 d688527b-c9ab-4aba-bd8d-4036d912da1d --- .../doc/moa_spss/HTTPSClientExampleClientAuth.txt | 139 +++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 spss.server/doc/moa_spss/HTTPSClientExampleClientAuth.txt (limited to 'spss.server/doc/moa_spss/HTTPSClientExampleClientAuth.txt') diff --git a/spss.server/doc/moa_spss/HTTPSClientExampleClientAuth.txt b/spss.server/doc/moa_spss/HTTPSClientExampleClientAuth.txt new file mode 100644 index 000000000..822093f91 --- /dev/null +++ b/spss.server/doc/moa_spss/HTTPSClientExampleClientAuth.txt @@ -0,0 +1,139 @@ +import java.io.FileInputStream; +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.LineSeparator; +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; + +/** + * @author Sven + * + * Dies ist eine Beispielklasse die den Zugriff auf MOA-SPSS mittels AXIS erklärt.
+ * Die Datenübertragung erfolgt über eine sichere Verbindung (Clientauthentisierung) + */ +public class HTTPSClientExampleClientAuth { + + // SOAP Konstanten + // CreationServer + private static final QName SERVICE_QNAME = new QName("SignatureCreation"); + private static final String ENDPOINT = "http://localhost:8080/moa-spss/services/SignatureCreation"; + // Secure Endpoint + private static final String SECURE_ENDPOINT = "https://localhost:8443/moa-spss/services/SignatureCreation"; + + /* + VerificationService + wenn Sie diese Werte für ENDPOINT und SERVICE verwenden können Sie eine + Signaturprüfung anstatt einer Signaturerstellung durchführen (entweder mit + ENDPOINT für eine nicht sichere Verbindung bzw. SECURE_ENDPOINT für eine + sichere Verbindung) + + private static final QName SERVICE_QNAME = new QName("SignatureVerification"); + private static final String ENDPOINT = + "http://localhost:8080/moa-spss/services/SignatureVerification"; + private static final String SECURE_ENDPOINT = + "https://localhost:8443/moa-spss/services/SignatureVerification"; + */ + 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 TRUSTSTORE = "javax.net.ssl.trustStore"; + public static final String TRUSTSTOREPASSWORD = "javax.net.ssl.trustStorePassword"; + + + /** + * 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 { + /* + Einrichten der SSL Verbindungseigenschaften + + Die Verbindung wird über SSL hergestellt, als TrustStore und als Keystore + wird ein JavaKeyStore verwendet der die notwendigen Daten enthält + */ + + Security.addProvider(new Provider()); + System.setProperty(HANDLER,"com.sun.net.ssl.internal.www.protocol"); + System.setProperty(KEYSTORE, "client.keystore"); + System.setProperty(KEYSTOREPASSWORD, "changeit"); + System.setProperty(TRUSTSTORE, "client.keystore"); + System.setProperty(TRUSTSTOREPASSWORD, "changeit"); + + // Datei mit Request einlesen + FileInputStream inputStream = new FileInputStream("example_request.xml"); + + // 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 ..."); + + // Ausgabe auf System.out zum Testen + OutputFormat format = new OutputFormat((Document)root_response); + + format.setLineSeparator("\n"); + format.setIndenting(false); + format.setPreserveSpace(true); + format.setOmitXMLDeclaration(false); + format.setEncoding("UTF-8"); + + XMLSerializer serializer = new XMLSerializer (System.out, format); + serializer.asDOMSerializer(); + serializer.serialize(root_response); + + // Antwort verarbeiten + // ... + // ... + } + catch(Exception e) + { + e.printStackTrace(); + } + + } +} -- cgit v1.2.3