Skip Headers
Oracle® Fusion Middleware Developer's Guide for Oracle IRM Server
11g Release 1 (11.1.1)
E12326-02
  Go To Documentation Library
Library
Go To Product List
Product
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
 
Next
Next
 

6.2 Using JDeveloper Generated Web Services Proxies

This section contains the following topics:

6.2.1 Introduction

The following section provides sample code that can be used with JAX-WS web service proxies generated using JDeveloper 11g.

6.2.2 Using the Samples

The JDeveloper 11g sample code comes packaged with a pre-generated set of web service proxy code so there is no need to generate the web service proxy code. The code samples in this document do not show this generated code, but assume this code is present in a package called generated. The easiest way to use the samples is to import them directly into a new or existing JDeveloper 11g project using the File > Import > Java Source menu.


Note:

Before running each sample, check the code to see what command line arguments the sample requires.

6.2.3 Generating a Web Service Proxy

If the web service proxy code needs to be generated by hand, these are the steps to follow within JDeveloper 11g:

  1. From the File menu, select New, then Business Tier, then Web Services, then Web Service Proxy.

  2. Select a JAX-WS Style client and press Next.

  3. Enter the required WSDL document URL as listed in the Web Services section of this document.

    For example, http://irm.example.com/irm_sealing/sealing_services?wsdl

    There is no need to copy the WSDL into the project.

  4. Press Next.

  5. Select Run against a service deployed to an external server.

  6. Press Finish.

6.2.4 Creating a Domain

The following code demonstrates how to create a domain. The sample code uses a fixed domain UUID so that all sample code can work against a known domain. A new domain would typically be given a new random UUID value. The authenticated user becomes the domain administrator. When a domain is created, a set of human-readable labels can be given to the domain for the target language audience.

Example 6-1

import generated.Domain;
import generated.DomainOperations;
import generated.DomainOperationsService;
import generated.Label;
 
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.util.Locale;
import java.util.Map;
 
import javax.xml.ws.BindingProvider;
 
public class SaveNewDomain {
 
    public static void main(String[] args) throws Exception {
 
        final String endpointAddress = args[0];
        final String username = args[1];
        final String password = args[2];
        
        // Configure an authenticator to provide the credentials
        // for the web service
        Authenticator.setDefault(new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password.toCharArray());
            }
        });
        

6.2.5 Creating a Role

The following code demonstrates how to create a role. The sample code uses a fixed role UUID so that all sample code can work with a known role. A new role would typically be given a new random UUID value. The sample role is set up to allow all the content operations required by the sample code. When assigned to a user, this role allows sealing, unsealing, resealing and (validated) peeking. This is done by a providing an appropriate set of features and export constraints.

Example 6-2

import generated.DocumentRole;
import generated.DocumentRoleExportConstraints;
import generated.DocumentRoleOperations;
import generated.DocumentRoleOperationsService;
import generated.DomainRef;
import generated.Feature;
import generated.FeatureUse;
import generated.ItemConstraintsType;
import generated.Label;
import generated.LicenseCriteriaStorage;
import generated.TimePeriod;
import generated.TimePeriodUnits;
 
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.util.List;
import java.util.Locale;
import java.util.Map;
 
import javax.xml.ws.BindingProvider;
 
public class SaveNewRole {
 
    public static void main(String[] args) throws Exception {
 
        final String endpointAddress = args[0];
        final String username = args[1];
        final String password = args[2];
        
        // Configure an authenticator to provide the credentials
        // for the web service
        Authenticator.setDefault(new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password.toCharArray());
            }
        });
        
        // Get the document role operations web service
        DocumentRoleOperationsService service = new DocumentRoleOperationsService();
        
        DocumentRoleOperations roleOperations = service.getDocumentRoleOperations();
 
        // Set the end point address
        Map<String, Object> requestContext = ((BindingProvider)roleOperations).getRequestContext();
        
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointAddress);
 
        // The Role UUID value - that identifies this role within the domain -
        // is fixed for sample code
        DocumentRole role = new DocumentRole();
        
        role.setUuid("ee82c3f9-152b-440d-afd7-dbf36b0c8188");
 
        // Role has one English label
        Label label = new Label();
        
        label.setLocale(Locale.ENGLISH.toString());
        label.setName("Sample Role");
        label.setDescription("This is a role created from sample code.");
 
        role.getLabels().add(label);
 
        // This role allows the user to access content while offline by persisting licenses on the desktop
        role.setStorage(LicenseCriteriaStorage.PERSISTENT);
 
        // This role allows content to be saved in the clear (unsealing and copying)
        role.setExportConstraints(DocumentRoleExportConstraints.NONE);
        
        // This role allows opening,
        Feature open = new Feature();
        
        open.setId("oracle.irm.generic.Open");
        open.setUse(FeatureUse.IMMEDIATE);
        open.setRecord(false);
        
        // sealing,
        Feature seal = new Feature();
            
        seal.setId("oracle.irm.generic.Seal");
        seal.setUse(FeatureUse.IMMEDIATE);
        seal.setRecord(false);   
            
        // and resealing.
        Feature reseal = new Feature();
        
        reseal.setId("oracle.irm.generic.Reseal");
        reseal.setUse(FeatureUse.IMMEDIATE);
        reseal.setRecord(false);  
        
        List<Feature> features = role.getFeatures();
        
        features.add(open);
        features.add(seal);
        features.add(reseal);
        
        // Role allows document exclusions to be listed, by default all items are allowed
        role.setItemConstraints(ItemConstraintsType.EXCLUSIONS);
        
        // This role allows content to be opened for one hour before refreshing the rights from the server
        // This role has no additional time constraints
        TimePeriod value = new TimePeriod();
        
        value.setAmount(1);
        value.setUnits(TimePeriodUnits.HOURS);
        
        role.setRefreshPeriod(value);
        
        // Domain UUID is fixed for sample code
        DomainRef domain = new DomainRef();
        
        domain.setUuid("6fab93fd-2858-461a-a0b3-34e261dbf8fd");
 
        // Save the new role
        roleOperations.saveNewRole(domain, role);
    }
}

6.2.6 Creating a Context Template

The following code demonstrates how to create a context template. The sample code uses a fixed template UUID so that all sample code can work with a known template. A new template would typically be given a new random UUID value. The sample template has one role and is active. This template is used to create contexts in the create context code sample.

Example 6-3

import static
oracle.irm.j2ee.jws.rights.context.ContextTemplateOperations.getContextTemplateOperationsEndpoint;

6.2.7 Creating a Context

The following code demonstrates how to create a context from a context template. The sample code uses a fixed context template reference (information that identifies the template) and provides a fixed UUID value for the new context. The authenticated user becomes the context manager. The context is created with two labels, English and German. This context is used in the sample code that assigns a role, as well as the sealing, unsealing, resealing, reclassification and peeking code samples.

Example 6-4

import generated.ContextInstanceVisibility;
import generated.ContextOperations;
import generated.ContextOperationsService;
import generated.ContextTemplateRef;
import generated.DomainRef;
import generated.Label;
 
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
 
import javax.xml.ws.BindingProvider;
 
public class CreateContextFromTemplate {
 
    public static void main(String[] args) throws Exception {
 
        final String endpointAddress = args[0];
        final String username = args[1];
        final String password = args[2];
        
        // Configure an authenticator to provide the credentials
        // for the web service
        Authenticator.setDefault(new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password.toCharArray());
            }
        });
        
        // Get the content operations endpoint
        ContextOperationsService service = new ContextOperationsService();
        
        ContextOperations contextOperations = service.getContextOperations();
        
        // Set the end point address
        Map<String, Object> requestContext = ((BindingProvider)contextOperations).getRequestContext();
        
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointAddress);
        
        // Domain UUID is fixed for sample code
        DomainRef domain = new DomainRef();
        
        domain.setUuid("6fab93fd-2858-461a-a0b3-34e261dbf8fd");
        
        // Create the context template reference
        ContextTemplateRef templateRef = new ContextTemplateRef();
        
        templateRef.setDomain(domain);
        
        // Context Template UUID is for the "standard" template automatically installed with a domain
        templateRef.setUuid("930876e6-a505-4a10-8d93-bc43d9a37c23");
        
        templateRef.setDomain(domain);
        
        // Context UUID is fixed for sample code
        String contextUUID = "46f910d9-dd30-476e-b060-4d01f88f8b05";
 
        // Context has two labels, English and German
        Label english = new Label();
        
        english.setLocale(Locale.ENGLISH.toString());
        english.setName("Sample Classification");
        english.setDescription("Created from sample code.");
 
        Label german = new Label();
        
        german.setLocale(Locale.GERMAN.toString());
        german.setName("Beispielklassifikation");
        german.setDescription("Verursacht vom Beispielcode.");
        
        List<Label> labels = new ArrayList<Label>();
        
        labels.add(english);
        labels.add(german);
        
        // Create a context based on that template
        contextOperations.createContextFromTemplate(
            contextUUID, // context UUID value 
            templateRef, // context template
            labels, // labels
            ContextInstanceVisibility.DOMAIN, // visibility 
            null); // additional context managers
    }
}

6.2.8 Assigning a Role to a User

The following code demonstrates how to assign a role to a user. To assign a role, the role, context and user or group must be specified. If the role is restricted to individual items then items can also be specified as in the assign role method.

Example 6-5

import generated.AccountRef;
import generated.ContextInstanceRef;
import generated.DocumentRightOperations;
import generated.DocumentRightOperationsService;
import generated.DocumentRoleRef;
import generated.DomainRef;
 
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URLEncoder;
import java.util.Collections;
import java.util.Map;
 
import javax.xml.ws.BindingProvider;
 
public class AssignRole {
 
    public static void main(String[] args) throws Exception {
 
        final String endpointAddress = args[0];
        final String username = args[1];
        final String password = args[2];
        
        // Configure an authenticator to provide the credentials
        // for the web service
        Authenticator.setDefault(new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password.toCharArray());
            }
        });
        
        // Get the document right operations endpoint
        DocumentRightOperationsService service = new DocumentRightOperationsService();
        
        DocumentRightOperations rightOperations = service.getDocumentRightOperations();
        
        // Set the end point address
        Map<String, Object> requestContext = ((BindingProvider)rightOperations).getRequestContext();
        
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointAddress);
 
        // Domain UUID is fixed for sample code
        DomainRef domainRef = new DomainRef();
        
        domainRef.setUuid("6fab93fd-2858-461a-a0b3-34e261dbf8fd");
 
        // Document Role UUID is for the "Sample Role" role
        DocumentRoleRef roleRef = new DocumentRoleRef();
        
        roleRef.setUuid("ee82c3f9-152b-440d-afd7-dbf36b0c8188");
        roleRef.setDomain(domainRef);
 
        // Context UUID is fixed for sample code
        ContextInstanceRef contextInstanceRef = new ContextInstanceRef();
        
        contextInstanceRef.setUuid("46f910d9-dd30-476e-b060-4d01f88f8b05");
        
        // Reference the account by user name
        AccountRef accountRef = new AccountRef();
        
        accountRef.setUuid("urn:user:" + URLEncoder.encode(username, "utf-8"));
 
        // Assign the role to the account
        rightOperations.assignRole(
            contextInstanceRef, 
            roleRef, 
            Collections.singletonList(accountRef), 
            null); // no item constraints
    }
}

6.2.9 Listing Rights Assigned to a User or Group

The following code demonstrates how to list the rights that have been assigned to a user or group. The code displays the role label and the context UUID from each right.

Example 6-6

import generated.AccountRef;
import generated.DocumentRight;
import generated.DocumentRightOperations;
import generated.DocumentRightOperationsService;
import generated.ItemCode;
 
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URLEncoder;
import java.util.Collection;
import java.util.Map;
 
import javax.xml.ws.BindingProvider;
 
public class ListRightsByAccount {
 
    public static void main(String[] args) throws Exception {
 
        final String endpointAddress = args[0];
        final String username = args[1];
        final String password = args[2];
        
        // Configure an authenticator to provide the credentials
        // for the web service
        Authenticator.setDefault(new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password.toCharArray());
            }
        });
 
        // Get the document right operations endpoint
        DocumentRightOperationsService service = new DocumentRightOperationsService();
        
        DocumentRightOperations rightOperations = service.getDocumentRightOperations();
        
        // Set the end point address
        Map<String, Object> requestContext = ((BindingProvider)rightOperations).getRequestContext();
        
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointAddress);
 
        // Reference the account by user name, allowed formats are
        //  urn:user:xxxx
        //  urn:group:xxxx
        //  00000000-0000-0000-0000-000000000000
        AccountRef accountRef = new AccountRef();
        
        accountRef.setUuid("urn:user:" + URLEncoder.encode(username, "utf-8"));
        
        // Get all of the rights assigned to the account
        Collection<DocumentRight> rights = rightOperations.listRightsByAccount(accountRef);
 
        // Display a summary of each right
        for (DocumentRight right : rights) {
            System.out.println("Account: " + right.getAccount().getUuid());
            System.out.println("Context: " + right.getContext().getUuid());
            System.out.println("Role: " + right.getRole().getUuid());
 
            // Show items
            Collection<ItemCode> itemCodes = right.getItemCodes();
            
            if (itemCodes != null) {
                for (ItemCode itemCode : itemCodes) {
                    System.out.println(" ItemCode: " + itemCode.getValue());
                }
            }
        }
    }
}

6.2.10 Altering the Role Assigned to a User or Group

The following code demonstrates how to alter a role assignment using the reassignRole method over web services. The sample code adds an item code exclusion to a role assignment. Typically this method is used to alter the role, but as the sample code only has one demonstration role it shows how to alter the item restrictions.

Example 6-7

import generated.AccountRef;
import generated.DocumentRight;
import generated.DocumentRightOperations;
import generated.DocumentRightOperationsService;
import generated.DocumentRightRef;
import generated.DocumentRoleRef;
import generated.DomainRef;
import generated.ItemCode;
 
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URLEncoder;
import java.util.Collections;
import java.util.List;
import java.util.Map;
 
import javax.xml.ws.BindingProvider;
 
public class ReassignRole {
 
    public static void main(String[] args) throws Exception {
 
        final String endpointAddress = args[0];
        final String username = args[1];
        final String password = args[2];
        
        // Configure an authenticator to provide the credentials
        // for the web service
        Authenticator.setDefault(new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password.toCharArray());
            }
        });
 
        // Get the document right operations endpoint
        DocumentRightOperationsService service = new DocumentRightOperationsService();
        
        DocumentRightOperations rightOperations = service.getDocumentRightOperations();
        
        // Set the end point address
        Map<String, Object> requestContext = ((BindingProvider)rightOperations).getRequestContext();
        
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointAddress);
 
        // Reference the account by user name
        AccountRef accountRef = new AccountRef();
        
        accountRef.setUuid("urn:user:" + URLEncoder.encode(username, "utf-8"));
        
        // Get all rights assigned to the account
        List<DocumentRight> rights = rightOperations.listRightsByAccount(accountRef);
 
        // Take the first one on the list
        DocumentRight right = rights.get(0);
 
        DocumentRightRef rightRef = new DocumentRightRef();
        rightRef.setUuid(right.getUuid());
        
        // Get a reference to the role to be reassigned
        DomainRef domainRef = right.getRole().getDomain();
 
        DocumentRoleRef roleRef = new DocumentRoleRef();
        
        roleRef.setUuid(right.getRole().getUuid());
        roleRef.setDomain(domainRef);
 
        // Change the item exclusion list to contain one sample item
        ItemCode itemCode = new ItemCode();
        itemCode.setValue("sample-item-code");
 
        // Reassign the role to the account
        rightOperations.reassignRole(Collections.singletonList(rightRef), 
                roleRef, Collections.singletonList(itemCode));
    }
}

6.2.11 Sealing a File

The following code demonstrates how to seal a file. The content to seal can be provided as any type of InputStream; this example uses a file input stream. The sample writes the resulting stream out as a file with a sealed file name inferred from the unsealed file name. The file is sealed using the context classification system, specifying a context with a known UUID value and an item code.

Example 6-8

import generated.Classification;
import generated.ClassificationSystemRef;
import generated.ContentType;
import generated.ContentTypeOperations;
import generated.ContentTypeOperationsService;
import generated.SealingOptions;
import generated.SealingServices;
import generated.SealingServicesService;
 
import java.io.File;
import java.io.FileOutputStream;
import java.io.StringReader;
import java.util.GregorianCalendar;
import java.util.Map;
 
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.ws.BindingProvider;
 
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;
 
import com.sun.xml.ws.developer.JAXWSProperties;
 
public class SealFile {
    
    /**
     * MTOM threshold.
     *
     * The size in bytes that binary data should be before being sent as an attachment in the
     * web service request or response.
     *
     * <br/><br/>Value: <tt>{@value}</tt>
     */
    static public final int MTOM_THRESHOLD = 16384;
 
    public static void main(String[] args) throws Exception {
 
        String hostPort = args[0];
        String username = args[1];
        String password = args[2];
 
        // The server URI. e.g. https://irm.example.com/irm_desktop
        String serverURI = args[3];
 
        // The filename to seal
        String filename = args[4];
 
        // Context UUID is fixed for sample code
        String contextUUID = "46f910d9-dd30-476e-b060-4d01f88f8b05";
        
        // Date for the item code time stamp
        DatatypeFactory dataTypeFactory = DatatypeFactory.newInstance();
        
        XMLGregorianCalendar date = dataTypeFactory.newXMLGregorianCalendar(
            new GregorianCalendar());
 
        // Create a context cookie for the classification - this specifies which context to use as
        // well as the item code for the content.
        //
        // Specifies an explicit item code value and time.
        String cookieXMLText =
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + 
            "<classifications:ContextCookie xmlns:classifications=\"http://xmlns.oracle.com/irm/classifications\">" +
            "    <context>" +
            "        <uuid>" + contextUUID + "</uuid>" +
            "    </context>" + "    <itemCode>" +
            "        <value>" + new File(filename).getName() + "</value>" +
            "        <time>" + date.toString() + "</time>" +
            "    </itemCode>" + "</classifications:ContextCookie>";
        
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        
        Document document = builder.parse(new InputSource(new StringReader(
            cookieXMLText.toString())));
 
        Element cookieElement = document.getDocumentElement();
 
        // Create the classification details used in the sealing options
        Classification classification = new Classification();
 
        // For the context classification system the classification Id is the context UUID value.
        classification.setId("46f910d9-dd30-476e-b060-4d01f88f8b05");
        
        // Context classification system
        ClassificationSystemRef contextSystemRef = new ClassificationSystemRef();
        contextSystemRef.setUuid("37c8da32-5420-4146-816c-27f63de27250");
 
        classification.setSystem(contextSystemRef);
 
        // As the key set is not known get the sealing process to automatically fill this in
        classification.setKeySet(null);
 
        // URL sealed into content that tells the desktop where to go to get licenses
        classification.setUri(serverURI);
 
        // Classification time set explicitly to the current time
        classification.setClassificationTime(date);
 
        // Set the context and item code details
        classification.setAny(cookieElement);
 
        // The classification is the only mandatory property for sealing options
        SealingOptions sealingOptions = new SealingOptions();
 
        sealingOptions.setClassification(classification);
        
        // Get the content type operations web service proxy
        ContentTypeOperationsService contentTypeOperationsService =
            new ContentTypeOperationsService();
        
        ContentTypeOperations contentTypeOperations = 
            contentTypeOperationsService.getContentTypeOperations();
        
        // Set the end point address for content type operations
        Map<String, Object> requestContext = ((BindingProvider)contentTypeOperations).getRequestContext();
        
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, hostPort + "/irm_sealing/content_type_operations");
 
        // Set the user name and password for content type operations
        requestContext.put(BindingProvider.USERNAME_PROPERTY, username);
        requestContext.put(BindingProvider.PASSWORD_PROPERTY, password);
 
        // Get the MIME type of the file to seal, this is inferred from the unsealed file name
        ContentType contentType = contentTypeOperations.getContentTypeFromPath(filename);
 
        String mimeType = contentType.getMimeTypes().get(0);
 
        // Get the sealing services web service proxy
        SealingServicesService sealingServicesService = new SealingServicesService();
        
        SealingServices sealingServices = sealingServicesService.getSealingServices(
            new javax.xml.ws.soap.MTOMFeature(true, MTOM_THRESHOLD));
 
        // Set the end point address for sealing services
        requestContext = ((BindingProvider)sealingServices).getRequestContext();
        
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, hostPort + "/irm_sealing/sealing_services");
 
        // Set the user name and password for sealing services
        requestContext.put(BindingProvider.USERNAME_PROPERTY, username);
        requestContext.put(BindingProvider.PASSWORD_PROPERTY, password);
        
        // Without this setting the client may get an java.lang.OutOfMemoryException
        // when large files are buffered into memory by the HTTP stack.
        //
        // For more information see:
        //  https://jax-ws.dev.java.net/guide/HTTP_client_streaming_support.html
        //  https://jax-ws.dev.java.net/guide/Large_Attachments.html
        requestContext.put(JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE, 4096);
 
        // Send the file contents to the server for sealing
        DataHandler input = new DataHandler(new FileDataSource(filename));
 
        DataHandler results = sealingServices.seal(input, mimeType, sealingOptions);
 
        // Get the sealed equivalent of the unsealed filename
        String sealedFilename = contentTypeOperations.getSealedFileName(filename);
 
        // Write the stream out to a file
        FileOutputStream outputStream = new FileOutputStream(sealedFilename);
 
        results.writeTo(
                outputStream);
 
        // Close the streams
        outputStream.close();
    }
}

6.2.12 Peeking a Sealed File

The following code demonstrates how to extract the metadata from sealed content using the peek method. This method sends the sealed content to the sealing server, the server extracts the metadata and returns this information to the caller. The sealed content can be provided as any type of InputStream; this example uses a file input stream. Once peeked the file metadata, which includes the Classification details, can be examined. The sample code prints out the human readable classification details (the labels) that were sealed into the content.

Example 6-9

import generated.Classification;
import generated.ContentDescription;
import generated.Label;
import generated.SealingServices;
import generated.SealingServicesService;
 
import java.util.Map;
 
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.xml.ws.BindingProvider;
 
import com.sun.xml.ws.developer.JAXWSProperties;
 
public class PeekFile {
    /**
     * MTOM threshold.
     *
     * The size in bytes that binary data should be before being sent as an attachment in the
     * web service request or response.
     *
     * <br/><br/>Value: <tt>{@value}</tt>
     */
    static public final int MTOM_THRESHOLD = 16384;
 
    public static void main(String[] args) throws Exception {
 
        String endpointAddress = args[0];
        String username = args[1];
        String password = args[2];
 
        // The name of the file to peek
        String filename = args[3];
 
        // Get the sealing services web service proxy
        SealingServicesService sealingServicesService = new SealingServicesService();
        
        SealingServices sealingServices = sealingServicesService.getSealingServices(
            new javax.xml.ws.soap.MTOMFeature(true, MTOM_THRESHOLD));
 
        // Set the end point address
        Map<String, Object> requestContext = ((BindingProvider)sealingServices).getRequestContext();
        
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointAddress);
 
        // Set the user name and password
        requestContext.put(BindingProvider.USERNAME_PROPERTY, username);
        requestContext.put(BindingProvider.PASSWORD_PROPERTY, password);
        
        // Without this setting the client may get an java.lang.OutOfMemoryException
        // when large files are buffered into memory by the HTTP stack.
        //
        // For more information see:
        //  https://jax-ws.dev.java.net/guide/HTTP_client_streaming_support.html
        //  https://jax-ws.dev.java.net/guide/Large_Attachments.html
        requestContext.put(JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE, 4096);
 
        // Perform the peek, providing a stream to the sealed file
        DataHandler input = new DataHandler(new FileDataSource(filename));
 
        ContentDescription results = sealingServices.peek(input);
 
        // Extract the classification details from the content
        Classification classification = results.getClassification();
 
        // Show all the labels sealed into content (assumes labels are available)
        for (Label label : classification.getLabels()) {
            System.out.println(label.getLocale() + " : " + label.getName());
        }
    }
}

6.2.13 Peeking a Sealed File and Checking the Digital Signature

The following code demonstrates how to extract the metadata from sealed content using the validatedPeek method. This method sends the sealed content to the sealing server, the server extracts the metadata and returns this information to the caller. The sealed content can be provided as any type of InputStream; this example uses a file input stream. Once peeked the file metadata, which includes the Classification details, can be examined. The sample code prints out the human readable classification details (the labels) that were sealed into the content.

Example 6-10

import generated.Classification;
import generated.ContentDescription;
import generated.Label;
import generated.SealingServices;
import generated.SealingServicesService;
 
import java.util.Map;
 
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.xml.ws.BindingProvider;
 
import com.sun.xml.ws.developer.JAXWSProperties;
 
public class ValidatedPeekFile {
    
    /**
     * MTOM threshold.
     *
     * The size in bytes that binary data should be before being sent as an attachment in the
     * web service request or response.
     *
     * <br/><br/>Value: <tt>{@value}</tt>
     */
    static public final int MTOM_THRESHOLD = 16384;
 
    public static void main(String[] args) throws Exception {
 
        String endpointAddress = args[0];
        String username = args[1];
        String password = args[2];
 
        // The name of the file to peek
        String filename = args[3];
 
        // Get the sealing services web service proxy
        SealingServicesService sealingServicesService = new SealingServicesService();
        
        SealingServices sealingServices = sealingServicesService.getSealingServices(
            new javax.xml.ws.soap.MTOMFeature(true, MTOM_THRESHOLD));
 
        // Set the end point address
        Map<String, Object> requestContext = ((BindingProvider)sealingServices).getRequestContext();
        
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointAddress);
 
        // Set the user name and password
        requestContext.put(BindingProvider.USERNAME_PROPERTY, username);
        requestContext.put(BindingProvider.PASSWORD_PROPERTY, password);
        
        // Without this setting the client may get an java.lang.OutOfMemoryException
        // when large files are buffered into memory by the HTTP stack.
        //
        // For more information see:
        //  https://jax-ws.dev.java.net/guide/HTTP_client_streaming_support.html
        //  https://jax-ws.dev.java.net/guide/Large_Attachments.html
        requestContext.put(JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE, 4096);
 
        // Send the file contents to the server for peeking
        DataHandler input = new DataHandler(new FileDataSource(filename));
 
        ContentDescription results = sealingServices.validatedPeek(input);
 
        // Extract the classification details from the content
        Classification classification = results.getClassification();
 
        // Show all the labels sealed into content (assumes labels are available)
        for (Label label : classification.getLabels()) {
            System.out.println(label.getLocale() + " : " + label.getName());
        }
    }
}

6.2.14 Changing Item Restrictions Associated with a Right

The following code demonstrates how to alter the item locks or exclusions associated with a right. The sample code replaces one item code with two item codes.

Example 6-11

import generated.AccountRef;
import generated.DocumentRight;
import generated.DocumentRightOperations;
import generated.DocumentRightOperationsService;
import generated.DocumentRightRef;
import generated.ItemCode;
 
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Map;
 
import javax.xml.datatype.DatatypeFactory;
import javax.xml.ws.BindingProvider;
 
public class SaveChangesToItems {
 
    public static void main(String[] args) throws Exception {
 
        final String endpointAddress = args[0];
        final String username = args[1];
        final String password = args[2];
        
        // Configure an authenticator to provide the credentials
        // for the web service
        Authenticator.setDefault(new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password.toCharArray());
            }
        });
 
        // Get the document right operations endpoint
        DocumentRightOperationsService service = new DocumentRightOperationsService();
        
        DocumentRightOperations rightOperations = service.getDocumentRightOperations();
        
        // Set the end point address
        Map<String, Object> requestContext = ((BindingProvider)rightOperations).getRequestContext();
        
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointAddress);
 
        // Reference the account by user name
        AccountRef accountRef = new AccountRef();
        
        accountRef.setUuid("urn:user:" + URLEncoder.encode(username, "utf-8"));
        
        // Get all rights assigned to the account
        List<DocumentRight> rights = rightOperations.listRightsByAccount(accountRef);
 
        // Take the first one on the list
        DocumentRight right = rights.get(0);
 
        DocumentRightRef rightRef = new DocumentRightRef();
        rightRef.setUuid(right.getUuid());
 
        // The save change method allows items to be added and/or removed in the same call.
        // It does this be comparing two sets of items and applying the differences.
        
        // Item codes
        ItemCode sampleItemCode = new ItemCode();
        sampleItemCode.setValue("sample-item-code");
        
        DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
        
        ItemCode sampleItemCodeOne = new ItemCode();
        sampleItemCodeOne.setValue("sample-item-code-one");
        sampleItemCodeOne.setTime(datatypeFactory.newXMLGregorianCalendar(new GregorianCalendar()));
        
        ItemCode sampleItemCodeTwo = new ItemCode();
        sampleItemCodeTwo.setValue("sample-item-code-two");
        sampleItemCodeTwo.setTime(datatypeFactory.newXMLGregorianCalendar(new GregorianCalendar()));
        
        // This example shows a delta where item "sample-item-code" is removed
        // and items "sample-item-code-one" and "sample-item-code-two" are added.
        List<ItemCode> itemCodes = Collections.singletonList(sampleItemCode);
        
        List<ItemCode> deltaItemCodes = new ArrayList<ItemCode>();
        
        deltaItemCodes.add(sampleItemCodeOne);
        deltaItemCodes.add(sampleItemCodeTwo);
                 
        // Alter the items
        rightOperations.saveChangesToItems(Collections.singletonList(rightRef),
                itemCodes, deltaItemCodes);
    }
}

6.2.15 Unassigning Rights Assigned to a User

The following code demonstrates how to unassign rights that have been assigned to a user. The sample first lists all the rights directly assigned to the user and unassigns them. To unassign the right the authenticated user must be a context manager for the related context.

Example 6-12

import generated.AccountRef;
import generated.DocumentRight;
import generated.DocumentRightOperations;
import generated.DocumentRightOperationsService;
import generated.DocumentRightRef;
 
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
import javax.xml.ws.BindingProvider;
 
public class UnassignRights {
 
    public static void main(String[] args) throws Exception {
 
        final String endpointAddress = args[0];
        final String username = args[1];
        final String password = args[2];
        
        // Configure an authenticator to provide the credentials
        // for the web service
        Authenticator.setDefault(new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password.toCharArray());
            }
        });
 
        // Get the document right operations endpoint
        DocumentRightOperationsService service = new DocumentRightOperationsService();
        
        DocumentRightOperations rightOperations = service.getDocumentRightOperations();
        
        // Set the end point address
        Map<String, Object> requestContext = ((BindingProvider)rightOperations).getRequestContext();
        
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointAddress);
 
        // Reference the account by user name
        AccountRef accountRef = new AccountRef();
        
        accountRef.setUuid("urn:user:" + URLEncoder.encode(username, "utf-8"));
        
        // Get all rights assigned to the account
        List<DocumentRight> rights = rightOperations.listRightsByAccount(accountRef);
 
        List<DocumentRightRef> rightRefs = new ArrayList<DocumentRightRef>(rights.size());
 
        for (DocumentRight right : rights) {
            DocumentRightRef rightRef = new DocumentRightRef();
            rightRef.setUuid(right.getUuid());
            
            rightRefs.add(rightRef);
        }
 
        // Unassign the rights
        rightOperations.unassignRights(rightRefs);
    }
}

6.2.16 Reclassifying a File

The following code demonstrates how to reclassify a sealed file using the reclassify method. The content to reclassify can be provided as any type of InputStream; this example uses a file input stream. The sample changes the labels of the classification and then writes the resulting stream out as a file.

Example 6-13

import generated.Classification;
import generated.ContentDescription;
import generated.Label;
import generated.SealingServices;
import generated.SealingServicesService;
 
import java.io.FileOutputStream;
import java.util.Locale;
import java.util.Map;
 
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.xml.ws.BindingProvider;
 
import com.sun.xml.ws.developer.JAXWSProperties;
 
public class ReclassifyFile {
    
    /**
     * MTOM threshold.
     *
     * The size in bytes that binary data should be before being sent as an attachment in the
     * web service request or response.
     *
     * <br/><br/>Value: <tt>{@value}</tt>
     */
    static public final int MTOM_THRESHOLD = 16384;
    
        public static void main(String[] args) throws Exception {
 
            String endpointAddress = args[0];
        String username = args[1];
        String password = args[2];
 
        // Get the file to reclassify
        String filename = args[3];
 
        // Get the label to apply to the classification
        String labelName = args[4];
 
        // Get the sealing services web service proxy
        SealingServicesService sealingServicesService = new SealingServicesService();
        
        SealingServices sealingServices = sealingServicesService.getSealingServices(
            new javax.xml.ws.soap.MTOMFeature(true, MTOM_THRESHOLD));
 
        // Set the end point address
        Map<String, Object> requestContext = ((BindingProvider)sealingServices).getRequestContext();
        
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointAddress);
 
        // Set the user name and password
        requestContext.put(BindingProvider.USERNAME_PROPERTY, username);
        requestContext.put(BindingProvider.PASSWORD_PROPERTY, password);
        
        // Without this setting the client may get an java.lang.OutOfMemoryException
        // when large files are buffered into memory by the HTTP stack.
        //
        // For more information see:
        //  https://jax-ws.dev.java.net/guide/HTTP_client_streaming_support.html
        //  https://jax-ws.dev.java.net/guide/Large_Attachments.html
        requestContext.put(JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE, 4096);
 
        // Peek the contents of the file to obtain the classification details
        DataHandler input = new DataHandler(new FileDataSource(filename));
 
        ContentDescription contentDescription = sealingServices.peek(input);
 
        // Extract the classification from the content description
        Classification classification = contentDescription.getClassification();
 
        // Replace the labels with one
        Label label = new Label();
        
        label.setLocale(Locale.ENGLISH.toString());
        label.setName(labelName);
 
        classification.getLabels().add(label);
 
        // Reclassify the sealed file with the new classification
        DataHandler results = sealingServices.reclassify(input,classification);
 
        // Write the stream out to the same file
        FileOutputStream outputStream = new FileOutputStream(filename);
 
        results.writeTo(
                outputStream);
 
        // Close the streams
        outputStream.close();
        }
}

6.2.17 Resealing a File with Different Custom Data

The following code demonstrates how to reseal a sealed file using the reseal method. The content to reseal can be provided as any type of InputStream; this example uses a file input stream. The sample adds XML-based custom data to the sealed file.

Example 6-14

import generated.CustomData;
import generated.SealingServices;
import generated.SealingServicesService;
 
import java.io.FileOutputStream;
import java.util.Collections;
import java.util.Map;
import java.util.UUID;
 
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.ws.BindingProvider;
 
import org.w3c.dom.Document;
import org.w3c.dom.Element;
 
import com.sun.xml.ws.developer.JAXWSProperties;
 
public class ResealFile {
    
    /**
     * MTOM threshold.
     *
     * The size in bytes that binary data should be before being sent as an attachment in the
     * web service request or response.
     *
     * <br/><br/>Value: <tt>{@value}</tt>
     */
    static public final int MTOM_THRESHOLD = 16384;
 
        public static void main(String[] args) throws Exception {
 
            String endpointAddress = args[0];
        String username = args[1];
        String password = args[2];
 
        // Get the file to reseal
        String filename = args[3];
 
        // Get the sealing services web service proxy
        SealingServicesService sealingServicesService = new SealingServicesService();
        
        SealingServices sealingServices = sealingServicesService.getSealingServices(
            new javax.xml.ws.soap.MTOMFeature(true, MTOM_THRESHOLD));
 
        // Set the end point address
        Map<String, Object> requestContext = ((BindingProvider)sealingServices).getRequestContext();
        
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointAddress);
 
        // Set the user name and password
        requestContext.put(BindingProvider.USERNAME_PROPERTY, username);
        requestContext.put(BindingProvider.PASSWORD_PROPERTY, password);
        
        // Without this setting the client may get an java.lang.OutOfMemoryException
        // when large files are buffered into memory by the HTTP stack.
        //
        // For more information see:
        //  https://jax-ws.dev.java.net/guide/HTTP_client_streaming_support.html
        //  https://jax-ws.dev.java.net/guide/Large_Attachments.html
        requestContext.put(JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE, 4096);
 
        // Custom data is provided as XML
        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
        Document document = documentBuilder.newDocument();
 
        Element element = document.createElement("SampleCustomData");
        element.setTextContent("Some example custom data provided as an XML text element");
 
        CustomData data = new CustomData();
 
        // UUID identifies the custom data, in this example just use a random UUID value
        data.setUuid(UUID.randomUUID().toString());
 
        // Custom data is XML document
        data.setAny(element);
 
        // Send the sealed file contents to the server for resealing
        DataHandler input = new DataHandler(new FileDataSource(filename));
 
        DataHandler results = sealingServices.reseal(input, Collections.singletonList(data));
 
        // Write the stream out to a file
        FileOutputStream outputStream = new FileOutputStream(filename);
 
        results.writeTo(
                outputStream);
 
        // Close the streams
        outputStream.close();
        }
}

6.2.18 Unsealing a File

The following code demonstrates how to unseal a sealed file using the unseal method. The content to unseal can be provided as any type of InputStream; this example uses a file input stream. The sample writes the resulting unsealed stream out to a file.

Example 6-15

import generated.SealingServices;
import generated.SealingServicesService;
 
import java.io.FileOutputStream;
import java.util.Map;
 
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.xml.ws.BindingProvider;
 
import com.sun.xml.ws.developer.JAXWSProperties;
 
public class UnsealFile {
    
    /**
     * MTOM threshold.
     *
     * The size in bytes that binary data should be before being sent as an attachment in the
     * web service request or response.
     *
     * <br/><br/>Value: <tt>{@value}</tt>
     */
    static public final int MTOM_THRESHOLD = 16384;
 
    public static void main(String[] args) throws Exception {
 
        String endpointAddress = args[0];
        String username = args[1];
        String password = args[2];
 
        // The file to unseal
        String sealedFilename = args[3];
 
        // The unsealed file name
        String unsealedFilename = args[4];
 
        // Get the sealing services web service proxy
        SealingServicesService sealingServicesService = new SealingServicesService();
        
        SealingServices sealingServices = sealingServicesService.getSealingServices(
            new javax.xml.ws.soap.MTOMFeature(true, MTOM_THRESHOLD));
 
        // Set the end point address
        Map<String, Object> requestContext = ((BindingProvider)sealingServices).getRequestContext();
        
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointAddress);
 
        // Set the user name and password
        requestContext.put(BindingProvider.USERNAME_PROPERTY, username);
        requestContext.put(BindingProvider.PASSWORD_PROPERTY, password);
        
        // Without this setting the client may get an java.lang.OutOfMemoryException
        // when large files are buffered into memory by the HTTP stack.
        //
        // For more information see:
        //  https://jax-ws.dev.java.net/guide/HTTP_client_streaming_support.html
        //  https://jax-ws.dev.java.net/guide/Large_Attachments.html
        requestContext.put(JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE, 4096);
 
        // Send the file contents to the server for unsealing
        DataHandler input = new DataHandler(new FileDataSource(sealedFilename));
 
        DataHandler results = sealingServices.unseal(input);
 
        // Write the stream out to a file
        FileOutputStream outputStream = new FileOutputStream(unsealedFilename);
 
        results.writeTo(
                outputStream);
 
        // Close the streams
        outputStream.close();
    }
}

6.2.19 Listing Classifications

The following code demonstrates how to list classification details from a sealing server using the listClassifications method. The sample code displays the list of Classifications details available to the authenticated user.

Example 6-16

import generated.Classification;
import generated.DesktopServices;
import generated.DesktopServicesService;
import generated.Label;
 
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.util.Collection;
import java.util.Map;
 
import javax.xml.ws.BindingProvider;
 
public class ListClassifications {
 
    public static void main(String[] args) throws Exception {
 
        final String endpointAddress = args[0];
        final String username = args[1];
        final String password = args[2];
        
        // Configure an authenticator to provide the credentials
        // for the web service
        Authenticator.setDefault(new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password.toCharArray());
            }
        });
        
        // Get the desktop services web service
        DesktopServicesService desktopServicesService = new DesktopServicesService();
        
        DesktopServices desktopServices = desktopServicesService.getDesktopServices();
        
        // Set the end point address
        Map<String, Object> requestContext = ((BindingProvider)desktopServices).getRequestContext();
        
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointAddress);
 
        // The server URI. e.g. https://irm.example.com/irm_desktop
        String serverURI = args[3];
 
        // List classifications available to the account
        Collection<Classification> classifications = desktopServices.listClassifications(serverURI);
 
        // Display the labels of the classifications
        for (Classification classification : classifications) {
 
            for (Label label : classification.getLabels()) {
                System.out.println(label.getLocale() + " : " + label.getName());
            }
        }
    }
}

6.2.20 Searching the Context Journal Using Web Services

The following code demonstrates how to search the content usage for context classified content. The sample code searches for all entries for the last twenty-four hours and displays a short summary for the first one hundred entries.

Example 6-17

import generated.ContextJournalEntry;
import generated.ContextOperations;
import generated.ContextOperationsService;
import generated.PageRange;
import generated.TimeRange;
 
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Map;
 
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.ws.BindingProvider;
 
public class SearchJournal {
 
    public static void main(String[] args) throws Exception {
 
        // The server address. e.g. https://irm.example.com
        final String endpointAddress = args[0];
        final String username = args[1];
        final String password = args[2];
        
        // Configure an authenticator to provide the credentials
        // for the web service
        Authenticator.setDefault(new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password.toCharArray());
            }
        });
        
        // Get the content operations endpoint
        ContextOperationsService service = new ContextOperationsService();
        
        ContextOperations contextOperations = service.getContextOperations();
        
        // Set the end point address
        Map<String, Object> requestContext = ((BindingProvider)contextOperations).getRequestContext();
        
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointAddress);
 
        // Use a calendar to work out the time range
        GregorianCalendar calendar = new GregorianCalendar();
        
        DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
 
        // Search for all records from the last 24 hours
        XMLGregorianCalendar end = datatypeFactory.newXMLGregorianCalendar(calendar);
 
        calendar.add(Calendar.DAY_OF_MONTH, -1);
        
        XMLGregorianCalendar begin = datatypeFactory.newXMLGregorianCalendar(calendar);
        
        TimeRange timeRange = new TimeRange();
        
        timeRange.setBegin(begin);
        timeRange.setEnd(end);
 
        // Search the context journal
        PageRange pageRange = new PageRange();
        
        pageRange.setFirst(1);
        pageRange.setLast(100);
        
        List<ContextJournalEntry> journalResults = contextOperations.searchJournal(
            null, // no accounts filter
            null, // no item codes filter
            timeRange, 
            pageRange, 
            null); // no sorting details
 
        if (journalResults.size() == 0)
            return;
 
        // Display the timestamp, URI and and feature for each entry
        for (ContextJournalEntry entry : journalResults) {
            
            System.out.print("Timestamp : " + entry.getTime());
            System.out.print(" Account   : " + entry.getAccount().getName());
            System.out.print(" Content   : " + (entry.getUri() != null ? entry.getUri() : ""));
            System.out.print(" Feature   : " + entry.getFeature().getId());
        }
    }
}

6.2.21 Checking in Licenses

The following code demonstrates how to check in licenses currently checked out to a sealing server. When the sealing server processes content it will usually check out licenses for the authenticated user. These licenses can no longer be used from other locations (for example, the Oracle IRM Desktop) until they expire or are manually checked in.

Example 6-18

import generated.DesktopServices;
import generated.DesktopServicesService;
 
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.util.Map;
 
import javax.xml.ws.BindingProvider;
 
public class CheckIn {
 
    public static void main(String[] args) {
 
        final String endpointAddress = args[0];
        final String username = args[1];
        final String password = args[2];
        
        // Configure an authenticator to provide the credentials
        // for the web service
        Authenticator.setDefault(new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password.toCharArray());
            }
        });
        
        // Get the desktop services web service
        DesktopServicesService desktopServicesService = new DesktopServicesService();
        
        DesktopServices desktopServices = desktopServicesService.getDesktopServices();
        
        // Set the end point address
        Map<String, Object> requestContext = ((BindingProvider)desktopServices).getRequestContext();
        
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointAddress);
 
        // The server URI. e.g. https://irm.example.com/irm_desktop
        String serverURI = args[3];
 
        // Check in all the licenses currently within the
        // desktop store for the given server
        desktopServices.checkIn(serverURI);
    }
}

6.2.22 Deleting a Domain

The following code demonstrates how to delete a domain. The sample code uses a fixed domain UUID for the new domain so that all sample code can work with a known domain. A new domain would typically be given a new random UUID value. The authenticated user must be a domain administrator. When a domain is deleted all the associated roles, templates and contexts are also deleted.

Example 6-19

import generated.DomainOperations;
import generated.DomainOperationsService;
import generated.DomainRef;
 
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.util.Map;
 
import javax.xml.ws.BindingProvider;
 
public class DeleteDomain {
 
    public static void main(String[] args) throws Exception {
 
        final String endpointAddress = args[0];
        final String username = args[1];
        final String password = args[2];
        
        // Configure an authenticator to provide the credentials
        // for the web service
        Authenticator.setDefault(new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password.toCharArray());
            }
        });
        
        // Get the domain operations web service
        DomainOperationsService service = new DomainOperationsService();
        
        DomainOperations domainOperations = service.getDomainOperations();
        
        // Set the end point address
        Map<String, Object> requestContext = ((BindingProvider)domainOperations).getRequestContext();
        
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointAddress);
        
        // Domain UUID is fixed for sample code
        DomainRef domain = new DomainRef();
        
        domain.setUuid("6fab93fd-2858-461a-a0b3-34e261dbf8fd");
        
        // Delete the domain using the domain reference
        domainOperations.deleteDomain(domain);
    }
}