ApiResourceProperty tag can not be compiled to GWT or ignored - gwt

We have a GWT app that exposes an API using Google Cloud Endpoints. As we use objectify we can not expose the Key tag to the API. For that we use the ApiResourceProperty in order to make the API ignore the field, but if we do that the GWT compilation fails.
I have tried everything, from using the exclude from source in the gwt.xml to using the #gwtincompatible
So... is there a way to ignore the ApiResourceProperty.class in the GWT compilation?
Any other idea? If not I would have to duplicate my entities for the API
Thanks in advance

The only option I had was to create custom DTOs for the API.

Related

Configure Swagger api with Play 2.4

Facing problem while configuring swagger api with play 2.4 framework.
Follow this url for configuration : https://github.com/swagger-api/swagger-play/tree/master/play-2.4/swagger-play2
After configuration gets a compile time error with message "type ApiHelpController is not a member of package controllers" as this ApiHelpController.scala file is present in app/controllers package.
Does anyone knows what i am missing.
Not sure what you are missing but let me show you an alternative for swagger play 2.4 integration
Unlike the one you were trying to use, this one does not require annotation, you write swagger spec directly in your routes files as comment. There are several benefits of this approach:
controller remain clean
you don't need to repeat path and parameters
you don't need to learn another API (the annotation api)
Also it generates swagger definition from case classes reflection.
Check it out:
https://github.com/iheartradio/play-swagger
Not sure about swagger-jaxrs, but swagger-play2 package works for me. You can refer to http://swagger.io/playing-with-swagger-using-swagger-and-swagger-ui-with-the-play-framework/

The error creating app Engine's DataStore Entity within GWT app

I try to create the entity like this:
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
Entity stock = new Entity("Stock", 1);
stock.setProperty("Stock", "FCB");
ds.put(stock);
but keep getting the error:
No source code is available for type com.google.appengine.api.datastore.DatastoreService; did you forget to inherit a required module?
The error means just what it says, the GWT compiler needs access to the Java source it compiles to Javascript, and obviously DatastoreService is not something that should exist on the frontend - so you have an architecture issue here.
You'll need to write a proxy that can call a server component (Which in turns calls the DatastoreService) and returns DTOs/value objects (that you define and thus have the source for).
Cheers,
No source code is available
GWT transliterate Java to Javascript, reading it's source code and there a limited language support.
What you're trying to achieve is a Server only operation and you're adding this operation within the client code, which will run on a browser. Neither GAE allow this or GWT has the source of these classes nor capability to do so.
Solution
You need to create a request to your server that will access the DatastoreService , the return the output to the client code.
Below a example of a properly architect GWT web application:

IoC, MVC4 Web API & HttpParameterBinding/ParameterBindingAttribute

I'm using ASP.Net MVC 4 RTM Web API. I have a controller action with a parameter that I'd like to populate via custom model binding. To achieve this, I created a class that derives from System.Web.Http.Controllers.HttpParameterBinding that sets the value of this parameter. I then created an attribute class that derives from System.Web.Http.ParameterBindingAttribute which I use to decorate the parameter on my controller action.
This is all working great, my HttpParameterBinding class is populating the action parameter correctly. The problem I have is that my custom parameter binding class has a dependency that I'd like resolved via my IoC container (Unity). Is there a way to override how Web API creates HttpParameterBinding instances so that I can build up my custom binding class dependency from Unity? I was able to do something similar for a filter attribute by creating a custom filter provider that uses Unity's BuildUp method to populate dependencies, however I'm not seeing anything similar for Web API's HttpParameterBindings.
In general: to use IoC / Unity in the Web API you need to set it up seperately.
Try downloading the nuget package Unity.WebApi and see if that helps!
Take a look at this article: Parameter Binding in WebAPI
It walks through a couple different options from Converters to Binders to BinderProviders. It sounds like you may be able to write a custom ModelBinderProvider which knows how to provide your dependency. If that isn't high enough in the chain you can look at replacing the default IActionValueBinder service. It's a DefaultActionValueBinder instance, which you can extend or simply re-implement.
I also highly recommend downloading the WebAPI source code, as it's been an incredible help for these issues as I've run into them. Here's the WebAPI source code. I recommend downloading it so you can open it in VS for easy navigation.
Feel free to check out FlitBit too (It's very modular, don't let the number of packages scare you off)! I'm working on a WebAPI package for supporting FlitBit, specifically FlitBit.IoC and FlitBit.Dto. I'll add an update if I work out my IoC issue, since it's very similar to yours.

Wicket 1.4 EJB Support

I tried implementing the JavaEE Inject jar from Wicket Stuff. (glassfish v3, wicket 1.4)
- however, the code given in the tutorial doesn't work
method
addComponentInstantiationListener in
class org.apache.wicket.Application
cannot be applied to given types
required:
org.apache.wicket.application.IComponentInstantiationListener
found:
org.wicketstuff.javaee.injection.JavaEEComponentInjector
looks to me like the API has changed. The JIRA link inside
http://wicketstuff.org/confluence/display/STUFFWIKI/JavaEE+Inject
and the Repository link are both broken. Is it still maintained?
Another short question: Is it possible to populate ListView directly with entity beans? I'd like to avoid too many proxy classes.
Thanks in advance
Yes, you can inject a ListView with entity beans. You should do so by creating an implementation of IDataProvider (or one of it's sub-interfaces) for the iterator and have it wrap the entities with LoadableDetachableModel so they can be reloaded instead of serialized as a part of the session.
Figured it out: I didn't expect there to be a difference between 1.4.13 and 1.4.14 but apparently the API changed there significantly.

GWT with JPA

I'm trying to build database application using GWT 1.5.3. I use JPA annotations with my objects. It seems in hosted mode GWT's RPC works fine. But when I try to compile my app using GWT-compiler I get errors like: "The import javax.persistence cannot be resolved", "Entity cannot be resolved to a type". toplink-essentials.jar is already included in my project path. What settings else do I need to solve this problem?
You can use Gilead (http://sourceforge.net/projects/gilead/) library to seamlessly manage JPA entities with GWT.
Regards
You need to include the source code for the JPA annotations in the build path for your GWT project. See here for more details:
http://code.google.com/p/google-web-toolkit/issues/detail?id=1830&can=1&q=jpa
Specifically this jar file which will fix your problem:
http://google-web-toolkit.googlecode.com/issues/attachment?aid=1475633892125294312&name=jpa-annotations-source.jar
The general problem of the JPA and GWT is that GWT itself doesn't support fancy JPA classes, so you just do simple POJO persistent entities DTO that implements the java.io.Serializable and have simple JPA resource annotations. You need to create the entity classes in the scope of the GWT client either have it under the yourproject.client package or add them with
source path="client"
source path="folderOfYourEntities"
in the GWT project's YouProject.gwt.xml file. This will include the entity objects in the GWT client so they can used them on client side of the RPC as well. The DAO must be on the server side and can contain anything that you container supports.
The problem you have now is that when compiling, GWT compiler saids that it desn't know what those imports for JPA annonations are in the entity DTO classes. That is why you need the javax.persistence class and source codes. The jpa-annotation-source.jar reference by Rustmyself works. It is just the javax.persistence compiled class files and source codes files plus a Persistence.gwt.xml. It is a simple GWT module for the javax.persistence package. If you know how to make your own GWT module, you should have problem making all this work. By the way, the official source for the Java EE can be found on the glassfish dev site's build section wiki.glassfish.java.net
There are many other solutions that wrap your fancy PU entities to simple objects automatically using proxy or to lazy load them at run time. They work, but not optimal solutions. The best practice is to make things simple and robust from the start by having POJO JPA DTO entities on the GWT client context and full blown DAO on the server.
GWTPersistence Example
I have added an actual working example on how to make GWT and JPA work seamlessly. It is a NetBean project with source codes and deployment file. See GWTPersistence on NingZhang.info
Ok, I've found what I was missing. I needed to include jpa-annotations-source.jar in my GWT-compiler path in myapp-compile.cmd script (or in ant build file). By the way can anyone tell me the origin of this jpa-annotations-source.jar file?
I am also working with JPA <--> GWT data transformation etc.
In an effort to eliminate the DTO layer I used Gilead too.
My objection here is about translating javax.persistence. To avoid this I used XML JPA mapping declarations (orm.xml)
Simply, keep another version of your Entities but without the annotations!
Rebounding on synergetic's comment, you now (from GWT 1.5) only need to add
<source path='javax.persistence'/>
to your Module.gwt.xml