<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>How use javax.ws.rs.ext.ExceptionMapper in osgi module</title>
  <link rel="self" href="https://uat.liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=113218863" />
  <subtitle>How use javax.ws.rs.ext.ExceptionMapper in osgi module</subtitle>
  <id>https://uat.liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=113218863</id>
  <updated>2026-10-15T11:16:43Z</updated>
  <dc:date>2026-10-15T11:16:43Z</dc:date>
  <entry>
    <title>RE: How use javax.ws.rs.ext.ExceptionMapper in osgi module</title>
    <link rel="alternate" href="https://uat.liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121625515" />
    <author>
      <name>Koen Olaerts</name>
    </author>
    <id>https://uat.liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121625515</id>
    <updated>2023-01-09T13:49:49Z</updated>
    <published>2023-01-09T13:44:34Z</published>
    <summary type="html">&lt;p&gt;Hello Joaquin,&lt;/p&gt;
&lt;p&gt;I came across your question today when investigating the same
  requirement. Sadly there has been no response on your question yet.
  Perhaps you have solved it already given it has been 4 years?&lt;/p&gt;
&lt;p&gt;After some research I found an answer to our problem. Using the
  example in this pull request from last year: https://github.com/liferay-appsec/liferay-portal/pull/546/files#diff-4ab4c23659f671466b78053e7413e5d2a1e53a069a3976a77e7ff9022060713d&lt;/p&gt;
&lt;p&gt;Configure the @Component annotation as below and your custom
  ExceptionMapper is used for the specific exception. You also don't
  need to provide the @Provider annotation.&lt;/p&gt;
&lt;pre&gt;
&lt;code class="language-java"&gt;@Component(
		property = {
				&amp;quot;osgi.jaxrs.application.select=(!(liferay.access.control.disable=true))&amp;quot;,
				&amp;quot;osgi.jaxrs.extension=true&amp;quot;
		},
		service = ExceptionMapper.class
)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt; Next step in my research: is it possible to combine multiple
  ExceptionMappers in one global class/configuration (iso having
  separate components per exceptionmapper/exceptiontype). Sort of like
  how in Spring Boot the @ControllerAdvice works with multiple
  @ExceptionHandler methods.&lt;br /&gt; Maybe this will bring me to a
  solution:
  https://github.com/eugenp/tutorials/blob/master/jersey/src/main/java/com/baeldung/jersey/exceptionhandling/ExceptionHandlingConfig.java.
  But I still have to investigate, will come back to you on this.&lt;br /&gt;
  Or maybe you already have some kind of solution for this?&lt;/p&gt;</summary>
    <dc:creator>Koen Olaerts</dc:creator>
    <dc:date>2023-01-09T13:44:34Z</dc:date>
  </entry>
  <entry>
    <title>How use javax.ws.rs.ext.ExceptionMapper in osgi module</title>
    <link rel="alternate" href="https://uat.liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=113218862" />
    <author>
      <name>Joaquin Cabal</name>
    </author>
    <id>https://uat.liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=113218862</id>
    <updated>2019-04-15T00:32:25Z</updated>
    <published>2019-04-15T00:32:25Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;Hi! Im trying to use an exception mapper for a osgi module, but is not working.&lt;br&gt;&lt;br&gt;The problem I think is tha the providers exception mapper are not registered as the jax-rs context. But I dont know how to config it ok.&lt;br&gt;&lt;br&gt;The code is something like this:&lt;pre&gt;&lt;code&gt;@Provider
public class UnauthorizedUserExceptionMapper implements ExceptionMapper&amp;lt;unauthorizeduserexception&amp;gt; {

&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; @Override
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; public Response toResponse(UnauthorizedUserException e) {
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; return Response
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; .status(Response.Status.UNAUTHORIZED)
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; .type(MediaType.APPLICATION_JSON)
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; .entity(e.getMessage())
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; .build();
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; }
}

&amp;lt;/unauthorizeduserexception&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;The rest services are working ok. I tryed to use the Exceptoin mapper as osgi @Component and also add the object to the Rest application singletons.&lt;br&gt;&lt;br&gt;But is not working yet.&lt;br&gt;Any helo on this, how to cacth the exception inside this mapper?&lt;br&gt;&lt;br&gt;Thanks in advance!&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Joaquin Cabal</dc:creator>
    <dc:date>2019-04-15T00:32:25Z</dc:date>
  </entry>
</feed>
