Example code that describes a client acting in the producer role, publishing a message to a broker.
This example is based on using the Java API for XML-based remote procedure call (JAX-RPC) APIs in conjunction with code generated using the WSDL2Java tool (run against the Notification Broker WSDL generated as a result of creating your WS-Notification service point) and WebSphere® Application Server APIs and SPIs.
// Look up the JAX-RPC service. The JNDI name is specific to your Web services client implementation InitialContext context = new InitialContext(); javax.xml.rpc.Service service = (javax.xml.rpc.Service) context.lookup( "java:comp/env/services/NotificationBroker"); // Get a stub for the port on which you want to invoke operations NotificationBroker stub = (NotificationBroker) service.getPort(NotificationBroker.class); // Create the message contents for a notification message SOAPElement messageContents = null; javax.xml.soap.SOAPFactory soapFactory = javax.xml.soap.SOAPFactory.newInstance(); if (soapFactory instanceof IBMSOAPFactory) { // You can use the value add methods provided by the IBMSOAPFactory API to create the SOAPElement // from an XML string. String messageContentsXML = "<xyz:MyData xmlns:xyz=\"uri:mynamespace\">Some data</xyz:MyData>"; messageContents = ((IBMSOAPFactory) soapFactory).createElementFromXMLString(messageContentsXML); } else { // Build up the SOAPElement using the standard javax.xml.soap APIs messageContents = soapFactory.createElement("MyData", "xyz", "uri:mynamespace"); messageContents.addTextNode("Some data"); } // Create a notification message from the contents NotificationMessage message = new NotificationMessage(messageContents); // Add a topic expression to the notification message indicating to which topic or topics the // message corresponds Map prefixMappings = new HashMap(); prefixMappings.put("abc", "uri:example"); TopicExpression exp = new TopicExpression(TopicExpression.SIMPLE_TOPIC_EXPRESSION, "abc:ExampleTopic", prefixMappings); message.setTopic(exp); // Create any optional information SOAPElement[] optionalInformation = new SOAPElement[] {}; /* Optional -------- The following line will cause the request to be associated with a particular publisher registration. You must do this if the broker requires publishers to register. The registrationEPR is the ConsumerReference EndpointReference returned by the broker in relation to an invocation of the RegisterPublisher operation. ((Stub) stub)._setProperty(WSAConstants.WSADDRESSING_DESTINATION_EPR, consumerReferenceEPR); */ // Invoke the Notify operation by calling the associated method on the stub stub.notify(new NotificationMessage[] { message }, optionalInformation);