X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=engine-d%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fholmes%2Fengine%2Fresources%2FDmaapConfigurationService.java;h=576170fe6adecd99cda50c260449b2af8a344a75;hb=c4bd70c1f74cd04c441f76de4359e166a089660a;hp=548b9b297030f46729f7b4312f1c40814d2d6e33;hpb=61da3e3d053548815054384e5e18750e87463ee9;p=holmes%2Fengine-management.git 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 name" - + " and url. Both fields are required.") DmaapConfigRequest config, - @Context HttpServletRequest request){ + @ApiParam(value = "A JSON object with the fields named name" + + " and url. 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 name" - + " and url. Both fields are required.") DmaapConfigRequest config, - @Context HttpServletRequest request){ + @ApiParam(value = "A JSON object with the fields named name" + + " and url. Both fields are required.") + @RequestBody DmaapConfigRequest config) { String url = config.getUrl(); if (url.startsWith("http://") || url.startsWith("https://")) { SecurityInfo securityInfo = new SecurityInfo();