ElasticBeanstalk Token Vending on iOS - ios

I am having trouble with the anonymous vending machine hosting on elastic beanstalk. The situation is that I'm using the code that AWS provides for iOS, but getting 500s back for the crypto generated uid / key that the KeyWrapper makes. The beanstalk logs seem to be pretty sparse but are showing the 500s, so they are at least talking.
This null pointer exception seems to be the only detailed error, although I am not sure what problem it is pointing towards.
May 10, 2013 4:10:48 PM com.amazonaws.tvm.GetTokenServlet processRequest
INFO: processing request
May 10, 2013 4:10:48 PM com.amazonaws.tvm.anonymous.AnonymousTokenVendingMachine validateTokenRequest
FINE: Timestamp [ 2013-05-10T16%3A10%3A48Z ] is valid
May 10, 2013 4:10:48 PM com.amazonaws.tvm.anonymous.AnonymousTokenVendingMachine validateTokenRequest
FINE: Signature matched!!!
May 10, 2013 4:10:48 PM com.amazonaws.tvm.TemporaryCredentialManagement getTemporaryCredentials
SEVERE: Exception during getTemporaryCredentials
java.lang.NullPointerException
at java.util.regex.Matcher.appendReplacement(Matcher.java:712)
at java.util.regex.Matcher.replaceAll(Matcher.java:823)
at java.lang.String.replaceAll(String.java:2201)
at com.amazonaws.tvm.TemporaryCredentialManagement.getPolicyObject(TemporaryCredentialManagement.java:56)
at com.amazonaws.tvm.TemporaryCredentialManagement.getTemporaryCredentials(TemporaryCredentialManagement.java:42)
at com.amazonaws.tvm.anonymous.AnonymousTokenVendingMachine.getToken(AnonymousTokenVendingMachine.java:88)
at com.amazonaws.tvm.GetTokenServlet.processRequest(GetTokenServlet.java:48)
at com.amazonaws.tvm.RootServlet.doGet(RootServlet.java:38)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:680)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:679)
May 10, 2013 4:10:48 PM com.amazonaws.tvm.GetTokenServlet processRequest
SEVERE: Error generating session credentials for UID : 6c6feea6848c6ca41c4a9e427896dba9
May 10, 2013 4:10:48 PM com.amazonaws.tvm.GetTokenServlet processRequest

I know this is a bit old question. But I also encountered the same problem while running a TVM in the environment (Amazon beanstalk micro instance) This issue has been solved once I restarted the beanstalk instance. But to make sure that you are not getting this error again, you have to make sure that the user policy of the IAM user who is used to access the TVM, is copied to the "TokenVendingMachinePolicy.json" file which is in the deployed TVM application. for further details refer http://aws.amazon.com/code/8872061742402990

Related

Apache ranger 2.1.0 - Installation failed

I am trying to install the latest version of Apache ranger 2.1.0 and getting this error while installing ranger admin. [E] Ranger all admins default password change request failed and there is not much error logs.
2020-09-05 20:21:14,541 [JISQL] /usr/lib/jvm/jre-11-openjdk-11.0.8.10-0.el7_8.x86_64/bin/java -cp /usr/share/java/mysql-connector-java.jar:/opt/apache-ranger/ranger-2.1.0-admin/jisql/lib/* org.apache.util.sql.Jisql -driver mysqlconj -cstring jdbc:mysql://localhost/ranger -u 'ranger' -p '********' -noheader -trim -c \; -query "insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('DEFAULT_ALL_ADMIN_UPDATE', current_timestamp, 'Ranger 2.1.0', current_timestamp, 'pas-bifrostx0.myntra.com','N') ;"
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
2020-09-05 20:21:15,219 [I] Ranger all admins default password change request is in process..
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.eclipse.persistence.internal.security.PrivilegedAccessHelper (file:/opt/apache-ranger/ranger-2.1.0-admin/ews/webapp/WEB-INF/lib/eclipselink-2.5.2.jar) to method com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.getXmlEncoding()
WARNING: Please consider reporting this to the maintainers of org.eclipse.persistence.internal.security.PrivilegedAccessHelper
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2020-09-05 20:21:19,448 [JISQL] /usr/lib/jvm/jre-11-openjdk-11.0.8.10-0.el7_8.x86_64/bin/java -cp /usr/share/java/mysql-connector-java.jar:/opt/apache-ranger/ranger-2.1.0-admin/jisql/lib/* org.apache.util.sql.Jisql -driver mysqlconj -cstring jdbc:mysql://localhost/ranger -u 'ranger' -p '********' -noheader -trim -c \; -query "delete from x_db_version_h where version = 'DEFAULT_ALL_ADMIN_UPDATE' and active = 'N' and updated_by='pas-bifrostx0.myntra.com';"
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
2020-09-05 20:21:20,073 [E] Ranger all admins default password change request failed
Also, regardless of this error, I was able to start the service with sudo ranger-admin start and is able to do telnet localhost 6080 but web UI is not showing up.
Found the following error in ews/logs/catalina.out
Internal Exception: Exception [EclipseLink-7161] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Entity class [class org.apache.ranger.entity.XXAccessAuditV4] has no primary key specified. It should define either an #Id, #EmbeddedId or an #IdClass. If you have defined PK using any of these annotations then make sure that you do not have mixed access-type (both fields and properties annotated) in your entity class hierarchy.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1619)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:481)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1082)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:857)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:443)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:325)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5128)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5653)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1689)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1679)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [defaultPU] failed.
Internal Exception: Exception [EclipseLink-7161] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Entity class [class org.apache.ranger.entity.XXAccessAuditV4] has no primary key specified. It should define either an #Id, #EmbeddedId or an #IdClass. If you have defined PK using any of these annotations then make sure that you do not have mixed access-type (both fields and properties annotated) in your entity class hierarchy.
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.createPredeployFailedPersistenceException(EntityManagerSetupImpl.java:1954)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1945)
at org.eclipse.persistence.jpa.PersistenceProvider.createContainerEntityManagerFactory(PersistenceProvider.java:322)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:360)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:384)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:371)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:336)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1677)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1615)
... 21 more
Caused by: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [defaultPU] failed.
Internal Exception: Exception [EclipseLink-7161] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Entity class [class org.apache.ranger.entity.XXAccessAuditV4] has no primary key specified. It should define either an #Id, #EmbeddedId or an #IdClass. If you have defined PK using any of these annotations then make sure that you do not have mixed access-type (both fields and properties annotated) in your entity class hierarchy.
at org.eclipse.persistence.exceptions.EntityManagerSetupException.predeployFailed(EntityManagerSetupException.java:230)
... 30 more
Caused by: Exception [EclipseLink-7161] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Entity class [class org.apache.ranger.entity.XXAccessAuditV4] has no primary key specified. It should define either an #Id, #EmbeddedId or an #IdClass. If you have defined PK using any of these annotations then make sure that you do not have mixed access-type (both fields and properties annotated) in your entity class hierarchy.
at org.eclipse.persistence.exceptions.ValidationException.noPrimaryKeyAnnotationsFound(ValidationException.java:1422)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor.validatePrimaryKey(EntityAccessor.java:1536)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor.processMappingAccessors(EntityAccessor.java:1243)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor.process(EntityAccessor.java:697)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProject.processStage2(MetadataProject.java:1793)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor.processORMMetadata(MetadataProcessor.java:576)
at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processORMetadata(PersistenceUnitProcessor.java:585)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1869)
... 28 more
Sep 05, 2020 2:56:32 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: One or more listeners failed to start. Full details will be found in the appropriate container log file
Sep 05, 2020 2:56:32 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [] startup failed due to previous errors
Sep 05, 2020 2:56:32 PM org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
Sep 05, 2020 2:56:32 PM org.apache.catalina.core.ApplicationContext log
INFO: Shutting down log4j
Sep 05, 2020 2:56:32 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc
SEVERE: The web application [] registered the JDBC driver [com.mysql.cj.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Sep 05, 2020 2:56:32 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc
SEVERE: The web application [] registered the JDBC driver [org.apache.solr.client.solrj.io.sql.DriverImpl] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Sep 05, 2020 2:56:32 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [org.apache.hadoop.fs.FileSystem$Statistics$StatisticsDataReferenceCleaner] but has failed to stop it. This is very likely to create a memory leak.
Sep 05, 2020 2:56:32 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [mysql-cj-abandoned-connection-cleanup] but has failed to stop it. This is very likely to create a memory leak.
Sep 05, 2020 2:56:32 PM org.apache.catalina.loader.WebappClassLoaderBase checkThreadLocalMapForLeaks
SEVERE: The web application [] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal#2dfce76e]) and a value of type [org.apache.hadoop.fs.FileSystem.Statistics.StatisticsData] (value [9910 bytes read, 0 bytes written, 0 read ops, 0 large read ops, 0 write ops]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Sep 05, 2020 2:56:32 PM org.apache.catalina.loader.WebappClassLoaderBase checkThreadLocalMapForLeaks
SEVERE: The web application [] created a ThreadLocal with key of type [org.apache.htrace.core.Tracer.ThreadLocalContext] (value [org.apache.htrace.core.Tracer$ThreadLocalContext#4073a8a9]) and a value of type [org.apache.htrace.core.Tracer.ThreadContext] (value [org.apache.htrace.core.Tracer$ThreadContext#42aecda1]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Sep 05, 2020 2:56:32 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-6080"]
Sep 05, 2020 2:56:37 PM org.apache.catalina.loader.WebappClassLoaderBase findResourceInternal
INFO: Illegal access: this web application instance has been stopped already. Could not load []. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
Can someone please help here or redirect me to Ranger community so that I can reach out to someone for here.
Thanks in advance.
Issues were related to JAVA 11. I was trying to run ranger with JAVA 11
(https://issues.apache.org/jira/browse/RANGER-2575) but seems like it doesn't work. Building and running against java 8 worked.

com.google.api.client.http.HttpRequest error when staging Dataflow to GCP

I am trying to run my Java Dataflow with the DataflowRunner on GCP.
Dataflow works fine with DirectRunner but when changing to DataflowRunner and running it, the console starts staging the files and I suddenly I get the following error several times:
mars 19, 2018 8:43:56 PM com.google.api.client.http.HttpRequest execute
AVERTISSEMENT: exception thrown while executing request
java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:170)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
at sun.security.ssl.InputRecord.read(InputRecord.java:503)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973)
at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:930)
at sun.security.ssl.AppInputStream.read(AppInputStream.java:105)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:704)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:647)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1569)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:338)
at com.google.api.client.http.javanet.NetHttpResponse.<init>(NetHttpResponse.java:37)
at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:94)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:981)
at com.google.api.client.googleapis.media.MediaHttpUploader.executeCurrentRequestWithoutGZip(MediaHttpUploader.java:545)
at com.google.api.client.googleapis.media.MediaHttpUploader.executeCurrentRequest(MediaHttpUploader.java:562)
at com.google.api.client.googleapis.media.MediaHttpUploader.resumableUpload(MediaHttpUploader.java:419)
at com.google.api.client.googleapis.media.MediaHttpUploader.upload(MediaHttpUploader.java:336)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:427)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
at com.google.cloud.hadoop.util.AbstractGoogleAsyncWriteChannel$UploadOperation.call(AbstractGoogleAsyncWriteChannel.java:357)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
But the staging continues (as the console still outputs some staging info) and at some point the errors pops again (may be for the 5th time) and then the following:
mars 19, 2018 8:48:13 PM org.apache.beam.runners.dataflow.util.PackageUtil stageClasspathElements
INFOS: Still staging 127 files
As the console says that it is still staging and don't understand whether this is staging issue or related to the execution of my code...
Any idea about it and how to solve this?
** EDIT **
There is another error that I didn't notice before:
mars 19, 2018 9:41:46 PM com.google.api.client.http.HttpRequest execute
AVERTISSEMENT: exception thrown while executing request
java.io.IOException: insufficient data written
at sun.net.www.protocol.http.HttpURLConnection$StreamingOutputStream.close(HttpURLConnection.java:3540)
at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:81)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:981)
at com.google.api.client.googleapis.media.MediaHttpUploader.executeCurrentRequestWithoutGZip(MediaHttpUploader.java:545)
at com.google.api.client.googleapis.media.MediaHttpUploader.executeCurrentRequest(MediaHttpUploader.java:562)
at com.google.api.client.googleapis.media.MediaHttpUploader.resumableUpload(MediaHttpUploader.java:419)
at com.google.api.client.googleapis.media.MediaHttpUploader.upload(MediaHttpUploader.java:336)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:427)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
at com.google.cloud.hadoop.util.AbstractGoogleAsyncWriteChannel$UploadOperation.call(AbstractGoogleAsyncWriteChannel.java:357)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
This was actually a networking issue. Workaround solution is to deploy the pipeline through a Compute Engine instance. This will assure you a good network bandwidth.

How to write a unit test with neo4j-in-memory-server

I have written a webservice and would now like to write some unit tests for it.
I stumbled across Michael Hunger's in memory server.
Due to the sparse documentation, I have a hard time setting up only one unit test.
I cloned the project, included it in my workspace and added it as a dependency to my project.
In order to test my web service, I wrote this method to create an in-memory neo4j server:
#BeforeClass
public static void setupInMemoryServer()
{
CommunityBootstrapper s = new CommunityBootstrapper();
int status = -1;
try
{
status = s.start();
}
catch(Exception e)
{
System.out.println("could not start server");
e.printStackTrace();
System.out.println(e.getMessage());
System.out.println(e.getCause());
System.out.println(e.getLocalizedMessage());
}
System.out.println(hostAvailabilityCheck());
System.out.println("status = "+status);
}
public static boolean hostAvailabilityCheck() {
try (Socket s = new Socket("127.0.0.1", 7474)) {
return true;
} catch (IOException ex) {
System.out.println ("Neo server not online");
}
return false;
}
When I run this code, I get the following output:
Mai 29, 2014 10:13:17 PM org.neo4j.server.logging.Logger log SEVERE: Unable to upgrade database Mai 29, 2014 10:13:17 PM
org.neo4j.server.logging.Logger log SEVERE:
org.neo4j.server.ServerStartupException: Starting Neo4j Server failed:
Startup failed due to preflight task [class
org.neo4j.server.preflight.PerformUpgradeIfNecessary]: Unable to
upgrade database at
org.neo4j.server.AbstractNeoServer.start(AbstractNeoServer.java:218)
at org.neo4j.server.Bootstrapper.start(Bootstrapper.java:87) at
org.neo4j.server.Bootstrapper.start(Bootstrapper.java:74) at
com.youtube.rest.status.test.CreateUserTest.setupInMemoryServer(CreateUserTest.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at
java.lang.reflect.Method.invoke(Unknown Source) at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.neo4j.server.preflight.PreflightFailedException:
Startup failed due to preflight task [class
org.neo4j.server.preflight.PerformUpgradeIfNecessary]: Unable to
upgrade database at
org.neo4j.server.AbstractNeoServer.runPreflightTasks(AbstractNeoServer.java:335)
at
org.neo4j.server.AbstractNeoServer.start(AbstractNeoServer.java:152)
... 19 more
Mai 29, 2014 10:13:17 PM org.neo4j.server.logging.Logger log SEVERE:
Failed to start Neo Server on port [7474]
true
status = 1
Mai 29, 2014
10:13:17 PM org.neo4j.server.logging.Logger log WARNING: Failed to
cleanly shutdown database. Mai 29, 2014 10:13:17 PM
org.neo4j.server.logging.Logger log INFO: Successfully shutdown Neo
Server on port [7474], database [unknown location]
I don't know why this happens since the server is built in memory and everything is (should) created temporarily. I neither understand, how database update conflicts can occur nor how to resolve them.
Based on the string "Unable to upgrade database" in your stack trace, it looks like your database needs to be upgraded, but the upgrade cannot be done automatically. You may need to do an "explicit upgrade", as described on this page.

RichFaces 5 on Tomcat 7: could not find factory

This question is similar to:
java.lang.IllegalStateException:Could not find backup for factory javax.faces.application.ApplicationFactory
But unfortunately it is not my case. I have richfaces-5.0.0.Alpha1.jar inside my WAR and jboss-jsf-api_2.1_spec-2.0.2.Final.jar in the Tomcat lib folder. Nothing else. I don't use MyFaces and never did.
The log is the following:
Grave: Application was not properly initialized at startup, could not find Factory: javax.faces.context.FacesContextFactory. Attempting to find backup.
dic 12, 2013 1:41:41 PM org.apache.catalina.core.ApplicationContext log
Grave: StandardWrapper.Throwable
java.lang.IllegalStateException: Could not find backup for factory javax.faces.context.FacesContextFactory.
at javax.faces.FactoryFinder$FactoryManager.getFactory(FactoryFinder.java:1008)
at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:343)
at javax.faces.webapp.FacesServlet.init(FacesServlet.java:302)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1266)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1185)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1080)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5027)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5314)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
"jboss-jsf-api_2.1_spec-2.0.2.Final.jar" why that one and not the proper JSF jar you can download from javaserverfaces.java.net? I think you have only the API and no JSF implementation here.
(Don't know how to convert a comment into an answer, so I just reposted).

Failure to deploy grails app with cloudfoundry plugin

"grails cf-push" results in errors listed below. Is there a way using the cloudfoundry plugin to "start fresh". I would prefer not to lose my test data in a MySQL database and a MongoDB database.
May 18, 2012 6:31:26 PM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
May 18, 2012 6:31:26 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [] startup failed due to previous errors
May 18, 2012 6:31:26 PM org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
SEVERE: The web application [] created a ThreadLocal with key of type [org.codehaus.groovy.reflection.ClassInfo.ThreadLocalMapHandler] (value [org.codehaus.groovy.reflection.ClassInfo$ThreadLocalMapHandler#6434d75f]) and a value of type [java.lang.ref.SoftReference] (value [java.lang.ref.SoftReference#4927d15e]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
2012-05-18 18:31:26,379 [main] ERROR context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsApplication' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/apache/http/conn/ClientConnectionManager
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:567)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:384)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
at org.codehaus.groovy.grails.web.context.GrailsContextLoader.initWebApplicationContext(GrailsContextLoader.java:66)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.NoClassDefFoundError: org/apache/http/conn/ClientConnectionManager
at java.lang.Class.forName(Class.java:169)
at java.lang.Class.forName(Class.java:247)
Caused by: java.lang.ClassNotFoundException: org.apache.http.conn.ClientConnectionManager
... 2 more
Stopping Tomcat because the context stopped.
stderr.log is :
May 18, 2012 6:41:00 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-31903
May 18, 2012 6:41:00 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 403 ms
May 18, 2012 6:41:00 PM org.apache.catalina.realm.JAASRealm setContainer
INFO: Set JAAS app name Catalina
May 18, 2012 6:41:00 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
May 18, 2012 6:41:00 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.35
May 18, 2012 6:41:00 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory ROOT
May 18, 2012 6:41:02 PM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
May 18, 2012 6:41:02 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [] startup failed due to previous errors
May 18, 2012 6:41:02 PM org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
SEVERE: The web application [] created a ThreadLocal with key of type [org.codehaus.groovy.reflection.ClassInfo.ThreadLocalMapHandler] (value org.codehaus.groovy.reflection.ClassInfo$ThreadLocalMapHandler#6d1576d7]) and a value of type [java.lang.ref.SoftReference] (value [java.lang.ref.SoftReference#1c2d5534]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
If you do cf-update or delete the app and re-run cf-push, it will ask you if you want to use the existing MySQL and Mongo services. If you do there isn't any data loss - just don't delete the services along with the app before re-running cf-push.
Make sure you're using 'grails prod cf-push' since that will use the production configuration - there is a warning displayed if you run 'grails cf-push' to that effect.
The root cause is a CNFE from the HttpClient library. See if you can get it working locally and it should work fine on Cloud Foundry since you're just pushing a war file.
I found the problem. I added a service that used an external jar from a third party package. The third party package shipped with 2 jars: one with dependencies and one without dependencies. I extracted the 3rd party zip into my classpath, but only included the one without dependencies in my lib directory. When I switched to using the jar with dependencies, the app deployed.The following things made this simple problem difficult to resolve:the error logs simply stated that there was a problem with 'grailsApplication' and there was a class not foundthe app ran on my workstation using run-app,the app doesn't run on my workstation using run-war (regardless of whether the correct jars are supplied),lack of sleep!
On to the next issue!

Resources