Is there a way not to expose a method to client side? - gwt

I’m using GWT 2.5, and RPC to exchange information between client and server.
I’m trying to define the interface that extends RemoteService and another one CRUDService<T> that has among others (CRUD methods) the following method:
public Class<T> getDtoType();
But this method is only intended to be user by the implementation, on the server side.
Is there a way not to expose this method to client side (transient method)?
Otherwise I’m getting an error, when I compile the project, saying Class<T> does not implements Serializable nor IsSerializable.
Could anyone help me?

Not possible. Atleast not without hacking gwt-dev and rpc related code for service proxy generation.
1) SampleService extends RemoteService, CrudService<String>
2) SampleService extends CrudService<String> ( where CrudService extends RemoteService )
In both above scenarios Async Interface cribs first. If you fix it then GWT proxy generators crib about Serialization interface.

Related

Does anyone know how to transfer data between classes in blazor server side?

startup Blazor server side
I already tried to register classes in scoped but it doesn't work
class where I send data to another class following the mvvm architecture
I also use iprovider service but in the same way I can't make it work.
class container
class where I implement the IServiceProvider

How do I inject into a Servlet with Dagger?

How do I inject objects into a Servlet using Dagger?
Since the servlet container instantiates the Servlets themselves, they are not created with Dagger. Therefore, the only mechanism I can see to inject into them is via static injections, which the dagger homepage warns against doing. Is there another (best practices) way to do it?
Specifically, I am using Jetty and GWT (my servlets extend RemoteServiceServlet), but I don't think those details matter.
There is not (yet) any stock infrastructure code to support a Java EE servlet stack for Dagger.
That said, there are ways you could home-brew it until we get to it. If you were using it only for singletons, then you could mirror what some people are doing on android, and initialize your graph at app startup using a context listener, then use the Servlet's init() method to self-inject
It gets much trickier when you try to add scoping to requests and such - not impossible, but it requires more scaffolding.
While there is no stock infrastructure for this, I did the following:
I put the ObjectGraph into the ServletContext of the web server. Then, for each Servlet, I can do the following,
#Inject
SomeDependency dependency;
#Inject
SomeOtherDependency otherDependency;
#Override
public void init(FilterConfig filterConfig) throws ServletException
{
((ObjectGraph) filterConfig.getServletContext().getAttribute(DaggerConstants.DAGGER_OBJECT_GRAPH)).inject(this);
}
where I have previously defined the DaggerConstants myself.
There are likely a variety of ways to get the ObjectGraph into the ServletContext, depending on what your application is. We use an embedded jetty server, so we control everything during startup. Not sure how you would do it in a general container, but presuming you instantiate your main ObjecGraph through some init servlet, you would do it there.
servletContext.setAttribute(DaggerConstants.DAGGER_OBJECT_GRAPH, objectGraph);
Note that our application uses a single ObjectGraph for the entire application, which might not be your situation.

Call class from server side in client side

I have class in server side and I want use method of this class in client side. How can I do it?
Thanks!
You have to look at the basics of how the communication of the client application works with the server.
All server side functionality has to be exposed as a service/RPC based functionality in GWT.
If you look at the tutorial at http://code.google.com/webtoolkit/doc/1.5/tutorial/RPC.html, you have to do the following.
For your requirement, you have to create another method (except the methods you already have created), so do the following:
Define the service – in the interface which extends RemoteService interface
Implementing the service – in the class which extends RemoteServiceServlet class and implements the service defined interface
Implements the server-side – in the class which extends RemoteServiceServlet and implements the service defined interface
Hope this would help.

How to #Inject a HttpSession object in a service layer (DAO) class in GWT using Guice?

I have such a dirty code in my GWT app, some of the classes of my service layer depend on an HttpSession object. So for example, in one of my DAO (which was a GWT-RPC endpoint) I have something like this :
public class MyExampleDAO extends RemoteServiceServlet {
public findItems() {
// here I need to get the object session to retrieve the currently logged in user in order to query for all its items...
}
}
The problem is that, I am currently migrating the code to use RequestFactory. My DAO will not be a GWT-RPC endpoint anymore. So no need to extend RemoteServiceServlet then ...
Do you know how I can get/inject (probably with Guice) my dependency to HttpSession Object, knowing that my class does not extend RemoteServiceServlet anymore?
getThreadLocalRequest().getSession() should do it. RequestFactoryServlet has a similar (but static) getThreadLocalRequest() method that you can access from your service.
Otherwise, you can get Guice to inject a Provider<HttpSession>, have a look at these projects https://github.com/mgenov/injecting-request-factory and https://github.com/etiennep/injected-requestfactory for some sample code using Guice with RequestFactory.

How do I avoid using an async class when using gwt dto?

Can anyone please explain how I can avoid using an aync class when using dto to serialize an object in a service?
If I understand your question, DTOs are only for passing data to the client side in a GWT application, when you can't pass the server side object directly. DTOs have nothing to do with the async classes, which the GWT compiler needs for RPC service calls.