Cayenne User Documentation
Remote Object Persistence Coding Client

### Connecting to the Service

Creating connection with a dedicated server-side context peer and no authentication:

    ClientConnection connection = new HessianConnection("http://localhost:8080/myapp/myservice");

HessianConnection also supports HTTP basic authentication:

    ClientConnection connection = new HessianConnection(
              "https://localhost:8080/myapp/mysecureservice",
              "username",
              "secret_password",
              null);

Finally a "shared" or "chat" session can be created when multiple client contexts share the same server-side context:

    String myChatRoom = "xyz";
    ClientConnection connection = new HessianConnection(
              "https://localhost:8080/myapp/mysecureservice",
              "username",
              "secret_password",
              myChatRoom);

### Obtaining ObjectContext

Once a `ClientConnection` is created, an ObjectContext instance can be obtained like this:

    DataChannel channel = new ClientChannel(connection);
    ObjectContext context = new CayenneContext(channel);

Note that the channel can be reused by multiple peer CayenneContexts.

### Running Client Without CWS

Cayenne ORM Tier and CWS Client Tier can be deployed together in the same virtual machine. This may be needed to speed up development, but also to achieve consistency and reuse of CWS client objects between thin clients and web applications. The solution is to use ClientServerChannel on top of a regular Cayenne stack:

    DataDomain defaultDomain = Configuration.getSharedConfiguration().getDomain();
    DataChannel serverChannel = new ClientServerChannel(defaultDomain);
    ObjectContext context = new CayenneContext(serverChannel);

    // use ObjectContext...

To fully emulate CWS behavior, we can add serialization to the picture:

    DataDomain defaultDomain = Configuration.getSharedConfiguration().getDomain();
    DataChannel serverChannel = new ClientServerChannel(defaultDomain);
    ClientConnection connector = new LocalConnection(
                    serverChannel,
                    LocalConnection.HESSIAN_SERIALIZATION);

    DataChannel clientChannel = new ClientChannel(connector);
    ObjectContext context = new CayenneContext(clientChannel);

.
Copyright ©2001-2007 Apache Software Foundation