2 * ============LICENSE_START===================================================
3 * SPARKY (AAI UI service)
4 * ============================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=====================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
25 package org.onap.aai.sparky.subscription;
27 import javax.servlet.http.HttpServletRequest;
29 import org.apache.camel.Exchange;
30 import org.onap.aai.cl.api.Logger;
31 import org.onap.aai.cl.eelf.LoggerFactory;
32 import org.onap.aai.restclient.client.OperationResult;
33 import org.onap.aai.sparky.logging.AaiUiMsgs;
34 import org.onap.aai.sparky.logging.util.ServletUtils;
35 import org.onap.aai.sparky.subscription.services.SubscriptionService;
37 public class SubscriptionServiceProcessor {
39 private static final String EMPTY_RESPONSE = "{}";
41 private static final Logger LOG =
42 LoggerFactory.getInstance().getLogger(SubscriptionServiceProcessor.class);
44 SubscriptionService subService;
47 public SubscriptionServiceProcessor(SubscriptionService subscriptionService) {
48 this.subService = subscriptionService;
52 public void getSubscription(Exchange exchange) {
54 HttpServletRequest request = exchange.getIn().getBody(HttpServletRequest.class);
55 ServletUtils.setUpMdcContext(exchange, request);
57 OperationResult subscriptionResult = null;
61 subscriptionResult = subService.buildSubscriptionPayload();
63 } catch (Exception exc) {
64 subscriptionResult = new OperationResult();
65 subscriptionResult.setResult(EMPTY_RESPONSE);
66 LOG.error(AaiUiMsgs.FAILURE_TO_PROCESS_REQUEST,
67 "Exception thrown during subscription processing: " + exc.getLocalizedMessage());
70 exchange.getOut().setBody(subscriptionResult.getResult());