mirror of
https://github.com/Rogiel/httpchannel
synced 2025-12-06 07:32:50 +00:00
Implements several services and improves API
This commit is contained in:
24
httpchannel-capcha/httpchannel-captcha-recaptcha/pom.xml
Normal file
24
httpchannel-capcha/httpchannel-captcha-recaptcha/pom.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<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>
|
||||
<artifactId>httpchannel-capcha</artifactId>
|
||||
<groupId>com.rogiel.httpchannel</groupId>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<artifactId>httpchannel-captcha-recaptcha</artifactId>
|
||||
<name>HttpChannel/CaptchaService/ReCaptcha</name>
|
||||
<description>This module provides captcha resolving for Google ReCaptcha</description>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.rogiel.httpchannel</groupId>
|
||||
<artifactId>httpchannel-api</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.rogiel.httpchannel</groupId>
|
||||
<artifactId>httpchannel-util</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.rogiel.httpchannel.captcha.impl;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import com.rogiel.httpchannel.captcha.AbstractImageCaptcha;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*
|
||||
*/
|
||||
public class ReCaptcha extends AbstractImageCaptcha {
|
||||
public ReCaptcha(URL url, String ID) {
|
||||
super(url, ID);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.rogiel.httpchannel.captcha.impl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.rogiel.httpchannel.captcha.AbstractImageCaptchaService;
|
||||
import com.rogiel.httpchannel.util.PatternUtils;
|
||||
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*
|
||||
*/
|
||||
public class ReCaptchaService extends AbstractImageCaptchaService<ReCaptcha> {
|
||||
// http://www.google.com/recaptcha/api/noscript?k=6LdRTL8SAAAAAE9UOdWZ4d0Ky-aeA7XfSqyWDM2m
|
||||
private static final Pattern CAPTCHA_URL_PATTERN = Pattern
|
||||
.compile("http://www\\.google\\.com/recaptcha/api/challenge\\?k=([0-9A-z|\\-]*)(&(.*))?");
|
||||
private static final Pattern CAPTCHA_IMAGE_PATTERN = Pattern
|
||||
.compile("challenge : '(.*)'");
|
||||
private static final String BASE_URL = "http://www.google.com/recaptcha/api/image?c=";
|
||||
|
||||
@Override
|
||||
public ReCaptcha create(HTMLPage page) throws IOException {
|
||||
final String url = page.findScriptSrc(CAPTCHA_URL_PATTERN);
|
||||
|
||||
if (url == null)
|
||||
return null;
|
||||
final String captchaPage = get(url).asString();
|
||||
|
||||
final String id = PatternUtils.find(CAPTCHA_IMAGE_PATTERN, captchaPage,
|
||||
1);
|
||||
return new ReCaptcha(new URL(BASE_URL + id), id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean resolve(ReCaptcha captcha) {
|
||||
// not supported!
|
||||
return false;
|
||||
}
|
||||
}
|
||||
16
httpchannel-capcha/pom.xml
Normal file
16
httpchannel-capcha/pom.xml
Normal file
@@ -0,0 +1,16 @@
|
||||
<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>
|
||||
<artifactId>httpchannel</artifactId>
|
||||
<groupId>com.rogiel.httpchannel</groupId>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<artifactId>httpchannel-capcha</artifactId>
|
||||
<name>HttpChannel/CaptchaService</name>
|
||||
<description>This module provides implementations for captcha resolving</description>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>httpchannel-captcha-recaptcha</module>
|
||||
</modules>
|
||||
</project>
|
||||
Reference in New Issue
Block a user