Fixes for sonar critical issues
[policy/engine.git] / PolicyEngineUtils / src / main / java / org / onap / policy / utils / BusConsumer.java
index bf92835..1b31394 100644 (file)
@@ -1,8 +1,30 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * PolicyEngineUtils
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
 package org.onap.policy.utils;
 
+import java.net.MalformedURLException;
 import java.util.List;
 import java.util.Properties;
 
+import com.att.nsa.mr.client.MRClient.MRApiException;
 import com.att.nsa.mr.client.impl.MRConsumerImpl;
 import com.att.nsa.mr.test.clients.ProtocolTypeConstants;
 
@@ -12,9 +34,9 @@ public interface BusConsumer {
         * fetch messages
         * 
         * @return list of messages
-        * @throws Exception when error encountered by underlying libraries
+        * @throws MRApiException when error encountered by underlying libraries
         */
-       public Iterable<String> fetch() throws Exception;
+       public Iterable<String> fetch() throws MRApiException;
        
        /**
         * close underlying library consumer
@@ -48,8 +70,7 @@ public interface BusConsumer {
                public DmaapConsumerWrapper(List<String> servers, String topic, 
                                                                String aafLogin, String aafPassword,
                                                                String consumerGroup, String consumerInstance,
-                                                               int fetchTimeout, int fetchLimit) 
-               throws Exception {
+                                                               int fetchTimeout, int fetchLimit)  throws MalformedURLException{
                                        
                        this.consumer = new MRConsumerImpl(servers, topic, 
                                                                                           consumerGroup, consumerInstance, 
@@ -70,8 +91,12 @@ public interface BusConsumer {
                /**
                 * {@inheritDoc}
                 */
-               public Iterable<String> fetch() throws Exception {
-                       return this.consumer.fetch();
+               public Iterable<String> fetch() throws MRApiException {
+                       try {
+                return this.consumer.fetch();
+            } catch (Exception e) {
+                throw new MRApiException("Error during MR consumer Fetch ",e);
+            }
                }
                
                /**