The Content Configuration Web Service

From Plnwiki

Allows to manage the archival unit configuration of the LOCKSS daemon.

Operations

WSDL

The Content Configuration web service WSDL (Web Services Description Language) file, an XML file that describes the functionality of a web service, can be obtained from the LOCKSS web application; if the application is running on port 80 of localhost, the URL

http://localhost/ws/ContentConfigurationService?wsdl

will display the WSDL file of the Content Configuration web service.

The WSDL file is particularly useful to automatically generate client stubs and other artifacts.

For Java, two tools that are widely available are wsimport and wsdl2java.

For Python, there is wsdl2py.

Client

The following is an example of a web service client that adds the archival unit with the identifier

org|lockss|plugin|emerald|EmeraldPlugin&base_url~http%3A%2F%2Fwww%2Eemeraldinsight%2Ecom%2F&journal_issn~0951-3574&volume_name~4

import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URL;
import java.util.List;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;

import org.lockss.ws.content.ContentConfigurationService;
import org.lockss.ws.entities.ContentConfigurationResult;

public class ContentConfigurationWsExample {
  private static final String USER_NAME = "lockss-u";
  private static final String PASSWORD = "lockss-p";
  private static final String ADDRESS_LOCATION =
      "http://localhost:8081/ws/ContentConfigurationService?wsdl";
  private static final String TARGET_NAMESPACE = "http://content.ws.lockss.org/";
  private static final String SERVICE_NAME = "ContentConfigurationServiceImplService";
  private static final String AU_ID =
      "org|lockss|plugin|emerald|EmeraldPlugin&base_url~http%3A%2F%2Fwww%2Eemeraldinsight%2Ecom%2F&journal_issn~0951-3574&volume_name~4";

  /**
   * The main method.
   * 
   * @param args
   *          A String[] with the command line arguments.
   * @throws Exception
   */
  public static void main(String args[]) throws Exception {
    ContentConfigurationWsExample example = new ContentConfigurationWsExample();

    // Authenticate.
    example.authenticate();

    // Get the service. If authentication fails, an exception will be thrown
    // with a message like
    //
    // Failed to access the WSDL at: http://... It failed with: 
    //	       Server redirected too many  times (20).
    Service service = Service.create(new URL(ADDRESS_LOCATION), new QName(
	TARGET_NAMESPACE, SERVICE_NAME));

    // Call the service and get the results of the operation.
    ContentConfigurationResult result =
	service.getPort(ContentConfigurationService.class).addAuById(AU_ID);

    System.out.println("result = " + result);
  }

  /**
   * Sets the authenticator that will be used by the networking code when the
   * HTTP server asks for authentication.
   */
  private void authenticate() {
    Authenticator.setDefault(new Authenticator() {
      @Override
      protected PasswordAuthentication getPasswordAuthentication() {
	return new PasswordAuthentication(USER_NAME, PASSWORD.toCharArray());
      }
    });
  }
}