Created
March 12, 2015 20:34
-
-
Save cfalzone/7708287544cadc0b6598 to your computer and use it in GitHub Desktop.
Example quartz job hitting a servlet for OSGI in dotCMS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.aquent.jobs; | |
import java.io.InputStream; | |
import java.net.URL; | |
import java.net.URLConnection; | |
import org.quartz.Job; | |
import org.quartz.JobDataMap; | |
import org.quartz.JobExecutionContext; | |
import org.quartz.JobExecutionException; | |
import com.dotmarketing.util.Logger; | |
import com.dotmarketing.util.UtilMethods; | |
public class CWImporterJob implements Job { | |
@Override | |
public void execute(JobExecutionContext ctx) throws JobExecutionException { | |
Logger.info(this, "===================================================="); | |
Logger.info(this, "CW Importer Job Starting"); | |
JobDataMap params = ctx.getJobDetail().getJobDataMap(); | |
int hours = (Integer) params.get("calhours"); | |
boolean importLines = (Boolean) ctx.getJobDetail().getJobDataMap().get("importLines"); | |
Logger.info(this, "Job started with calhours="+hours+" and importLines="+importLines); | |
try { | |
URL url = new URL("http://localhost:8080/app/cwImporter?calhours="+hours+"&importLines="+importLines); | |
URLConnection connection = url.openConnection(); | |
connection.setRequestProperty("Accept-Charset", "UTF-8"); | |
InputStream response = connection.getInputStream(); | |
if(UtilMethods.isSet(response)) { | |
Logger.info(this, "Received response from servlet"); | |
} else { | |
Logger.error(this, "No response from servlet"); | |
} | |
} catch(Exception e) { | |
Logger.error(this, "Exception hitting the servlet", e); | |
} | |
Logger.info(this, "CW Importer Job Finished"); | |
Logger.info(this, "===================================================="); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment