View Javadoc

1   /*
2    * Copyright (C) 2007 ETH Zurich
3    *
4    * This file is part of Fosstrak (www.fosstrak.org).
5    *
6    * Fosstrak is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License version 2.1, as published by the Free Software Foundation.
9    *
10   * Fosstrak is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13   * Lesser General Public License for more details.
14   *
15   * You should have received a copy of the GNU Lesser General Public
16   * License along with Fosstrak; if not, write to the Free
17   * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18   * Boston, MA  02110-1301  USA
19   */
20  
21  package org.fosstrak.epcis.repository.query;
22  
23  import org.fosstrak.epcis.model.ArrayOfString;
24  import org.fosstrak.epcis.model.EmptyParms;
25  import org.fosstrak.epcis.model.GetSubscriptionIDs;
26  import org.fosstrak.epcis.model.ImplementationException;
27  import org.fosstrak.epcis.model.ImplementationExceptionSeverity;
28  import org.fosstrak.epcis.model.Poll;
29  import org.fosstrak.epcis.model.QueryResults;
30  import org.fosstrak.epcis.model.Subscribe;
31  import org.fosstrak.epcis.model.Unsubscribe;
32  import org.fosstrak.epcis.model.VoidHolder;
33  import org.fosstrak.epcis.repository.EpcisQueryControlInterface;
34  import org.fosstrak.epcis.soap.DuplicateSubscriptionExceptionResponse;
35  import org.fosstrak.epcis.soap.EPCISServicePortType;
36  import org.fosstrak.epcis.soap.ImplementationExceptionResponse;
37  import org.fosstrak.epcis.soap.InvalidURIExceptionResponse;
38  import org.fosstrak.epcis.soap.NoSuchNameExceptionResponse;
39  import org.fosstrak.epcis.soap.NoSuchSubscriptionExceptionResponse;
40  import org.fosstrak.epcis.soap.QueryParameterExceptionResponse;
41  import org.fosstrak.epcis.soap.QueryTooComplexExceptionResponse;
42  import org.fosstrak.epcis.soap.QueryTooLargeExceptionResponse;
43  import org.fosstrak.epcis.soap.SecurityExceptionResponse;
44  import org.fosstrak.epcis.soap.SubscribeNotPermittedExceptionResponse;
45  import org.fosstrak.epcis.soap.SubscriptionControlsExceptionResponse;
46  import org.fosstrak.epcis.soap.ValidationExceptionResponse;
47  import org.apache.commons.logging.Log;
48  import org.apache.commons.logging.LogFactory;
49  
50  /**
51   * This class redirects the calls received from the Web service stack to the
52   * underlying QueryOperationsModule and ensures that any uncaught exception is
53   * properly catched and wrapped into an ImplementationExceptionResponse.
54   * 
55   * @author Marco Steybe
56   */
57  public class QueryOperationsWebService implements EPCISServicePortType {
58  
59      private static final Log LOG = LogFactory.getLog(QueryOperationsWebService.class);
60  
61      private EpcisQueryControlInterface queryModule;
62  
63      public QueryOperationsWebService() {
64      }
65  
66      public QueryOperationsWebService(EpcisQueryControlInterface queryModule) {
67          this.queryModule = queryModule;
68      }
69  
70      /**
71       * @see org.fosstrak.epcis.soap.EPCISServicePortType#getQueryNames(org.fosstrak.epcis.model.EmptyParms)
72       */
73      public ArrayOfString getQueryNames(EmptyParms empty) throws ImplementationExceptionResponse,
74              SecurityExceptionResponse, ValidationExceptionResponse {
75          ArrayOfString aos = new ArrayOfString();
76          aos.getString().addAll(queryModule.getQueryNames());
77          return aos;
78      }
79  
80      /**
81       * @see org.fosstrak.epcis.soap.EPCISServicePortType#getStandardVersion(org.fosstrak.epcis.model.EmptyParms)
82       */
83      public String getStandardVersion(EmptyParms empty) throws ImplementationExceptionResponse,
84              SecurityExceptionResponse, ValidationExceptionResponse {
85          return queryModule.getStandardVersion();
86      }
87  
88      /**
89       * @see org.fosstrak.epcis.soap.EPCISServicePortType#getSubscriptionIDs(org.fosstrak.epcis.model.GetSubscriptionIDs)
90       */
91      public ArrayOfString getSubscriptionIDs(GetSubscriptionIDs req) throws ImplementationExceptionResponse,
92              SecurityExceptionResponse, ValidationExceptionResponse, NoSuchNameExceptionResponse {
93          ArrayOfString aos = new ArrayOfString();
94          aos.getString().addAll(queryModule.getSubscriptionIDs(req.getQueryName()));
95          return aos;
96      }
97  
98      /**
99       * @see org.fosstrak.epcis.soap.EPCISServicePortType#getVendorVersion(org.fosstrak.epcis.model.EmptyParms)
100      */
101     public String getVendorVersion(EmptyParms empty) throws ImplementationExceptionResponse, SecurityExceptionResponse,
102             ValidationExceptionResponse {
103         return queryModule.getVendorVersion();
104     }
105 
106     /**
107      * @see org.fosstrak.epcis.soap.EPCISServicePortType#poll(org.fosstrak.epcis.model.Poll)
108      */
109     public QueryResults poll(Poll poll) throws ImplementationExceptionResponse, QueryTooComplexExceptionResponse,
110             QueryTooLargeExceptionResponse, SecurityExceptionResponse, ValidationExceptionResponse,
111             NoSuchNameExceptionResponse, QueryParameterExceptionResponse {
112         // log and wrap any error that is not one of the expected exceptions
113         try {
114             return queryModule.poll(poll.getQueryName(), poll.getParams());
115         } catch (ImplementationExceptionResponse e) {
116             throw e;
117         } catch (QueryTooComplexExceptionResponse e) {
118             throw e;
119         } catch (QueryTooLargeExceptionResponse e) {
120             throw e;
121         } catch (SecurityExceptionResponse e) {
122             throw e;
123         } catch (ValidationExceptionResponse e) {
124             throw e;
125         } catch (NoSuchNameExceptionResponse e) {
126             throw e;
127         } catch (QueryParameterExceptionResponse e) {
128             throw e;
129         } catch (Exception e) {
130             String msg = "Unexpected error occurred while processing request";
131             LOG.error(msg, e);
132             ImplementationException ie = new ImplementationException();
133             ie.setReason(msg);
134             ie.setSeverity(ImplementationExceptionSeverity.ERROR);
135             if (poll != null) {
136                 ie.setQueryName(poll.getQueryName());
137             }
138             throw new ImplementationExceptionResponse(msg, ie, e);
139         }
140     }
141 
142     /**
143      * @see org.fosstrak.epcis.soap.EPCISServicePortType#subscribe(org.fosstrak.epcis.model.Subscribe)
144      */
145     public VoidHolder subscribe(Subscribe subscribe) throws DuplicateSubscriptionExceptionResponse,
146             ImplementationExceptionResponse, QueryTooComplexExceptionResponse, SecurityExceptionResponse,
147             InvalidURIExceptionResponse, ValidationExceptionResponse, SubscribeNotPermittedExceptionResponse,
148             NoSuchNameExceptionResponse, SubscriptionControlsExceptionResponse, QueryParameterExceptionResponse {
149         // log and wrap any error that is not one of the expected exceptions
150         try {
151             queryModule.subscribe(subscribe.getQueryName(), subscribe.getParams(), subscribe.getDest(),
152                     subscribe.getControls(), subscribe.getSubscriptionID());
153             return new VoidHolder();
154         } catch (DuplicateSubscriptionExceptionResponse e) {
155             throw e;
156         } catch (ImplementationExceptionResponse e) {
157             throw e;
158         } catch (QueryTooComplexExceptionResponse e) {
159             throw e;
160         } catch (SecurityExceptionResponse e) {
161             throw e;
162         } catch (InvalidURIExceptionResponse e) {
163             throw e;
164         } catch (ValidationExceptionResponse e) {
165             throw e;
166         } catch (SubscribeNotPermittedExceptionResponse e) {
167             throw e;
168         } catch (NoSuchNameExceptionResponse e) {
169             throw e;
170         } catch (SubscriptionControlsExceptionResponse e) {
171             throw e;
172         } catch (QueryParameterExceptionResponse e) {
173             throw e;
174         } catch (Exception e) {
175             String msg = "Unknown error occurred while processing request";
176             LOG.error(msg, e);
177             ImplementationException ie = new ImplementationException();
178             ie.setReason(msg);
179             ie.setSeverity(ImplementationExceptionSeverity.ERROR);
180             if (subscribe != null) {
181                 ie.setQueryName(subscribe.getQueryName());
182                 ie.setSubscriptionID(subscribe.getSubscriptionID());
183             }
184             throw new ImplementationExceptionResponse(msg, ie, e);
185         }
186     }
187 
188     /**
189      * @see org.fosstrak.epcis.soap.EPCISServicePortType#unsubscribe(org.fosstrak.epcis.model.Unsubscribe)
190      */
191     public VoidHolder unsubscribe(Unsubscribe unsubscribe) throws ImplementationExceptionResponse,
192             SecurityExceptionResponse, ValidationExceptionResponse, NoSuchSubscriptionExceptionResponse {
193         // log and wrap any error that is not one of the expected exceptions
194         try {
195             queryModule.unsubscribe(unsubscribe.getSubscriptionID());
196             return new VoidHolder();
197         } catch (ImplementationExceptionResponse e) {
198             throw e;
199         } catch (SecurityExceptionResponse e) {
200             throw e;
201         } catch (NoSuchSubscriptionExceptionResponse e) {
202             throw e;
203         } catch (Exception e) {
204             String msg = "Unknown error occurred while processing request";
205             LOG.error(msg, e);
206             ImplementationException ie = new ImplementationException();
207             ie.setReason(msg);
208             ie.setSeverity(ImplementationExceptionSeverity.ERROR);
209             if (unsubscribe != null) {
210                 ie.setSubscriptionID(unsubscribe.getSubscriptionID());
211             }
212             throw new ImplementationExceptionResponse(msg, ie, e);
213         }
214     }
215 
216     /**
217      * @return the queryModule
218      */
219     public EpcisQueryControlInterface getQueryModule() {
220         return queryModule;
221     }
222 
223     /**
224      * @param queryModule
225      *            the queryModule to set
226      */
227     public void setQueryModule(EpcisQueryControlInterface queryModule) {
228         this.queryModule = queryModule;
229     }
230 
231 }