You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by siva <si...@bizruntime.com> on 2017/10/15 10:17:19 UTC
custom restful service using jetty server on top of ignite grid to
perform crud operations and configure cache store
Hi,
we need to implement a rest service which have to perform all the crud
operations on ignite grid and as well as configure the cache store to
persist the data in RDBMS.
As per following link,
http://apache-ignite-users.70518.x6.nabble.com/WebServer-on-Ignite-td314.html
i have created a service and started the jetty server in init method,here
how i can to get the ignite instance to perform the operations on ignite
grid. Is this correct way or any other way is there?
following is the code snippet
@Path("/service/test")
public class InmemoryService implements Service {
@IgniteInstanceResource
private Ignite ignite;
private IgniteCache<String, String> cache;
@GET
@Path("/create")
public String create(@QueryParam("tenantId")String tenantId,
@QueryParam("key") String key, @QueryParam("value") String value) {
String result = "SUCCESS";
try {
System.out.println("Inside create ");
cache = createOrGetCache(tenantId, CacheAtomicityMode.ATOMIC);
cache.put(key, value);
} catch (Exception e) {
return e.getMessage();
}
return result;
}
@Override
public void init(ServiceContext ctx) throws Exception {
// TODO Auto-generated method stub
ServletContextHandler context = new
ServletContextHandler(ServletContextHandler.NO_SESSIONS);
context.setContextPath("/");
Server jettyServer = new Server(9999);
jettyServer.setHandler(context);
ServletHolder jerseyServlet =
context.addServlet(ServletContainer.class, "/*");
jerseyServlet.setInitOrder(0);
// Tells the Jersey Servlet which REST service/class to load.
jerseyServlet.setInitParameter("jersey.config.server.provider.packages","com.v2r.service");
try {
jettyServer.start();
jettyServer.join();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Thanks
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: custom restful service using jetty server on top of ignite
grid to perform crud operations and configure cache store
Posted by dkarachentsev <dk...@gridgain.com>.
Hi,
In your code Ignite could not inject it's instance, because you have two
instances of your class: one in Ignite as a service, another one is object
that processes requests in Jersey. So when you're doing http query, it goes
to jersey instance.
How do you start Ignite? You may get ignite with Ignition.ignite().
Thanks!
-Dmitry
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: custom restful service using jetty server on top of ignite
grid to perform crud operations and configure cache store
Posted by siva <si...@bizruntime.com>.
when i am calling using rest ,each time new instance is creating and not able
to getting the ignite instance using the @IgniteInstanceResource annotation.
could you please help how to get the ignite instance in our scenario.How
ignite http module has been implemented using jetty server.
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: custom restful service using jetty server on top of ignite
grid to perform crud operations and configure cache store
Posted by siva <si...@bizruntime.com>.
Is this the correct way to create a jetty rest server in ignite service?
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: custom restful service using jetty server on top of ignite
grid to perform crud operations and configure cache store
Posted by siva <si...@bizruntime.com>.
Hi,
Yes,I have also used "*IgniteInstanceResource"* in code to get the
instance,as per my code snippet ,when i call the "*create*" method using
*proxy *its working fine ,but when i call the same method using my custom
rest "*ignite*" instance getting null.
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: custom restful service using jetty server on top of ignite
grid to perform crud operations and configure cache store
Posted by dkarachentsev <dk...@gridgain.com>.
Hi,
@IgniteInstanceResource annotation is a correct and the best way to get
Ignite instance in service.
Thanks!
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/