예: WS-Notification 이용자 등록
제공된 코드 추출 예를 기반으로 브로커에 공개자(생성자) 애플리케이션을 등록하여 공개자 등록 역할을 수행하는 JAX-RPC 클라이언트에 대한 코드를 작성하려면 이 태스크를 사용합니다.
이 태스크 정보
이 예제는 XML 기반 원격 프로시저 호출(JAX-RPC) API용 Java™ API를 WS-Notification 서비스 지점 작성의 결과로 생성된 알림 브로커 WSDL에 대해 실행되는 WSDL2Java 도구를 사용하여 생성된 코드와 WebSphere® Application Server API 및 SPI와 함께 사용하는 것을 기반으로 합니다.
- JAX-WS
- JAX-WS 클라이언트 프로그래밍 모델
- 정적 JAX-WS 웹 서비스 클라이언트 구현
- WS-Notification에 대해 JAX-WS 애플리케이션 쓰기
- 웹 서비스 힌트 및 팁: JAX-RPC 및 JAX-WS, 파트 1
이 예에서 첫 번째 선택적 코드 블록은 원시 등록을 작성하는 방법을 보여줍니다. 이 개념은 웹 서비스 기본 알림 스펙의 섹션 4.2에 정의됩니다.
일반적으로 랩핑된 등록은 일치 이벤트 알림을 사용할 수 있게 될 때 NotificationConsumer의 알림 조작을 구동시킵니다. 대신 등록자가 대신 새 등록을 작성하는 경우에는 이벤트 알림의 애플리케이션 특정 컨텐츠(즉, NotificationMessage 요소의 컨텐츠)만 대상 이용자 엔드포인트로 전송됩니다. UseRaw(즉, 원시 등록 요청)도 지정하는 등록 요청의 ConsumerReference에서 지정된 웹 서비스 엔드포인트는 NotificationConsumer 포트 유형을 구현하지 않아도 됩니다. 이벤트 알림을 전달하기 위해 알림 조작이 사용되지 않기 때문입니다.
이는 지정된 토픽에서 공개될 애플리케이션 컨텐츠 유형 각각에 대한 조작을 이용자가 승인할 수 있어야 함을 의미합니다. 이 패턴은 WS-Notification이 WS-Notification을 인식하지 못하지만 동일한 정보를 수신해야 하는 기존 웹 서비스 애플리케이션 그룹을 호출할 수 있도록 허용합니다.
JAX-WS는 조치 기반 디스패치를 지원하며 JAX-WS 원시 이용자 애플리케이션은 http://docs.oasis-open.org/wsn/bw-2/NotificationConsumer/Notify 조치 URI를 승인해야 합니다. 자세한 정보는 문제점 해결 팁 중개 대상 알림의 원 이용자인 JAX-WS 애플리케이션이 알림 브로커 SOAP 조치를 인식해야 함의 내용을 참조하십시오.
브로커에 공개자(생성자) 애플리케이션을 등록하여 공개자 등록 역할을 수행하는 JAX-RPC 클라이언트에 대한 코드를 작성하려면 코드 추출 예에서 자세한 정보를 참조하여 다음 단계를 완료하십시오.
프로시저
예
// 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 ConsumerReference. This contains the address of the consumer web service that is being
// subscribed, or alternatively is a reference to a pull point (see alternative below). Specifying a
// pull point EPR indicates that the consumer is to use pull-based notifications.
EndpointReference consumerEPR =
EndpointReferenceManager.createEndpointReference(new URI("http://myserver.mycom.com:9080/Consumer"));
/*
// Alternative ConsumerReference for pull-based notifications:
EndpointReference consumerEPR = pullPointEPR;
*/
// Create the Filter. This provides the name of the topic to which you want to subscribe the consumer
Filter filter = new Filter();
// Create a topic expression and add it to the filter. The prefixMappings are mappings between namespace
// prefixes and their corresponding namespaces for prefixes used in the expression
Map prefixMappings = new HashMap();
prefixMappings.put("abc", "uri:example");
TopicExpression exp =
new TopicExpression(TopicExpression.SIMPLE_TOPIC_EXPRESSION, "abc:ExampleTopic", prefixMappings);
filter.addTopicExpression(exp);
//Create an XPath 1.0 message content filter
//This example selects a subset of the available messages in the topic, based upon salary level
String filterExpression = "/company/department/employee/salary > 10000";
URI xpathURI = new URI(http://www.w3.org/TR/1999/REC-xpath-19991116);
QueryExpression qexp =
new QueryExpression(xpathURI, filterExpression);
filter.addMessageContentExpression(qexp);
// Create the InitialTerminationTime. This is the time when you want the subscription to terminate.
// For example, set a time of 1 year in the future.
Calendar cal = Calendar.getInstance();
cal.add(Calendar.YEAR, 1);
AbsoluteOrRelativeTime initialTerminationTime = new AbsoluteOrRelativeTime(cal);
// Create the Policy information
SOAPElement[] policyElements = null;
/*
Optional
--------
The following lines show how to construct a policy indicating that the consumer is to
receive raw style notifications:
javax.xml.soap.SOAPFactory soapFactory = javax.xml.soap.SOAPFactory.newInstance();
SOAPElement useRawElement = null;
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 useRawElementXML = "<mno:UseRaw xmlns:mno=\"http://docs.oasis-open.org/wsn/b-2\"/>";
useRawElement = ((IBMSOAPFactory) soapFactory).createElementFromXMLString(useRawElementXML);
} else {
useRawElement = soapFactory.createElement("UseRaw", "mno", "http://docs.oasis-open.org/wsn/b-2");
}
policyElements = new SOAPElement[] { useRawElement };
*/
// Create holders to hold the multiple values returned from the broker:
// The subscription reference
EndpointReferenceTypeHolder subscriptionRefHolder = new EndpointReferenceTypeHolder();
// The current time at the broker
CalendarHolder currentTimeHolder = new CalendarHolder();
// The termination time for the subscription
CalendarHolder terminationTimeHolder = new CalendarHolder();
// Any additional elements
AnyArrayHolder anyOtherElements = new AnyArrayHolder();
// Invoke the Subscribe operation by calling the associated method on the stub
stub.subscribe(consumerEPR,
filter,
initialTerminationTime,
policyElements,
anyOtherElements,
subscriptionRefHolder,
currentTimeHolder,
terminationTimeHolder);
// Get the returned values:
// An endpoint reference for the subscription that has been created. It is required for
// subsequent lifetime management of the subscription, for example pausing the subscription
com.ibm.websphere.wsaddressing.EndpointReference subscriptionRef = subscriptionRefHolder.value;
// The current time at the broker
Calendar currentTime = currentTimeHolder.value;
// The termination time of the subscription
Calendar terminationTime = terminationTimeHolder.value;
// Any other information
SOAPElement[] otherElements = anyOtherElements.value;