I came to know GAE cloud endpoints yesterday. From that time I am trying to generate APIs for my current web application. I am using JPA2.0, I chose one of my entity classes right clicked on it and then "generate Google endpoint class" . So now I have another class for this entity with #API annotations, etc.
But the problem is after deploying the app when I go to : https://developers.google.com/apis-explorer/?base=https://myAppId.appspot.com/_ah/api#p/
the services tab is empty. Same thing when I check it locally(Image below)
You need to Generate Cloud Endpoints Library (in Eclipse, right click on the Project, it's under Google) as well.
I had similar issue and it was caused by missing public attribute in methods.
#Api
public class MyApi {
#ApiMethod
void myMethod() { }
}
caused that I saw no methods. While added
#Api
public class MyApi {
#ApiMethod
public void myMethod() { }
}
methods started to be visible.
1.Login appengine
https://appengine.google.com/
2.Click the [Version] link in a Main category
3.Select your version and [Make Default] button
4.You can access the api explorer
https://myAppId.appspot.com/_ah/api/explorer
Best Regard.
I actually managed to resolve the above issue. So I had a web application existing and I thought I could just add annotations to it and have the APIs represented for it after deployment. But I realized that I had to start from scratch by creating an android app and then generate the back-end for that app and add my classes there. It now works. Thank you.
Points to remember before working on endpoints :
Need to create an endpoint client library before running your project.(In Eclipse : Project -> Right click -> Google -> Generate cloud endpoints library)
Check whether you are using latest Google Plugin or not. Because files required by endpoints will be executed from the plugin. If you are not able to generate the endpoint library. problem is with the plugin .Try updating it.
Endpoints will work only on default versions. Make sure that you made your version default.
finally try loading http://myApp.appspot.com/_ah/api/explorer. Everything should be fine now.
Related
I had made a project using ASP.NET Core and React, in this project I made requests in the controller using a command something like this.
const response = await fetch('MyController/GetAll');
and the controller was something like this (simplifying the logic):
using Microsoft.AspNetCore.Mvc;
namespace Crud2.Controllers
{
[ApiController]
[Route("[controller]/[action]")]
public class MyController : ControllerBase
{
[HttpGet]
public bool GetAll()
{
return true;
}
}
}
The structure of the program was like this before:
Now the structure is like this:
But now I need to adjust for ASP.NET and React, so much so that the structure of the project they passed me has changed, now I can't even call the controller, how can I solve this?
I tried to include the Program.cs file, I tried to create the controller in another solution, I even tried to change the controller name and in all cases the result was none.
I tried to include the Program.cs file, I tried to create the
controller in another solution, I even tried to change the controller
name and in all cases the result was none
Well, as per your description, its evident you are following wrong approach. ASP.NET Core either Web Api or MVC project doesn't work in this way. Hence, if you suddenly include Program.cs and Controller files in other types of project it certaily wouldn't work. To check this, you check weather your MyController running on any server or not.
Why Its not working:
As you might know ASP.NET Core requires a web server along with certain port to run any perticular app same as React app or other SPAs does. For instance, while we run ASP.NET Core app locally, IIS express does the work for us (Server and port stuff), actually Visual studio managed it by itself. So, When you are adding Program.cs and Conterller Class wihtin your Portal Web Project (Not sure what kind of project it is) it certainly missing all necessary configuration files which a standard ASP.NET Core needs. Therefore, you cannot call the controller because, no service is running or port is listenning to your controller.
Correct way:
Before reaching to any particular solution let's have a look how any SPAs(single page application) constructed with asp.net core appliction.
As you may know, we need server/port as well to run or host a client side app. So our project structure should be either following type:
SPA in speperate project
SPA and Asp.net core project integrated within same porject.
Above two structures are pre-requisite for building a SPA with Asp.net core project.
First kind of project runs individually, can you can call directly to any backend service with out any issue becuase two projects are running in different server. No additional configuration is required here.
However, for second type of project structure, we need to configure our SPA project in Program.cs as following:
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "YourSPAName/build";
});
app.UseStaticFiles();
app.UseSpaStaticFiles();
app.UseSpa(spa =>
{
spa.Options.SourcePath = "YourSPAName";
if (env.IsDevelopment())
{
spa.UseReactDevelopmentServer(npmScript: "start");
}
});
Solution:
As per your scenario, you have two choices now, either take completely segregate project and call API the way it generally does.
On the other hand, in case of dual integration, first you have to take Web API project and with this project you should add SPA project in different folder because, React App, it requires, node js server. Thus, you should install all necessary files in that folder. In addition, in Program.cs files you have to tell the compiler how and from where your SPA would be loaded.
In your project, you are adding controller in SPA project which will not work in this way as it requires many additional service and middleware in configuration. So, better approach would be either follow approach 1 or 2.
Note: If you need more infromation, you could check our offical document.
Dear fellow programmers,
I am very new to programming and i am following the tutorial on using app engine backend tutorial. However i face some problem along the way.
I have Setup App Engine Backend Application Project, created a CheckIn entity class.
After which, i follow the instruction to create a new class with the name CheckInEndPoint.java
I copy the code from the snippet over to the Class.
When i try to Generate Cloud Endpoint Class, i faced an error message.
Error Generating API
This is not a JDO/JPA entity class.
Kindly seek your advice on how to troubleshoot it.
https://cloud.google.com/developers/articles/how-to-build-mobile-app-with-app-engine-backend-tutorial#ecdp
The instructions as provided by Google are confusing. What the instructions intended to say is after creating CheckIn.java, right-click on the CheckIn.java file and select Google->Generate Cloud Endpoint Class. This will then automatically create the CheckInEndpoint.java file.
Read through the entire "Entity Design Class Pattern" paragraph as given in the link you provided. You'll recognise that their instructions are ambiguous and is actually meant to be carried out from point 6.
Try adding this annotation to your CheckIn class:
import javax.jdo.annotations.PersistenceCapable;
#PersistenceCapable
public class CheckIn ...
This way it will find it as a JDO entity class and it will generate your CheckInEndPoint class.
I had the same error, I have first renamed the class CheckInEndPoint I've created manually to avoid any kind of conflicts. After that I have right clicked on
CheckIn class -> Google ->Generate Cloud Endpoint Class.
If you get some dependencies errors, please try check whether all the classes like ApiKeysAndIds.java, UserAccount.java are in the package.
I'm trying to create my first GAE Endpoint app, and instead of generating an endpoint from a class, I'd like to create my own personalised Endpoint... is this possible?
I've written this class:
#Api(name="my_endpoint", path="my_endpoint")
public class MyFirstEndpoint {
#ApiMethod (name="my_method", path="my_method", httpMehod=HttpMethod.GET)
public Response myMethod(#Named("param1") String param1) {
...
}
}
But when I try to generate the Endpoint Client Library in Eclipse, it says that there was an error... and the worst thing is that it doesn't say what error it is!
Yes it's possible to create custom Endpoints.
I had the same error. I think you can't use "_" in the name of the Api nor the ApiMethod...
Try using "myEndpoint" and "myMethod" as the names and keep the "_" in the paths.
A bit unrelated to this particular case, but it's the first thing that popped up on Google when searching for the error: you can't have overloaded methods in your Endpoints classes. Found this by looking in the Error console as described above in a comment.
I have a simple GAE application using JPA and eclipse plugin for GAE (sdk version 1.7.2).
I only have one simple entity mapped wit 2 properties : 1 Key key ; and one String name.
I have created only one class (taken from the "Datastore Callbacks" documentation of gae)
public class PostPutCallbacks {
static Logger logger = Logger.getLogger(PostPutCallbacks.class.getName());
#PostPut
public void collectSample(PutContext context) {
logger.fine("Finished putting " + context.getCurrentElement().getKey());
}
}
The database callback is not called.
I tried with several other annotations (#PrePut #PreGet) but they still didn't work .
I've also tried with the Datastore low leve API and the callback is still not called.
I searched the web to see if there is a configuration besides the annotation processing jar manualy added for eclipse but I didn't find anything..
Can anyone give me a hint?
I want to provide more information in this thread. If you are unable to see the datastore callbacks being triggered. Try this procedure as documented. You need to do some simple project set up at Eclipse in order to make it work. Hope this helps.
I jumped a little fast to stackoverflow..I had to restart eclipse and it worked
I'm trying to use Guice to inject properties of a JSF managed bean. This is all running on Google App Engine (which may or may not be important)
I've followed the instructions here:
http://code.google.com/docreader/#p=google-guice&s=google-guice&t=GoogleAppEngine
One problem is in the first step. I can't subclass the Servlet module and setup my servlet mappings there because Faces is handled by the javax.faces.webapp.FacesServlet which subclasses Servlet, not HttpServlet. So, I tried leaving my servlet configuration in the web.xml file and simply instantiating a new ServletModel() along with my business module when creating the injector in the context listener described in the second step.
Having done all that, along with the web.xml configuration, my managed bean isn't getting any properties injected. The method is as follows
#ManagedBean
#ViewScoped
public class ViewTables implements Serializable
{
private DataService<Table> service;
#Inject
public void setService( DataService<Table> service )
{
this.service = service;
}
public List<Table> getTables()
{
return service.getAll();
}
}
So, I'm wondering if there is a trick to get Guice injecting into a JSF managed bean? I obviously can't use the constructor injection because JSF needs a no-arg constructor to create the bean.
Check the following JSF-Guice integration framework/advice:
http://code.google.com/p/jsf-sugar/
http://notdennisbyrne.blogspot.com/2007/09/integrating-guice-and-jsf.html
http://cagataycivici.wordpress.com/2007/03/26/integrating_guice_and_jsf/
http://snippets.dzone.com/posts/show/7171
You can also create an HTTP servlet that then simple delegates the request on to a FacesServlet (like a wrapper). This should give you the same effect using Guice Servlet.
How about this approach, works well for us:
http://uudashr.blogspot.com/2008/12/guicing-jsf-with-guice.html
being the developer of jsf sugar I really would like to know the problem you had using it. We are already using it in production here so there shouldn't be any "show stoppers", maybe something is just not well documented? Just drop me a mail: murbanek(at)gmx_net (replace the _ with a .) .
check out http://code.google.com/p/guice2jsf/, and website starchu.blogspot.com, it has excellent library that provides Guice and JSF 2.0 integration
As information in this post are getting out of date but the question is still relevant, I'd like to share my findings about this topic. I wrote a little tutorial including a runnable sample project on how to setup a fully guice powered web stack. You can find it here: https://github.com/skuzzle/guice-jsf