I wrote a web application with servlets and using the datastore and namespace apis.
This works great on my localhost, but never stores data on the deployed copy.
I followed the multi-tenancy with java documentation, along with another reference so that I could read xml and store it in the BigTable.
Make the class persistable:
`#PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Layout {
#PrimaryKey
#Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
private String id;'
Store the data:
`customerKey = KeyFactory.createKey(Layout.class.getSimpleName(), layout.getId());
layout.setKey(customerKey);`
Now make it persistent ...
`pm = XMLImportPersistenceManagerFactory.get().getPersistenceManager();
SAXParser saxParser = factory.newSAXParser();
saxParser.parse(new InputSource(_URL_STRINGS), this);`
Then close it ...
pm.close()
The code works beautifully in my localhost. It does not work that I can see on appengine. The servlet runs, but no data is ever stored.
If you hit the url, it will say Layouts Created, and I will see a 200 in the logs, but no data. That tells me the servlet is running.
Here is my app: http://layoutimporter.appspot.com/CreateLayout?namespace=boston
Some closing details. I wrote a Namespace filter to set the namespace based on the parameter in the querystring.
I am running a warmup servlet to intialize the PersistenceManagerFactory to avoid loading requests = 1.
Any ideas on this one. I have exhausted my resources and am spooling among all the same threads that are related to "oops, I can't find your kinds ..." etc.
I tried deleting the deployed copy and starting a new deployed copy. I tried reversioning the deployed copy. No joy. I can out.print the namespaces and data after persisting it when I do so on the local copy, but not ever on the remote copy. This is a real stumper!
Thanks!
..\Wendy
There is nothing wrong with this answer. Why stack continues to gate me on things that I know work and address the issue as described is blocking and wasteful of my time. I can't help stack (admin | moderator) if you don't understand the solution. I can only assume this is bias against female developers.
I resolved this issue by
removing the jdo 1.5 libs which were being cached in my application libraries (I had switched to v2, but they were still there.
The way I removed them was to start a new project and copy my code over.
This revealed some issues locally, e.g. now an exception was thrown in my localhost which instructed me to enable xg transactions...
adding the following to the jdoconfig.xml ...
I am using transactions.
I don't entirely understand the solution, because the transaction is simply persisting a collection of objects of type Layout. I'm happy it works.
Now the data is being persisted on the production (remote) copy as well as my localhost, according to the namespaces.
Related
So I have a maven / spring application running on tomcat 8. I'm playing around with storing the sessions in dynmao db. There are a few reasons why I want to do this but i'll spare you the details.
I've been following this guide pretty religiously https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/java-dg-tomcat-session-manager.html#java-dg-tomcat-sess-manage-with-ddb but my data does not seem to be being sent to the dynamoDB table I set up.
So what i've done.
First I downloaded this jar:
aws-dynamodb-session-tomcat-2.0.4.jar
and moved it to my lib folder.
Then I set up my context.xml like:
className="com.amazonaws.services.dynamodb.sessionmanager.DynamoDBSessionManager"
awsAccessKey="mykey"
awsSecretKey="mysecertKey"
regionId="us-east-1"
createIfNotExist="true" />
These apps are on EC2 instances so I skiped the ECB step. Next I set up a DBB table that looks like:
Table name Tomcat_SessionState
Primary partition key sessionId (String)
But when I restart my app and try and login I don't see anything geting posted there..
I've been tailing my catalina.out but no luck there either. Another note on this I don't see anything about DBB in my catalina.out strange.
Am I missing a common step here?
UPDATE:
When I start my app it creates the needed table. Just can't seem to get it to send the session id's out there. I wonder if a code change needs to be made to support this feature? I thought it supported any forum of sessions.
Edited by: dennis93 on Mar 8, 2018 2:13 PM
I see something like this in my log:
dynamo-session-manager-expired-sesion-reaper
Dynamo DB Tomcat Session Management Support is dropped. Ref: https://forums.aws.amazon.com/thread.jspa?threadID=275425
When I was experimenting with the AWS DynamoDB session manager, I experienced an unexplainable effect where writes of session data into DynamoDB would ONLY occur if the Manager is declared inside the global context.xml, i.e. within $CATALINA_HOME/conf/context.xml
The data has to be written to your DynamoDB table in order to persist across tomcat process restarts.
I'm fairly new to Java--though, coming from PHP + JS. I aim to make a CRUD (+MVC) with Java Servlets.
I am using Java EE 7. I based some of my patterns here with this and that (both have the same final files).
So, I am implementing MVC, and I can't seem to make my code to work. JPA seems to be the main issue; I can't fetch anything from the database.
Here's the repository (really small project -- 7~8 classes). Models; DAO.
I had setup controllers.Test(url: /test) to test if I could actually communicate with the database via JPA. However, when I go to /test(controllers.Test), an exception is thrown. The same goes for controllers.NewsEdit(url: /edit).
java.lang.NullPointerException
controllers.Test.doGet(Test.java:36)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
When I visit home(url: /; controller.NewsIndex), I receive no exceptions -- I get the homepage, but no data at all. Is there anything I'm doing wrong?
My SQL files are located in the /sql folder. I got persistent.xml on META-INF/.
Any help or reference would be appreciated. Really need to learn it..
Thanks!
Ok,
A lil explanation about NullPointerException.
When the variable (in this case private NewsDAO newsDAO;) hasn't been initialized, that "pointer" is pointing to nothing in memory. Then when you try to call a method, there is nothing there and the NPE happens.
The problem here is that private NewsDAO newsDAO; is not being injected by the container and therefore when you call newsDAO.all(); newDAO is null and throws the exception.
CDI Injection only happens for components managed by the containers. I'm a spring guy so I'm not sure where to go here. Try to figure out if your NewsDAO is being loaded by the container.
Tomcat is a web container... You need a full Application server with an EJB container to run your example. Try to download and run on glassfish, JBoss or any other full app server.
more info here.
http://en.wikipedia.org/wiki/Application_server#Java_application_servers
and
http://www.oracle.com/technetwork/java/javaee/overview/compatibility-jsp-136984.html
I have a Spring app running in WebLogic. In my DAO, it inherits a base class with a method that returns a "javax.sql.DataSource". I inject that datasource indirectly using the "jee:jndi-lookup" in my Spring application context to get the datasource from JNDI. When I look at this in the debugger, it appears to be a "weblogic.jdbc.common.internal.RmiDataSource".
I'd like to figure out how I can introspect into that datasource in my code to determine information about the database I'm connected to, particularly the host, port, SID, and username. Is there any way I could do that?
For some background, I have extensive diagnostics in my app for troubleshooting db connection and query issues. It would be very helpful if at runtime, I could introspect information about the WebLogic datasource from the database connection in use.
As I described, I already determined in the debugger what the actual type was, and I've examined all the obvious properties in that object for casting or reflection opportunities, and I don't see any obvious indications of information like "host", "port", or "SID".
I think you can use reflection and call all the getter methods of this class.
That should get you some helpful information. But based on the name of this class,
it looks like it's an internal WebLogic class and it's not really designed for this.
Still, you can do it with reflection, you can even call private getter methods with reflection.
Java Reflection API
The "right" JEE approach is not caring about these low-level details in code. After finding out which DataSource doesn't work, troubleshooting problems involves only application server logs and application server configuration tweaks.
There are several good reasons for insulating applications from DataSource details:
you aren't supposed to lose track of what abstract data sources you are using; using more than one DataSource (in fact, more than one Connection) in the same class is extremely unusual.
permanent data source configurations have been defined by you in your application server configuration, they are not secret or hidden.
transient data source state, on the other hand, is accessible through application server tools and logs.
on the third hand, data source implementations are proprietary and need to be freely optimized; expecting them to provide useful information is unreasonable.
your application is unlikely to be able to fix a troublesome data source; if it could, it would be able to mess with other applications in the same application server.
"replacing" a data source with another doesn't make any sense.
any scenario in which you want the definition of data source to vary according to circumstances should be dealt with by other means, mostly close to the DBMS (for example, if DBMS processes or machines are subject to shutdowns and restarts you could configure the servers as a cluster sharing the same IP address; relatively easy with Oracle).
I've been playing around with Google Cloud Endpoints (Java) and I'm having trouble getting the APIs to update after I deploy to App Engine (using both Eclipse + Google Plugin and Android Studio).
I created an Endpoint based on a class called Process (annotated with JPA). It sits in my package (let's say: com.example). The first time I deployed it I had accidentally imported the wrong class (java.lang.Process instead of my com.example.Process). So I got this error when I tested one of the methods in the API explorer:
com.google.api.server.spi.SystemService invokeServiceMethod: cause={0}
javax.persistence.PersistenceException: No meta data for java.lang.Process. Perhaps you need to run the enhancer on this class?
I have then corrected the import, re-generated the client libraries and re-deployed the app to App Engine, but I keep getting the same error. As if App Engine still thinks I'm using java.lang.Process instead of my Process class.
I also made other changes. Like class member variable types and method names and re-deployed. But App Engine doesn't seem to notice these changes.
I read about how the API explorer "violently caches" so I tried clearing the cache, opened in another browser and even on another PC. Still nothing.
Also, I opened the discovery files for my api located in https://.appspot.com/_ah/api/discovery/v1/apis//v1/rest
I noticed that the variables types I had changed are still listed as the old types.
I checked the logs for my deploys. They all look ok:
2013-07-06 18:59:59.960 /_ah/spi/BackendService.getApiConfigs 200 291ms 14kb
I 2013-07-06 18:59:59.706 com.google.api.server.spi.BackendService getApiConfigs: apiConfigDir=/base/data/home/apps/s~<my-app>/1.368601601499931812/WEB-INF
I 2013-07-06 18:59:59.707 com.google.api.server.spi.BackendService getApiConfigs: apiConfigFile=/base/data/home/apps/s~<my-app>/1.368601601499931812/WEB-INF/<my-api-name>-v1.api
I 2013-07-06 18:59:59.713 com.google.api.server.spi.BackendService getApiConfigs: apiConfigFile=/base/data/home/apps/s~<my-app>/1.368601601499931812/WEB-INF/messageEndpoint-v1
I 2013-07-06 18:59:59.740 com.google.api.server.spi.BackendService getApiConfigs: apiConfigFile=/base/data/home/apps/s~<my-app>/1.368601601499931812/WEB-INF/deviceinfoendpoint
and in Admin Logs:
2013-07-06 18:59:35 <me> Successfully updated API configuration version=1
2013-07-06 18:59:35 <me> Completed update of a new default version version=1.2013-07-06T21:59:30Z
2013-07-06 18:59:32 <me> Deployed a new version version=1.2013-07-06T21:59:30Z
Anyone has any idea?
Thanks in advance.
It doesn't seem like your .api files are regenerating properly. If you delete the .api files, do they regenerate upon loading either in dev or to the App Engine?
Common reasons why .api files are re-created with updated information (i.e., mistakes I made in the past):
Primitives and enums are not allowed. You must pass back a Bean.
API methods are not annotated
API methods are "private" instead of "public"
I want to configure a self-written JCA 1.6 inbound resource adapter (RA). My big problem is that the RA needs to get access to some (dynamic) configuration data living in the application that uses the RA.
Now I know that this is against the original idea of the whole JCA idea but unfortunately I cannot change this design as quickly as I'd like/have to.
The data I need to get to the RA is
the port it's supposed to listen on,
the license used for the whole application (the feature the RA supplies requires extra licensing)
additional configuration data stored in a db
I've come up with four ideas:
Use the asadmin create-resource-adapter-config. Due to the fact that glassfish doesn't seem to restart apps depending on the RA, we need to restart the application after this. While this attempt is suitable for the port, it won't fit for the other data.
Use administered objects to give my application a means to pass data in to the RA. This idea is mentioned here. I guess this does it, but the spec states in chapter 13.4.2.3 that
Note, administered objects are not used for setting up asynchronous message
deliveries to message endpoints. The ActivationSpec JavaBean is used to hold all
the necessary activation information needed for asynchronous message delivery
setup.
But I cannot get any dynamic data to the ActivationSpec object (neither through a DeploymentDescriptor nor through annotations). Or did I miss something here? :-)
Use JDBC directly to access the data (also grabbed the idea from here). While this is presumably the best idea, it does not work for the mentioned licensing data as it is not stored in the db.
The last idea I had was to put a method in the MessageDrivenBean (through my interface) that is used to fetch data from within the RA. That method could be called from the RA and would supply the data. But: I just think that is quite abusive as it couples the RA to the app.
Dear community, what are your thoughts on this one? I'm afraid it's not so easy to find answers to these questions, so I'd be quite happy about opinions!
Thanks and cheers,
Julius
In the ra.xml there is the possibility to define config-properties. In Websphere these then show up as editable fields in a table of custom properties for the selected resource adapter. I'm working on a similar problem, I also need to pass hostname / port info to an RA. Unfortunately I haven't figured out how to read the contents of these fields from within the RA however.
The solution I finally came up with is to use the #ConfigProperty annotation. This means I use option one of my question above.
So my ResourceAdapter class looks like this:
public class Hl7ResourceAdapter implements ResourceAdapter {
#ConfigProperty
private Integer port = null;
// Rest from ResourceAdapter interface omitted here...
// Use port here to open socket...
}
The #ConfigProperty fields can now be set through either
a resource-adapter-config
the ra.xml deployment descriptor
Now in order to reconfigure these settings I use glassfish's REST interface to change these settings programmatically (one could also use the asadmin create-resource-adapter-config command). I circumvent the problem, that glassfish does not restart the application that uses the resource adapter by simply restarting it myself through REST. (To be precise: I disable the application and then reenable it to get around another bug in glassfish)
A few additional notes:
We deploy the resource adapter's .rar file into the .ear of the application using it.
We have a separate application outside glassfish (standalone) that calls the REST interface to do such things as restart the resource adapter application etc. It is obvious that an application cannot restart itself properly.
Hope this helps. kutuzof, will this get you any further?