This project has retired. For details please refer to its Attic page.
UDDIClientSubscriptionListenerImpl xref
View Javadoc
1   /*
2    * Copyright 2001-2008 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   */
17  
18  package org.apache.juddi.v3.client.mapping;
19  
20  import java.io.StringWriter;
21  
22  import javax.jws.WebService;
23  import javax.xml.bind.JAXBContext;
24  import javax.xml.bind.Marshaller;
25  
26  import org.apache.commons.logging.Log;
27  import org.apache.commons.logging.LogFactory;
28  import org.apache.juddi.v3.client.subscription.SubscriptionCallbackListener;
29  import org.uddi.api_v3.DispositionReport;
30  import org.uddi.api_v3.Result;
31  import org.uddi.subr_v3.NotifySubscriptionListener;
32  import org.uddi.v3_service.DispositionReportFaultMessage;
33  import org.uddi.v3_service.UDDISubscriptionListenerPortType;
34  
35  /**
36   * WebService which implements the UDDI v3 SubscriptionListener API. This service will be called by
37   * the UDDI registry when any change to a Service or BindingTemplate
38   * call in to it.
39   * 
40   * @author kstam
41   * @see SubscriptionCallbackListener
42   *
43   */
44  @WebService(serviceName="UDDIClientSubscriptionListenerService", 
45  			endpointInterface="org.uddi.v3_service.UDDISubscriptionListenerPortType",
46  			targetNamespace = "urn:uddi-org:v3_service")
47  
48  public class UDDIClientSubscriptionListenerImpl implements UDDISubscriptionListenerPortType {
49  	
50  	private static final Log logger = LogFactory.getLog(UDDIClientSubscriptionListenerImpl.class);
51  	private UDDIServiceCache serviceCache = null;
52  
53  	public UDDIClientSubscriptionListenerImpl() {
54  		super();
55  	}	
56  
57  	public UDDIClientSubscriptionListenerImpl(String bindingKey, UDDIServiceCache serviceCache) {
58  		super();
59  		this.serviceCache = serviceCache;
60  	}
61  
62  	
63          /**
64           * The SubscriptionListener is called by the UDDI Server when there is a change to any of the
65  	 * services Endpoints. With every call the serviceCache is cleared.
66           * @param body
67           * @return success or fail
68           * @throws DispositionReportFaultMessage 
69           */
70  	public DispositionReport notifySubscriptionListener(
71  			NotifySubscriptionListener body)
72  			throws DispositionReportFaultMessage 
73  	{
74  		try {
75  			JAXBContext context = JAXBContext.newInstance(body.getClass());
76  			Marshaller marshaller = context.createMarshaller();
77  			StringWriter sw = new StringWriter();
78  			marshaller.marshal(body, sw);
79  			logger.info("Notification received by UDDISubscriptionListenerService : " + sw.toString());
80  			// reset the cache, big hammer for now, we could figure out changed from the
81  			// subscriptionResults, and be more selective.
82  			if (serviceCache!=null) serviceCache.removeAll();
83  			
84  		} catch (Exception e) {
85  			logger.error(e.getMessage(),e);
86  		}
87  			
88  		DispositionReport dr = new DispositionReport();
89  		Result res = new Result();
90  		dr.getResult().add(res);
91  		return dr;
92  	}
93  	
94  }