diff options
Diffstat (limited to 'engine-d/src/main/java/org/onap/holmes/engine/resources/DmaapConfigurationService.java')
-rw-r--r-- | engine-d/src/main/java/org/onap/holmes/engine/resources/DmaapConfigurationService.java | 52 |
1 files changed, 19 insertions, 33 deletions
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/resources/DmaapConfigurationService.java b/engine-d/src/main/java/org/onap/holmes/engine/resources/DmaapConfigurationService.java index 548b9b2..576170f 100644 --- a/engine-d/src/main/java/org/onap/holmes/engine/resources/DmaapConfigurationService.java +++ b/engine-d/src/main/java/org/onap/holmes/engine/resources/DmaapConfigurationService.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 ZTE Corporation. + * Copyright 2017-2022 ZTE Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,45 +18,35 @@ package org.onap.holmes.engine.resources; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.DELETE; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.core.MediaType; import lombok.extern.slf4j.Slf4j; -import org.jvnet.hk2.annotations.Service; import org.onap.holmes.common.dcae.DcaeConfigurationsCache; import org.onap.holmes.common.dcae.entity.SecurityInfo; -import org.onap.holmes.common.dropwizard.ioc.utils.ServiceLocatorHolder; +import org.onap.holmes.common.utils.SpringContextUtil; import org.onap.holmes.dsa.dmaappolling.Subscriber; import org.onap.holmes.engine.dmaap.SubscriberAction; import org.onap.holmes.engine.request.DmaapConfigRequest; +import org.springframework.web.bind.annotation.*; -@Service @Slf4j -//@Api(tags = {"DMaaP Configurations"}) -@Path("/dmaap") +@RestController +@RequestMapping("/dmaap") public class DmaapConfigurationService { - @PUT - @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "Subscribe to a new topic. " + "If the topic already exists, it is replaced with the new configuration.") - @Path("/sub") + @RequestMapping(value = "/sub", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON) public String addSubInfo( - @ApiParam (value = "A JSON object with the fields named <b>name</b>" - + " and <b>url</b>. Both fields are required.") DmaapConfigRequest config, - @Context HttpServletRequest request){ + @ApiParam(value = "A JSON object with the fields named <b>name</b>" + + " and <b>url</b>. Both fields are required.") + @RequestBody DmaapConfigRequest config) { String url = config.getUrl(); if (url.startsWith("http://") || url.startsWith("https://")) { Subscriber subscriber = new Subscriber(); subscriber.setTopic(config.getName()); subscriber.setUrl(url); - SubscriberAction subscriberAction = ServiceLocatorHolder.getLocator() - .getService(SubscriberAction.class); + SubscriberAction subscriberAction = SpringContextUtil.getBean(SubscriberAction.class); subscriberAction.removeSubscriber(subscriber); subscriberAction.addSubscriber(subscriber); @@ -67,30 +57,26 @@ public class DmaapConfigurationService { return "{\"message\": \"Only the HTTP or HTTPS protocol is supported!\"}"; } - @DELETE @Path("/sub/{topic}") @ApiOperation(value = "Unsubscribe a topic from DMaaP.") - @Produces(MediaType.APPLICATION_JSON) - public String removeSubInfo(@PathParam("topic") String topic){ + @RequestMapping(value = "/sub/{topic}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON) + public String removeSubInfo(@PathVariable("topic") String topic) { Subscriber subscriber = new Subscriber(); subscriber.setTopic(topic); - SubscriberAction subscriberAction = ServiceLocatorHolder.getLocator() - .getService(SubscriberAction.class); + SubscriberAction subscriberAction = SpringContextUtil.getBean(SubscriberAction.class); subscriberAction.removeSubscriber(subscriber); return "{\"message\": \"Topic unsubscribed.\"}"; } - @PUT - @Produces(MediaType.APPLICATION_JSON) - @Path("/pub") @ApiOperation(value = "Add/Update a publishing topic. " + "If the topic already exists, it is replaced with the new configuration.") + @RequestMapping(value = "/pub", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON) public String updatePubInfo( - @ApiParam (value = "A JSON object with the fields named <b>name</b>" - + " and <b>url</b>. Both fields are required.") DmaapConfigRequest config, - @Context HttpServletRequest request){ + @ApiParam(value = "A JSON object with the fields named <b>name</b>" + + " and <b>url</b>. Both fields are required.") + @RequestBody DmaapConfigRequest config) { String url = config.getUrl(); if (url.startsWith("http://") || url.startsWith("https://")) { SecurityInfo securityInfo = new SecurityInfo(); |