-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1,838 changed files
with
253,825 additions
and
0 deletions.
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 @@ | ||
.idea |
Large diffs are not rendered by default.
Oops, something went wrong.
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,22 @@ | ||
### An example of proxy-server. | ||
|
||
The application allows to create a local proxy server for local debugging of web applications. | ||
|
||
### Requirements | ||
Installation of the Java 6 or higher. | ||
|
||
### Build and run | ||
|
||
```bash | ||
mvn -f ./pom.xml -Dproxy.target=https://target.com -Denv.src.path=C:/sources/project -Denv.proxy.port=8090 -Dproxy.pattern=/api* -Dproxy.debug=true clean install | ||
``` | ||
|
||
### Features | ||
|
||
Ability to specify: | ||
+ debug mode (-Dproxy.debug) | ||
+ REST-pattern (-Dproxy.pattern) | ||
+ local server port (-Denv.proxy.port) | ||
+ remote server (-Dproxy.target) | ||
+ local web sources directory (-Denv.src.path) | ||
|
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,202 @@ | ||
<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/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>poterenko.com</groupId> | ||
<artifactId>app.proxy</artifactId> | ||
<packaging>war</packaging> | ||
<version>1.0</version> | ||
<name>An example of proxy-server</name> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<src.version>1.7</src.version> | ||
<webapp.dir>${env.src.path}</webapp.dir> | ||
<proxy.port>${env.proxy.port}</proxy.port> | ||
<artifact.name>app-proxy</artifact.name> | ||
<javax.servlet.api.version>3.0.1</javax.servlet.api.version> | ||
<guice.version>3.0</guice.version> | ||
<maven.compiler.plugin.version>3.3</maven.compiler.plugin.version> | ||
<maven.jetty.plugin.version>6.1.26</maven.jetty.plugin.version> | ||
<commons.io.version>1.3.2</commons.io.version> | ||
<google.http.client.version>1.20.0</google.http.client.version> | ||
<slf4j.api.version>1.6.2</slf4j.api.version> | ||
<slf4j.simple.version>1.7.9</slf4j.simple.version> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<!--Servlets--> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>javax.servlet-api</artifactId> | ||
<version>${javax.servlet.api.version}</version> | ||
</dependency> | ||
<!--Jetty--> | ||
<dependency> | ||
<groupId>org.mortbay.jetty</groupId> | ||
<artifactId>maven-jetty-plugin</artifactId> | ||
<version>${maven.jetty.plugin.version}</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-nop</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-jdk14</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<!--Apache--> | ||
<dependency> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>${maven.compiler.plugin.version}</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-nop</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-jdk14</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-io</artifactId> | ||
<version>${commons.io.version}</version> | ||
</dependency> | ||
<!--Http--> | ||
<dependency> | ||
<groupId>com.google.http-client</groupId> | ||
<artifactId>google-http-client</artifactId> | ||
<version>${google.http.client.version}</version> | ||
</dependency> | ||
<!--Log--> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>${slf4j.api.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-simple</artifactId> | ||
<version>${slf4j.simple.version}</version> | ||
</dependency> | ||
<!--IoC--> | ||
<dependency> | ||
<groupId>com.google.inject</groupId> | ||
<artifactId>guice</artifactId> | ||
<version>${guice.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.inject.extensions</groupId> | ||
<artifactId>guice-servlet</artifactId> | ||
<version>${guice.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<!--Servlets--> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>javax.servlet-api</artifactId> | ||
</dependency> | ||
<!--Jetty--> | ||
<dependency> | ||
<groupId>org.mortbay.jetty</groupId> | ||
<artifactId>maven-jetty-plugin</artifactId> | ||
</dependency> | ||
<!--Apache--> | ||
<dependency> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-io</artifactId> | ||
</dependency> | ||
<!--Http--> | ||
<dependency> | ||
<groupId>com.google.http-client</groupId> | ||
<artifactId>google-http-client</artifactId> | ||
</dependency> | ||
<!--Log--> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-simple</artifactId> | ||
</dependency> | ||
<!--IoC--> | ||
<dependency> | ||
<groupId>com.google.inject</groupId> | ||
<artifactId>guice</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.inject.extensions</groupId> | ||
<artifactId>guice-servlet</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<finalName>${artifact.name}</finalName> | ||
<sourceDirectory>src/main/java</sourceDirectory> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>${maven.compiler.plugin.version}</version> | ||
<configuration> | ||
<source>${src.version}</source> | ||
<target>${src.version}</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.mortbay.jetty</groupId> | ||
<artifactId>maven-jetty-plugin</artifactId> | ||
<version>${maven.jetty.plugin.version}</version> | ||
<configuration> | ||
<webAppConfig> | ||
<defaultsDescriptor>${basedir}/src/main/resources/webdefault.xml</defaultsDescriptor> | ||
<contextPath>/</contextPath> | ||
<baseResource implementation="org.mortbay.resource.ResourceCollection"> | ||
<resourcesAsCSV>${webapp.dir}</resourcesAsCSV> | ||
</baseResource> | ||
</webAppConfig> | ||
<connectors> | ||
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector"> | ||
<port>${proxy.port}</port> | ||
</connector> | ||
</connectors> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>install-jetty</id> | ||
<phase>install</phase> | ||
<goals> | ||
<goal>run</goal> | ||
</goals> | ||
<configuration> | ||
<daemon>false</daemon> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
10 changes: 10 additions & 0 deletions
10
coding-style/java/app-proxy/src/main/java/com/poterenko/proxy/ProxyConstants.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,10 @@ | ||
package com.poterenko.proxy; | ||
|
||
public final class ProxyConstants { | ||
|
||
public static final String PROXY_TARGET = "proxy.target"; | ||
public static final String PROXY_PATTERN = "proxy.pattern"; | ||
public static final String PROXY_DEBUG = "proxy.debug"; | ||
public static final String QUERY_SEPARATOR = "?"; | ||
public static final String DEBUG_COOKIE_NAME = "debug"; | ||
} |
53 changes: 53 additions & 0 deletions
53
coding-style/java/app-proxy/src/main/java/com/poterenko/proxy/ProxyModule.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,53 @@ | ||
package com.poterenko.proxy; | ||
|
||
import com.google.api.client.http.HttpRequest; | ||
import com.google.api.client.http.HttpRequestFactory; | ||
import com.google.api.client.http.HttpTransport; | ||
import com.google.api.client.http.javanet.NetHttpTransport; | ||
import com.google.common.base.Function; | ||
|
||
import com.google.inject.Provides; | ||
import com.google.inject.TypeLiteral; | ||
import com.google.inject.servlet.ServletModule; | ||
import com.poterenko.proxy.cookie.CookieChecker; | ||
import com.poterenko.proxy.cookie.impl.CookieCheckerImpl; | ||
import com.poterenko.proxy.cookie.impl.ToCookieNameFunction; | ||
import com.poterenko.proxy.request.ProxyRequestProvider; | ||
import com.poterenko.proxy.servlets.ProxyApiFilter; | ||
import com.poterenko.proxy.servlets.ProxyCookieFilter; | ||
|
||
import static java.lang.System.getProperty; | ||
import static org.apache.maven.shared.utils.StringUtils.isEmpty; | ||
|
||
import javax.inject.Named; | ||
import javax.inject.Singleton; | ||
import javax.servlet.http.Cookie; | ||
|
||
public class ProxyModule extends ServletModule { | ||
|
||
@Override | ||
protected void configureServlets() { | ||
if (!isEmpty(getProperty(ProxyConstants.PROXY_DEBUG))) { | ||
filter("*").through(ProxyCookieFilter.class); | ||
} | ||
filter(getProperty(ProxyConstants.PROXY_PATTERN)).through(ProxyApiFilter.class); | ||
|
||
bind(HttpRequest.class).toProvider(ProxyRequestProvider.class); | ||
bind(HttpTransport.class).toInstance(new NetHttpTransport.Builder().build()); | ||
bind(CookieChecker.class).to(CookieCheckerImpl.class).asEagerSingleton(); | ||
bind(new TypeLiteral<Function<Cookie, String>>() {}).to(ToCookieNameFunction.class); | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
@Named(ProxyConstants.PROXY_TARGET) | ||
protected String getHost() { | ||
return getProperty(ProxyConstants.PROXY_TARGET); | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
protected HttpRequestFactory getHttpRequestFactory(HttpTransport transport) { | ||
return transport.createRequestFactory(); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
coding-style/java/app-proxy/src/main/java/com/poterenko/proxy/cookie/CookieChecker.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,6 @@ | ||
package com.poterenko.proxy.cookie; | ||
|
||
public interface CookieChecker { | ||
|
||
boolean hasCookie(String name); | ||
} |
29 changes: 29 additions & 0 deletions
29
...style/java/app-proxy/src/main/java/com/poterenko/proxy/cookie/impl/CookieCheckerImpl.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,29 @@ | ||
package com.poterenko.proxy.cookie.impl; | ||
|
||
import com.google.common.base.Function; | ||
import com.poterenko.proxy.cookie.CookieChecker; | ||
|
||
import javax.annotation.Nullable; | ||
import javax.inject.Inject; | ||
import javax.inject.Provider; | ||
import javax.servlet.http.Cookie; | ||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import static com.google.common.collect.Collections2.transform; | ||
import static java.util.Arrays.asList; | ||
|
||
public class CookieCheckerImpl implements CookieChecker { | ||
|
||
@Inject | ||
private Provider<HttpServletRequest> servletRequestProvider; | ||
@Inject | ||
private Function<Cookie, String> toCookieNameFunction; | ||
|
||
@Override | ||
public boolean hasCookie(String name) { | ||
final HttpServletRequest request = servletRequestProvider.get(); | ||
|
||
final @Nullable Cookie[] cookies = request.getCookies(); | ||
return cookies != null && transform(asList(cookies), toCookieNameFunction).contains(name); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...le/java/app-proxy/src/main/java/com/poterenko/proxy/cookie/impl/ToCookieNameFunction.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,13 @@ | ||
package com.poterenko.proxy.cookie.impl; | ||
|
||
import com.google.common.base.Function; | ||
|
||
import javax.servlet.http.Cookie; | ||
|
||
public class ToCookieNameFunction implements Function<Cookie, String> { | ||
|
||
@Override | ||
public String apply(Cookie c) { | ||
return c.getName(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
coding-style/java/app-proxy/src/main/java/com/poterenko/proxy/guice/InjectorHelper.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,14 @@ | ||
package com.poterenko.proxy.guice; | ||
|
||
import com.google.inject.Injector; | ||
|
||
import javax.servlet.ServletContextEvent; | ||
|
||
public class InjectorHelper { | ||
|
||
public static Injector getInjector(ServletContextEvent servletContextEvent) { | ||
return (Injector) servletContextEvent | ||
.getServletContext() | ||
.getAttribute(Injector.class.getName()); | ||
} | ||
} |
Oops, something went wrong.