683d013eb1b54aefd2d5e8fd7ac4fc13f8035255
[policy/xacml-pdp.git] / main / src / main / java / org / onap / policy / pdpx / main / startstop / XacmlPdpRestServer.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.pdpx.main.startstop;
22
23 import java.util.List;
24 import java.util.Properties;
25 import javax.servlet.Filter;
26 import org.onap.policy.common.endpoints.http.server.JsonExceptionMapper;
27 import org.onap.policy.common.endpoints.http.server.RestServer;
28 import org.onap.policy.common.endpoints.http.server.YamlExceptionMapper;
29 import org.onap.policy.common.endpoints.http.server.YamlMessageBodyHandler;
30 import org.onap.policy.common.endpoints.parameters.RestServerParameters;
31 import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
32 import org.onap.policy.common.gson.GsonMessageBodyHandler;
33 import org.onap.policy.pdpx.main.rest.serialization.XacmlJsonExceptionMapper;
34 import org.onap.policy.pdpx.main.rest.serialization.XacmlJsonMessageBodyHandler;
35 import org.onap.policy.pdpx.main.rest.serialization.XacmlXmlExceptionMapper;
36 import org.onap.policy.pdpx.main.rest.serialization.XacmlXmlMessageBodyHandler;
37
38 /**
39  * Class to manage life cycle of a rest server that is particularly used by xacml pdp.
40  *
41  * @author Chenfei Gao (cgao@research.att.com)
42  */
43 public class XacmlPdpRestServer extends RestServer {
44
45     /**
46      * Constructs the object.
47      *
48      * @param restServerParameters the rest server parameters
49      * @param filters class of object to use to filter requests, or {@code null}
50      * @param jaxrsProviders classes providing the services
51      */
52     public XacmlPdpRestServer(final RestServerParameters restServerParameters,
53             List<Class<? extends Filter>> filters, List<Class<?>> jaxrsProviders) {
54
55         super(restServerParameters, filters, jaxrsProviders);
56     }
57
58     @Override
59     protected Properties getServerProperties(RestServerParameters restServerParameters, String names) {
60
61         final var props = super.getServerProperties(restServerParameters, names);
62         final String svcpfx =
63                         PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + restServerParameters.getName();
64
65         props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_SERIALIZATION_PROVIDER,
66                 String.join(",", GsonMessageBodyHandler.class.getName(), YamlMessageBodyHandler.class.getName(),
67                                 JsonExceptionMapper.class.getName(), YamlExceptionMapper.class.getName(),
68                                 XacmlJsonMessageBodyHandler.class.getName(), XacmlJsonExceptionMapper.class.getName(),
69                                 XacmlXmlMessageBodyHandler.class.getName(), XacmlXmlExceptionMapper.class.getName()));
70         return props;
71     }
72 }