blob: 5adafe7eb2157694f6a77becedd63ad3a862bb9e [file] [log] [blame]
Title: Remote Object Persistence Coding Client
<H3><A name="RemoteObjectPersistenceCodingClient-ConnectingtotheService"></A>Connecting to the Service</H3>
<P>Creating connection with a dedicated server-side context peer and no authentication:</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">ClientConnection connection = <SPAN class="code-keyword">new</SPAN> HessianConnection(<SPAN class="code-quote">&quot;http:<SPAN class="code-comment">//localhost:8080/myapp/myservice&quot;</SPAN>);</SPAN></PRE>
</DIV></DIV>
<P>HessianConnection also supports HTTP basic authentication:</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">ClientConnection connection = <SPAN class="code-keyword">new</SPAN> HessianConnection(
<SPAN class="code-quote">&quot;https:<SPAN class="code-comment">//localhost:8080/myapp/mysecureservice&quot;</SPAN>,
</SPAN> <SPAN class="code-quote">&quot;username&quot;</SPAN>,
<SPAN class="code-quote">&quot;secret_password&quot;</SPAN>,
<SPAN class="code-keyword">null</SPAN>);</PRE>
</DIV></DIV>
<P>Finally a &quot;shared&quot; or &quot;chat&quot; session can be created when multiple client contexts share the same server-side context:</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java"><SPAN class="code-object">String</SPAN> myChatRoom = <SPAN class="code-quote">&quot;xyz&quot;</SPAN>;
ClientConnection connection = <SPAN class="code-keyword">new</SPAN> HessianConnection(
<SPAN class="code-quote">&quot;https:<SPAN class="code-comment">//localhost:8080/myapp/mysecureservice&quot;</SPAN>,
</SPAN> <SPAN class="code-quote">&quot;username&quot;</SPAN>,
<SPAN class="code-quote">&quot;secret_password&quot;</SPAN>,
myChatRoom);</PRE>
</DIV></DIV>
<H3><A name="RemoteObjectPersistenceCodingClient-ObtainingObjectContext"></A>Obtaining ObjectContext</H3>
<P>Once a <TT>ClientConnection</TT> is created, an ObjectContext instance can be obtained like this: </P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">DataChannel channel = <SPAN class="code-keyword">new</SPAN> ClientChannel(connection);
ObjectContext context = <SPAN class="code-keyword">new</SPAN> CayenneContext(channel);</PRE>
</DIV></DIV>
<P>Note that the channel can be reused by multiple peer CayenneContexts.</P>
<H3><A name="RemoteObjectPersistenceCodingClient-RunningClientWithoutCWS"></A>Running Client Without CWS</H3>
<P>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:</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">DataDomain defaultDomain = Configuration.getSharedConfiguration().getDomain();
DataChannel serverChannel = <SPAN class="code-keyword">new</SPAN> ClientServerChannel(defaultDomain);
ObjectContext context = <SPAN class="code-keyword">new</SPAN> CayenneContext(serverChannel);
<SPAN class="code-comment">// use ObjectContext...</SPAN></PRE>
</DIV></DIV>
<P>To fully emulate CWS behavior, we can add serialization to the picture:</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">DataDomain defaultDomain = Configuration.getSharedConfiguration().getDomain();
DataChannel serverChannel = <SPAN class="code-keyword">new</SPAN> ClientServerChannel(defaultDomain);
ClientConnection connector = <SPAN class="code-keyword">new</SPAN> LocalConnection(
serverChannel,
LocalConnection.HESSIAN_SERIALIZATION);
DataChannel clientChannel = <SPAN class="code-keyword">new</SPAN> ClientChannel(connector);
ObjectContext context = <SPAN class="code-keyword">new</SPAN> CayenneContext(clientChannel);</PRE>
</DIV></DIV>