This project has retired. For details please refer to its Attic page.
UDDISubscriptionListenerImpl 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.api.impl;
19  
20  import java.io.StringWriter;
21  
22  import javax.jws.WebService;
23  import javax.persistence.EntityManager;
24  import javax.persistence.EntityTransaction;
25  import javax.xml.bind.JAXBContext;
26  import javax.xml.bind.JAXBException;
27  import javax.xml.bind.Marshaller;
28  
29  import org.apache.commons.logging.Log;
30  import org.apache.commons.logging.LogFactory;
31  import org.apache.juddi.config.PersistenceManager;
32  import org.apache.juddi.mapping.MappingModelToApi;
33  import org.apache.juddi.subscription.NotificationList;
34  import org.apache.juddi.v3.error.ErrorMessage;
35  import org.apache.juddi.v3.error.FatalErrorException;
36  import org.apache.juddi.v3.error.InvalidKeyPassedException;
37  import org.apache.juddi.validation.ValidateSubscriptionListener;
38  import org.uddi.api_v3.DispositionReport;
39  import org.uddi.api_v3.Result;
40  import org.uddi.subr_v3.NotifySubscriptionListener;
41  import org.uddi.v3_service.DispositionReportFaultMessage;
42  import org.uddi.v3_service.UDDISubscriptionListenerPortType;
43  
44  /**
45   * This class implements the UDDI v3 Subscription Listener API (server side) 
46   * for jUDDI. It is primarily used for server to server subscriptions.
47   * 
48   */
49  @WebService(serviceName="UDDISubscriptionListenerService", 
50  			endpointInterface="org.uddi.v3_service.UDDISubscriptionListenerPortType",
51  			targetNamespace = "urn:uddi-org:api_v3_portType")
52  public class UDDISubscriptionListenerImpl extends AuthenticatedService implements
53  		UDDISubscriptionListenerPortType {
54  	
55  	private static Log logger = LogFactory.getLog(UDDISubscriptionListenerImpl.class);
56  		
57  	@SuppressWarnings("unchecked")
58  	public DispositionReport notifySubscriptionListener(
59  			NotifySubscriptionListener body)
60  			throws DispositionReportFaultMessage {
61  		try {
62  			JAXBContext context = JAXBContext.newInstance(body.getClass());
63  			Marshaller marshaller = context.createMarshaller();
64  			StringWriter sw = new StringWriter();
65  			marshaller.marshal(body, sw);
66  
67  			logger.info("Notification received by UDDISubscriptionListenerService : " + sw.toString());
68  			
69  			@SuppressWarnings("rawtypes")
70  			NotificationList nl = NotificationList.getInstance();
71  			nl.getNotifications().add(sw.toString());
72  			
73  			org.apache.juddi.api_v3.ClientSubscriptionInfo apiClientSubscriptionInfo = null;
74  			
75  			//find the clerks to go with this subscription
76  			EntityManager em = PersistenceManager.getEntityManager();
77  			EntityTransaction tx = em.getTransaction();
78  			try {
79  				tx.begin();
80  		
81  				this.getEntityPublisher(em, body.getAuthInfo());
82  				String subscriptionKey = body.getSubscriptionResultsList().getSubscription().getSubscriptionKey();
83  				org.apache.juddi.model.ClientSubscriptionInfo modelClientSubscriptionInfo = null;
84  				try {
85  					modelClientSubscriptionInfo = em.find(org.apache.juddi.model.ClientSubscriptionInfo.class, subscriptionKey);
86  				} catch (ClassCastException e) {}
87  				if (modelClientSubscriptionInfo == null) {
88  					throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.SubscripKeyNotFound", subscriptionKey));
89  				}
90  				apiClientSubscriptionInfo = new org.apache.juddi.api_v3.ClientSubscriptionInfo();
91  				MappingModelToApi.mapClientSubscriptionInfo(modelClientSubscriptionInfo, apiClientSubscriptionInfo,em);
92  		
93  				tx.commit();
94  			} finally {
95  				if (tx.isActive()) {
96  					tx.rollback();
97  				}
98  				em.close();
99  			}
100 			
101 			XRegisterHelper.handle(apiClientSubscriptionInfo.getFromClerk(),apiClientSubscriptionInfo.getToClerk(), body.getSubscriptionResultsList());
102 			
103 		} catch (JAXBException jaxbe) {
104 			logger.error("", jaxbe);
105 			throw new FatalErrorException(new ErrorMessage("errors.subscriptionnotifier.client"));
106 		}	
107 		
108 		new ValidateSubscriptionListener().validateNotification(body);
109 			
110 		DispositionReport dr = new DispositionReport();
111 		Result res = new Result();
112 		dr.getResult().add(res);
113 		return dr;
114 	}
115 }