Finding objects in MongoDB

53 views
Skip to first unread message

Janusz Dalecki

unread,
Nov 28, 2012, 2:32:40 AM11/28/12
to mor...@googlegroups.com

Hi All,

Just to put you up the context, we are running our software under the jersy implementation - (com.sun.jersey.spi.container.servlet.ServletContainer is handling all requests to url-pattern “/api/*”).

I initialized the mongo and morphia objects in our InitContextListener (derived form ServletContextListener) derived class (method public void contextInitialized(ServletContextEvent arg0) {):

mongo = new Mongo();

morphia = new Morphia();

morphia.map(Product.class);

datastore = morphia.createDatastore(mongo, "my_database");

All mongo/morphia and datastore are static fields;

Then I used the statically created morphia Datastore object (datastore) to find my “Product” objects stored in the mongo db (which I verified that they are in the db using mongo console tool – they are there). The class that is handling the finding request url http://localhost:8888/api/products is defined like this:

@Path("/products")

@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })

public class ProductsResource {

@GET

  @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })

  public List<Product> getAllProducts() {

Query<Product> products = InitContextListener.getDatastore().find(Product.class);

return products.asList();

  }

}

When I invoke the url http://localhost:8888/api/products (which calls the method mentioned above (public List<Product> getAllProducts())from the browser I always get:

java.io.IOException: couldn't connect to [/127.0.0.1:27017] bc:java.net.SocketException: Permission denied: Not allowed to issue a socket connect: permission denied.

       at com.mongodb.DBPort._open(DBPort.java:214)

       at com.mongodb.DBPort.go(DBPort.java:107)

Any clues what is going on? 

Cheers,

Janusz

James Green

unread,
Nov 28, 2012, 2:51:53 AM11/28/12
to morphia
Reply all
Reply to author
Forward
0 new messages