Apache Muse - Testing Your Application
When communicating with a resource, you must create a client to that resource as described earlier.
After adding the generated client jar to your compilation classpath, you can create a client for the sample resource like so:
In the above code you should replace "http://..." with the URI to your deployed resource. For resources created using
the wsdl2java tooling, a default resource is created when the endpoint is deployed. The URI to this resource is as follows.
public static void main(String[] args) {
try {
// insert your endpoint URIs here
URI producerURI = URI.create("http://...");
URI consumerURI = URI.create("http://...");
EndpointReference epr = new EndpointReference(producerURI);
MyServiceProxy proxy = new MyServiceProxy(epr);
// optional, but useful
proxy.setTrace(true);
// get the ServerName property
String serverName = proxy.getServerName();
// invoke the WSN Subscribe operation
EndpointReference consumer = new EndpointReference(consumerURI);
proxy.subscribe(consumer, null, null);
} catch (Exception e) {
e.printStackTrace();
}
}
For J2EE applications (Axis2 or Mini):
For example, if the PORT is 8080, the name of the WAR file is myWar.war and the name of the service is MyService. The URI would be:
- Hostname:
http://localhost:PORT
where PORT is replaced with your J2EE container port.- WAR path: this is the name of the WAR file that you deployed.
- Resource path:
services/NAME
where NAME is the name of the generated service. This is the value specified in muse.xml's <context-path/> element.
http://localhost:8080/myWar/services/MyService
For OSGi:
For example, if the PORT is 80, the name of the WAR file is myBundle and the name of the service is MyService. The URI would be:
- Hostname:
http://localhost:PORT
where PORT is replaced with your OSGi HTTP service port.- Bundle path: this is the name of the bundle.
- Resource path:
NAME
where NAME is the name of the generated service. This is the value specified in muse.xml's <context-path/> element.
http://localhost:80/myBundle/MyService
Finally, the setTrace() call will print all of the outgoing and incoming messages to standard output. This is extremely useful when developing your endpoints. This operation is available on all generated clients, but the other methods will be specific to your endpoint.