apache > ws.apache
Apache Muse
 

Apache Muse - Testing Your Application

When communicating with a resource, you can create a client for that resource, as described earlier. After adding the generated client to your classpath, you can create a test application for the sample resource like so:

    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 client = new MyServiceProxy(epr);

            // optional, but useful
            client.setTrace(true);

            // get the ServerName property
            String serverName = client.getServerName();

            // invoke the WSN Subscribe operation
            EndpointReference consumer = new EndpointReference(consumerURI);
            client.subscribe(consumer, null, null);
        }
        
        catch (SoapFault fault) {
            fault.printStackTrace();
        }
    }
    
In the above code you should replace "http://..." literals with the URI for your resource types. For resources created using the wsdl2java tooling, a default resource instance is created when the endpoint is deployed. The URIs are defined as follows:

For J2EE applications:

  • Host: http://host:port where host is your IP address, host name, or localhost, and port is your J2EE container's port number.
  • J2EE context path: The context path for the WAR (this is usually the name of the .war file).
  • Resource context path: services/name where name is the name of the generated service. This value is also specified in muse.xml's <context-path/> element.
For example, if the port number is 8080, the name of the WAR file is my-resources.war, and the name of the service is MyResource, then a valid URI would be:
http://localhost:8080/my-resources/services/MyResource

For OSGi applications:

  • Host: http://host:port where host is your IP address, host name, or
  • Bundle context path: this is the name of the OSGi bundle.
  • Resource context path: services/name where name is the name of the generated service. This value is also specified in muse.xml's <context-path/> element.
For example, if the port number is 80, the name of the bundle file is my-resources.jar, and the name of the service is MyResource, then a valid URI would be:
http://localhost:80/my-resources/MyResource

The setTrace() call that is shown above will cause the client to print all of the outgoing and incoming messages to standard output. This is extremely useful when developing your endpoints.

Finally, the EndpointReference.addParameter() method can be used in the code above to target resources whose EPRs that have one or more WS-A reference parameters.


< Back (J2EE)      < Back (OSGi on J2SE)      < Back (OSGi on J2ME)