diff options
Diffstat (limited to 'pdf-as-web-client/src/test/java/at/gv/egiz/pdfas')
3 files changed, 190 insertions, 45 deletions
diff --git a/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/BulkRequestThread.java b/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/BulkRequestThread.java new file mode 100644 index 00000000..b9277c09 --- /dev/null +++ b/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/BulkRequestThread.java @@ -0,0 +1,109 @@ +package at.gv.egiz.pdfas.web.client.test; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import sun.misc.IOUtils; +import at.gv.egiz.pdfas.api.ws.PDFASBulkSignRequest; +import at.gv.egiz.pdfas.api.ws.PDFASBulkSignResponse; +import at.gv.egiz.pdfas.api.ws.PDFASSignParameters; +import at.gv.egiz.pdfas.api.ws.PDFASSignRequest; +import at.gv.egiz.pdfas.api.ws.PDFASSignResponse; +import at.gv.egiz.pdfas.api.ws.PDFASSignParameters.Connector; +import at.gv.egiz.pdfas.web.client.RemotePDFSigner; + +public class BulkRequestThread implements Runnable { + private Thread t; + private String threadName; + private RemotePDFSigner signer; + PDFASSignParameters signParameters; + private byte[] inputData; + int bulkSize; + int queries; + + public BulkRequestThread(String name, URL endpoint, int queries, int bulkSize) + throws IOException { + threadName = name; + this.queries = queries; + this.bulkSize = bulkSize; + System.out.println("Creating " + threadName); + + signer = new RemotePDFSigner(endpoint, false); + + FileInputStream fis = new FileInputStream( + "/home/afitzek/Documents/arm_arm.pdf"); + inputData = IOUtils.readFully(fis, -1, true); + + signParameters = new PDFASSignParameters(); + signParameters.setConnector(Connector.JKS); + signParameters.setPosition(null); + signParameters.setProfile("SIGNATURBLOCK_DE"); + + } + + private PDFASSignRequest getNewRequest() { + PDFASSignRequest request = new PDFASSignRequest(); + request.setInputData(inputData); + request.setParameters(signParameters); + request.setRequestID(UUID.randomUUID().toString()); + return request; + } + + private PDFASBulkSignRequest getBlukRequest(int count) { + + List<PDFASSignRequest> bulk = new ArrayList<PDFASSignRequest>(); + for (int i = 0; i < count; i++) { + bulk.add(getNewRequest()); + } + + PDFASBulkSignRequest bulkRequest = new PDFASBulkSignRequest(); + bulkRequest.setSignRequests(bulk); + + return bulkRequest; + } + + public void run() { + System.out.println("Running " + threadName); + try { + for (int i = 0; i < queries; i++) { + System.out.println("Thread: " + threadName + ", " + i); + PDFASBulkSignResponse responses = signer + .signPDFDokument(getBlukRequest(bulkSize)); + + for (int j = 0; j < responses.getSignResponses().size(); j++) { + PDFASSignResponse bulkresponse = responses + .getSignResponses().get(j); + System.out.println("Thread: " + threadName + ", " +"ID: " + bulkresponse.getRequestID()); + if (bulkresponse.getError() != null) { + System.out.println("Thread: " + threadName + ", " + "ERROR: " + bulkresponse.getError()); + } else { + System.out.println("Thread: " + threadName + ", " + "OK"); + } + } + Thread.sleep(50); + } + } catch (InterruptedException e) { + System.out.println("Thread " + threadName + " interrupted."); + } + System.out.println("Thread " + threadName + " exiting."); + } + + public void start() { + System.out.println("Starting " + threadName); + if (t == null) { + t = new Thread(this, threadName); + t.start(); + } + } + + public void join() throws InterruptedException { + if(t != null) { + t.join(); + } + } +} diff --git a/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/PerformanceTest.java b/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/PerformanceTest.java new file mode 100644 index 00000000..17a98276 --- /dev/null +++ b/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/PerformanceTest.java @@ -0,0 +1,34 @@ +package at.gv.egiz.pdfas.web.client.test; + +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +public class PerformanceTest { + public static void main(String[] args) { + try { + List<BulkRequestThread> threads = new ArrayList<BulkRequestThread>(); + + URL endpoint = new URL( + "http://localhost:8080/pdf-as-web/wssign?wsdl"); + + for (int i = 0; i < 10; i++) { + threads.add(new BulkRequestThread("T" + i, endpoint, 10, 10)); + } + + + for (int i = 0; i < threads.size(); i++) { + threads.get(i).start(); + } + + for (int i = 0; i < threads.size(); i++) { + threads.get(i).join(); + } + + System.out.println("DONE"); + + } catch (Throwable e) { + e.printStackTrace(); + } + } +} 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 index 161e45cc..e7696ceb 100644 --- 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 @@ -20,7 +20,7 @@ public class SimpleTest { public static void main(String[] args) { try { FileInputStream fis = new FileInputStream( - "/home/afitzek/simple.pdf"); + "/home/afitzek/Documents/arm_arm.pdf"); byte[] inputData = IOUtils.readFully(fis, -1, true); PDFASSignParameters signParameters = new PDFASSignParameters(); @@ -33,62 +33,64 @@ public class SimpleTest { request.setParameters(signParameters); request.setRequestID("SOME TEST ID"); - URL endpoint = new URL("http://demo.egiz.gv.at/demoportal-pdf_as/wssign?wsdl"); - //URL endpoint = new URL( - // "http://localhost:8080/pdf-as-web/wssign?wsdl"); + // URL endpoint = new + // URL("http://demo.egiz.gv.at/demoportal-pdf_as/wssign?wsdl"); + URL endpoint = new URL( + "http://localhost:8080/pdf-as-web/wssign?wsdl"); RemotePDFSigner signer = new RemotePDFSigner(endpoint, false); - System.out.println("Simple Request:"); - byte[] outputFile = signer.signPDFDokument(inputData, - signParameters); + /* + * System.out.println("Simple Request:"); byte[] outputFile = + * signer.signPDFDokument(inputData, signParameters); + * + * FileOutputStream fos = new FileOutputStream( + * "/home/afitzek/simple_request_signed.pdf"); + * fos.write(outputFile); fos.close(); + * + * System.out.println("Simple Request Obj:"); PDFASSignResponse + * response = signer.signPDFDokument(request); + * + * if (response.getSignedPDF() != null) { FileOutputStream fos2 = + * new FileOutputStream( + * "/home/afitzek/simple_request_obj_signed.pdf"); + * fos2.write(response.getSignedPDF()); fos2.close(); } + * + * if(response.getError() != null) { System.out.println("ERROR: " + + * response.getError()); } + */ - FileOutputStream fos = new FileOutputStream( - "/home/afitzek/simple_request_signed.pdf"); - fos.write(outputFile); - fos.close(); - - System.out.println("Simple Request Obj:"); - PDFASSignResponse response = signer.signPDFDokument(request); - - if (response.getSignedPDF() != null) { - FileOutputStream fos2 = new FileOutputStream( - "/home/afitzek/simple_request_obj_signed.pdf"); - fos2.write(response.getSignedPDF()); - fos2.close(); - } - - if(response.getError() != null) { - System.out.println("ERROR: " + response.getError()); - } - List<PDFASSignRequest> bulk = new ArrayList<PDFASSignRequest>(); - for(int i = 0; i < 10; i++) { + for (int i = 0; i < 10; i++) { bulk.add(request); } PDFASBulkSignRequest bulkRequest = new PDFASBulkSignRequest(); bulkRequest.setSignRequests(bulk); - - System.out.println("Bulk Request:"); - PDFASBulkSignResponse responses = signer.signPDFDokument(bulkRequest); - - for(int i = 0; i < responses.getSignResponses().size(); i++) { - PDFASSignResponse bulkresponse = responses.getSignResponses().get(i); - System.out.println("ID: " + bulkresponse.getRequestID()); - - if (bulkresponse.getSignedPDF() != null) { - FileOutputStream fos2 = new FileOutputStream( - "/home/afitzek/simple_request_obj_signed_"+ i +".pdf"); - fos2.write(bulkresponse.getSignedPDF()); - fos2.close(); - } - - if(bulkresponse.getError() != null) { - System.out.println("ERROR: " + bulkresponse.getError()); + + for (int j = 0; j < 10; j++) { + System.out.println("Bulk Request:"); + PDFASBulkSignResponse responses = signer + .signPDFDokument(bulkRequest); + + for (int i = 0; i < responses.getSignResponses().size(); i++) { + PDFASSignResponse bulkresponse = responses + .getSignResponses().get(i); + System.out.println("ID: " + bulkresponse.getRequestID()); + /* + * if (bulkresponse.getSignedPDF() != null) { + * FileOutputStream fos2 = new FileOutputStream( + * "/home/afitzek/simple_request_obj_signed_"+ i +".pdf"); + * fos2.write(bulkresponse.getSignedPDF()); fos2.close(); } + */ + if (bulkresponse.getError() != null) { + System.out.println("ERROR: " + bulkresponse.getError()); + } else { + System.out.println("OK"); + } } } - + System.out.println("Done!"); } catch (Throwable e) { e.printStackTrace(); |