In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is the role of dubbo's DubboSwaggerService". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "what is the role of dubbo's DubboSwaggerService"!
order
This article focuses on dubbo's DubboSwaggerService
DubboSwaggerService
dubbo-2.7.2/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/integration/swagger/DubboSwaggerService.java
@Path("dubbo")@Consumes({MediaType.APPLICATION_JSON, MediaType.TEXT_XML})@Produces({MediaType.APPLICATION_JSON + "; " + "charset=UTF-8", MediaType.TEXT_XML + "; " + "charset=UTF-8"})public interface DubboSwaggerService { @GET @Path("swagger") public Response getListingJson(@Context Application app, @Context ServletConfig sc, @Context HttpHeaders headers, @Context UriInfo uriInfo) throws JsonProcessingException;}
DubboSwaggerService defines getListingJson method
DubboSwaggerApiListingResource
dubbo-2.7.2/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/integration/swagger/DubboSwaggerApiListingResource.java
@Servicepublic class DubboSwaggerApiListingResource extends BaseApiListingResource implements DubboSwaggerService { @Context ServletContext context; @Override public Response getListingJson(Application app, ServletConfig sc, HttpHeaders headers, UriInfo uriInfo) throws JsonProcessingException { Response response = getListingJsonResponse(app, context, sc, headers, uriInfo); response.getHeaders().add("Access-Control-Allow-Origin", "*"); response.getHeaders().add("Access-Control-Allow-Headers", "x-requested-with, ssi-token"); response.getHeaders().add("Access-Control-Max-Age", "3600"); response.getHeaders().add("Access-Control-Allow-Methods","GET,POST,PUT,DELETE,OPTIONS"); return response; }}
DubboSwaggerApiListingResource inherits the BaseApiListingResource of swagger-jaxrs and implements the DubboSwaggerService interface; its getListingJson method first calls getListingJsonResponse of the parent class to get response, and then adds cross-domain settings to the header.
examples
dubbo-2.7.2/dubbo-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/integration/swagger/DubboSwaggerApiListingResourceTest.java
public class DubboSwaggerApiListingResourceTest { private Application app; private ServletConfig sc; @Test public void test() throws Exception { DubboSwaggerApiListingResource resource = new DubboSwaggerApiListingResource(); app = mock(Application.class); sc = mock(ServletConfig.class); Set>(); sets.add(SwaggerService.class); when(sc.getServletContext()).thenReturn(mock(ServletContext.class)); when(app.getClasses()).thenReturn(sets); Response response = resource.getListingJson(app, sc, null, new ResteasyUriInfo(new URI("http://rest.test"))); Assertions.assertNotNull(response); Swagger swagger = (Swagger)response.getEntity(); Assertions.assertEquals("SwaggerService",swagger.getTags().get(0).getName()); Assertions.assertEquals("/demoService/hello",swagger.getPaths().keySet().toArray()[0].toString()); }}
Here verify the swagger path of the entity returned by resource.getListingJson
summary
DubboSwaggerService defines getListingJson method;DubboSwaggerApiListingResource inherits BaseApiListingResource of swagger-jaxrs and implements DubboSwaggerService interface; getListingJson method implemented by DubboSwaggerService first calls getListingJsonResponse of parent class, and then adds cross-domain setting to header.
At this point, I believe everyone has a deeper understanding of "dubbo's DubboSwaggerService", so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.