Nishant Joshi wrote:
Still now i m using eclipse 3.3's facility to create a web service client
and my client is stand alone client.
It might be a part of any large system.in eclipse client i didnt do anything
to joint it with any large system a proxy is generated with methods so
just use (the method as metioned below) in a large system.
But for callback service i need a tuscany client only so want to know the
structure of client code.
here is my client code snippet which i have used for polling mechanism, it
was not running in a tuscany environment, but now i want to run it under
tuscany environment to use callback mechanism.
-----------------------------------------------
StartServicePortTypeProxy proxy = *new* StartServicePortTypeProxy();
proxy.getResult("Any Name");
*int* i = 1;
Thread.*sleep*(1000);
System.*out*.println("Doing something on client side");
Thread.*sleep*(4000);
*while*(!proxy.polling()) {
System.*out*.println("waiting..." + i);
i++;
Thread.*sleep*(100);
}
System.*out*.println("In client " + proxy.getData());
---------------------------------------------
here, mainly three methods, getResult(String ) is a @OneWay method,
polling() is used to check the status and getData() is used to get data from
service.
In example service take more than 10000 ms, so client will wait for it to
complete.
This client code can be easily embed with any java based system, all other
classes was generated by eclipse so no need to bother about it.
So now in Tuscany client i need a other interface (callback interface) to
get result from client so can you please guide me how can i write a
client(remote) code for simple-callback-ws.
I don't want to use polling mechanism, want to use only callback mechanism.
so currently we can assume that there is no complex client system it was a
simple standalone client as mentioned above.
To use the Tuscany callback mechanism in your remote client, the Tuscany
runtime needs to be loaded and initialized as part of your client. This
is quite easy to do. Here are the steps to enable a Java standalone client
to run as a Java Tuscany client:
1. The Tuscany binary distro must be installed on the client machine.
I'll assume that it's installed in a directory called %TUSCANY_HOME%.
2. The client can be packaged as a jar file, a set of classes in a
directory structure, or a webapp. I'll assume that it's a set of
classes in a directory structure under the %APP_HOME% directory
with all client classes in a Java package called "myapp", and that
the server has defined its service and callback classes in a Java
package called "myserver".
3. Create a .composite file in the %APP_HOME% directory. This can
have any filename. In this example I'll assume that it's called
myapp.composite.
4. The myapp.composite file should contain code like the following:
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
targetNamespace="http://myapp"
name="myapp">
<component name="MyClientComponent">
<implementation.java class="myapp.MyClientImpl" />
<reference name="myService">
<interface.java interface="myserver.MyService"
callbackInterface="myserver.MyServiceCallback" />
<binding.ws
uri="http://server-host:server-port/MyServiceComponent" />
<callback>
<binding.ws />
</callback>
</reference>
</component>
</composite>
You will need to change server-host:server-port to the actual server
hostname and port that you are using.
5. The client application code is in the following files:
myapp/MyClient.java
myapp/MyClientImpl.java
myserver/MyService.java
myserver/MyServiceCallback.java
6. The MyClientImpl.java file contains the following code:
package myapp;
import myserver.MyService;
import myserver.MyServiceCallback;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.osoa.sca.annotations.Reference;
import org.osoa.sca.annotations.Scope;
import org.osoa.sca.annotations.Service;
@Service(MyClient.class)
@Scope("COMPOSITE")
public class MyClientImpl implements MyClient, MyServiceCallback {
@Reference
protected MyService myService;
public void aClientMethod() {
myService.someMethod(" -> someMethod "); // calls the server
}
public void receiveResult(String result) {
System.out.println("Result: " + result); // callback from the
server
}
public static void main(String[] args) throws Exception {
SCADomain scaDomain = SCADomain.newInstance("myapp.composite");
MyClient myClient = scaDomain.getService(MyClient.class,
"MyClientComponent");
myClient.aClientMethod();
Thread.sleep(5000); // don't exit before callback arrives
scaDomain.close();
}
}
7. MyClient, MyService, and MyServiceCallback are all interfaces and
contain the following code:
myapp/MyClient.java:
package myapp;
public interface MyClient {
void aClientMethod();
}
myserver/MyService.java:
package myserver;
import org.osoa.sca.annotations.Callback;
import org.osoa.sca.annotations.OneWay;
import org.osoa.sca.annotations.Remotable;
@Remotable
@Callback(MyServiceCallback.class)
public interface MyService {
@OneWay
void someMethod(String arg);
}
myserver/MyServiceCallback.java:
package myserver;
import org.osoa.sca.annotations.Remotable;
@Remotable
public interface MyServiceCallback {
void receiveResult(String result);
}
8. To run the client, first start the server, then enter the following
command line from the %APP_HOME% directory:
java -cp .;%TUSCANY_HOME%/lib/tuscany-sca-manifest.jar
I have checked in sample code for both client and server under
samples/callback-ws-client and samples/callback-ws-service.
Simon
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]