I have been developing and application and I create all the web services using google endpoints.
For default is using Cloud DataStorage, and i want to change it to Cloud SQL storage. I'm following this steps from the documentation https://cloud.google.com/appengine/docs/java/cloud-sql/
import java.util.Map;
import java.util.HashMap;
import com.google.appengine.api.utils.SystemProperty;
...
// Set the persistence driver and url based on environment, production or local.
Map<String, String> properties = new HashMap();
if (SystemProperty.environment.value() ==
SystemProperty.Environment.Value.Production) {
properties.put("javax.persistence.jdbc.driver",
"com.mysql.jdbc.GoogleDriver");
properties.put("javax.persistence.jdbc.url",
"jdbc:google:mysql://your-project-id:your-instance-name/demo");
} else {
properties.put("javax.persistence.jdbc.driver",
"com.mysql.jdbc.Driver");
properties.put("javax.persistence.jdbc.url",
"jdbc:mysql://127.0.0.1:3306/demo");
}
// Create a EntityManager which will perform operations on the database.
PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(propertiesMap, "persistence-unit-name");
What "persistence-unit-name" means in the last line?
As per the definition, A persistence unit defines a set of all entity classes that are managed by EntityManager instances in an application.
Please refer to the following link for more details.
Now, once your application is built and since this is a web application, as per the link above "If you package the persistence unit as a set of classes in a WAR file, persistence.xml should be located in the WAR file’s WEB-INF/classes/META-INF directory." Look inside the META-INF folder under src directory and you should see a persistence.xml file, which will have the persistent unit name defined as the one you specified while getting the PMF.
Hope this helps.
Related
I have a React app created with create-react-app which I have deployed to an Azure Web App. There is no back-end: the site is purely 'static'.
In the production environment, there are a number of keys to API services and other secrets that I need to keep secure, but which the client app needs to be able to read.
In React there's a mechanism for accessing environment-specific information using .env files, such as .env.production, but this is not suitable for keeping secrets, as environment variables mentioned in the code are substituted with the actual value from the .env file during the build process, and are consequently visible to anyone looking at the JavaScript in their browser.
Setting the values of the AppSettings can be done on the Azure Portal (or via suitable scripting in the CI/CD pipeline), but how can I read the AppSettings values at runtime?
A number of StackOverflow questions have been asked about this, but none of the answers address the fundamental question properly, or seem to miss the point. For example, here and here.
First off, this topic is puzzling lot of developers around the globe and it should be addressed properly in Aspnet Core. One viable option would be to set up Server-Side Rendering, but there are some of us who wouldn't benefit from it. Also, there are no proper examples for doing it for ReactJS + Redux in Aspnet Core world.
My solution is to go for a InMemoryFileProvider, see https://github.com/dazinator/Dazinator.AspNet.Extensions.FileProviders for details about the NuGet package.
To start using one, in my Configure() I'll do a:
configuredSpaFileProvider = CreateFileProvider(env);
app.UseSpaStaticFiles(new StaticFileOptions
{
FileProvider = configuredSpaFileProvider
});
My CreateFileProvider() contains an instantiation of InMemoryFileProvider-class, which can be populated with additional fake "files". Pre-existing static file on filesystem will be served with a PhysicalFileProvider.
To allow access to index.html, CSS, JavaScript and all possible static files, do what a DefaultSpaStaticFileProvider would do:
var defaultPath = "build";
if (env.IsDevelopment())
defaultPath = "public";
var absoluteRootPath = System.IO.Path.Combine(
env.ContentRootPath,
$"{ReactJSdirectory}/{defaultPath}");
var physicalFileProvider = new PhysicalFileProvider(absoluteRootPath);
Then create a provider and virtual file like this:
var inMemoryProvider = new InMemoryFileProvider();
inMemoryProvider.Directory.AddFile("/", new StringFileInfo(configJsContent, "app.config.js"));
Finally glue them together, prioritizing on the virtual files:
return new CompositeFileProvider(inMemoryProvider, physicalFileProvider);
Now that a dynamic JavaScript-file exists, it needs to be accessed on client-code. There are options for this, but I'll simply do a:
<script src="/app.config.js" async defer></script>
in my index.html. The trick is to construct a string with suitable JavaScript-parseable content setting up variables and storing them into window-object and accessing them later on a client.
Now my 12 factor application is fully compliant with third factor "Store config in the environment".
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 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.
I'm developing a portlet that is deployed as WAR. Database models are created by service builder. How can I insert initial data models to the database when the WAR is installed?
Add to the project a portal.properties file with the property:
application.startup.events=com.my.project.MyStartupAction
and impliment the startup import as extension of SimpleAction:
package com.my.project;
import com.liferay.portal.kernel.events.ActionException;
import com.liferay.portal.kernel.events.SimpleAction;
public class MyStartupAction extends SimpleAction {
#Override
public void run(String[] arg0) throws ActionException {
if(startupDataNotExist()) {
createStartupData();
}
}
...
You can do this either as StartupAction, executed on startup of the plugin (read: during deployment AND during subsequent server starts) or as an UpgradeAction.
A good example for this is the sevencogs-hook that comes with Liferay CE and has the source code included. This is implemented as an UpgradeAction - e.g. on first start your database content will be "upgraded" to contain the sevencogs sample data.
Also you can do it with UpgradingProcess. Here are step-by-step instructions
In the development admin console, when I look at my data, it says "Select different namespace".
What are namespaces for and how should I use them?
Namespaces allow you to implement segregation of data for multi-tenant applications. The official documentation links to some sample projects to give you an idea how it might be used.
Namespaces is used in google app engine to create Multitenant Applications. In Multitenent applications single instance of the application runs on a server, serving multiple client organizations (tenants). With this, an application can be designed to virtually partition its data and configuration (business logic), and each client organization works with a customized virtual application instance..you can easily partition data across tenants simply by specifying a unique namespace string for each tenant.
Other Uses of namespace:
Compartmentalizing user information
Separating admin data from application data
Creating separate datastore instances for testing and production
Running multiple apps on a single app engine instance
For More information visit the below links:
http://www.javacodegeeks.com/2011/12/multitenancy-in-google-appengine-gae.html
https://developers.google.com/appengine/docs/java/multitenancy/
http://java.dzone.com/articles/multitenancy-google-appengine
http://www.sitepoint.com/multitenancy-and-google-app-engine-gae-java/
Looking, towards this question is not that much good reviewed and answered so trying to give this one.
When using namespaces, we can have a best practice of key and value separation there on a given namespace. Following is the best example of giving the namespace information thoroughly.
from google.appengine.api import namespace_manager
from google.appengine.ext import db
from google.appengine.ext import webapp
class Counter(db.Model):
"""Model for containing a count."""
count = db.IntegerProperty()
def update_counter(name):
"""Increment the named counter by 1."""
def _update_counter(name):
counter = Counter.get_by_key_name(name)
if counter is None:
counter = Counter(key_name=name);
counter.count = 1
else:
counter.count = counter.count + 1
counter.put()
# Update counter in a transaction.
db.run_in_transaction(_update_counter, name)
class SomeRequest(webapp.RequestHandler):
"""Perform synchronous requests to update counter."""
def get(self):
update_counter('SomeRequest')
# try/finally pattern to temporarily set the namespace.
# Save the current namespace.
namespace = namespace_manager.get_namespace()
try:
namespace_manager.set_namespace('-global-')
update_counter('SomeRequest')
finally:
# Restore the saved namespace.
namespace_manager.set_namespace(namespace)
self.response.out.write('<html><body><p>Updated counters')
self.response.out.write('</p></body></html>')