404 from JAX-RS Resource

2,095 views
Skip to first unread message

robert.p...@leidos.com

unread,
Feb 21, 2018, 10:59:06 AM2/21/18
to bndtools-users
Hi,

I have imported projects R7 Postgres example from here:  https://github.com/timothyjward/osgi.enroute/tree/postgres

I have created our own packages, added our Java code, removed the example Java code (after mimicking it), and changed the pom.xml files to make it all build with our groupId.  All of the projects build and resolve, and I see all of the bundles running in my Gogo console.

The 404 problem occurs when I try to run a GET request from my browser to a component with a method that is annotated with @GET.  I see the request and response in my browser's development tools.  In the Eclipse console, I see the GET request arrive, and then I see the 404 response.  But, there is no exception to tell me what went wrong.

I have attached my log.

Here is my restful resource class:

package my.package;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.OPTIONS;
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.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;

import org.apache.johnzon.mapper.Mapper;
import org.apache.johnzon.mapper.MapperBuilder;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardResource;
import org.osgi.service.jaxrs.whiteboard.propertytypes.JSONRequired;
import org.osgi.service.jaxrs.whiteboard.propertytypes.JaxrsResource;

import my.package.MyDao;
import my.package.dto.MyDto;


@Component(service=MyResource.class)
@JaxrsResource
@Path("/myresource")
@Produces(MediaType.APPLICATION_JSON)
@JSONRequired
@HttpWhiteboardResource(pattern="/microservice/*", prefix="static")
public class MyResource {

@Reference
private MyDao dao;

@GET
@Path("/mymethod")
@Produces(MediaType.APPLICATION_JSON)
public Response get() throws Exception {
try {
Mapper mapper = new MapperBuilder().build();
return Response.ok(mapper.writeArrayAsString(dao.list())).header("Access-Control-Allow-Origin", "*").build();
} catch(Exception ex) {
return Response.status(Status.INTERNAL_SERVER_ERROR).header("Access-Control-Allow-Origin", "*").build();
}
}

}

I have tried numerous URLs and I have tried a class that extends javax.ws.rs.core.Application.  I have been reading from RESTful Java with JAX-RS.  The book said to extend Application but that's not in the example.

Thanks!
404_Not_Found.txt

Raymond Auge

unread,
Feb 21, 2018, 11:16:00 AM2/21/18
to bndtool...@googlegroups.com
A couple of things to consider:

1) I think you should completely remove this line unless you really understand why/how it would be used:


@HttpWhiteboardResource(pattern="/microservice/*", prefix="static")

2) Have you tried the URL:

localhost:8080/myresource/mymethod

3) Is the component actually resolved? Is there a service which satisfies this reference?

@Reference
private MyDao dao;

Try adding a method annotated with @Activate to make sure the component successfully activates.

- Ray


--
You received this message because you are subscribed to the Google Groups "bndtools-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bndtools-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Raymond Augé (@rotty3000)
Senior Software Architect Liferay, Inc. (@Liferay)
Board Member & EEG Co-Chair, OSGi Alliance (@OSGiAlliance)

Raymond Auge

unread,
Feb 21, 2018, 11:17:44 AM2/21/18
to bndtool...@googlegroups.com
On Wed, Feb 21, 2018 at 11:15 AM, Raymond Auge <raymon...@liferay.com> wrote:
A couple of things to consider:

1) I think you should completely remove this line unless you really understand why/how it would be used:

@HttpWhiteboardResource(pattern="/microservice/*", prefix="static")

2) Have you tried the URL:

localhost:8080/myresource/mymethod

3) Is the component actually resolved? Is there a service which satisfies this reference?

@Reference
private MyDao dao;

Try adding a method annotated with @Activate to make sure the component successfully activates.

Here I meant to add "with debug logging, or by using a breakpoint".

robert.p...@leidos.com

unread,
Feb 21, 2018, 12:02:21 PM2/21/18
to bndtools-users
I tried commenting out "@HttpWhiteboardResource(pattern="/microservice/*", prefix="static")" and the "@Reference" on my dao variable.  This made my @Activate method run successfully, so I assume that my DAO dao-impl-jpa is failing to inject with Declarative Services.

Also, when I try the GET request, I get a 500 error.

robert.p...@leidos.com

unread,
Feb 21, 2018, 12:46:43 PM2/21/18
to bndtools-users
I see that my get() method in my resource class is getting executed.  So, how do I get the DAO to inject?


On Wednesday, February 21, 2018 at 10:59:06 AM UTC-5, robert.p...@leidos.com wrote:

robert.p...@leidos.com

unread,
Feb 21, 2018, 12:54:25 PM2/21/18
to bndtools-users
I have attached my console output when I start the rest-app-jpa bundle.

Thanks


On Wednesday, February 21, 2018 at 10:59:06 AM UTC-5, robert.p...@leidos.com wrote:
startup.txt

Raymond Auge

unread,
Feb 21, 2018, 1:51:18 PM2/21/18
to bndtool...@googlegroups.com
you seem to have gogo installed, so you can check if there's any provider of a service `MyDao` by doing:

inspect cap service | grep MyDao

- Ray

--
You received this message because you are subscribed to the Google Groups "bndtools-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bndtools-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

robert.p...@leidos.com

unread,
Feb 21, 2018, 3:05:53 PM2/21/18
to bndtools-users
inspect cap service | grep MyDao returns false.


On Wednesday, February 21, 2018 at 10:59:06 AM UTC-5, robert.p...@leidos.com wrote:

Raymond Auge

unread,
Feb 21, 2018, 3:20:56 PM2/21/18
to bndtool...@googlegroups.com
that means there's nobody providing that service you are trying to reference!

that's what you need to figure out.

Sincerely,
- Ray

--
You received this message because you are subscribed to the Google Groups "bndtools-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bndtools-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

robert.p...@leidos.com

unread,
Feb 21, 2018, 3:27:15 PM2/21/18
to bndtools-users
Yes.  I just commented out the @Reference annotations on the transactionControl and emProvider instance variables, and commented out the logger variable.  This made the command returned true.  So, it looks like the DAO class's dependencies are not getting wired up correctly.

Also, I created an activate method, annotated with @Activate, and it doesn't run.  I would think this method would run when the command returns true.


On Wednesday, February 21, 2018 at 10:59:06 AM UTC-5, robert.p...@leidos.com wrote:

robert.p...@leidos.com

unread,
Feb 21, 2018, 4:04:36 PM2/21/18
to bndtools-users
I have figured out that the emProvider injection is to blame (see below).  When I comment out emProvider's @Reference annotation, the DAO gets created, activated, and injected into my rest service.  Is this a problem in configuration.json?
//@Reference(name="provider")
JPAEntityManagerProvider emProvider;

My persistence.xml is empty except a hibernate annotation:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence-unit name="microservice-dao">
<description>Microservice Persistence Unit</description>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
</properties>
</persistence-unit>
</persistence>

Here is my configuration.json:

{
    // Global Settings
    ":configurator:resource-version" : 1,
    ":configurator:symbolicname" : "my.package.microservice.jpa.config",
    ":configurator:version" : "1.0.0-SNAPSHOT",

    // Configure a JPA resource provider
    "org.apache.aries.tx.control.jpa.xa~microservice": {
           "name": "microservice.database",
           "osgi.jdbc.driver.class": "org.postgresql.Driver",
           "url": "jdbc:postgresql://myserver/mydb",
           "osgi.unit.name": "microservice-dao",
           "user": "myuser",
           "password": "mypassword" },

    // Target the Dao impls at the provider we configured
    "my.package.MyDaoImpl": {
           "provider.target": "(name=microservice.database)" }
}

On Wednesday, February 21, 2018 at 10:59:06 AM UTC-5, robert.p...@leidos.com wrote:

Raymond Auge

unread,
Feb 21, 2018, 4:24:20 PM2/21/18
to bndtool...@googlegroups.com
.. now you've ventured into a place unknown to me as I've not played with the new enroute stuff nor the transaction control/jpa stuff :)

If your project could be shared that might help, otherwise you may have to wait until Tim Ward is around again.

Sincerely,
- Ray

--
You received this message because you are subscribed to the Google Groups "bndtools-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bndtools-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

robert.p...@leidos.com

unread,
Feb 22, 2018, 11:56:00 AM2/22/18
to bndtools-users
Where can I find current documentation on configuration.json, @Reference, and JPAEntityManagerProvider?


On Wednesday, February 21, 2018 at 10:59:06 AM UTC-5, robert.p...@leidos.com wrote:

Raymond Auge

unread,
Feb 22, 2018, 12:17:30 PM2/22/18
to bndtool...@googlegroups.com
On Thu, Feb 22, 2018 at 11:56 AM, <robert.p...@leidos.com> wrote:
Where can I find current documentation on configuration.json,

--
You received this message because you are subscribed to the Google Groups "bndtools-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bndtools-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

robert.p...@leidos.com

unread,
Feb 22, 2018, 1:18:49 PM2/22/18
to bndtools-users
I see this configurator dependency in the example's rest-app-jpa.bndrun file:

org.apache.felix.configurator;version='[0.0.1,0.0.2)',\

It's missing from my work project.  When I copy and paste it in, and click "Resolve", it disappears.  I'm using Bndtools version 4.  What could cause this?


On Wednesday, February 21, 2018 at 10:59:06 AM UTC-5, robert.p...@leidos.com wrote:

Raymond Auge

unread,
Feb 22, 2018, 3:36:11 PM2/22/18
to bndtool...@googlegroups.com
You are missing a _requirement_ which causes that dependency to get pulled into your resolution.

- Ray

--
You received this message because you are subscribed to the Google Groups "bndtools-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bndtools-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Raymond Auge

unread,
Feb 22, 2018, 3:39:25 PM2/22/18
to bndtool...@googlegroups.com
However, since this is using unreleased features you also need the latest snapshots of bnd and it's associated plugins for your build env to make sure this get's processed (because it's a build time thing rather than a runtime thing).

- Ray

Tim Ward

unread,
Feb 26, 2018, 10:45:59 AM2/26/18
to bndtool...@googlegroups.com
Hi Robert,

Have you managed to get things working now?

Best Regards,

Tim

To unsubscribe from this group and stop receiving emails from it, send an email to bndtools-user...@googlegroups.com.

Michael Hauer

unread,
Mar 20, 2019, 6:28:20 PM3/20/19
to bndtools-users
Hi,

I have exactly the same situation.

If you have found a solution for this problem it would be great if you could share it.

Michael

Tim Ward

unread,
Mar 25, 2019, 11:03:37 AM3/25/19
to bndtool...@googlegroups.com
There have been several released updates since this email chain, and you haven’t provided much information to work with in providing assistance. What versions of the various bundles are you using? Are you also seeing a missing JPAEntityManagerProvider service? What configuration are you using? Do you have the necessary requirement annotations attached to your bundles?

Best Regards,

Tim

Message has been deleted
Message has been deleted
Message has been deleted

Michael Hauer

unread,
Apr 3, 2019, 8:21:33 AM4/3/19
to bndtools-users
Hi Tim,

I am sorry for the late answer. Sure I didn't provide any information :-) I just thought, that Roberts solution would maybe be helpful for me.
I placed a copy of my microservice-tutorial at https://ufile.io/q5gm7 which is modified (JRE 11, Postgresql). The link should work for 30-days.

I get the following output on scr:list and scr:info:
g! scr:list
org.osgi.enroute.examples.microservice.rest.JsonpConvertingPlugin in bundle 16 (org.osgi.enroute.examples.microservice.rest-service:0.0.1) enabled, 1 instance.
    Id: 0, State:ACTIVE
org.osgi.enroute.examples.microservice.rest.RestComponentImpl in bundle 16 (org.osgi.enroute.examples.microservice.rest-service:0.0.1) enabled, 1 instance.
    Id: 1, State:UNSATISFIED REFERENCE
org.osgi.enroute.examples.microservice.dao.impl.jpa.AddressDaoImpl in bundle 43 (org.osgi.enroute.examples.microservice.dao-impl-jpa:0.0.1) enabled, 1 instance.
    Id: 2, State:UNSATISFIED REFERENCE, PID(s): [org.osgi.enroute.examples.microservice.dao.impl.jpa.AddressDaoImpl]
org.osgi.enroute.examples.microservice.dao.impl.jpa.ComponentImpl in bundle 43 (org.osgi.enroute.examples.microservice.dao-impl-jpa:0.0.1) enabled, 1 instance.
    Id: 3, State:ACTIVE
org.osgi.enroute.examples.microservice.dao.impl.jpa.PersonDaoImpl in bundle 43 (org.osgi.enroute.examples.microservice.dao-impl-jpa:0.0.1) enabled, 1 instance.
    Id: 4, State:UNSATISFIED REFERENCE, PID(s): [org.osgi.enroute.examples.microservice.dao.impl.jpa.PersonDaoImpl]
g! scr:info org.osgi.enroute.examples.microservice.dao.impl.jpa.AddressDaoImpl
Component Description: org.osgi.enroute.examples.microservice.dao.impl.jpa.AddressDaoImpl
=========================================================================================
Class:         org.osgi.enroute.examples.microservice.dao.impl.jpa.AddressDaoImpl
Bundle:        43 (org.osgi.enroute.examples.microservice.dao-impl-jpa:0.0.1)
Enabled:       true
Immediate:     false
Services:      [org.osgi.enroute.examples.microservice.dao.api.AddressDAO]
Scope:         singleton
Config PID(s): [org.osgi.enroute.examples.microservice.dao.impl.jpa.AddressDaoImpl], Policy: optional
Base Props:    (0 entries)

Component Configuration Id: 2
-----------------------------
State:        UNSATISFIED REFERENCE
Config Props: (4 entries)
  component.id<Long> = 2
  component.name<String> = org.osgi.enroute.examples.microservice.dao.impl.jpa.AddressDaoImpl
  provider.target<String> = (name=microservice.database)
  service.pid<String> = org.osgi.enroute.examples.microservice.dao.impl.jpa.AddressDaoImpl
References:   (total 2)
  - provider: org.osgi.service.transaction.control.jpa.JPAEntityManagerProvider UNSATISFIED 1..1 static
    target=(*) scope=bundle
  - transactionControl: org.osgi.service.transaction.control.TransactionControl SATISFIED 1..1 static
    target=(*) scope=bundle (no active bindings)
g!

Thank you very much in advance for your time and help!

Regards,
Michael
Tim

To unsubscribe from this group and stop receiving emails from it, send an email to bndtool...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages