From b1ba8ef51edabee26acaf74e226eeb269297aec7 Mon Sep 17 00:00:00 2001 From: Jerry Flood Date: Tue, 16 Apr 2019 09:06:17 -0400 Subject: More checkstyle changes for Dublin Issue-ID: OPTFRA-466 Change-Id: Ied602196284bf3aed56ff491a749f14503395c88 Signed-off-by: Jerry Flood --- cmso-ticketmgt/pom.xml | 2 +- .../java/org/onap/observations/MessageHeaders.java | 24 +++- .../optf/cmso/CMSEnvironmentPostProcessor.java | 61 --------- .../optf/cmso/CmsoEnvironmentPostProcessor.java | 61 +++++++++ .../org/onap/optf/cmso/common/CMSRequestError.java | 79 ------------ .../onap/optf/cmso/common/CmsoRequestError.java | 79 ++++++++++++ .../optf/cmso/common/exceptions/CMSException.java | 81 ------------ .../optf/cmso/common/exceptions/CmsoException.java | 81 ++++++++++++ .../ticketmgt/CMSEnvironmentPostProcessor.java | 61 --------- .../ticketmgt/CmsoEnvironmentPostProcessor.java | 61 +++++++++ .../onap/optf/ticketmgt/JerseyConfiguration.java | 4 +- .../optf/ticketmgt/aaf/AafAuthorizationFilter.java | 4 +- .../org/onap/optf/ticketmgt/aaf/AafFilter.java | 4 +- .../onap/optf/ticketmgt/aaf/ResponseFormatter.java | 4 +- .../optf/ticketmgt/filters/CMSOClientFilters.java | 84 ------------- .../ticketmgt/filters/CMSOContainerFilters.java | 139 --------------------- .../optf/ticketmgt/filters/CmsoClientFilters.java | 84 +++++++++++++ .../ticketmgt/filters/CmsoContainerFilters.java | 139 +++++++++++++++++++++ .../service/rs/AvailabilityInterface.java | 8 +- .../ticketmgt/service/rs/TicketManagement.java | 14 +-- 20 files changed, 545 insertions(+), 529 deletions(-) delete mode 100644 cmso-ticketmgt/src/main/java/org/onap/optf/cmso/CMSEnvironmentPostProcessor.java create mode 100644 cmso-ticketmgt/src/main/java/org/onap/optf/cmso/CmsoEnvironmentPostProcessor.java delete mode 100644 cmso-ticketmgt/src/main/java/org/onap/optf/cmso/common/CMSRequestError.java create mode 100644 cmso-ticketmgt/src/main/java/org/onap/optf/cmso/common/CmsoRequestError.java delete mode 100644 cmso-ticketmgt/src/main/java/org/onap/optf/cmso/common/exceptions/CMSException.java create mode 100644 cmso-ticketmgt/src/main/java/org/onap/optf/cmso/common/exceptions/CmsoException.java delete mode 100644 cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/CMSEnvironmentPostProcessor.java create mode 100644 cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/CmsoEnvironmentPostProcessor.java delete mode 100644 cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/filters/CMSOClientFilters.java delete mode 100644 cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/filters/CMSOContainerFilters.java create mode 100644 cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/filters/CmsoClientFilters.java create mode 100644 cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/filters/CmsoContainerFilters.java (limited to 'cmso-ticketmgt') diff --git a/cmso-ticketmgt/pom.xml b/cmso-ticketmgt/pom.xml index 1274360..88dce59 100644 --- a/cmso-ticketmgt/pom.xml +++ b/cmso-ticketmgt/pom.xml @@ -22,7 +22,7 @@ 1.0.1-SNAPSHOT - org.onap.optf.cmso.tcketmgt + org.onap.optf.cmso.ticketmgt cmso-ticketmgt jar diff --git a/cmso-ticketmgt/src/main/java/org/onap/observations/MessageHeaders.java b/cmso-ticketmgt/src/main/java/org/onap/observations/MessageHeaders.java index f140aec..e968728 100644 --- a/cmso-ticketmgt/src/main/java/org/onap/observations/MessageHeaders.java +++ b/cmso-ticketmgt/src/main/java/org/onap/observations/MessageHeaders.java @@ -69,7 +69,7 @@ public class MessageHeaders { } /** The Constant supportedMajorVersions. */ - public static final Map supportedMajorVersions = new HashMap(); + private static final Map supportedMajorVersions = new HashMap(); static { supportedMajorVersions.put("v1", "0"); @@ -77,7 +77,7 @@ public class MessageHeaders { } /** The Constant supportedMajorMinorVersions. */ - public static final Set supportedMajorMinorVersions = new HashSet(); + private static final Set supportedMajorMinorVersions = new HashSet(); static { supportedMajorMinorVersions.add("v1.0"); @@ -85,10 +85,10 @@ public class MessageHeaders { } /** The Constant latestVersion. */ - public static final String latestVersion = "2.0.0"; + private static final String latestVersion = "2.0.0"; /** The Constant patchVersion. */ - public static final String patchVersion = "0"; + private static final String patchVersion = "0"; /** * From string. @@ -156,4 +156,20 @@ public class MessageHeaders { } return true; } + + public static Map getSupportedmajorversions() { + return supportedMajorVersions; + } + + public static Set getSupportedmajorminorversions() { + return supportedMajorMinorVersions; + } + + public static String getLatestversion() { + return latestVersion; + } + + public static String getPatchversion() { + return patchVersion; + } } diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/cmso/CMSEnvironmentPostProcessor.java b/cmso-ticketmgt/src/main/java/org/onap/optf/cmso/CMSEnvironmentPostProcessor.java deleted file mode 100644 index eb9ddad..0000000 --- a/cmso-ticketmgt/src/main/java/org/onap/optf/cmso/CMSEnvironmentPostProcessor.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); - * you may not use this documentation except in compliance with the License. - * You may obtain a copy of the License at - * - * https://creativecommons.org/licenses/by/4.0/ - * - * Unless required by applicable law or agreed to in writing, documentation - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. -*/ - -package org.onap.optf.cmso; - -import java.util.HashMap; -import java.util.Map; -import org.onap.optf.cmso.common.PropertiesManagement; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.env.EnvironmentPostProcessor; -import org.springframework.core.env.ConfigurableEnvironment; -import org.springframework.core.env.MapPropertySource; -import org.springframework.core.env.MutablePropertySources; - -public class CMSEnvironmentPostProcessor implements EnvironmentPostProcessor { - // TODO tested in ONAP springboot and this is called before all of the properties files have been - // loaded... - // perhaps there is a post post processor? Until this works. DB password will be in the clear in the - // proeprties files. - @Override - public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { - String pwd = environment.getProperty("cmso.database.password"); - if (pwd != null) { - pwd = PropertiesManagement.getDecryptedValue(pwd); - Map map = new HashMap(); - map.put("spring.datasource.password", pwd); - MapPropertySource propertySource = new MapPropertySource("abc", map); - MutablePropertySources proeprtySources = environment.getPropertySources(); - proeprtySources.addLast(propertySource); - } - } - -} diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/cmso/CmsoEnvironmentPostProcessor.java b/cmso-ticketmgt/src/main/java/org/onap/optf/cmso/CmsoEnvironmentPostProcessor.java new file mode 100644 index 0000000..2426a5c --- /dev/null +++ b/cmso-ticketmgt/src/main/java/org/onap/optf/cmso/CmsoEnvironmentPostProcessor.java @@ -0,0 +1,61 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package org.onap.optf.cmso; + +import java.util.HashMap; +import java.util.Map; +import org.onap.optf.cmso.common.PropertiesManagement; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.env.EnvironmentPostProcessor; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.MapPropertySource; +import org.springframework.core.env.MutablePropertySources; + +public class CmsoEnvironmentPostProcessor implements EnvironmentPostProcessor { + // TODO tested in ONAP springboot and this is called before all of the properties files have been + // loaded... + // perhaps there is a post post processor? Until this works. DB password will be in the clear in the + // proeprties files. + @Override + public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { + String pwd = environment.getProperty("cmso.database.password"); + if (pwd != null) { + pwd = PropertiesManagement.getDecryptedValue(pwd); + Map map = new HashMap(); + map.put("spring.datasource.password", pwd); + MapPropertySource propertySource = new MapPropertySource("abc", map); + MutablePropertySources proeprtySources = environment.getPropertySources(); + proeprtySources.addLast(propertySource); + } + } + +} diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/cmso/common/CMSRequestError.java b/cmso-ticketmgt/src/main/java/org/onap/optf/cmso/common/CMSRequestError.java deleted file mode 100644 index 4ba7d48..0000000 --- a/cmso-ticketmgt/src/main/java/org/onap/optf/cmso/common/CMSRequestError.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); - * you may not use this documentation except in compliance with the License. - * You may obtain a copy of the License at - * - * https://creativecommons.org/licenses/by/4.0/ - * - * Unless required by applicable law or agreed to in writing, documentation - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. -*/ - -package org.onap.optf.cmso.common; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -public class CMSRequestError implements Serializable { - private static final long serialVersionUID = 1L; - @JsonProperty - RequestError requestError; - - public CMSRequestError(String messageId, String text, List variables) { - requestError = new RequestError(messageId, text, variables); - } - - public CMSRequestError(String messageId, String text) { - requestError = new RequestError(messageId, text, new ArrayList()); - } - - public class RequestError { - @JsonProperty - private String messageId; - @JsonProperty - private String text; - @JsonProperty - private List variables; - - private RequestError(String messageId, String text, List variables) { - this.messageId = "Scheduler." + messageId; - this.text = text; - this.variables = variables; - } - - @Override - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append(messageId).append(":").append(text).append(":").append(variables); - return sb.toString(); - - } - } - - @Override - public String toString() { - return requestError.toString(); - } -} diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/cmso/common/CmsoRequestError.java b/cmso-ticketmgt/src/main/java/org/onap/optf/cmso/common/CmsoRequestError.java new file mode 100644 index 0000000..ba28a2d --- /dev/null +++ b/cmso-ticketmgt/src/main/java/org/onap/optf/cmso/common/CmsoRequestError.java @@ -0,0 +1,79 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package org.onap.optf.cmso.common; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +public class CmsoRequestError implements Serializable { + private static final long serialVersionUID = 1L; + @JsonProperty + RequestError requestError; + + public CmsoRequestError(String messageId, String text, List variables) { + requestError = new RequestError(messageId, text, variables); + } + + public CmsoRequestError(String messageId, String text) { + requestError = new RequestError(messageId, text, new ArrayList()); + } + + public class RequestError { + @JsonProperty + private String messageId; + @JsonProperty + private String text; + @JsonProperty + private List variables; + + private RequestError(String messageId, String text, List variables) { + this.messageId = "Scheduler." + messageId; + this.text = text; + this.variables = variables; + } + + @Override + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append(messageId).append(":").append(text).append(":").append(variables); + return sb.toString(); + + } + } + + @Override + public String toString() { + return requestError.toString(); + } +} diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/cmso/common/exceptions/CMSException.java b/cmso-ticketmgt/src/main/java/org/onap/optf/cmso/common/exceptions/CMSException.java deleted file mode 100644 index e8b5e03..0000000 --- a/cmso-ticketmgt/src/main/java/org/onap/optf/cmso/common/exceptions/CMSException.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright © 2017-2019 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); - * you may not use this documentation except in compliance with the License. - * You may obtain a copy of the License at - * - * https://creativecommons.org/licenses/by/4.0/ - * - * Unless required by applicable law or agreed to in writing, documentation - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. -*/ - -package org.onap.optf.cmso.common.exceptions; - -import com.att.eelf.i18n.EELFResourceManager; -import java.util.ArrayList; -import java.util.List; -import javax.ws.rs.core.Response.Status; -import org.onap.observations.ObservationInterface; -import org.onap.optf.cmso.common.CMSRequestError; - -public class CMSException extends Exception { - private static final long serialVersionUID = 1L; - - protected CMSRequestError requestError = null; - private List variables = new ArrayList(); - protected ObservationInterface messageCode; - protected Status status; - - /** - * Instantiates a new CMS exception. - * - * @param status the status - * @param messageCode the message code - * @param args the args - */ - public CMSException(Status status, ObservationInterface messageCode, String... args) { - super(EELFResourceManager.format(messageCode, args)); - this.status = status; - this.messageCode = messageCode; - for (String arg : args) { - variables.add(arg); - } - requestError = new CMSRequestError(messageCode.name(), getMessage(), variables); - } - - public Status getStatus() { - return status; - } - - public ObservationInterface getMessageCode() { - return messageCode; - } - - public String[] getVariables() { - return variables.toArray(new String[variables.size()]); - } - - public CMSRequestError getRequestError() { - return requestError; - } -} diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/cmso/common/exceptions/CmsoException.java b/cmso-ticketmgt/src/main/java/org/onap/optf/cmso/common/exceptions/CmsoException.java new file mode 100644 index 0000000..c80cd56 --- /dev/null +++ b/cmso-ticketmgt/src/main/java/org/onap/optf/cmso/common/exceptions/CmsoException.java @@ -0,0 +1,81 @@ +/* + * Copyright © 2017-2019 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package org.onap.optf.cmso.common.exceptions; + +import com.att.eelf.i18n.EELFResourceManager; +import java.util.ArrayList; +import java.util.List; +import javax.ws.rs.core.Response.Status; +import org.onap.observations.ObservationInterface; +import org.onap.optf.cmso.common.CmsoRequestError; + +public class CmsoException extends Exception { + private static final long serialVersionUID = 1L; + + protected CmsoRequestError requestError = null; + private List variables = new ArrayList(); + protected ObservationInterface messageCode; + protected Status status; + + /** + * Instantiates a new CMS exception. + * + * @param status the status + * @param messageCode the message code + * @param args the args + */ + public CmsoException(Status status, ObservationInterface messageCode, String... args) { + super(EELFResourceManager.format(messageCode, args)); + this.status = status; + this.messageCode = messageCode; + for (String arg : args) { + variables.add(arg); + } + requestError = new CmsoRequestError(messageCode.name(), getMessage(), variables); + } + + public Status getStatus() { + return status; + } + + public ObservationInterface getMessageCode() { + return messageCode; + } + + public String[] getVariables() { + return variables.toArray(new String[variables.size()]); + } + + public CmsoRequestError getRequestError() { + return requestError; + } +} diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/CMSEnvironmentPostProcessor.java b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/CMSEnvironmentPostProcessor.java deleted file mode 100644 index d955e75..0000000 --- a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/CMSEnvironmentPostProcessor.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); - * you may not use this documentation except in compliance with the License. - * You may obtain a copy of the License at - * - * https://creativecommons.org/licenses/by/4.0/ - * - * Unless required by applicable law or agreed to in writing, documentation - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. -*/ - -package org.onap.optf.ticketmgt; - -import java.util.HashMap; -import java.util.Map; -import org.onap.optf.cmso.common.PropertiesManagement; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.env.EnvironmentPostProcessor; -import org.springframework.core.env.ConfigurableEnvironment; -import org.springframework.core.env.MapPropertySource; -import org.springframework.core.env.MutablePropertySources; - -public class CMSEnvironmentPostProcessor implements EnvironmentPostProcessor { - // TODO tested in ONAP springboot and this is called before all of the properties files have been - // loaded... - // perhaps there is a post post processor? Until this works. DB password will be in the clear in the - // proeprties files. - @Override - public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { - String pwd = environment.getProperty("cmso.database.password"); - if (pwd != null) { - pwd = PropertiesManagement.getDecryptedValue(pwd); - Map map = new HashMap(); - map.put("spring.datasource.password", pwd); - MapPropertySource propertySource = new MapPropertySource("abc", map); - MutablePropertySources proeprtySources = environment.getPropertySources(); - proeprtySources.addLast(propertySource); - } - } - -} diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/CmsoEnvironmentPostProcessor.java b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/CmsoEnvironmentPostProcessor.java new file mode 100644 index 0000000..1230591 --- /dev/null +++ b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/CmsoEnvironmentPostProcessor.java @@ -0,0 +1,61 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package org.onap.optf.ticketmgt; + +import java.util.HashMap; +import java.util.Map; +import org.onap.optf.cmso.common.PropertiesManagement; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.env.EnvironmentPostProcessor; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.MapPropertySource; +import org.springframework.core.env.MutablePropertySources; + +public class CmsoEnvironmentPostProcessor implements EnvironmentPostProcessor { + // TODO tested in ONAP springboot and this is called before all of the properties files have been + // loaded... + // perhaps there is a post post processor? Until this works. DB password will be in the clear in the + // proeprties files. + @Override + public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { + String pwd = environment.getProperty("cmso.database.password"); + if (pwd != null) { + pwd = PropertiesManagement.getDecryptedValue(pwd); + Map map = new HashMap(); + map.put("spring.datasource.password", pwd); + MapPropertySource propertySource = new MapPropertySource("abc", map); + MutablePropertySources proeprtySources = environment.getPropertySources(); + proeprtySources.addLast(propertySource); + } + } + +} diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/JerseyConfiguration.java b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/JerseyConfiguration.java index c4fe51a..1cbf19c 100644 --- a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/JerseyConfiguration.java +++ b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/JerseyConfiguration.java @@ -44,7 +44,7 @@ import org.glassfish.jersey.client.ClientConfig; import org.glassfish.jersey.logging.LoggingFeature; import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.servlet.ServletProperties; -import org.onap.optf.ticketmgt.filters.CMSOContainerFilters; +import org.onap.optf.ticketmgt.filters.CmsoContainerFilters; import org.onap.optf.ticketmgt.service.rs.AdminToolImpl; import org.onap.optf.ticketmgt.service.rs.AvailabilityInterfaceImpl; import org.onap.optf.ticketmgt.service.rs.HealthCheckImpl; @@ -91,7 +91,7 @@ public class JerseyConfiguration extends ResourceConfig { // TODO: Examine which logging features to enable register(new LoggingFeature(log)); - register(CMSOContainerFilters.class); + register(CmsoContainerFilters.class); } /** diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/aaf/AafAuthorizationFilter.java b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/aaf/AafAuthorizationFilter.java index ffbd94e..ea044a4 100644 --- a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/aaf/AafAuthorizationFilter.java +++ b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/aaf/AafAuthorizationFilter.java @@ -26,7 +26,7 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.onap.observations.Observation; -import org.onap.optf.cmso.common.exceptions.CMSException; +import org.onap.optf.cmso.common.exceptions.CmsoException; import org.onap.optf.ticketmgt.SpringProfiles; import org.onap.optf.ticketmgt.common.LogMessages; import org.springframework.beans.factory.annotation.Value; @@ -69,7 +69,7 @@ public class AafAuthorizationFilter extends OrderedRequestContextFilter { if (!request.isUserInRole(permission)) { Observation.report(LogMessages.UNAUTHORIZED); ResponseFormatter.errorResponse(request, response, - new CMSException(LogMessages.UNAUTHORIZED.getStatus(), LogMessages.UNAUTHORIZED, "")); + new CmsoException(LogMessages.UNAUTHORIZED.getStatus(), LogMessages.UNAUTHORIZED, "")); } else { filterChain.doFilter(request, response); } diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/aaf/AafFilter.java b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/aaf/AafFilter.java index c0c8106..1f27fee 100644 --- a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/aaf/AafFilter.java +++ b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/aaf/AafFilter.java @@ -29,7 +29,7 @@ import javax.servlet.http.HttpServletResponse; import org.onap.aaf.cadi.PropAccess; import org.onap.aaf.cadi.filter.CadiFilter; import org.onap.observations.Observation; -import org.onap.optf.cmso.common.exceptions.CMSException; +import org.onap.optf.cmso.common.exceptions.CmsoException; import org.onap.optf.ticketmgt.Application; import org.onap.optf.ticketmgt.SpringProfiles; import org.onap.optf.ticketmgt.common.LogMessages; @@ -67,7 +67,7 @@ public class AafFilter extends OrderedRequestContextFilter { cadiFilter.doFilter(request, response, filterChain); if (response.getStatus() >= 400 && response.getStatus() < 500) { Observation.report(LogMessages.UNAUTHENTICATED); - ResponseFormatter.errorResponse(request, response, new CMSException( + ResponseFormatter.errorResponse(request, response, new CmsoException( LogMessages.UNAUTHENTICATED.getStatus(), LogMessages.UNAUTHENTICATED, "")); } } else { diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/aaf/ResponseFormatter.java b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/aaf/ResponseFormatter.java index b9b222c..156b3ce 100644 --- a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/aaf/ResponseFormatter.java +++ b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/aaf/ResponseFormatter.java @@ -23,12 +23,12 @@ package org.onap.optf.ticketmgt.aaf; import java.io.IOException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.onap.optf.cmso.common.exceptions.CMSException; +import org.onap.optf.cmso.common.exceptions.CmsoException; class ResponseFormatter { - static void errorResponse(HttpServletRequest request, HttpServletResponse response, CMSException error) + static void errorResponse(HttpServletRequest request, HttpServletResponse response, CmsoException error) throws IOException { response.setStatus(error.getStatus().getStatusCode()); response.getWriter().write(error.getRequestError().toString()); diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/filters/CMSOClientFilters.java b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/filters/CMSOClientFilters.java deleted file mode 100644 index 54b1b38..0000000 --- a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/filters/CMSOClientFilters.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright © 2017-2019 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); - * you may not use this documentation except in compliance with the License. - * You may obtain a copy of the License at - * - * https://creativecommons.org/licenses/by/4.0/ - * - * Unless required by applicable law or agreed to in writing, documentation - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. -*/ - -package org.onap.optf.ticketmgt.filters; - -import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID; - -import java.io.IOException; -import javax.ws.rs.client.ClientRequestContext; -import javax.ws.rs.client.ClientRequestFilter; -import javax.ws.rs.client.ClientResponseContext; -import javax.ws.rs.client.ClientResponseFilter; -import javax.ws.rs.core.MultivaluedMap; -import org.onap.observations.Mdc; -import org.onap.observations.MessageHeaders; -import org.onap.observations.MessageHeaders.HeadersEnum; -import org.onap.observations.Observation; -import org.onap.optf.ticketmgt.common.LogMessages; -import org.slf4j.MDC; -import org.springframework.stereotype.Component; - -// @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") -@Component -public class CMSOClientFilters implements ClientRequestFilter, ClientResponseFilter { - - private static String appId = "cmso"; - - @Override - public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException { - // On the way back - Mdc.metricEnd(responseContext); - Mdc.setCaller(17); - Observation.report(LogMessages.OUTGOING_MESSAGE_RETURNED, requestContext.getMethod(), - requestContext.getUri().getPath().toString(), responseContext.getStatusInfo().toString()); - } - - @Override - public void filter(ClientRequestContext requestContext) throws IOException { - // On the way out - Mdc.metricStart(requestContext); - Mdc.setCaller(17); - Observation.report(LogMessages.OUTGOING_MESSAGE, requestContext.getMethod(), - requestContext.getUri().getPath().toString()); - MultivaluedMap headers = requestContext.getHeaders(); - - String transactionId = (String) headers.getFirst(MessageHeaders.HeadersEnum.TransactionID.toString()); - String mdcId = MDC.get(MDC_KEY_REQUEST_ID); - if (transactionId == null || transactionId.equals("")) { - if (mdcId != null) { - headers.add(HeadersEnum.TransactionID.toString(), mdcId); - } - } - headers.add(HeadersEnum.FromAppID.toString(), appId); - } - -} diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/filters/CMSOContainerFilters.java b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/filters/CMSOContainerFilters.java deleted file mode 100644 index 4f6b8e7..0000000 --- a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/filters/CMSOContainerFilters.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright © 2017-2019 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); - * you may not use this documentation except in compliance with the License. - * You may obtain a copy of the License at - * - * https://creativecommons.org/licenses/by/4.0/ - * - * Unless required by applicable law or agreed to in writing, documentation - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. -*/ - -package org.onap.optf.ticketmgt.filters; - -import java.io.IOException; -import java.util.UUID; -import javax.annotation.Priority; -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.container.ContainerRequestContext; -import javax.ws.rs.container.ContainerRequestFilter; -import javax.ws.rs.container.ContainerResponseContext; -import javax.ws.rs.container.ContainerResponseFilter; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.ResponseBuilder; -import javax.ws.rs.ext.Provider; -import org.onap.observations.Mdc; -import org.onap.observations.MessageHeaders; -import org.onap.observations.MessageHeaders.HeadersEnum; -import org.onap.observations.Observation; -import org.onap.optf.ticketmgt.common.LogMessages; -import org.springframework.stereotype.Component; - -@Priority(1) -@Provider -@Component -public class CMSOContainerFilters implements ContainerRequestFilter, ContainerResponseFilter { - - - @Context - private HttpServletRequest servletRequest; - - @Override - public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) - throws IOException { - try { - Mdc.auditEnd(requestContext, responseContext); - Observation.report(LogMessages.INCOMING_MESSAGE_RESPONSE, requestContext.getMethod(), - requestContext.getUriInfo().getPath().toString(), - responseContext.getStatusInfo().toString()); - MultivaluedMap reqHeaders = requestContext.getHeaders(); - MultivaluedMap respHeaders = responseContext.getHeaders(); - String minorVersion = reqHeaders.getFirst(HeadersEnum.MinorVersion.toString()); - respHeaders.add(HeadersEnum.MinorVersion.toString(), minorVersion); - respHeaders.add(HeadersEnum.LatestVersion.toString(), MessageHeaders.latestVersion); - respHeaders.add(HeadersEnum.PatchVersion.toString(), MessageHeaders.patchVersion); - - } catch (Exception e) { - if (e instanceof WebApplicationException) { - Observation.report(LogMessages.EXPECTED_EXCEPTION, e.getMessage()); - } else { - Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e.getMessage()); - } - } - } - - @Override - public void filter(ContainerRequestContext requestContext) throws IOException { - try { - // On the way in - Mdc.auditStart(requestContext, servletRequest); - Observation.report(LogMessages.INCOMING_MESSAGE, requestContext.getMethod(), - requestContext.getUriInfo().getPath().toString()); - - String majorVersion = requestContext.getUriInfo().getPath(); - if (majorVersion != null) { - - if (majorVersion.startsWith("dispatch/")) { - return; - } - majorVersion = majorVersion.replaceAll("/.*$", ""); - } - if (!MessageHeaders.validateMajorVersion(majorVersion)) { - ResponseBuilder builder = null; - String response = "Unsupported Major version"; - builder = Response.status(Response.Status.NOT_FOUND).entity(response); - throw new WebApplicationException(builder.build()); - } - MultivaluedMap headers = requestContext.getHeaders(); - String transactionId = headers.getFirst(HeadersEnum.TransactionID.toString()); - if (transactionId == null) { - transactionId = UUID.randomUUID().toString(); - headers.add(HeadersEnum.TransactionID.toString(), transactionId); - } - String minorVersion = headers.getFirst(HeadersEnum.MinorVersion.toString()); - if (minorVersion == null) { - minorVersion = MessageHeaders.supportedMajorVersions.get(majorVersion); - headers.add(HeadersEnum.MinorVersion.toString(), minorVersion); - } - if (!MessageHeaders.validateMajorMinorVersion(majorVersion, minorVersion)) { - ResponseBuilder builder = null; - String response = "Unsupported API version"; - builder = Response.status(Response.Status.NOT_FOUND).entity(response); - throw new WebApplicationException(builder.build()); - - } - } catch (Exception e) { - if (e instanceof WebApplicationException) { - Observation.report(LogMessages.EXPECTED_EXCEPTION, e.getMessage()); - throw e; - } else { - Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e.getMessage()); - } - } - - } - -} diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/filters/CmsoClientFilters.java b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/filters/CmsoClientFilters.java new file mode 100644 index 0000000..ac1569c --- /dev/null +++ b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/filters/CmsoClientFilters.java @@ -0,0 +1,84 @@ +/* + * Copyright © 2017-2019 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package org.onap.optf.ticketmgt.filters; + +import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID; + +import java.io.IOException; +import javax.ws.rs.client.ClientRequestContext; +import javax.ws.rs.client.ClientRequestFilter; +import javax.ws.rs.client.ClientResponseContext; +import javax.ws.rs.client.ClientResponseFilter; +import javax.ws.rs.core.MultivaluedMap; +import org.onap.observations.Mdc; +import org.onap.observations.MessageHeaders; +import org.onap.observations.MessageHeaders.HeadersEnum; +import org.onap.observations.Observation; +import org.onap.optf.ticketmgt.common.LogMessages; +import org.slf4j.MDC; +import org.springframework.stereotype.Component; + +// @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") +@Component +public class CmsoClientFilters implements ClientRequestFilter, ClientResponseFilter { + + private static String appId = "cmso"; + + @Override + public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException { + // On the way back + Mdc.metricEnd(responseContext); + Mdc.setCaller(17); + Observation.report(LogMessages.OUTGOING_MESSAGE_RETURNED, requestContext.getMethod(), + requestContext.getUri().getPath().toString(), responseContext.getStatusInfo().toString()); + } + + @Override + public void filter(ClientRequestContext requestContext) throws IOException { + // On the way out + Mdc.metricStart(requestContext); + Mdc.setCaller(17); + Observation.report(LogMessages.OUTGOING_MESSAGE, requestContext.getMethod(), + requestContext.getUri().getPath().toString()); + MultivaluedMap headers = requestContext.getHeaders(); + + String transactionId = (String) headers.getFirst(MessageHeaders.HeadersEnum.TransactionID.toString()); + String mdcId = MDC.get(MDC_KEY_REQUEST_ID); + if (transactionId == null || transactionId.equals("")) { + if (mdcId != null) { + headers.add(HeadersEnum.TransactionID.toString(), mdcId); + } + } + headers.add(HeadersEnum.FromAppID.toString(), appId); + } + +} diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/filters/CmsoContainerFilters.java b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/filters/CmsoContainerFilters.java new file mode 100644 index 0000000..5b73a85 --- /dev/null +++ b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/filters/CmsoContainerFilters.java @@ -0,0 +1,139 @@ +/* + * Copyright © 2017-2019 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +package org.onap.optf.ticketmgt.filters; + +import java.io.IOException; +import java.util.UUID; +import javax.annotation.Priority; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.container.ContainerRequestContext; +import javax.ws.rs.container.ContainerRequestFilter; +import javax.ws.rs.container.ContainerResponseContext; +import javax.ws.rs.container.ContainerResponseFilter; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.ResponseBuilder; +import javax.ws.rs.ext.Provider; +import org.onap.observations.Mdc; +import org.onap.observations.MessageHeaders; +import org.onap.observations.MessageHeaders.HeadersEnum; +import org.onap.observations.Observation; +import org.onap.optf.ticketmgt.common.LogMessages; +import org.springframework.stereotype.Component; + +@Priority(1) +@Provider +@Component +public class CmsoContainerFilters implements ContainerRequestFilter, ContainerResponseFilter { + + + @Context + private HttpServletRequest servletRequest; + + @Override + public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) + throws IOException { + try { + Mdc.auditEnd(requestContext, responseContext); + Observation.report(LogMessages.INCOMING_MESSAGE_RESPONSE, requestContext.getMethod(), + requestContext.getUriInfo().getPath().toString(), + responseContext.getStatusInfo().toString()); + MultivaluedMap reqHeaders = requestContext.getHeaders(); + MultivaluedMap respHeaders = responseContext.getHeaders(); + String minorVersion = reqHeaders.getFirst(HeadersEnum.MinorVersion.toString()); + respHeaders.add(HeadersEnum.MinorVersion.toString(), minorVersion); + respHeaders.add(HeadersEnum.LatestVersion.toString(), MessageHeaders.getLatestversion()); + respHeaders.add(HeadersEnum.PatchVersion.toString(), MessageHeaders.getPatchversion()); + + } catch (Exception e) { + if (e instanceof WebApplicationException) { + Observation.report(LogMessages.EXPECTED_EXCEPTION, e.getMessage()); + } else { + Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e.getMessage()); + } + } + } + + @Override + public void filter(ContainerRequestContext requestContext) throws IOException { + try { + // On the way in + Mdc.auditStart(requestContext, servletRequest); + Observation.report(LogMessages.INCOMING_MESSAGE, requestContext.getMethod(), + requestContext.getUriInfo().getPath().toString()); + + String majorVersion = requestContext.getUriInfo().getPath(); + if (majorVersion != null) { + + if (majorVersion.startsWith("dispatch/")) { + return; + } + majorVersion = majorVersion.replaceAll("/.*$", ""); + } + if (!MessageHeaders.validateMajorVersion(majorVersion)) { + ResponseBuilder builder = null; + String response = "Unsupported Major version"; + builder = Response.status(Response.Status.NOT_FOUND).entity(response); + throw new WebApplicationException(builder.build()); + } + MultivaluedMap headers = requestContext.getHeaders(); + String transactionId = headers.getFirst(HeadersEnum.TransactionID.toString()); + if (transactionId == null) { + transactionId = UUID.randomUUID().toString(); + headers.add(HeadersEnum.TransactionID.toString(), transactionId); + } + String minorVersion = headers.getFirst(HeadersEnum.MinorVersion.toString()); + if (minorVersion == null) { + minorVersion = MessageHeaders.getSupportedmajorversions().get(majorVersion); + headers.add(HeadersEnum.MinorVersion.toString(), minorVersion); + } + if (!MessageHeaders.validateMajorMinorVersion(majorVersion, minorVersion)) { + ResponseBuilder builder = null; + String response = "Unsupported API version"; + builder = Response.status(Response.Status.NOT_FOUND).entity(response); + throw new WebApplicationException(builder.build()); + + } + } catch (Exception e) { + if (e instanceof WebApplicationException) { + Observation.report(LogMessages.EXPECTED_EXCEPTION, e.getMessage()); + throw e; + } else { + Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e.getMessage()); + } + } + + } + +} diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/service/rs/AvailabilityInterface.java b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/service/rs/AvailabilityInterface.java index 3360927..df23f7d 100644 --- a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/service/rs/AvailabilityInterface.java +++ b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/service/rs/AvailabilityInterface.java @@ -45,7 +45,7 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import org.onap.optf.cmso.common.CMSRequestError; +import org.onap.optf.cmso.common.CmsoRequestError; import org.onap.optf.ticketmgt.service.rs.models.ActiveTicketsRequest; import org.onap.optf.ticketmgt.service.rs.models.ActiveTicketsResponse; import org.springframework.web.bind.annotation.PathVariable; @@ -72,7 +72,7 @@ public interface AvailabilityInterface { + "optimizer will begin to poll the request until COMPLETED.", response = ActiveTicketsResponse.class) @ApiResponses(value = {@ApiResponse(code = 200, message = "OK"), - @ApiResponse(code = 400, message = "Bad request", response = CMSRequestError.class), + @ApiResponse(code = 400, message = "Bad request", response = CmsoRequestError.class), @ApiResponse(code = 500, message = "Unexpected Runtime error", response = Exception.class)}) public Response getActiveTickets( @ApiParam(value = "v1") @PathParam("apiVersion") @PathVariable( @@ -92,7 +92,7 @@ public interface AvailabilityInterface { + "receipt of the response.", response = ActiveTicketsResponse.class) @ApiResponses(value = {@ApiResponse(code = 200, message = "OK"), - @ApiResponse(code = 404, message = "Not found.", response = CMSRequestError.class), + @ApiResponse(code = 404, message = "Not found.", response = CmsoRequestError.class), @ApiResponse(code = 500, message = "Unexpected Runtime error", response = Exception.class)}) public Response pollActiveTickets( @ApiParam(value = "v1") @PathParam("apiVersion") @PathVariable( @@ -111,7 +111,7 @@ public interface AvailabilityInterface { + " treat Not found reponse on as normal.", response = ActiveTicketsResponse.class) @ApiResponses(value = {@ApiResponse(code = 204, message = "OK"), - @ApiResponse(code = 404, message = "Not found", response = CMSRequestError.class), + @ApiResponse(code = 404, message = "Not found", response = CmsoRequestError.class), @ApiResponse(code = 500, message = "Unexpected Runtime error", response = Exception.class)}) public Response deleteActiveTicketsRequest( @ApiParam(value = "v1") @PathParam("apiVersion") @PathVariable( diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/service/rs/TicketManagement.java b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/service/rs/TicketManagement.java index 16346bf..60a517b 100644 --- a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/service/rs/TicketManagement.java +++ b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/service/rs/TicketManagement.java @@ -47,7 +47,7 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import org.onap.optf.cmso.common.CMSRequestError; +import org.onap.optf.cmso.common.CmsoRequestError; import org.onap.optf.ticketmgt.service.rs.models.TicketData; @Api("Ticket Management") @@ -61,7 +61,7 @@ public interface TicketManagement { @ApiOperation(value = "Fetch Ticket", notes = "Returns ticket information for the provided ticket id.", response = TicketData.class) @ApiResponses(value = {@ApiResponse(code = 200, message = "OK"), - @ApiResponse(code = 404, message = "No record found", response = CMSRequestError.class), + @ApiResponse(code = 404, message = "No record found", response = CmsoRequestError.class), @ApiResponse(code = 500, message = "Unexpected Runtime error", response = Exception.class)}) public Response fetchTicket(@ApiParam(value = "v1") @PathParam("apiVersion") @DefaultValue("v1") String apiVersion, @ApiParam(value = "Unique ticket identifier") @PathParam("id") String id); @@ -74,7 +74,7 @@ public interface TicketManagement { @ApiResponses(value = { @ApiResponse(code = 200, message = "Ticket Created. Ticket Id returned.", response = TicketData.class), - @ApiResponse(code = 400, message = "Bad request.", response = CMSRequestError.class), + @ApiResponse(code = 400, message = "Bad request.", response = CmsoRequestError.class), @ApiResponse(code = 500, message = "Unexpected Runtime error", response = Exception.class)}) public Response createTicket(@ApiParam(value = "v1") @PathParam("apiVersion") @DefaultValue("v1") String apiVersion, @ApiParam(value = "Data for creating a ticket") TicketData ticketData); @@ -85,7 +85,7 @@ public interface TicketManagement { @Produces({MediaType.APPLICATION_JSON}) @ApiOperation(value = "Update Ticket", notes = "Updates a ticket to the passed data") @ApiResponses(value = {@ApiResponse(code = 204, message = "Ticket Updated."), - @ApiResponse(code = 400, message = "Bad request.", response = CMSRequestError.class), + @ApiResponse(code = 400, message = "Bad request.", response = CmsoRequestError.class), @ApiResponse(code = 500, message = "Unexpected Runtime error", response = Exception.class)}) public Response updateTicket(@ApiParam(value = "v1") @PathParam("apiVersion") @DefaultValue("v1") String apiVersion, @ApiParam(value = "Data for updating a ticket") TicketData ticketData); @@ -96,8 +96,8 @@ public interface TicketManagement { @Produces({MediaType.APPLICATION_JSON}) @ApiOperation(value = "Cancel the ticket", notes = "Cancels the ticket.") @ApiResponses(value = {@ApiResponse(code = 204, message = "Delete successful"), - @ApiResponse(code = 404, message = "No record found", response = CMSRequestError.class), - @ApiResponse(code = 400, message = "Bad request", response = CMSRequestError.class), + @ApiResponse(code = 404, message = "No record found", response = CmsoRequestError.class), + @ApiResponse(code = 400, message = "Bad request", response = CmsoRequestError.class), @ApiResponse(code = 500, message = "Unexpected Runtime error", response = Exception.class)}) public Response deleteScheduleRequest( @ApiParam(value = "v1") @PathParam("apiVersion") @DefaultValue("v1") String apiVersion, @@ -113,7 +113,7 @@ public interface TicketManagement { @ApiOperation(value = "Search Tickets", notes = "Returns a list of based upon the filter criteria.", response = TicketData.class, responseContainer = "List") @ApiResponses(value = {@ApiResponse(code = 200, message = "OK"), - @ApiResponse(code = 400, message = "Bad request", response = CMSRequestError.class), + @ApiResponse(code = 400, message = "Bad request", response = CmsoRequestError.class), @ApiResponse(code = 500, message = "Unexpected Runtime error", response = Exception.class)}) public Response searchTcikets( @ApiParam(value = "v1") @PathParam("apiVersion") @DefaultValue("v1") String apiVersion, -- cgit 1.2.3-korg