我尝试使用以下类为Nexus2的插件创建REST端点:
@Path(NexusPlugin.URI)
@Named
@Singleton
public class NexusPlugin extends ComponentSupport implements Resource {
public static final String URI ="/nexusplugin";
@GET
@Produces(MediaType.TEXT_PLAIN)
public Response get(){
return Response.ok("Config Updated").build();
}
}
根据我的理解,实现Resource接口应该足够了,Nexus / siesta应该实例化该类并创建Resource。我不使用任何web.xml,我目前不自己实例化该类。
代码基于Nexus2 logging plugin的代码,它也提供了REST端点,我可能错过了那里的东西。
Siesta总是返回这样的错误:
{
"id": "ae015d47-5968-4cb6-88c3-d5615c677c0c",
"message": "No resource available at 'nexusplugin'"
}
Nexus2日志显示以下错误:
admin org.sonatype.sisu.siesta.server.internal.SiestaServlet - Processing: GET /nexus/service/siesta/nexusplugin (http://localhost:8081/nexus/service/siesta/nexusplugin)
2018-01-30 08:40:47,816+0100 DEBUG [esh-1-thread-5] admin org.sonatype.nexus.feeds.record.NexusAuthenticationEventInspector - Successfully authenticated user [admin] from IP address 127.0.0.1
2018-01-30 08:40:47,816+0100 DEBUG [qtp491414393-52] admin org.sonatype.sisu.siesta.server.internal.mappers.WebApplicationExceptionMapper - (ID e92c848c-d603-4541-bb0c-ddd60fddb5e4) Mapping exception: com.sun.jersey.api.NotFoundException: null for uri: http://localhost:8081/nexus/service/siesta/nexusplugin
2018-01-30 08:40:47,820+0100 WARN [qtp491414393-52] admin org.sonatype.sisu.siesta.server.internal.mappers.WebApplicationExceptionMapper - (ID e92c848c-d603-4541-bb0c-ddd60fddb5e4) Response: [404] ErrorXO{id='e92c848c-d603-4541-bb0c-ddd60fddb5e4', message='No resource available at 'nexusplugin''} mapped from com.sun.jersey.api.NotFoundException/null for uri: http://localhost:8081/nexus/service/siesta/nexusplugin
com.sun.jersey.api.NotFoundException: null for uri: http://localhost:8081/nexus/service/siesta/nexusplugin
这不是很有用,因为任何URL都会引发错误。
问题如果最终解决了。 siesta插件在pom.xml中的依赖关系需要以下附加行:
<type>${nexus-plugin.type}</type>
所以它看起来像这样:
<dependency>
<groupId>org.sonatype.nexus.plugins</groupId>
<artifactId>nexus-siesta-plugin</artifactId>
<version>2.13.0-01</version>
<type>${nexus-plugin.type}</type>
<scope>provided</scope>
</dependency>