Howdy,
I’m trying to centralize error-handling in my Jira plugin so that I can present a custom error object (rather than throwing a full stack trace to the user).
I can get this working in the ref-app with @Provider on my ExceptionMapper class, however I’m not able to get this registered in my Java-configuration-based app. (for Jira Server 8.1.3)
I’ve tried AutoWiring the application context and also have tried @InjectParam in the constructor directly…but it isn’t working.
AppConfig.java
@Configuration
public class AppConfig {
////
// Makes no difference
@Bean
public ExceptionMapper<Throwable> exceptionMapper() {
return new ExceptionHandler();
}
@Bean
FactoryBean<ServiceRegistration> exportExceptionMapper() {
ExportOptions serviceProperties = ExportOptions.as(ExceptionMapper.class);
return exportOsgiService(exceptionMapper(), serviceProperties);
}
////
}
atlassian-plugin.xml
<atlassian-plugin key="${atlassian.plugin.key}" name="${project.name}" plugins-version="2">
<plugin-info>
<name>${project.name}</name>
<description>${project.description}</description>
<version>${project.version}</version>
<vendor name="${project.organization.name}" url="${project.organization.url}" />
</plugin-info>
<rest key="${atlassian.plugin.key}-1"
path="/myplugin"
version="1"
>
<description>Provides REST services for this plugin</description>
</rest>
</atlassian-plugin>
SomeResource.java
@Path("/foo")
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public class SomeResource {
@GET
@Path("/bar")
public Response bar() {
throw new RunTimeException("oh no");
}
}
ExceptionHandler.java
@Provider
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public class ExceptionHandler implements ExceptionMapper<Throwable> {
public Response toResponse(Throwable throwable) {
return Response
.status(Response.Status.BAD_REQUEST)
.entity("You've been stick-bugged, lol")
.build();
}
}
Not entirely sure how the REST module is supposed to work with Java Configuration anyway? I mean, I don’t even have to register my @Path annotated classes as Beans. (whether I do makes no difference)
Anybody else having this problem?
Anyone found a solution that works for them?