2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.aai.schemaservice.interceptors.post;
22 import org.onap.aai.exceptions.AAIException;
23 import org.onap.aai.logging.ErrorLogHelper;
24 import org.onap.aai.schemaservice.interceptors.AAIContainerFilter;
26 import javax.annotation.Priority;
27 import javax.ws.rs.container.ContainerRequestContext;
28 import javax.ws.rs.container.ContainerResponseContext;
29 import javax.ws.rs.container.ContainerResponseFilter;
30 import javax.ws.rs.core.MediaType;
31 import java.io.IOException;
32 import java.util.ArrayList;
33 import java.util.List;
35 @Priority(AAIResponseFilterPriority.INVALID_RESPONSE_STATUS)
36 public class InvalidResponseStatus extends AAIContainerFilter implements ContainerResponseFilter {
39 public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
42 if (responseContext.getStatus() == 405) {
44 responseContext.setStatus(400);
45 AAIException e = new AAIException("AAI_3012");
46 ArrayList<String> templateVars = new ArrayList<>();
48 List<MediaType> mediaTypeList = new ArrayList<>();
50 String contentType = responseContext.getHeaderString("Content-Type");
52 if (contentType == null) {
53 mediaTypeList.add(MediaType.APPLICATION_XML_TYPE);
55 mediaTypeList.add(MediaType.valueOf(contentType));
58 String message = ErrorLogHelper.getRESTAPIErrorResponse(mediaTypeList, e, templateVars);
60 responseContext.setEntity(message);