ERROR org.quartz.core.JobRunShell - Job group1.JobReport threw an unhandled Exception - quartz-scheduler

There is a strange problem when generating the report using QUARTZ scheduler
I can generate a report fine! no problem.
the method (reportsBean) works normally, but there is a problem when passing through quartz
Any idea please?? I don't know what to do anymore :/
13449 [MyScheduler_Worker-1] ERROR org.quartz.core.JobRunShell - Job
group1.JobReport threw an unhandled Exception:
java.lang.NullPointerException at
com.changes.bean.ReportsBean.createPdfCriticalChanges(ReportsBean.java:104)
at com.changes.quartz.JobReport.execute(JobReport.java:36) at
org.quartz.core.JobRunShell.run(JobRunShell.java:202) at
org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
13452 [MyScheduler_Worker-1] ERROR org.quartz.core.ErrorLogger - Job
(group1.JobReport threw an exception. org.quartz.SchedulerException:
Job threw an unhandled exception. [See nested exception:
java.lang.NullPointerException] at
org.quartz.core.JobRunShell.run(JobRunShell.java:213) at
org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
Caused by: java.lang.NullPointerException at
com.changes.bean.ReportsBean.createPdfCriticalChanges(ReportsBean.java:104)
at com.changes.quartz.JobReport.execute(JobReport.java:36) at
org.quartz.core.JobRunShell.run(JobRunShell.java:202)
reportsbean
public class JobReport implements Job {
public void execute(JobExecutionContext context) throws JobExecutionException {
//BasicConfigurator.configure();
try {
ReportsBean reportsBean = new ReportsBean();
reportsBean.createPdfCriticalChanges();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy – hh:mm:ss");
System.out.println("Rodou: " + dateFormat.format( new Date() ));
} catch (JRException | SQLException e) {
e.printStackTrace();
}
}
}
quartz.properties
org.quartz.scheduler.instanceName = MyScheduler
org.quartz.threadPool.threadCount = 3
org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
org.quartz.plugin.jobInitializer.class =org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin
org.quartz.plugin.jobInitializer.fileNames = com/changes/quartz/quartz-config.xml
org.quartz.plugin.jobInitializer.failOnFileNotFound = true
web.xml
<!-- Inicio Quartz -->
<servlet>
<servlet-name>QuartzServlet</servlet-name>
<servlet-class>com.changes.quartz.servlet.QuartzServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>QuartzInitializer</servlet-name>
<servlet-class>org.quartz.ee.servlet.QuartzInitializerServlet</servlet-class>
<init-param>
<param-name>config-file</param-name>
<param-value>quartz.properties</param-value>
</init-param>
<init-param>
<param-name>shutdown-on-unload</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>start-scheduler-on-load</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<!-- Fim Quartz -->

The Problem is that you have a NullPointerException in your ReportsBean.
Since the signature of the Quartz execute method is
public void execute(JobExecutionContext context) throws JobExecutionException
Quartz can only deal with JobExecutionException's that will be thrown within this method. But in your case it gets an unexpected NullPointerException.
To solve this Problem you should remove the cause of the NullPointer.
From the sourcecode above I couldnt figure out the cause of this exception since it occurs within your ReportsBean.
Certainly your method ReportsBean.createPdfCriticalChanges trys to access an uninitialized member.

at the line 104:
String report FacesContext.getCurrentInstance().getExternalContext().getRealPath("/web/reports/criticalcr.jrxml");
Remember: it's working out of quartz.
ReportsBean
public void createPdfCriticalChanges() throws JRException,SQLException {
System.out.println("generating report...");
String report = FacesContext.getCurrentInstance().getExternalContext().getRealPath("/web/reports/criticalcr.jrxml");
JasperReport pathjrxml = JasperCompileManager.compileReport(report);
//JasperReport pathjrxml = JasperCompileManager.compileReport("web/reports/criticalcr.jrxml"); //Funciona com o inicia Agenda em XML "web/reports/changetracker_criticalcr.jrxml"
JasperPrint printReport = JasperFillManager.fillReport(pathjrxml, null, conn.getConn());
JasperExportManager.exportReportToPdfFile(printReport, "/web/reports/changetracker_criticalcr.pdf"); //Funciona com o inicia Agenda em XML "web/reports/criticalcr.pdf"
System.out.println("report generated!");
}

it's not throws JobExecutionExceptionnb use #postController and #override method init

I had same issue, I solved by putting time greater than current time in table that stores next_fire_time. then restart the server.

ReportsBean is not able to create an object on this place. If it's a Spring application please use #Autowired annotations to fix this issue:
#Autowired
ReportsBean reportsBean;
Then use call reportsBean.yourMethod();.

I fix this problem by creating a Lookup Utils, job was like this :
public class LimpezaColetaDadosPessoaJob implements Job {
#Override
public void execute(JobExecutionContext context) throws JobExecutionException {
try {
this.executar();
} catch (final BusinessException e) {
} catch (final Exception e) {
e.printStackTrace();
}
}
private void executar() throws NamingException {
final ColetorDadosPessoasIntegracaoService service = LookupUtils
.lookup(ColetorDadosPessoasIntegracaoService.class);
service.executarLimpezaDaTabela();
}
}

Related

custom shiro filter for rest api

I have a old rest filter. Can the following be ported to shiro.ini? Or, is it possible to initialize/configure a filter in shiro.ini and extend it in java with doFilter()? It looks like there are some strange things going on with error handling and a "shiro bug". I'm not looking for someone to write my code, but a hint where to look would be helpful. Thank you.
UPDATE: MyRestFilter class:
#Override
#SneakyThrows(Throwable.class)
public void doFilter(final HttpServletRequest request, final HttpServletResponse response,
HttpSession httpSession, final FilterChain chain) throws ServletException, IOException
{
debugRequest(request);
List<String> sessionIds = Servlets.getRequestQueryStringMap(request).get(SESSION_ID);
String sessionId = sessionIds == null? null : Iterables.getOnlyElement(sessionIds);
String sessionIdHeader = request.getHeader(SESSION_ID_HEADER);
if(sessionId == null)
{
sessionId = sessionIdHeader;
}
ThreadContext.unbindSubject();
ThreadContext.bind(securityManager);
if(sessionId != null)
{
// strip out host / instance ID from the session
sessionId = sessionId.replaceFirst("\\.[\\w_\\-+]+$", "");
Subject subject = new Subject.Builder().sessionId(sessionId).buildSubject();
Session session = subject.getSession(false);
if(session != null)
{
session.touch(); // this should not be necessary, but due to Shiro bug, it is
StatefulUtil.pingStateful(session);
}
if(subject.getPrincipal() == null)
{
response.sendError(HttpStatus.SC_UNAUTHORIZED, "Unauthorized API Call");
}
else
{
try
{
subject.execute(() ->
{
SharedWebstats webStats = Beans.getReference(SharedWebstats.class);
webStats.webStats("mobile");
if (chain != null)
{
chain.doFilter(request, response);
}
return null;
});
}
catch(ExecutionException e)
{
// unwrap Shiro's ExecutionException, interferes
// with global exceptino handling mechanisms
Throwable cause = e.getCause();
if (cause != null)
{
throw cause;
}
else
{
throw e;
}
}
}
}
else
{
chain.doFilter(request, response);
}
ThreadContext.unbindSecurityManager();
}
//MyRestFilter also contains an init() which contains the real problem: how to set a session timeout that applies to the /api/ url only? (note, many of these SecurityManagerFactories are deprecated which is why I have to rewrite this).
#Override
public void init() throws ServletException
{
//securityManager = new WebIniSecurityManagerFactory("classpath:META-INF/shiro.ini").createInstance();
securityManager = WebIniSecurityManagerFactory("classpath:META-INF/shiro.ini").createInstance();
int sessionTimeout = WebXml.INSTANCE.getSessionTimeout();
DefaultSecurityManager dsm = (DefaultSecurityManager)securityManager;
DefaultSessionManager sm = (DefaultSessionManager)dsm.getSessionManager();
sm.setGlobalSessionTimeout(sessionTimeout * 60 * 1000);
realmCache.putAll(securityManager);
ssse.addSessionListeners(sm.getSessionListeners());
}
private org.apache.shiro.mgt.SecurityManager securityManager;
private #Inject RealmCacheHolder realmCache;
private #Inject ShiroSessionScopeExtension ssse;
Here is some configuration. Currently I have:
<filter>
<filter-name>ShiroFilter</filter-name>
<filter-class>com.dependencyfromhell.shiro.ee.filters.ShiroFilter</filter-class>
<async-supported>true</async-supported>
</filter>
<context-param>
<param-name>shiroConfigLocations</param-name>
<param-value>classpath:META-INF/shiro.ini</param-value>
</context-param>
<!-- Security - Enforce Filter Ordering -->
<filter-mapping>
<filter-name>ShiroFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>MyRestFilter</filter-name>
<url-pattern/>
</filter-mapping>
I'd like to have something like this.
# rest support
rest = MyRestFilter
#Rest api
/api/* = MyRestFilter
Could I configure MyRestFilter in shiro.ini for the session timeout, but then have a MyRestFilter class with the doFilter method? Thanks.
Your init() method looks to be the source of your problems.
You basically have two instances of Shiro configured. One from the ShiroFilter in your web.xml and another in your custom filter's init() method.
I'm guessing this was a workaround to inject your RealmCacheHolder and ShiroSessionScopeExtension, but it's unclear how they are used.
You can bootstrap Shiro using an IoC framework. (Shiro has direct support for Guice and Spring), if you are using CDI (or something else), it can still be done, but it would require some custom code (likely similar to what you have).
You would implement a WebEnvironment and set the shiroEnvironmentClass filter context param with its classname.
You might want to hit up the Shiro User list if want to get a little deeper into the WebEnvironment options.

WebSphere 8.5.5.9 with Jersey 2.25

I am deploying web application having jersey 2.25 on WebSphere 8.5.5.9. We are registering resources via below class.
public class ApplicationResourceConfig extends ResourceConfig {
/**
*
*/
public ApplicationResourceConfig() {
packages(verifyAndLoadResources());
}
/**
* #return
*/
private String[] getAllResources() {
List<String> resources = new ArrayList<>();
resources.add("com.ofs.fsapps.commonapps.appPreferences.resource.AppPreferencesResource");
resources.add("com.ofs.fsapps.commonapps.summary.rest.Summary");
return resources.toArray(new String[0]);
}
/**
* #return
*/
private String[] verifyAndLoadResources() {
List<String> packageResourceList = new ArrayList<>();
for (String resource : getAllResources()) {
try {
Class<?> result = Class.forName(resource);
if (result != null) {
register(StringUtils.substringAfterLast(resource, ".") + ".class");
packageResourceList.add(StringUtils.substringBeforeLast(resource, "."));
}
} catch (ClassNotFoundException e) {
System.out.println("Package/Class not Found : "+resource);
}catch(Exception e) {
System.out.println("Exception in loading Package/Class : "+resource);
}
}
return packageResourceList.toArray(new String[0]);
}
}
With above approach, none of the rest calls are working and responding as 404. If we make entry of packages/classes in web.xml then everything is working properly.
<servlet>
<servlet-name>CommonRESTServlet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>com.ofs.fsapps.commonapps.summary.rest.Summary, com.ofs.fsapps.commonapps.appPreferences.resource.AppPreferencesResource</param-value>
</init-param>
</servlet>
Please note that shared library has been created and the same is linked with EAR as well.
Below are exceptions in SystemErr.log.
java.lang.NullPointerException
at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.existsServletForUrlPattern(WSServletContextListener.java:186)
at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.registerWSServlet(WSServletContextListener.java:168)
at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.parseAdaptersAndCreateDelegate(WSServletContextListener.java:132)
at com.sun.xml.ws.transport.http.servlet.WSServletContainerInitializer.onStartup(WSServletContainerInitializer.java:65)
at com.ibm.ws.webcontainer.webapp.WebAppImpl.initializeServletContainerInitializers(WebAppImpl.java:619)
at com.ibm.ws.webcontainer.webapp.WebAppImpl.initialize(WebAppImpl.java:409)
at com.ibm.ws.webcontainer.webapp.WebGroupImpl.addWebApplication(WebGroupImpl.java:88)
at com.ibm.ws.webcontainer.VirtualHostImpl.addWebApplication(VirtualHostImpl.java:170)
at com.ibm.ws.webcontainer.WSWebContainer.addWebApp(WSWebContainer.java:904)
at com.ibm.ws.webcontainer.WSWebContainer.addWebApplication(WSWebContainer.java:789)
at com.ibm.ws.webcontainer.component.WebContainerImpl.install(WebContainerImpl.java:427)
at com.ibm.ws.webcontainer.component.WebContainerImpl.start(WebContainerImpl.java:719)

Camel Restlet and CXF SOA Integration Issue

I am new to Camel and am facing an issue with a route I need to setup. It will be great if someone can either guide me to the correct forum or better still rectify the issue I am facing.
Here is what I need to do - expose a restlet endpoint to accept data; use this data as input to an external SOAP web service and send back the response in JSON format back to the caller...
Here is what I have done...however, I am getting the following error while Camel tries to call the Web Service...can anyone guide me here? Thanks.
I am using camel 2.11.1 and cxf-codegen-plugin version 2.7.11
I am getting the following exception: org.restlet.data.Parameter cannot be cast to java.lang.String.
public class IntegrationTest extends CamelTestSupport {
String restletURL = <url>;
#org.junit.Test
public void integTest() throws Exception {
//trying to simulate the rest service call...
template.sendBodyAndHeader(restletURL, "Body does not matter here", "data", "{\"FromCurrency\":\"AUD\",\"ToCurrency\":\"USD\"}");
}
#Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
#Override
public void configure() throws Exception {
System.out.println("In Counfigure");
String cxfEndpoint = "cxf://http://www.webservicex.net/CurrencyConvertor.asmx?"
+ "wsdlURL=http://www.webservicex.net/CurrencyConvertor.asmx?wsdl&"
+ "serviceName={http://www.webserviceX.NET/}CurrencyConvertor&"
+ "portName={http://www.webserviceX.NET/}CurrencyConvertorSoap&"
+ "dataFormat=MESSAGE";
XmlJsonDataFormat xmlJsonFormat = new XmlJsonDataFormat();
SoapJaxbDataFormat soap = new SoapJaxbDataFormat("net.webservicex", new ServiceInterfaceStrategy(CurrencyConvertorSoap.class, true));
GsonDataFormat gson = new GsonDataFormat(ConversionRate.class);
gson.setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE);
from(restletURL).routeId("Restlet")
.process(new Processor() {
#Override
public void process(Exchange exchange) throws Exception {
String data = (String) URLDecoder.decode((String) exchange.getIn().getHeader("data"), "UTF-8");
System.out.println(data);
// get the mail body as a String
exchange.getIn().setBody(data);
Response.getCurrent().setStatus(Status.SUCCESS_OK);
}
})
.unmarshal(gson)
.marshal(soap)
.log("${body}")
.to(cxfEndpoint)
.unmarshal(soap)
.marshal(xmlJsonFormat);
.log("${body}");
}
};
}
}
However, the sample works when I try out the individual pieces - restlet alone and CXF alone...
Thanks,
Ritwick.
Sure Willem, here is the entire configure implementation:
#Override
public void configure() throws Exception {
String restletURL = "restlet:http://localhost:8080/convert/{data}?restletMethods=get";
String cxfEndpoint = "cxf://http://www.webservicex.net/CurrencyConvertor.asmx?"
+ "portName={http://www.webserviceX.NET/}CurrencyConvertorSoap&"
+ "dataFormat=MESSAGE&loggingFeatureEnabled=true&defaultOperationName=ConversionRate&defaultOperationNamespace={http://www.webserviceX.NET/}&synchronous=true";
SoapJaxbDataFormat soap = new SoapJaxbDataFormat("net.webservicex", new ServiceInterfaceStrategy(CurrencyConvertorSoap.class, true));
soap.setVersion("1.2");
GsonDataFormat gson = new GsonDataFormat(ConversionRate.class);
gson.setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE);
from(restletURL).routeId("Restlet")
.process(new Processor() {
#Override
public void process(Exchange exchange) throws Exception {
String data = (String) URLDecoder.decode((String) exchange.getIn().getHeader("data"), "UTF-8");
exchange.getIn().setHeader("org.restlet.http.headers", "");
exchange.getIn().setHeader("data", "");
exchange.getIn().setBody(data);
Response.getCurrent().setStatus(Status.SUCCESS_OK);
}
})
.unmarshal(gson)
.marshal(soap)
.to(cxfEndpoint)
.unmarshal(soap)
.marshal(gson)
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
String output = exchange.getIn().getBody(String.class);
exchange.getOut().setBody(output);
}
});
}
The issue I was facing has been resolved. In addition to "exchange.getIn().setBody(data);", I added the following line of code "exchange.getIn().setHeader("org.restlet.http.headers", "");" in order to get rid of the class cast exception I was getting. The restlet headers were causing this issue and once these headers were removed (I didn't need the headers in the first place), everything worked as expected.
Thanks,
Ritwick.

Provider<HttpSession> not getting injected

I am using gwt dispatch to communicate and get data from server to client.
In order to get user specific data I want to store the user object in httpsession and access application specific data from servlet context
but when I inject Provider<HttpSession> when the handler execute is called but the dispatchservlet the provider is null i.e it does not get injected.
following is the code from my action handler
#Inject
Provider<HttpSession> provider;
public ReadEntityHandler() {
}
#Override
public EntityResult execute(ReadEntityAction arg0, ExecutionContext arg1) throws DispatchException {
HttpSession session = null;
if (provider == null)
System.out.println("httpSession is null..");
else {
session = provider.get();
System.out.println("httpSession not null..");
}
System.out.println("reached execution");
return null;
}
and my Dispatch servlet
#Singleton
public class ActionDispatchServlet extends RemoteServiceServlet implements StandardDispatchService {
private Dispatch dispatch;
private Dispatch dispatch;
#Inject ReadEntityHandler readEntityHandler;
public ActionDispatchServlet() {
InstanceActionHandlerRegistry registry = new DefaultActionHandlerRegistry();
registry.addHandler(readEntityHandler);
dispatch = new SimpleDispatch(registry);
}
#Override
public Result execute(Action<?> action) throws DispatchException {
try {
return dispatch.execute(action);
}
catch (RuntimeException e) {
log("Exception while executing " + action.getClass().getName() + ": " + e.getMessage(), e);
throw e;
}
}
}
when I try to inject the ReadEntityHandler it throws the following exception
[WARN] failed guiceFilter
com.google.inject.ProvisionException: Guice provision errors:
1) Error injecting constructor, java.lang.NullPointerException
at com.ensarm.wikirealty.server.service.ActionDispatchServlet.<init>(ActionDispatchServlet.java:22)
at com.ensarm.wikirealty.server.service.ActionDispatchServlet.class(ActionDispatchServlet.java:22)
while locating com.ensarm.wikirealty.server.service.ActionDispatchServlet
1 error
at com.google.inject.internal.InjectorImpl$4.get(InjectorImpl.java:834)
at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:856)
at com.google.inject.servlet.ServletDefinition.init(ServletDefinition.java:74)
at com.google.inject.servlet.ManagedServletPipeline.init(ManagedServletPipeline.java:84)
at com.google.inject.servlet.ManagedFilterPipeline.initPipeline(ManagedFilterPipeline.java:106)
at com.google.inject.servlet.GuiceFilter.init(GuiceFilter.java:168)
at org.mortbay.jetty.servlet.FilterHolder.doStart(FilterHolder.java:97)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:593)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:513)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
at com.google.gwt.dev.shell.jetty.JettyLauncher$WebAppContextWithReload.doStart(JettyLauncher.java:468)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.handler.RequestLogHandler.doStart(RequestLogHandler.java:115)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.Server.doStart(Server.java:222)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at com.google.gwt.dev.shell.jetty.JettyLauncher.start(JettyLauncher.java:672)
at com.google.gwt.dev.DevMode.doStartUpServer(DevMode.java:509)
at com.google.gwt.dev.DevModeBase.startUp(DevModeBase.java:1068)
at com.google.gwt.dev.DevModeBase.run(DevModeBase.java:811)
at com.google.gwt.dev.DevMode.main(DevMode.java:311)
Caused by: java.lang.NullPointerException
at net.customware.gwt.dispatch.server.DefaultActionHandlerRegistry.addHandler(DefaultActionHandlerRegistry.java:21)
at com.ensarm.wikirealty.server.service.ActionDispatchServlet.<init>(ActionDispatchServlet.java:24)
at com.ensarm.wikirealty.server.service.ActionDispatchServlet$$FastClassByGuice$$e0a28a5d.newInstance(<generated>)
at com.google.inject.internal.cglib.reflect.FastConstructor.newInstance(FastConstructor.java:40)
at com.google.inject.internal.DefaultConstructionProxyFactory$1.newInstance(DefaultConstructionProxyFactory.java:58)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:84)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:200)
at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:43)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:878)
at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
at com.google.inject.Scopes$1$1.get(Scopes.java:64)
at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:40)
at com.google.inject.internal.InjectorImpl$4$1.call(InjectorImpl.java:825)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:871)
at com.google.inject.internal.InjectorImpl$4.get(InjectorImpl.java:821)
... 25 more
You create instance of ReadEntityHandler registry.addHandler(new ReadEntityHandler()); himself not by container.Provider<HttpSession> provider; is null
Try:
#Inject
public ActionDispatchServlet(ReadEntityHandler handler) {
InstanceActionHandlerRegistry registry = new DefaultActionHandlerRegistry();
registry.addHandler(handler);
dispatch = new SimpleDispatch(registry);
}
Caused by: java.lang.NullPointerException
at net.customware.gwt.dispatch.server.DefaultActionHandlerRegistry.addHandler(DefaultActionHandlerRegistry.java:21)
Is it possible that DefaultActionHandlerRegistry has a bug in it at line 21, and that the error is happening there? I don't see the code for that class, so it isn't clear if this is the cause of your issue, or just a symptom.

Quartz scheduler in not running in war

I am using quartz scheduler in gwt web application.My application structure is like below.
I have two project.One is gwt web application client project(for ui part) & other is java project for server side call.(for database interaction).In client project I put a server project for reference.While running I create a war from client and add a jar of server project to war folder.
Now I used scheduler at server side for some task to auto complete.While running it locally (with out war) scheduler working properly.
But while running war at jboss server scheduler is not running.
My all scheduler related code and Quartz.jar is at server side.There is no any reference of Quartz in client side project.is this the problem???
Here is my code for scheduler
public class QuartzJob implements Job {
public void execute(JobExecutionContext jobExecutionContext)
throws JobExecutionException {
JobDataMap map = jobExecutionContext.getJobDetail().getJobDataMap();
ActivityTransactionSettingsMap map2 = (ActivityTransactionSettingsMap) map
.get("task");
if (map2.getAutoCompleteDate() != null) {
WorkFlowFacade facade = new WorkFlowFacade();
facade.completeAutoCompleteTask(map2);
Scheduler scheduler=(Scheduler) map.get("scheduler");
try {
scheduler.shutdown();
} catch (SchedulerException e) {
e.printStackTrace();
}
}
}
}
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
scheduler.start();
JobDataMap map2 = new JobDataMap();
map2.put("task", actsMap);
map2.put("scheduler", scheduler);
JobDetail job = newJob(QuartzJob.class).withIdentity("job"+String.valueOf(actsMap.getId()))
.usingJobData(map2).build();
Trigger trigger = newTrigger().withIdentity("trigger"+String.valueOf(actsMap.getId()))
.startAt(actsMap.getAutoCompleteDate()).build();
scheduler.scheduleJob(job, trigger);
Or do I need to shift my scheduler related project at client side only??
I am not getting how to solve this.
Please help me out
For the scheduler to run , there should be something to kick start it . I am not sure how the process is happening but you could write this scheduler in a servlet
public class MySchedulerServlet extends GenericServlet {
private static final long serialVersionUID = 1477091380142883153L;
/**
* Constant to represent property for the cron expression.
*/
private static final String CRON_EXPRESSION = "0 0 0 ? * SUN";
public void init(ServletConfig servletConfig) throws ServletException {
super.init(servletConfig);
// The Quartz Scheduler
Scheduler scheduler = null;
try {
// Initiate a Schedule Factory
SchedulerFactory schedulerFactory = new StdSchedulerFactory();
// Retrieve a scheduler from schedule factory
scheduler = schedulerFactory.getScheduler();
// Initiate JobDetail with job name, job group and
// executable job class
JobDetail jobDetail = new JobDetail("RetryJob", "RetryGroup", QuartzJob.class);
// Initiate CronTrigger with its name and group name
CronTrigger cronTrigger = new CronTrigger("cronTrigger",
"triggerGroup");
// setup CronExpression
CronExpression cexp = new CronExpression(CRON_EXPRESSION);
// Assign the CronExpression to CronTrigger
cronTrigger.setCronExpression(cexp);
// schedule a job with JobDetail and Trigger
scheduler.scheduleJob(jobDetail, cronTrigger);
// start the scheduler
scheduler.start();
} catch (Exception e) {
e.printStackTrace();
}
}
public void service(ServletRequest serveletRequest,
ServletResponse servletResponse) throws ServletException, IOException {
}
}
and in your web.xml load sceduler on startup. This works for me.
<servlet>
<servlet-name>QuartzInitializer</servlet-name>
<servlet-class>org.quartz.ee.servlet.QuartzInitializerServlet</servlet-class>
<init-param>
<param-name>shutdown-on-unload</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>start-scheduler-on-load</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-name>MySchedulerServlet </servlet-name>
<servlet-class>com.servlet.MySchedulerServlet </servlet-class>
<load-on-startup>2</load-on-startup>
I used thread in this case.
public class AutoCompleteTaskThread extends Thread {
private ActivityTransactionSettingsMap taskMap;
public AutoCompleteTaskThread(ActivityTransactionSettingsMap map) {
this.taskMap = map;
}
#Override
public void run() {
try {
new AutoCompleteTaskScheduler().ScheduleJob(taskMap);
} catch (Exception e) {
e.printStackTrace();
}
}
}
As below and in local machine it is working fine.but for jboss server it is not working.
I used an instance of AutoCompleteTaskThread class and called start method on this.
private void addAutoCompleteTask(ActivityTransactionSettingsMap newTask) {
AutoCompleteTaskThread thread = new AutoCompleteTaskThread(newTask);
thread.start();
}
Here for I started a thread for any new task for which I want to start new thread.