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=========================================================
21 package org.onap.aai.schemaservice.interceptors.post;
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.List;
27 import javax.annotation.Priority;
28 import javax.print.attribute.standard.Media;
29 import javax.ws.rs.container.ContainerRequestContext;
30 import javax.ws.rs.container.ContainerResponseContext;
31 import javax.ws.rs.container.ContainerResponseFilter;
32 import javax.ws.rs.core.MediaType;
33 import javax.ws.rs.core.UriInfo;
35 import org.onap.aai.exceptions.AAIException;
36 import org.onap.aai.logging.ErrorLogHelper;
37 import org.onap.aai.schemaservice.interceptors.AAIContainerFilter;
39 @Priority(AAIResponseFilterPriority.INVALID_RESPONSE_STATUS)
40 public class InvalidResponseStatus extends AAIContainerFilter implements ContainerResponseFilter {
43 public void filter(ContainerRequestContext requestContext,
44 ContainerResponseContext responseContext) throws IOException {
46 String contentType = responseContext.getHeaderString("Content-Type");
47 ArrayList<String> templateVars = new ArrayList<>();
48 List<MediaType> mediaTypeList = new ArrayList<>();
52 if (responseContext.getStatus() == 405) {
54 // add the accept type error msg here as well.
56 responseContext.setStatus(400);
57 e = new AAIException("AAI_3012");
59 if (contentType == null) {
60 mediaTypeList.add(MediaType.APPLICATION_XML_TYPE);
62 mediaTypeList.add(MediaType.valueOf(contentType));
65 message = ErrorLogHelper.getRESTAPIErrorResponse(mediaTypeList, e, templateVars);
67 responseContext.setEntity(message);
68 } else if (responseContext.getStatus() == 406) {
69 responseContext.setStatus(406);
70 mediaTypeList.add(MediaType.valueOf(contentType));
71 if (contentType == null) {
72 mediaTypeList.add(MediaType.APPLICATION_XML_TYPE);
73 e = new AAIException("AAI_3019", "null");
74 } else if (contentType.equals(MediaType.APPLICATION_XML)) {
75 e = new AAIException("AAI_3019", MediaType.APPLICATION_XML);
76 } else if (contentType.equals(MediaType.APPLICATION_JSON)) {
77 e = new AAIException("AAI_3019", MediaType.APPLICATION_JSON);
79 mediaTypeList.add(MediaType.valueOf(contentType));
80 e = new AAIException("AAI_3019", contentType);
82 message = ErrorLogHelper.getRESTAPIErrorResponse(mediaTypeList, e, templateVars);
83 responseContext.setEntity(message);