Error in request sent to appengine backend devserver - java

I have a bunch of code which would run on backend but when testing locally I am getting memcache related error
INFO : { AppEngineUserRealm isUserInRole } - Checking if principal test#example.com is in role admin
SEVERE : { ShardedMemcacheUtil get } - Error encountered while getting [ configuration ] from memcache.
java.lang.ClassCastException: com.google.appengine.tools.appstats.StatsProtos$RequestStatProto$Builder cannot be cast to com.google.appengine.tools.appstats.StatsProtos$RequestStatProto$Builder
at com.google.appengine.tools.appstats.MemcacheWriter.write(MemcacheWriter.java:210)
at com.google.appengine.tools.appstats.Recorder.processRecordingFuture(Recorder.java:456)
at com.google.appengine.tools.appstats.Recorder.processAsyncRpc(Recorder.java:404)
at com.google.appengine.tools.appstats.RecordingFuture.maybeRecordStats(RecordingFuture.java:140)
at com.google.appengine.tools.appstats.RecordingFuture.get(RecordingFuture.java:110)
at com.google.appengine.tools.appstats.RecordingFuture.get(RecordingFuture.java:20)
at com.google.appengine.api.utils.FutureWrapper.get(FutureWrapper.java:88)
at com.google.appengine.api.memcache.MemcacheServiceImpl.quietGet(MemcacheServiceImpl.java:26)
at com.google.appengine.api.memcache.MemcacheServiceImpl.get(MemcacheServiceImpl.java:49)
The request was sent to the following URL so that the code is executed in backend.
http://localhost:52843/
The above request runs fine when sent to
http://localhost:8888/
Which is actually devserver.
Any clue what's wrong with it when run inside backend ? Also why there are two ports opened for backend 58251 and 58252
INFO : { JettyLogger info } - Started SelectChannelConnector#127.0.0.1:8888
INFO : { AbstractModule startup } - Module instance default is running at http://localhost:8888/
INFO : { AbstractModule startup } - The admin console is running at http://localhost:8888/_ah/admin
INFO : { JettyLogger info } - jetty-6.1.x
INFO : { ApiProxyLocalImpl log } - javax.servlet.ServletContext log: Initializing Spring FrameworkServlet 'dispatcher'
INFO : { JettyLogger info } - Started SelectChannelConnector#127.0.0.1:58251
INFO : { ServerWrapper startup } - server: -1.backend1 is running on port 58251
INFO : { JettyLogger info } - jetty-6.1.x
INFO : { ApiProxyLocalImpl log } - javax.servlet.ServletContext log: Initializing Spring FrameworkServlet 'dispatcher'
INFO : { JettyLogger info } - Started SelectChannelConnector#127.0.0.1:58252
INFO : { ServerWrapper startup } - server: 0.backend1 is running on port 58252
INFO : { DevAppServerImpl doStart } - Dev App Server is now running
UPDATE Looks like it was happening because I compiles with Jdk8. I came to know only after I deployed to cloud and it gave me version error. Still not sure why only backend was effected locally.

Related

Unable to set the logger name in payara server log

When writing the logs of a war into payara server logs, it was not able to determine/identify the Logger name.
When I see it on the admin console, the Logger value us blank, and it is printing Log Level as SEVERE even it is just an INFO level log.
Following is the entry in payara server
Log Entry Detail
Timestamp : Mar 25, 2022 12:37:03.439
Log Level : SEVERE
Logger :
Name-Value Pairs : {levelValue=1000, timeMillis=1648211823439}
Record Number : 679
Message ID :
Complete Message : [http-thread-pool::http-listener-1(18)] INFO com.test.LogTest - com.test.LogTest
Sample code looks like the following
public class LogTest {
static Logger logger = LoggerFactory.getLogger(LogTest.class);
public static void main(String[] args) {
logger.info(logger.getName());
logger.debug("debug");
logger.info("info");
}
}
In my local I was able to get the following output
[main] INFO com.test.LogTest - com.test.LogTest
[main] DEBUG com.test.LogTest - debug
[main] INFO com.test.LogTest - info
I am using SimpleLogger (slf4j) as the logging library
Please help me on how to set the Logger value in the payara server logs, for the logs that I am logging

Not starting the JMS listener using jmsListenerEndpointRegistry.start()

I am trying to start the JMS listener using jmsListenerEndpointRegistry.start() which was stopped using jmsListenerEndpointRegistry.stop(). But looks like it is not getting started. When I am trying to consume the messages it is not allowing me to do so as it is still stopped. Please help me how to start it back using start method.
In application.properties I have spring.jms.listener.auto-startup=true
Using Apache ActiveMQ(Version-5.16.3)
2022-01-06 16:27:54.699 INFO 28804 --- [nio-9091-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 22 ms
2022-01-06 16:27:54.726 ERROR 28804 --- [nio-9091-exec-1] com.jms.poc.controller.JmsController : --------- Trying to start JMS using jmsListenerEndpointRegistry.start()----------
2022-01-06 16:27:54.727 ERROR 28804 --- [nio-9091-exec-1] com.jms.poc.controller.JmsController : ----------jmsListenerEndpointRegistry.isRunning()-------- : false
There is no need to change the autoStartup property in startJmsListener - that property only applies when the application context is initialized.
You have no #JmsListeneners - the only one is commented out.
registry.isRunning() only returns true when at least one of its containers is running.

camel kafka route does not stay up

I am trying to use kafka with camel and set up the following route:
public class WorkflowEventConsumerRoute extends RouteBuilder {
private static final String KAFKA_ENDPOINT =
"kafka:payments-bus?brokers=localhost:9092";
...
#Override
public void configure() {
from(KAFKA_ENDPOINT)
.routeId(format(KAFKA_CONSUMER))
.to("mock:end);
}
}
When I start my spring boot application I can see the route gets started but immediately after this it shuts down without any reasons given in the logs:
2018-12-21 12:06:45.012 INFO 12184 --- [ main] o.a.kafka.common.utils.AppInfoParser : Kafka version : 2.0.1
2018-12-21 12:06:45.013 INFO 12184 --- [ main] o.a.kafka.common.utils.AppInfoParser : Kafka commitId : fa14705e51bd2ce5
2018-12-21 12:06:45.014 INFO 12184 --- [ main] o.a.camel.spring.SpringCamelContext : Route: kafka-consumer started and consuming from: kafka://payments-bus?brokers=localhost%3A9092
2018-12-21 12:06:45.015 INFO 12184 --- [r[payments-bus]] o.a.camel.component.kafka.KafkaConsumer : Subscribing payments-bus-Thread 0 to topic payments-bus
2018-12-21 12:06:45.015 INFO 12184 --- [ main] o.a.camel.spring.SpringCamelContext : Total 1 routes, of which 1 are started
2018-12-21 12:06:45.015 INFO 12184 --- [ main] o.a.camel.spring.SpringCamelContext : Apache Camel 2.23.0 (CamelContext: camel-1) started in 0.234 seconds
2018-12-21 12:06:45.019 INFO 12184 --- [ main] a.c.n.t.p.workflow.WorkflowApplication : Started WorkflowApplication in 3.815 seconds (JVM running for 4.513)
2018-12-21 12:06:45.024 INFO 12184 --- [ Thread-10] o.a.camel.spring.SpringCamelContext : Apache Camel 2.23.0 (CamelContext: camel-1) is shutting down
On the other hand if create an unit test and point to the same kafka endpoint I am able to read the kafka topic content using the org.apache.camel.ConsumerTemplate instance provided by the CamelTestSupport
Ultimately if I replace the kafka endpoint in my route with an activemq one the route starts OK and the application stays up.
Obviously I am missing something but I cannot figure out what.
Thank you in advance for your help.
Do your spring-boot app have a -web-starter or not. If not then you should turn on the camel run-controller to keep the boot application running.
In the application.properties add
camel.springboot.main-run-controller = true

Why Cryptoki.C_OpenSession disconnect from HSM sometimes

I' created a web service isAlive to check if I can create session with the HSM soft using the Cryptoki ,I automated the execution of my web service using SoapUI so I execute my service in a loop each 40s ,it work well but after a number of call I can't connect to my HSM until I restart my App : this the part of code that I used to connect to HSM
// create session handle
CK_SESSION_HANDLE session= new CK_SESSION_HANDLE();
// return code
CK_RV retcode;
// get session
retcode=Cryptoki.C_OpenSession(safeNetSlot, CKF.RW_SESSION, null, null, session);
checkRetCode(retcode, "Could not open session on HSM");
log.debug("Session [{}]",session.longValue());
// do login
final String recovHsmPassword = PasswordManagement.recoverPassword(hsmPassword);
retcode=Cryptoki.C_Login(session, CKU.USER, recovHsmPassword.getBytes(), recovHsmPassword.length());
checkRetCode(retcode, "Could not login as user");
During the execution of my service I watch logs I look that the session.longValue() incremented with each calls :
This's the logs :
INFO 5056 --- [nio-8191-exec-5] ccom.test.app.V1Controler : Request for isAlive API
DEBUG 5056 --- [nio-8191-exec-5] com.test.app.hsm.HsmService : Session [1]
INFO 5056 --- [nio-8191-exec-5] com.test.app.V1Controler : Request for isAlive API
DEBUG 5056 --- [nio-8191-exec-5] com.test.app.hsm.HsmService : Session [2]
INFO 5056 --- [nio-8191-exec-5] com.test.app.V1Controler : Request for isAlive API
DEBUG 5056 --- [nio-8191-exec-5] com.test.app.hsm.HsmService : Session [3]
INFO 5056 --- [nio-8191-exec-5] com.test.app.V1Controler : Request for isAlive API
......
INFO 5056 --- [nio-8191-exec-5] com.test.app.V1Controler : Request for isAlive API
DEBUG 5056 --- [nio-8191-exec-5] com.test.app.hsm.HsmService : Session [1176]
INFO 5056 --- [nio-8191-exec-5] com.test.app.V1Controler : Request for isAlive API
2018-08-14 10:39:06.550 ERROR 1 --- [nio-8443-exec-3] com.test.app.hsm.HsmService : HSM return error [MSG_ERROR general error]
I ask if someone have an idea how Cryptoki.C_OpenSession works and why I desconnect from my HSM
Generally HSM's have a bounded number of sessions available. Currently you are opening sessions, but you are never closing them with C_CloseSession. You should handle sessions as if they are resources, and resources may be sparse.
Note that there is also a function called C_TokenInfo that can be used to check the token status. Make sure you are using the right function for the job. You don't want to use a password when not required.

What causes Spring scheduler to execute before the application and servlet starts up?

I have a simple Spring-Boot web application with some scheduling tasks:
#SpringBootApplication
#EnableScheduling
public class Application extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(final SpringApplicationBuilder app) {
return app.sources(Application.class);
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
And a service executing two scheduling tasks:
#Service
public class SchedulingService {
#Scheduled(fixedRate = 15000)
private void first() {
// log first
}
#Scheduled(fixedRate = 6000)
public void second() {
// log second
}
}
Is there any explanation revealing why one of the scheduling tasks has been executed before the application and servlet starts up? This happens repeatedly and the log order is always the same, so I suspect the multithreading doesn't take place - there is nearly one-second difference between the first and the second scheduling task.
Here is the log with highlighted parts of the scheduling task log:
2018-08-18 20:47:53.085 INFO 251168 --- [ost-startStop-1] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page template: index
2018-08-18 20:47:53.300 INFO 251168 --- [ost-startStop-1] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-08-18 20:47:53.314 INFO 251168 --- [ost-startStop-1] s.a.ScheduledAnnotationBeanPostProcessor : No TaskScheduler/ScheduledExecutorService bean found for scheduled processing
2018-08-18 20:47:53.321 HERE LOGGED FIRST
2018-08-18 20:47:53.344 INFO 251168 --- [ost-startStop-1] my.appname.Application : Started Application in 5.565 seconds (JVM running for 16.93)
2018-08-18 20:47:53.396 INFO 251168 --- [ main] org.apache.coyote.ajp.AjpNioProtocol : Starting ProtocolHandler ["ajp-nio-8009"]
2018-08-18 20:47:53.400 INFO 251168 --- [ main] org.apache.catalina.startup.Catalina : Server startup in 15970 ms
2018-08-18 20:47:53.477 INFO 251168 --- [nio-8080-exec-1] o.a.c.c.C.[.[localhost].[/Rattle] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2018-08-18 20:47:53.477 INFO 251168 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2018-08-18 20:47:53.520 INFO 251168 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 43 ms
2018-08-18 20:47:54.103 HERE LOGGED SECOND
2018-08-18 20:47:59.335 HERE LOGGED SECOND
2018-08-18 20:48:05.334 HERE LOGGED SECOND
2018-08-18 20:48:08.334 HERE LOGGED FIRST
I just created an empty SpringBoot project, added your class and tried to reproduce the same issue.
On SpringBoot 2.0.4.RELEASE I see that both tasks run at the same time and same thread:
2018-08-18 21:16:54.145 INFO 10239 --- [pool-1-thread-1] com.test.SchedulingService : LOG FIRST
2018-08-18 21:16:54.145 INFO 10239 --- [pool-1-thread-1] com.test.SchedulingService : LOG SECOND
Then, I added a Thread.sleep(100) on the both tasks as I cannot predict the execution order.
2018-08-18 21:21:14.775 INFO 10274 --- [pool-1-thread-1] com.test.SchedulingService : LOG FIRST
2018-08-18 21:21:14.878 INFO 10274 --- [pool-1-thread-1] com.test.SchedulingService : LOG SECOND
The delay of aprox 100ms between the log entries, confirm that they run on the same thread.
You might think that setting the initialDelay = 0 on the #Scheduled might help, but it will not; everything will still be on the main thread.
The solution I found is defining a custom bean that creates a customTaskScheduler:
#Bean()
public ThreadPoolTaskScheduler taskScheduler(){
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.setPoolSize(2);
taskScheduler.setThreadNamePrefix("Async-");
return taskScheduler;
}
Now, the logs show that both tasks are executed at the same time and by different threads:
2018-08-18 21:30:26.482 INFO 10383 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2018-08-18 21:30:26.486 INFO 10383 --- [ main] com.test.ProjectApplication : Started ProjectApplication in 1.767 seconds (JVM running for 2.137)
2018-08-18 21:30:26.555 INFO 10383 --- [ Async-2] com.test.SchedulingService : LOG SECOND
2018-08-18 21:30:26.555 INFO 10383 --- [ Async-1] com.test.SchedulingService : LOG FIRST
I defined a thread pool of size = 2. What will happen if I have 3 tasks to run? One of the tasks will need to wait to complete the execution of the previous 2, get the thread released and check the execution queue again.
2018-08-18 21:33:48.895 INFO 10412 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2018-08-18 21:33:48.899 INFO 10412 --- [ main] com.test.ProjectApplication : Started ProjectApplication in 1.888 seconds (JVM running for 2.258)
2018-08-18 21:33:48.960 INFO 10412 --- [ Async-1] com.test.SchedulingService : LOG FIRST
2018-08-18 21:33:48.960 INFO 10412 --- [ Async-2] com.test.SchedulingService : LOG SECOND
2018-08-18 21:33:49.065 INFO 10412 --- [ Async-2] com.test.SchedulingService : LOG THIRD
I had same issue, but I was able to get around it by specifying the cron parameter instead of using fixedRate or fixedRateString like so #Scheduled(cron = "0 0 4 ? * SUN,THU")
More details on using the cron expression in spring-boot can be found here https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/scheduling/support/CronExpression.html

Categories

Resources