From f81b3716ac27094ab1845668cb38a1fe6a2d5f8c Mon Sep 17 00:00:00 2001 From: Alexander Marsalek Date: Wed, 4 Jun 2014 18:50:50 +0200 Subject: added DocumentService --- .../documentservice/utils/ExternalDocservice.java | 105 +++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 DocumentService/src/eu/stork/documentservice/utils/ExternalDocservice.java (limited to 'DocumentService/src/eu/stork/documentservice/utils/ExternalDocservice.java') diff --git a/DocumentService/src/eu/stork/documentservice/utils/ExternalDocservice.java b/DocumentService/src/eu/stork/documentservice/utils/ExternalDocservice.java new file mode 100644 index 000000000..821d636a2 --- /dev/null +++ b/DocumentService/src/eu/stork/documentservice/utils/ExternalDocservice.java @@ -0,0 +1,105 @@ +package eu.stork.documentservice.utils; + +import java.net.MalformedURLException; +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 eu.stork.documentservice.DocumentService; +import eu.stork.documentservice.exceptions.DocumentServiceException; + +public class ExternalDocservice { + + /** + * Get document from external DTL + * @param documentTransferRequest the document transfer request (attribute query) + * @param dtlUrl the URL of external DTL + * @return the document found + * @throws DocumentServiceException + */ + public static byte[] getDocument(String documentTransferRequest, String dtlUrl) throws DocumentServiceException + { + if (documentTransferRequest != null && !documentTransferRequest.isEmpty()) + { + if (dtlUrl != null && !dtlUrl.isEmpty()) + { + try + { + URL url = new URL(dtlUrl); + + QName qname = new QName("http://stork.eu", + "DocumentService"); + + Service service = Service.create(url, qname); + DocumentService docservice = service.getPort(DocumentService.class); + + BindingProvider bp = (BindingProvider) docservice; + SOAPBinding binding = (SOAPBinding) bp.getBinding(); + binding.setMTOMEnabled(true); + + return docservice.getDocument(documentTransferRequest, dtlUrl); + } + catch (MalformedURLException e) { + e.printStackTrace(); + throw new DocumentServiceException("DTL url is invalid.", e); + } + catch (Exception e) { + e.printStackTrace(); + throw new DocumentServiceException(e); + } + } + else + throw new DocumentServiceException("DTL url is empty."); + } + else + throw new DocumentServiceException("Document transfer request is empty."); + } + + /** + * Get document mime from external DTL + * @param docId the document id + * @param dtlUrl the URL of external DTL + * @return the document mime found + * @throws DocumentServiceException + */ + public static String getDocumentMime(String docId, String dtlUrl) throws DocumentServiceException + { + if (docId != null && !docId.isEmpty()) + { + if (dtlUrl != null && !dtlUrl.isEmpty()) + { + try + { + URL url = new URL(dtlUrl); + + QName qname = new QName("http://stork.eu", + "DocumentService"); + + Service service = Service.create(url, qname); + DocumentService docservice = service.getPort(DocumentService.class); + + BindingProvider bp = (BindingProvider) docservice; + SOAPBinding binding = (SOAPBinding) bp.getBinding(); + binding.setMTOMEnabled(true); + + return docservice.getDocumentMime(docId, dtlUrl); + } + catch (MalformedURLException e) { + e.printStackTrace(); + throw new DocumentServiceException("DTL url is invalid.", e); + } + catch (Exception e) { + e.printStackTrace(); + throw new DocumentServiceException(e); + } + } + else + throw new DocumentServiceException("DTL url is empty."); + } + else + throw new DocumentServiceException("Document Id is empty."); + } +} -- cgit v1.2.3