-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Decouple the crawler service for use in other frameworks #740
Open
BenDol
wants to merge
11
commits into
ArcBees:master
Choose a base branch
from
BenDol:bd_crawler
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9cc4bf2
Decouple the crawler service for use in other frameworks.
BenDol e12fddf
Move these out of guice package.
BenDol 76eccca
Move AbstractCrawlServiceServlet to gwtp-crawler module.
BenDol 2b2a661
Checkstyle fix
BenDol fb9846f
Decouple more crawler logic & started Spring implementation.
BenDol 1a40592
Add DefaultCrawlCacheService and clean up.
BenDol 4741aab
Fix checkstyle issues.
BenDol fd48298
Working Spring crawler support (filter and service base support).
BenDol 31260a5
Fix license dates and some javadoc.
BenDol 28a74a8
AbstractCrawlServiceModule should extend AbstractCrawlerModule.
BenDol a7bcce9
Add previous ServiceKey class with deprecation.
BenDol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>com.gwtplatform</groupId> | ||
<artifactId>gwtp-core</artifactId> | ||
<version>1.6-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>gwtp-crawler-guice</artifactId> | ||
<name>GWTP Crawler for Guice</name> | ||
|
||
<build> | ||
<resources> | ||
<!-- Bundle sources with the jar, so they are visible to GWT's compiler --> | ||
<resource> | ||
<directory>src/main/java</directory> | ||
<includes> | ||
<include>**/*.java</include> | ||
</includes> | ||
</resource> | ||
<!-- Bundle module descriptor with the jar, so it is visible to GWT's compiler --> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
<includes> | ||
<include>**/*.gwt.xml</include> | ||
</includes> | ||
</resource> | ||
</resources> | ||
</build> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>gwtp-crawler</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>servlet-api</artifactId> | ||
</dependency> | ||
|
||
<!-- DI dependencies --> | ||
<dependency> | ||
<groupId>com.google.inject</groupId> | ||
<artifactId>guice</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
This file contains 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
This file contains 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
40 changes: 40 additions & 0 deletions
40
...ler-guice/src/main/java/com/gwtplatform/crawler/server/guice/filter/GuiceCrawlFilter.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright 2015 ArcBees Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package com.gwtplatform.crawler.server.guice.filter; | ||
|
||
import java.util.logging.Logger; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
|
||
import com.gwtplatform.crawler.server.CrawlFilter; | ||
import com.gwtplatform.crawler.server.guice.ServiceKey; | ||
|
||
/** | ||
* Guice implementation for the {@link CrawlFilter}. | ||
* @author Ben Dol | ||
*/ | ||
@Singleton | ||
public final class GuiceCrawlFilter extends CrawlFilter { | ||
|
||
@Inject | ||
GuiceCrawlFilter(@ServiceUrl String serviceUrl, | ||
@ServiceKey String key, | ||
Logger log) { | ||
super(serviceUrl, key, log); | ||
} | ||
} |
This file contains 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
This file contains 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
72 changes: 72 additions & 0 deletions
72
...guice/src/main/java/com/gwtplatform/crawler/server/guice/service/CrawlServiceServlet.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2015 ArcBees Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package com.gwtplatform.crawler.server.guice.service; | ||
|
||
import java.util.logging.Logger; | ||
|
||
import javax.inject.Provider; | ||
import javax.inject.Singleton; | ||
|
||
import com.gargoylesoftware.htmlunit.WebClient; | ||
import com.google.inject.Inject; | ||
import com.gwtplatform.crawler.server.AbstractCrawlServiceServlet; | ||
import com.gwtplatform.crawler.server.CrawlCacheService; | ||
import com.gwtplatform.crawler.server.guice.ServiceKey; | ||
|
||
/** | ||
* Guice Crawl Service Servlet. | ||
* @author Ben Dol | ||
*/ | ||
@Singleton | ||
public class CrawlServiceServlet extends AbstractCrawlServiceServlet { | ||
|
||
@Inject(optional = true) | ||
@HtmlUnitTimeoutMillis | ||
private long timeoutMillis = 5000; | ||
|
||
@Inject(optional = true) | ||
@CachedPageTimeoutSec | ||
private long cachedPageTimeoutSec = 15 * 60; | ||
|
||
private final Provider<WebClient> webClientProvider; | ||
|
||
@Inject | ||
protected CrawlServiceServlet( | ||
Provider<WebClient> webClientProvider, | ||
Logger log, | ||
CrawlCacheService crawlCacheService, | ||
@ServiceKey String key) { | ||
super(log, key, crawlCacheService); | ||
|
||
this.webClientProvider = webClientProvider; | ||
} | ||
|
||
@Override | ||
protected WebClient getWebClient() { | ||
return webClientProvider.get(); | ||
} | ||
|
||
@Override | ||
public long getCachedPageTimeoutSec() { | ||
return cachedPageTimeoutSec; | ||
} | ||
|
||
@Override | ||
public long getTimeoutMillis() { | ||
return timeoutMillis; | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>com.gwtplatform</groupId> | ||
<artifactId>gwtp-core</artifactId> | ||
<version>1.6-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>gwtp-crawler-spring</artifactId> | ||
<name>GWTP Crawler for Spring</name> | ||
|
||
<build> | ||
<resources> | ||
<!-- Bundle sources with the jar, so they are visible to GWT's compiler --> | ||
<resource> | ||
<directory>src/main/java</directory> | ||
<includes> | ||
<include>**/*.java</include> | ||
</includes> | ||
</resource> | ||
<!-- Bundle module descriptor with the jar, so it is visible to GWT's compiler --> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
<includes> | ||
<include>**/*.gwt.xml</include> | ||
</includes> | ||
</resource> | ||
</resources> | ||
</build> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>gwtp-crawler</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>servlet-api</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-core</artifactId> | ||
<version>${spring.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-context</artifactId> | ||
<version>${spring.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-beans</artifactId> | ||
<version>${spring.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-web</artifactId> | ||
<version>${spring.version}</version> | ||
</dependency> | ||
|
||
<!-- Test dependencies --> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-test</artifactId> | ||
<version>${spring.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
35 changes: 35 additions & 0 deletions
35
...ler-spring/src/main/java/com/gwtplatform/crawler/server/spring/AbstractCrawlerModule.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2015 ArcBees Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package com.gwtplatform.crawler.server.spring; | ||
|
||
import java.util.logging.Logger; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
|
||
/** | ||
* Abstract crawler module for {@link @Configuration} setup. | ||
* @author Ben Dol | ||
*/ | ||
public abstract class AbstractCrawlerModule { | ||
@Bean | ||
protected Logger crawlLogger() { | ||
return Logger.getAnonymousLogger(); | ||
} | ||
|
||
@Bean | ||
protected abstract String crawlKey(); | ||
} |
35 changes: 35 additions & 0 deletions
35
...src/main/java/com/gwtplatform/crawler/server/spring/filter/AbstractCrawlFilterModule.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2015 ArcBees Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package com.gwtplatform.crawler.server.spring.filter; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.ComponentScan; | ||
|
||
import com.gwtplatform.crawler.server.spring.AbstractCrawlerModule; | ||
|
||
/** | ||
* Abstract crawl filter module for {@link @Configuration} setup. | ||
* @author Ben Dol | ||
*/ | ||
@ComponentScan(basePackages = { | ||
"com.gwtplatform.crawler.server.spring.filter" | ||
}) | ||
public abstract class AbstractCrawlFilterModule extends AbstractCrawlerModule { | ||
|
||
@Bean | ||
protected abstract String serviceUrl(); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a breaking change. We should either use inheritance or duplicate it and support classes from both the new and old packages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it really matter if its a breaking change in this case? Since its a simple import change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if I just added a
@Deprecated
and directed them to the new ServiceKey annotation? Rather than bloat the code with unnecessary legacy support.