Mappa.Mundi Magazine
Rocket Science » SpaceKit for Java » Tutorial Rocket Science Index »

Olive Left Top Corner Spacer Image
SpaceKit for Java, page 2
Spacer Image
Olive Right Top Corner


1 Introduction
» The Blocks SpaceKit for Java Client
3 Connecting and Channel Creation
4 Client Examples
5 The Blocks SpaceKit for Java Server: SpaceBxxd
6 SpaceBxxd - Responses
7 Localization Class Structure and Utilities
8 Reference

ascii
html
xml
this article in RFC-2629 formats

Khaki Left Bottom Corner
Khaki Right Bottom Corner
The Blocks SpaceKit for Java Client
download the code | copyright | legal | join the discussion list

A Complete SpaceExample For The Impatient

      The SpaceExample shows a typical flow for creating a connection to a SpaceServer, creating a SpaceChannel and doing a simple SEP request:

  SpaceExample
  public class SpaceExample {

  //-------------------------------------------------------------
  //  main
  //-------------------------------------------------------------
  public static void main(String[] argv) {
    SpaceServer server = null;

    try {
      //---------------------------------------------------------
      //  set blocks server host
      //---------------------------------------------------------
      if(argv.length != 1) {
        System.err.println("Usage: java SpaceExample hostname");
        return;
        }

      //---------------------------------------------------------
      //  instantiate the blocks server
      //---------------------------------------------------------
      server = new SpaceServer(argv[0]);

      server.setTrace(true);

      //---------------------------------------------------------
      //  connect to blocks server
      //---------------------------------------------------------
      SpaceResponse greeting = server.connect(true);

      //---------------------------------------------------------
      //  show valid profiles
      //---------------------------------------------------------
      String[] profiles = greeting.getProfiles();
      for(int k=0;k<profiles.length;++k) {
        System.err.println("Profile: " + profiles[k]);
        }

      //---------------------------------------------------------
      //  show localization
      //---------------------------------------------------------
      System.err.println("Localize: " + greeting.getLocalize());

      //---------------------------------------------------------
      //  show features
      //---------------------------------------------------------
      System.err.println("Features: " + greeting.getFeatures());

      //---------------------------------------------------------
      //  free the greeting
      //---------------------------------------------------------
      server.free(greeting);

      //---------------------------------------------------------
      //  start a non-authenticated channel
      //---------------------------------------------------------
      SpaceChannel channel = server.getChannel(SpaceProfile.sep);
      SpaceResponse response = channel.start(false);

      //---------------------------------------------------------
      //  build an sep fetch request while waiting for start response
      //---------------------------------------------------------
      StringBuffer fetch = new StringBuffer();

      fetch.append("<fetch>\r\n");
      fetch.append("<union>\r\n");
      fetch.append("<intersect>\r\n");
      fetch.append("<compare subtree='doc.rfc' operator='contains' ");
      fetch.append("caseSensitive='false'>\r\n");
      fetch.append("<path><element property='email' /></path>\r\n");
      fetch.append("<value>mrose@</value>\r\n");
      fetch.append("</compare>\r\n");
      fetch.append("</intersect>\r\n");
      fetch.append("</union>\r\n");
      fetch.append("</fetch>\r\n");

      //---------------------------------------------------------
      //  wait on the channel start and see if error
      //---------------------------------------------------------
      channel.wait(response);

      if(response.isError()) {
        System.err.println("Start Error: " + response.getErrorCode());
        return;
        }

      //---------------------------------------------------------
      //  do the request
      //---------------------------------------------------------
      response = channel.request(fetch.toString(),true);

      if(response.isError()) {
        System.err.println("Request Error: " + response.getErrorCode());
        return;
        }

      //---------------------------------------------------------
      //  show the response on standard output
      //---------------------------------------------------------
      System.out.println(response.toString());

      //---------------------------------------------------------
      //  free the response
      //---------------------------------------------------------
      channel.free(response);
      }
    catch(SpaceTimeout e) {
      System.err.println(e.toString());
      }
    catch(SpaceException e) {
      System.err.println(e.toString());
      }
    finally {
      //---------------------------------------------------------
      //  always close the server
      //---------------------------------------------------------
      if(server != null) {
        server.close();
        }
      }
    }
  }

Sample Output From SpaceExample:

  ------------------------------------------------------------------
  :  ID  : Channel : Serial :  Length  : Frames : Complete : Error :
  ------------------------------------------------------------------
  : 0    : 0       : 0      :      255 : 1      : Yes      : No    :
  ------------------------------------------------------------------
  ------------------------------------------------------------------
  :  ID  : Channel : Serial :  Length  : Frames : Complete : Error :
  ------------------------------------------------------------------
  : 0    : 0       : 0      :      255 : 1      : Yes      : No    :
  ------------------------------------------------------------------
  Profile: http://xml.resource.org/profiles/sasl/ANONYMOUS
  Profile: http://xml.resource.org/profiles/SEP
  Profile: http://xml.resource.org/profiles/NULL/ECHO
  Profile: http://xml.resource.org/profiles/NULL/SINK
  Profile: http://xml.resource.org/profiles/sasl/OTP
  Localize: en-US
  Features: none

  ------------------------------------------------------------------
  :  ID  : Channel : Serial :  Length  : Frames : Complete : Error :
  ------------------------------------------------------------------
  : 0    : 0       : 1      :       51 : 1      : Yes      : No    :
  ------------------------------------------------------------------
  ------------------------------------------------------------------
  :  ID  : Channel : Serial :  Length  : Frames : Complete : Error :
  ------------------------------------------------------------------
  : 0    : 0       : 1      :       51 : 1      : Yes      : No    :
  ------------------------------------------------------------------
  ------------------------------------------------------------------
  :  ID  : Channel : Serial :  Length  : Frames : Complete : Error :
  ------------------------------------------------------------------
  : 0    : 1       : 1      :     1335 : 1      : Yes      : No    :
  ------------------------------------------------------------------
  ------------------------------------------------------------------
  :  ID  : Channel : Serial :  Length  : Frames : Complete : Error :
  ------------------------------------------------------------------
  : 0    : 1       : 1      :     1335 : 1      : Yes      : No    :
  ------------------------------------------------------------------
  <response reqno='1' ttl='86400' creator="bxxp://sqa.invisible.net/">
  <answers actualNum='1'>
  <rfc name="doc.rfc.2629" serial="2">
  <rfc.props relativeSize="46132" number="2629" category="info"></rfc.props>
  <doc.props>
  <doc.front>
  <doc.title>Writing I-Ds and RFCs using XML</doc.title>
  <doc.author initials="M.T." surname="Rose" fullname="Marshall T. Rose">
  <organization>Invisible Worlds, Inc.</organization>
  <address>
  <postal>
  <street>660 York Street</street>
  <city>San Francisco</city>
  <region>CA</region>
  <code>94110</code>
  <country>US</country></postal>
  <phone>+1 415 695 3975</phone>
  <email>mrose@invisible.net</email>
  <uri>http://invisible.net/</uri></address></doc.author>
  <doc.date month="June" year="1999"></doc.date>
  <doc.area>General</doc.area>
  <doc.keyword>RFC</doc.keyword>
  <doc.keyword>Request for Comments</doc.keyword>
  <doc.keyword>I-D</doc.keyword>
  <doc.keyword>Internet-Draft</doc.keyword>
  <doc.keyword>XML</doc.keyword>
  <doc.keyword>Extensible Markup Language</doc.keyword></doc.front><doc.extras abstract="true" note="false"></doc.extras>
  <doc.links>
  </doc.links>
  </doc.props>
  <remote.props uri="http://sqa.invisible.net/public/rfc/html/rfc2629.html"></remote.props>
  <remote.props uri="http://sqa.invisible.net/public/rfc/txt/rfc2629.txt" language="text"></remote.props>
  </rfc>
  </answers>
  </response>
  ------------------------------------------------------------------
  :  ID  : Channel : Serial :  Length  : Frames : Complete : Error :
  ------------------------------------------------------------------
  : 0    : 0       : 1      :        0 : 1      : Yes      : No    :
  ------------------------------------------------------------------


Next » Connecting and Channel Creation.


 Copyright © 2000 Invisible Worlds. All Rights Reserved.

Invisible Worlds
contact | about | site map | home T-O