2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.aai.sparky.subscription;
23 import javax.servlet.http.HttpServletRequest;
25 import org.apache.camel.Exchange;
26 import org.onap.aai.cl.api.Logger;
27 import org.onap.aai.cl.eelf.LoggerFactory;
28 import org.onap.aai.restclient.client.OperationResult;
29 import org.onap.aai.sparky.logging.AaiUiMsgs;
30 import org.onap.aai.sparky.logging.util.ServletUtils;
31 import org.onap.aai.sparky.subscription.services.SubscriptionService;
33 public class SubscriptionServiceProcessor {
35 private static final String EMPTY_RESPONSE = "{}";
37 private static final Logger LOG =
38 LoggerFactory.getInstance().getLogger(SubscriptionServiceProcessor.class);
40 SubscriptionService subService;
43 public SubscriptionServiceProcessor(SubscriptionService subscriptionService) {
44 this.subService = subscriptionService;
48 public void getSubscription(Exchange exchange) {
50 HttpServletRequest request = exchange.getIn().getBody(HttpServletRequest.class);
51 ServletUtils.setUpMdcContext(exchange, request);
53 OperationResult subscriptionResult = null;
57 subscriptionResult = subService.buildSubscriptionPayload();
59 } catch (Exception exc) {
60 subscriptionResult = new OperationResult();
61 subscriptionResult.setResult(EMPTY_RESPONSE);
62 LOG.error(AaiUiMsgs.FAILURE_TO_PROCESS_REQUEST,
63 "Exception thrown during subscription processing: " + exc.getLocalizedMessage());
66 exchange.getOut().setBody(subscriptionResult.getResult());