package de.jeha.kame.crawler.scheduler.services;

import de.jeha.kame.crawler.scheduler.model.CrawlJob;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author jenshadlich@googlemail.com
 */
public class QuartzCrawlJob implements Job {

    private static final Logger LOG = LoggerFactory.getLogger(QuartzCrawlJob.class);

    public static final String CRAWL_JOB = "CRAWL_JOB";

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        CrawlJob crawlJob = (CrawlJob) context.getJobDetail().getJobDataMap().get(CRAWL_JOB);
        LOG.info("{}", crawlJob);
    }

}

@@ -54,53 +54,475 @@
 ort 
-de.jeha.kame.crawler.scheduler.model.CrawlJob
+com.fasterxml.jackson.annotation.JsonProperty;%0Aimport com.fasterxml.jackson.databind.ObjectMapper;%0Aimport de.jeha.kame.crawler.core.http.ContentType;%0Aimport de.jeha.kame.crawler.core.http.Headers;%0Aimport de.jeha.kame.crawler.scheduler.model.CrawlJob;%0Aimport org.apache.http.HttpResponse;%0Aimport org.apache.http.client.methods.HttpPost;%0Aimport org.apache.http.entity.StringEntity;%0Aimport org.apache.http.impl.client.HttpClients;%0Aimport org.apache.http.util.EntityUtils
 ;%0Aim
@@ -680,16 +680,45 @@
 ctory;%0A%0A
+import java.io.IOException;%0A%0A
 /**%0A * @
@@ -1136,16 +1136,16 @@
 L_JOB);%0A
-
         
@@ -1170,16 +1170,964 @@
 wlJob);%0A
+%0A        ObjectMapper objectMapper = new ObjectMapper();%0A        CrawlRequest request = new CrawlRequest(crawlJob.getSeedUrl());%0A%0A        HttpPost httpPost = new HttpPost(%22http://localhost:8080/crawl%22);%0A        httpPost.setHeader(Headers.CONTENT_TYPE, ContentType.APPLICATION_JSON.getValue());%0A%0A        try %7B%0A            httpPost.setEntity(new StringEntity(objectMapper.writeValueAsString(request), %22UTF-8%22));%0A            HttpResponse response = HttpClients.createDefault().execute(httpPost);%0A%0A            String responseJson = EntityUtils.toString(response.getEntity());%0A            LOG.info(%22%7B%7D%22, responseJson);%0A%0A        %7D catch (IOException e) %7B%0A            throw new JobExecutionException(e);%0A        %7D%0A%0A    %7D%0A%0A    public class CrawlRequest %7B%0A%0A        @JsonProperty%0A        private String url;%0A%0A        public CrawlRequest(String url) %7B%0A            this.url = url;%0A        %7D%0A%0A        public String getUrl() %7B%0A            return url;%0A        %7D%0A%0A
     %7D%0A%0A%7D

call crawler service (wip hack)