Skip to content
This repository has been archived by the owner on Jun 2, 2019. It is now read-only.

Commit

Permalink
crawler: add mapper on msg
Browse files Browse the repository at this point in the history
  • Loading branch information
T4ze committed Dec 9, 2017
1 parent ce90057 commit 86ce8aa
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/main/java/com/epita/guereza/CrawlerApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.epita.domain.Crawler;
import com.epita.domain.RawDocument;
import com.epita.eventbus.EventBusClient;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -40,9 +41,16 @@ private void storeUrls(final String[] urls) {
public void run() {
eventBus.subscribe(subscribeUrl, msg -> {
if (msg != null) {
LOGGER.info("Receive url: {}", msg.getContent());
final String[] urls = crawlAndExtract(msg.getContent());
storeUrls(urls);
try {
Class c = ClassLoader.getSystemClassLoader().loadClass(msg.getMessageType());
String url = (String)new ObjectMapper().readValue(msg.getContent(), c);
LOGGER.info("Receive url: {}", url);
final String[] urls = crawlAndExtract(url);
storeUrls(urls);
} catch (Exception e) {
e.printStackTrace();
}


requestNextUrl();
} else {
Expand Down

0 comments on commit 86ce8aa

Please sign in to comment.