예: WS-Notification 메시지 공개
제공된 코드 추출 예를 기반으로 알림 메시지를 브로커에 공개할 수 있는 공개자 클라이언트 애플리케이션에 대한 코드를 작성하려면 이 태스크를 사용합니다.
이 태스크 정보
이 예제는 XML 기반 원격 프로시저 호출(JAX-RPC) API용 Java™ API를 WS-Notification 서비스 지점 작성의 결과로 생성된 알림 브로커 WSDL에 대해 실행되는 WSDL2Java 도구를 사용하여 생성된 코드와 WebSphere® Application Server API 및 SPI와 함께 사용하는 것을 기반으로 합니다.
WebSphere Application Server에서는 WS-Notification
서비스의 두 가지 구현(버전 6.1 및 버전 7.0)이 있습니다. 이 JAX-RPC 예제는 버전 6.1 또는 버전 7.0 WS-Notification 서비스 지점과 상호작용할 수 있습니다. 그러나 정책 세트가 있는 WS-Notification을 사용하려면(예를 들어, WS-ReliableMessaging이 있는 컴포지션을 사용하려면), WS-Notification 애플리케이션이 XML 기반 웹 서비스(JAX-WS) 프로그래밍 모델용 Java API를 사용하도록 인코딩되어야 하며 버전 7.0 WS-Notification 서비스 지점과 상호작용해야 합니다. JAX-WS 클라이언트 애플리케이션 프로그래밍에 생소하면 다음 주제를 참조하십시오.
- JAX-WS
- JAX-WS 클라이언트 프로그래밍 모델
- 정적 JAX-WS 웹 서비스 클라이언트 구현
- WS-Notification에 대해 JAX-WS 애플리케이션 쓰기
- 웹 서비스 힌트 및 팁: JAX-RPC 및 JAX-WS, 파트 1
알림 메시지를 브로커에 공개할 수 있는 공개자 클라이언트 애플리케이션의 코드를 작성하려면 다음 단계를 완료하십시오. 자세한 정보는 코드 추출 예를 참조하십시오.
프로시저
- JAX-RPC 서비스를 찾아보십시오. JNDI 이름은 웹 서비스 클라이언트 구현에 따라 다릅니다.
- 조작을 호출하려는 포트의 스텁을 가져오십시오.
- 알림 메시지의 메시지 컨텐츠를 작성하십시오.
- 컨텐츠에서 알림 메시지를 작성하십시오.
- 알림 메시지에 토픽 표현식을 추가하십시오. 토픽 표현식은 메시지에 해당하는 하나 이상의 토픽을 표시해야 합니다.
- 선택적 정보를 작성하십시오.
- 옵션: 브로커에 등록할 공개자 클라이언트 애플리케이션이 필요한 경우 특정 공개자 등록과 요청을 연관시키십시오. registrationEPR은 RegisterPublisher 조작 호출과 관련하여 브로커가 리턴하는 ConsumerReference EndpointReference입니다.
- 스텁에서 연관된 메소드를 호출하여 알림 조작을 호출하십시오.
예
다음 코드 예는 알림 메시지를 브로커에 공개할 수 있는 공개자 클라이언트 애플리케이션을 나타냅니다.
// 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);