The Content Web Service

From Plnwiki

Allows the retrieval of content stored by the LOCKSS daemon.

Operations

Upcoming (1.68)

WSDL

The Content 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/ContentService?wsdl

will display the WSDL file of the Content 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.

For .NET, Content Service (fetchFile) requires MTOM-encoded WCF Service Model .NET Client Configuration

Client

The following is an example of a web service client that obtains the content pointed to by the link

http://www.emeraldinsight.com/journals.htm?issn=0951-3574&volume=4&issue=4&articleid=869571&show=pdf

import java.io.File;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;

import org.lockss.ws.content.ContentService;
import org.lockss.ws.entities.ContentResult;

public class ContentWsExample {
  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/ContentService?wsdl";
  private static final String TARGET_NAMESPACE = "http://content.ws.lockss.org/";
  private static final String SERVICE_NAME = "ContentServiceImplService";
  private static final String TIMEOUT_KEY =
      "com.sun.xml.internal.ws.request.timeout";
  // The length of the client connection timeout in seconds.
  private static final int TIMEOUT_VALUE = 600;
  private static final String URL =
      "http://www.emeraldinsight.com/journals.htm?issn=0951-3574&volume=4&issue=4&articleid=869571&show=pdf";

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

    // Authenticate.
    example.authenticate();

    // Get the service.
    Service service = Service.create(new URL(ADDRESS_LOCATION), new QName(
	TARGET_NAMESPACE, SERVICE_NAME));

    ContentService port = service.getPort(ContentService.class);

    // Set the client connection timeout.
    ((javax.xml.ws.BindingProvider) port).getRequestContext().put(TIMEOUT_KEY,
	new Integer(TIMEOUT_VALUE*1000));

    // Call the service and get the results of the operation.
    ContentResult result = port.fetchFile(URL, null);

    // Write the received content to a local file.
    File outputFile = result.writeContentToFile("/tmp/content869571.pdf");
  }

  /**
   * 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());
      }
    });
  }
}