How to use Discover Web Services target type

book

Article ID: 160667

calendar_today

Updated On:

Products

Data Loss Prevention Network Discover

Issue/Introduction

The Web Services target type is a standards-based replacement for the Drop Folder target type.  The Web Services target type allows users to write custom scanners that send content and metadata to Discover as SOAP requests. The Network Discover Server becomes a Web service.

Resolution

The following example uses a Java client to send content and metadata of all the files in a folder to the Discover Server.

1.       Log into the Enforce Server and create a  Discover Web Services target type. Use the default settings. Note the scanner port number (default will be 8090).

2.       Start the scan.

3.       Browse the URL http://<discover server>:8090/?wsdl  and save the page as DiscoverSOAPTarget.wsdl in a folder (for example <sample_folder>). Edit the URL to replace port number 8090 if scanner port number is different in Step 1.

4.       Install Java Development Kit(JDK) if it is not available on your system.

5.       Set JAVA_HOME=<jdk_install_dir>

6.       Install apache-cxf from http://cxf.apache.org/

7.       Run <apache-cxf install dir>\bin\wsdl2java -client <sample_folder>\DiscoverSOAPTarget.wsdl. Java source files should be automatically created under packages com.vontu.discover and com.vontu.wsdl.discoversoaptarget.

8.       Edit the code at the end of this document into a file named DiscoverSOAPClient.java in the folder <sample_folder> created in Step 3. Place the new code at the beginning of this file. Change the constants as needed.

9.     Compile the java code by using the command javac DiscoverSOAPClient.java

10.   Run the program using the command java DiscoverSOAPClient

11.   On the Enforce Server verify that the expected number of items are reported for the Discover target created in Step 1.

Source code

The following source code needs to be inserted into the file named DiscoverSOAPClient.java at Step 8.

import javax.xml.datatype.DatatypeFactory;

import javax.xml.namespace.QName;

import java.io.ByteArrayOutputStream;

import java.io.File;

import java.io.FileInputStream;

import java.net.URL;

import java.util.Date;

import com.vontu.discover.ComponentContentType;

import com.vontu.discover.ComponentType;

import com.vontu.discover.DocumentType;

import com.vontu.discover.ProcessDocumentsType;

import com.vontu.wsdl.discoversoaptarget.DiscoverSOAPTargetPortType;

import com.vontu.wsdl.discoversoaptarget.DiscoverSOAPTargetService;

import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;

  

public class DiscoverSOAPClient

{

                private static final QName SERVICE_NAME = new QName("http://www.vontu.com/wsdl/DiscoverSOAPTarget.wsdl", "DiscoverSOAPTarget_Service");

                private static final String OWNER = "DiscoverSOAPClient";

                private static final String BODY = "This is the body";

                private static final String TYPE = "Text";

                private static final String ENCODING = "base64";

                private static final String TEST_FOLDER_NAME = "c:\\temp\\data"; //Change this value according to your needs

                private static final String WSDL_PATH = "http://localhost:8090/?wsdl"; //Change this based on your discover host name and scanner port

 

                public static void main(String []args)

                {

                                try

                                {

                                                URL wsdl = new URL(WSDL_PATH);

                                                File folder = new File(TEST_FOLDER_NAME);

DiscoverSOAPTargetService service =

new DiscoverSOAPTargetService(wsdl, SERVICE_NAME);

                                                DiscoverSOAPTargetPortType client = service.getDiscoverPort();

                                                for(File file : folder.listFiles())

                                                {

                                                                if(file.isDirectory())

                                                                {

                                                                                //only files within the test folder will be sent to discover

                                                                                continue;

                                                                }

                                                                System.out.println(file);

                                                                ProcessDocumentsType processDocumentsType =

new ProcessDocumentsType();

                                                                DocumentType documentType = new DocumentType();

                                                                processDocumentsType.getDocument().add(documentType);

                                                                documentType.setOwner(OWNER);

                                                                documentType.setURI(file.toString());

                                                                GregorianCalendar time = new GregorianCalendar();

                                                                time.setTime(new Date(file.lastModified()));

                                                                documentType.setLastModifiedDate(

        DatatypeFactory.newInstance().newXMLGregorianCalendar(time));

                                                                documentType.setLastModifiedDate(

       DatatypeFactory.newInstance().newXMLGregorianCalendar(time));

 

                                                                //create a component

                                                                ComponentType body = new ComponentType();

                                                                documentType.setComponent(body);

                                                                body.setName(file.getName());

 

                                                                //add body

                                                                ComponentContentType bodyContent = new ComponentContentType();

                                                                                body.setComponentContent(bodyContent);

                                                                bodyContent.setType(TYPE);

                                                                bodyContent.setContent(BODY);

 

                                                                ComponentType attachment = new ComponentType();

                                                                body.getComponent().add(attachment);

                                                                attachment.setName(file.getName());

 

                                                                //add some content to the component

                                                                ComponentContentType attachmentContent =

new ComponentContentType();

                                                                attachment.setComponentContent(attachmentContent);

                                                                attachmentContent.setType(ENCODING);

 

                                                                ByteArrayOutputStream bytes = new ByteArrayOutputStream();

                                                                FileInputStream in = new FileInputStream(file);

                                                                byte[] buf = new byte[1024];

 

                                                                for(;;)

                                                                {

                                                                                int len = in.read(buf);

                                                                                if(len == -1)

                                                                                {

                                                                                                break;

                                                                                }

                                                                                bytes.write(buf,0,len);

                                                                }

 

                                                                attachmentContent.setContent(Base64.encode(bytes.toByteArray()));

 

                                                                //make the SOAP call

                                                                client.processDocuments(processDocumentsType);

                                                }

                                }catch(Exception e)

                                {

                                }

                }

}

See the Symantec DLP 9.0 Admin Guide for information on how to set up a Discover target.