Skip to content

Commit 45cade5

Browse files
alxptral-pt-old
authored andcommitted
*initial commit
0 parents  commit 45cade5

File tree

1,975 files changed

+257245
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,975 files changed

+257245
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

README.md

+212
Large diffs are not rendered by default.

coding-style/java/app-proxy/README.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
### An example of proxy-server.
2+
3+
The application allows to create a local proxy server for local debugging of web applications.
4+
5+
### Requirements
6+
Installation of the Java 6 or higher.
7+
8+
### Build and run
9+
10+
```bash
11+
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
12+
```
13+
14+
### Features
15+
16+
Ability to specify:
17+
+ debug mode (-Dproxy.debug)
18+
+ REST-pattern (-Dproxy.pattern)
19+
+ local server port (-Denv.proxy.port)
20+
+ remote server (-Dproxy.target)
21+
+ local web sources directory (-Denv.src.path)
22+

coding-style/java/app-proxy/pom.xml

+202
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>poterenko.com</groupId>
6+
<artifactId>app.proxy</artifactId>
7+
<packaging>war</packaging>
8+
<version>1.0</version>
9+
<name>An example of proxy-server</name>
10+
11+
<properties>
12+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13+
<src.version>1.7</src.version>
14+
<webapp.dir>${env.src.path}</webapp.dir>
15+
<proxy.port>${env.proxy.port}</proxy.port>
16+
<artifact.name>app-proxy</artifact.name>
17+
<javax.servlet.api.version>3.0.1</javax.servlet.api.version>
18+
<guice.version>3.0</guice.version>
19+
<maven.compiler.plugin.version>3.3</maven.compiler.plugin.version>
20+
<maven.jetty.plugin.version>6.1.26</maven.jetty.plugin.version>
21+
<commons.io.version>1.3.2</commons.io.version>
22+
<google.http.client.version>1.20.0</google.http.client.version>
23+
<slf4j.api.version>1.6.2</slf4j.api.version>
24+
<slf4j.simple.version>1.7.9</slf4j.simple.version>
25+
</properties>
26+
27+
<dependencyManagement>
28+
<dependencies>
29+
<!--Servlets-->
30+
<dependency>
31+
<groupId>javax.servlet</groupId>
32+
<artifactId>javax.servlet-api</artifactId>
33+
<version>${javax.servlet.api.version}</version>
34+
</dependency>
35+
<!--Jetty-->
36+
<dependency>
37+
<groupId>org.mortbay.jetty</groupId>
38+
<artifactId>maven-jetty-plugin</artifactId>
39+
<version>${maven.jetty.plugin.version}</version>
40+
<exclusions>
41+
<exclusion>
42+
<groupId>org.slf4j</groupId>
43+
<artifactId>slf4j-api</artifactId>
44+
</exclusion>
45+
<exclusion>
46+
<groupId>org.slf4j</groupId>
47+
<artifactId>slf4j-nop</artifactId>
48+
</exclusion>
49+
<exclusion>
50+
<groupId>org.slf4j</groupId>
51+
<artifactId>slf4j-jdk14</artifactId>
52+
</exclusion>
53+
</exclusions>
54+
</dependency>
55+
<!--Apache-->
56+
<dependency>
57+
<groupId>org.apache.maven.plugins</groupId>
58+
<artifactId>maven-compiler-plugin</artifactId>
59+
<version>${maven.compiler.plugin.version}</version>
60+
<exclusions>
61+
<exclusion>
62+
<groupId>org.slf4j</groupId>
63+
<artifactId>slf4j-api</artifactId>
64+
</exclusion>
65+
<exclusion>
66+
<groupId>org.slf4j</groupId>
67+
<artifactId>slf4j-nop</artifactId>
68+
</exclusion>
69+
<exclusion>
70+
<groupId>org.slf4j</groupId>
71+
<artifactId>slf4j-jdk14</artifactId>
72+
</exclusion>
73+
</exclusions>
74+
</dependency>
75+
<dependency>
76+
<groupId>org.apache.commons</groupId>
77+
<artifactId>commons-io</artifactId>
78+
<version>${commons.io.version}</version>
79+
</dependency>
80+
<!--Http-->
81+
<dependency>
82+
<groupId>com.google.http-client</groupId>
83+
<artifactId>google-http-client</artifactId>
84+
<version>${google.http.client.version}</version>
85+
</dependency>
86+
<!--Log-->
87+
<dependency>
88+
<groupId>org.slf4j</groupId>
89+
<artifactId>slf4j-api</artifactId>
90+
<version>${slf4j.api.version}</version>
91+
</dependency>
92+
<dependency>
93+
<groupId>org.slf4j</groupId>
94+
<artifactId>slf4j-simple</artifactId>
95+
<version>${slf4j.simple.version}</version>
96+
</dependency>
97+
<!--IoC-->
98+
<dependency>
99+
<groupId>com.google.inject</groupId>
100+
<artifactId>guice</artifactId>
101+
<version>${guice.version}</version>
102+
</dependency>
103+
<dependency>
104+
<groupId>com.google.inject.extensions</groupId>
105+
<artifactId>guice-servlet</artifactId>
106+
<version>${guice.version}</version>
107+
</dependency>
108+
</dependencies>
109+
</dependencyManagement>
110+
111+
<dependencies>
112+
<!--Servlets-->
113+
<dependency>
114+
<groupId>javax.servlet</groupId>
115+
<artifactId>javax.servlet-api</artifactId>
116+
</dependency>
117+
<!--Jetty-->
118+
<dependency>
119+
<groupId>org.mortbay.jetty</groupId>
120+
<artifactId>maven-jetty-plugin</artifactId>
121+
</dependency>
122+
<!--Apache-->
123+
<dependency>
124+
<groupId>org.apache.maven.plugins</groupId>
125+
<artifactId>maven-compiler-plugin</artifactId>
126+
</dependency>
127+
<dependency>
128+
<groupId>org.apache.commons</groupId>
129+
<artifactId>commons-io</artifactId>
130+
</dependency>
131+
<!--Http-->
132+
<dependency>
133+
<groupId>com.google.http-client</groupId>
134+
<artifactId>google-http-client</artifactId>
135+
</dependency>
136+
<!--Log-->
137+
<dependency>
138+
<groupId>org.slf4j</groupId>
139+
<artifactId>slf4j-api</artifactId>
140+
</dependency>
141+
<dependency>
142+
<groupId>org.slf4j</groupId>
143+
<artifactId>slf4j-simple</artifactId>
144+
</dependency>
145+
<!--IoC-->
146+
<dependency>
147+
<groupId>com.google.inject</groupId>
148+
<artifactId>guice</artifactId>
149+
</dependency>
150+
<dependency>
151+
<groupId>com.google.inject.extensions</groupId>
152+
<artifactId>guice-servlet</artifactId>
153+
</dependency>
154+
</dependencies>
155+
156+
<build>
157+
<finalName>${artifact.name}</finalName>
158+
<sourceDirectory>src/main/java</sourceDirectory>
159+
<plugins>
160+
<plugin>
161+
<groupId>org.apache.maven.plugins</groupId>
162+
<artifactId>maven-compiler-plugin</artifactId>
163+
<version>${maven.compiler.plugin.version}</version>
164+
<configuration>
165+
<source>${src.version}</source>
166+
<target>${src.version}</target>
167+
</configuration>
168+
</plugin>
169+
<plugin>
170+
<groupId>org.mortbay.jetty</groupId>
171+
<artifactId>maven-jetty-plugin</artifactId>
172+
<version>${maven.jetty.plugin.version}</version>
173+
<configuration>
174+
<webAppConfig>
175+
<defaultsDescriptor>${basedir}/src/main/resources/webdefault.xml</defaultsDescriptor>
176+
<contextPath>/</contextPath>
177+
<baseResource implementation="org.mortbay.resource.ResourceCollection">
178+
<resourcesAsCSV>${webapp.dir}</resourcesAsCSV>
179+
</baseResource>
180+
</webAppConfig>
181+
<connectors>
182+
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
183+
<port>${proxy.port}</port>
184+
</connector>
185+
</connectors>
186+
</configuration>
187+
<executions>
188+
<execution>
189+
<id>install-jetty</id>
190+
<phase>install</phase>
191+
<goals>
192+
<goal>run</goal>
193+
</goals>
194+
<configuration>
195+
<daemon>false</daemon>
196+
</configuration>
197+
</execution>
198+
</executions>
199+
</plugin>
200+
</plugins>
201+
</build>
202+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.poterenko.proxy;
2+
3+
public final class ProxyConstants {
4+
5+
public static final String PROXY_TARGET = "proxy.target";
6+
public static final String PROXY_PATTERN = "proxy.pattern";
7+
public static final String PROXY_DEBUG = "proxy.debug";
8+
public static final String QUERY_SEPARATOR = "?";
9+
public static final String DEBUG_COOKIE_NAME = "debug";
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.poterenko.proxy;
2+
3+
import com.google.api.client.http.HttpRequest;
4+
import com.google.api.client.http.HttpRequestFactory;
5+
import com.google.api.client.http.HttpTransport;
6+
import com.google.api.client.http.javanet.NetHttpTransport;
7+
import com.google.common.base.Function;
8+
9+
import com.google.inject.Provides;
10+
import com.google.inject.TypeLiteral;
11+
import com.google.inject.servlet.ServletModule;
12+
import com.poterenko.proxy.cookie.CookieChecker;
13+
import com.poterenko.proxy.cookie.impl.CookieCheckerImpl;
14+
import com.poterenko.proxy.cookie.impl.ToCookieNameFunction;
15+
import com.poterenko.proxy.request.ProxyRequestProvider;
16+
import com.poterenko.proxy.servlets.ProxyApiFilter;
17+
import com.poterenko.proxy.servlets.ProxyCookieFilter;
18+
19+
import static java.lang.System.getProperty;
20+
import static org.apache.maven.shared.utils.StringUtils.isEmpty;
21+
22+
import javax.inject.Named;
23+
import javax.inject.Singleton;
24+
import javax.servlet.http.Cookie;
25+
26+
public class ProxyModule extends ServletModule {
27+
28+
@Override
29+
protected void configureServlets() {
30+
if (!isEmpty(getProperty(ProxyConstants.PROXY_DEBUG))) {
31+
filter("*").through(ProxyCookieFilter.class);
32+
}
33+
filter(getProperty(ProxyConstants.PROXY_PATTERN)).through(ProxyApiFilter.class);
34+
35+
bind(HttpRequest.class).toProvider(ProxyRequestProvider.class);
36+
bind(HttpTransport.class).toInstance(new NetHttpTransport.Builder().build());
37+
bind(CookieChecker.class).to(CookieCheckerImpl.class).asEagerSingleton();
38+
bind(new TypeLiteral<Function<Cookie, String>>() {}).to(ToCookieNameFunction.class);
39+
}
40+
41+
@Provides
42+
@Singleton
43+
@Named(ProxyConstants.PROXY_TARGET)
44+
protected String getHost() {
45+
return getProperty(ProxyConstants.PROXY_TARGET);
46+
}
47+
48+
@Provides
49+
@Singleton
50+
protected HttpRequestFactory getHttpRequestFactory(HttpTransport transport) {
51+
return transport.createRequestFactory();
52+
}
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.poterenko.proxy.cookie;
2+
3+
public interface CookieChecker {
4+
5+
boolean hasCookie(String name);
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.poterenko.proxy.cookie.impl;
2+
3+
import com.google.common.base.Function;
4+
import com.poterenko.proxy.cookie.CookieChecker;
5+
6+
import javax.annotation.Nullable;
7+
import javax.inject.Inject;
8+
import javax.inject.Provider;
9+
import javax.servlet.http.Cookie;
10+
import javax.servlet.http.HttpServletRequest;
11+
12+
import static com.google.common.collect.Collections2.transform;
13+
import static java.util.Arrays.asList;
14+
15+
public class CookieCheckerImpl implements CookieChecker {
16+
17+
@Inject
18+
private Provider<HttpServletRequest> servletRequestProvider;
19+
@Inject
20+
private Function<Cookie, String> toCookieNameFunction;
21+
22+
@Override
23+
public boolean hasCookie(String name) {
24+
final HttpServletRequest request = servletRequestProvider.get();
25+
26+
final @Nullable Cookie[] cookies = request.getCookies();
27+
return cookies != null && transform(asList(cookies), toCookieNameFunction).contains(name);
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.poterenko.proxy.cookie.impl;
2+
3+
import com.google.common.base.Function;
4+
5+
import javax.servlet.http.Cookie;
6+
7+
public class ToCookieNameFunction implements Function<Cookie, String> {
8+
9+
@Override
10+
public String apply(Cookie c) {
11+
return c.getName();
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.poterenko.proxy.guice;
2+
3+
import com.google.inject.Injector;
4+
5+
import javax.servlet.ServletContextEvent;
6+
7+
public class InjectorHelper {
8+
9+
public static Injector getInjector(ServletContextEvent servletContextEvent) {
10+
return (Injector) servletContextEvent
11+
.getServletContext()
12+
.getAttribute(Injector.class.getName());
13+
}
14+
}

0 commit comments

Comments
 (0)