From a2b5bfc1203dfe53de937820d8b8dc59afbf56c3 Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Tue, 6 May 2014 13:26:59 +0200 Subject: added web-client, java SOAP client library --- pdf-as-web-client/.gitignore | 1 + pdf-as-web-client/build.gradle | 31 +++++++++++++++++ .../gv/egiz/pdfas/web/client/RemotePDFSigner.java | 38 +++++++++++++++++++++ .../gv/egiz/pdfas/web/client/test/SimpleTest.java | 39 ++++++++++++++++++++++ settings.gradle | 2 +- 5 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 pdf-as-web-client/.gitignore create mode 100644 pdf-as-web-client/build.gradle create mode 100644 pdf-as-web-client/src/main/java/at/gv/egiz/pdfas/web/client/RemotePDFSigner.java create mode 100644 pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/SimpleTest.java diff --git a/pdf-as-web-client/.gitignore b/pdf-as-web-client/.gitignore new file mode 100644 index 00000000..5e56e040 --- /dev/null +++ b/pdf-as-web-client/.gitignore @@ -0,0 +1 @@ +/bin diff --git a/pdf-as-web-client/build.gradle b/pdf-as-web-client/build.gradle new file mode 100644 index 00000000..c6fdb479 --- /dev/null +++ b/pdf-as-web-client/build.gradle @@ -0,0 +1,31 @@ +apply plugin: 'java' +apply plugin: 'eclipse' + +jar { + manifest { + attributes 'Implementation-Title': 'PDF-AS-4 WEB CLIENT', 'JARMANIFEST': 'PDF-AS-WEB-CLIENT' + } +} + + +repositories { + mavenCentral() +} + +dependencies { + compile group: 'commons-collections', name: 'commons-collections', version: '3.2' + compile project (':pdf-as-common') + testCompile group: 'junit', name: 'junit', version: '4.+' +} + +test { + systemProperties 'property': 'value' +} + +uploadArchives { + repositories { + flatDir { + dirs 'repos' + } + } +} diff --git a/pdf-as-web-client/src/main/java/at/gv/egiz/pdfas/web/client/RemotePDFSigner.java b/pdf-as-web-client/src/main/java/at/gv/egiz/pdfas/web/client/RemotePDFSigner.java new file mode 100644 index 00000000..9e80faf5 --- /dev/null +++ b/pdf-as-web-client/src/main/java/at/gv/egiz/pdfas/web/client/RemotePDFSigner.java @@ -0,0 +1,38 @@ +package at.gv.egiz.pdfas.web.client; + +import java.net.URL; + +import javax.xml.namespace.QName; +import javax.xml.ws.BindingProvider; +import javax.xml.ws.Service; +import javax.xml.ws.soap.SOAPBinding; + +import at.gv.egiz.pdfas.api.ws.PDFASSignParameters; +import at.gv.egiz.pdfas.api.ws.PDFASSigning; + +public class RemotePDFSigner implements PDFASSigning { + + private URL urlEndpoint; + private Service service; + + private PDFASSigning proxy; + + public RemotePDFSigner(URL endpoint, boolean useMTOM) { + this.urlEndpoint = endpoint; + QName qname = new QName("http://ws.web.pdfas.egiz.gv.at/", + "PDFASSigningImplService"); + service = Service.create(endpoint, qname); + + proxy = service.getPort(PDFASSigning.class); + + BindingProvider bp = (BindingProvider) proxy; + SOAPBinding binding = (SOAPBinding) bp.getBinding(); + binding.setMTOMEnabled(useMTOM); + } + + public byte[] signPDFDokument(byte[] inputDocument, + PDFASSignParameters parameters) { + return proxy.signPDFDokument(inputDocument, parameters); + } + +} diff --git a/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/SimpleTest.java b/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/SimpleTest.java new file mode 100644 index 00000000..954d0e2e --- /dev/null +++ b/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/SimpleTest.java @@ -0,0 +1,39 @@ +package at.gv.egiz.pdfas.web.client.test; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.net.URL; + +import at.gv.egiz.pdfas.api.ws.PDFASSignParameters; +import at.gv.egiz.pdfas.api.ws.PDFASSignParameters.Connector; +import at.gv.egiz.pdfas.web.client.RemotePDFSigner; +import sun.misc.IOUtils; + +public class SimpleTest { + + public static void main(String[] args) { + try { + FileInputStream fis = new FileInputStream("/home/afitzek/simple.pdf"); + byte[] inputData = IOUtils.readFully(fis, -1, true); + + PDFASSignParameters signParameters = new PDFASSignParameters(); + signParameters.setConnector(Connector.JKS); + signParameters.setPosition(null); + signParameters.setProfile("SIGNATURBLOCK_DE"); + + URL endpoint = new URL("http://localhost:8080/pdf-as-web/wssign?wsdl"); + + RemotePDFSigner signer = new RemotePDFSigner(endpoint, false); + + byte[] outputFile = signer.signPDFDokument(inputData, signParameters); + + FileOutputStream fos = new FileOutputStream("/home/afitzek/signed.pdf"); + fos.write(outputFile); + fos.close(); + + } catch(Throwable e) { + e.printStackTrace(); + } + } + +} diff --git a/settings.gradle b/settings.gradle index f22a46a4..5def47c1 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,2 @@ -include "pdf-as-common", "signature-standards:sigs-pkcs7detached", "signature-standards:sigs-pades", "pdf-as-lib", "pdf-as-cli", "pdf-as-legacy", "pdf-as-web" +include "pdf-as-common", "signature-standards:sigs-pkcs7detached", "signature-standards:sigs-pades", "pdf-as-lib", "pdf-as-cli", "pdf-as-legacy", "pdf-as-web", "pdf-as-web-client" -- cgit v1.2.3