thundr-contrib-proxy

An intercepting reverse proxy module for Thundr

Лицензия

Лицензия

Группа

Группа

com.threewks.thundr
Идентификатор

Идентификатор

thundr-contrib-proxy
Последняя версия

Последняя версия

0.1.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

thundr-contrib-proxy
An intercepting reverse proxy module for Thundr
Ссылка на сайт

Ссылка на сайт

http://github.com/kuhnza/thundr-contrib-proxy/
Организация-разработчик

Организация-разработчик

3wks
Система контроля версий

Система контроля версий

https://github.com/kuhnza/thundr-contrib-proxy

Скачать thundr-contrib-proxy

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.threewks.thundr/thundr-contrib-proxy/ -->
<dependency>
    <groupId>com.threewks.thundr</groupId>
    <artifactId>thundr-contrib-proxy</artifactId>
    <version>0.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.threewks.thundr/thundr-contrib-proxy/
implementation 'com.threewks.thundr:thundr-contrib-proxy:0.1.0'
// https://jarcasting.com/artifacts/com.threewks.thundr/thundr-contrib-proxy/
implementation ("com.threewks.thundr:thundr-contrib-proxy:0.1.0")
'com.threewks.thundr:thundr-contrib-proxy:jar:0.1.0'
<dependency org="com.threewks.thundr" name="thundr-contrib-proxy" rev="0.1.0">
  <artifact name="thundr-contrib-proxy" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.threewks.thundr', module='thundr-contrib-proxy', version='0.1.0')
)
libraryDependencies += "com.threewks.thundr" % "thundr-contrib-proxy" % "0.1.0"
[com.threewks.thundr/thundr-contrib-proxy "0.1.0"]

Зависимости

compile (3)

Идентификатор библиотеки Тип Версия
com.threewks.thundr : thundr jar 1.1.0
com.threewks.thundr : thundr-http jar 1.1.0
com.google.http-client : google-http-client jar 1.17.0-rc

provided (1)

Идентификатор библиотеки Тип Версия
javax.servlet : servlet-api jar 2.5

test (3)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.11
org.hamcrest : hamcrest-all jar 1.3
org.mockito : mockito-all jar 1.9.5

Модули Проекта

Данный проект не имеет модулей.

Thundr Proxy

An intercepting reverse proxy module for Thundr.

Build Status

Usage

In your ApplicationModule:

@Override
public void requires(DependencyRegistry dependencyRegistry) {
    super.requires(dependencyRegistry);

    dependencyRegistry.addDependency(ProxyModule.class);
}

Configuring Routes

Thundr Proxy registers a new ActionResolver which means that you register routes you're interested proxying in your routes.json like so:

{
  "/foo/**": {
    "GET": "proxy",
    "POST": "proxy",
    "PUT": "proxy",
    "DELETE": "proxy"
  }
}

Of course you can omit any HTTP verbs that you'd prefer to ignore.

Adding Rules

Once you've defined a route you'd like to proxy you'll need to define a proxy rule. A rule allows you to define what to do when your app receives a request for one of the routes you've registered.

Let's say you wanted to reverse proxy requests beginning with the path /foo over to the upstream server http://www.example.org/ instead of handling it in your app. Using the included SimpleProxyRule class in your injection configuration add the following:

SimpleProxyRule rule = new SimpleProxyRule("/foo", "http://www.example.org/");
ProxyActionResolver resolver = injectionContext.get(ProxyActionResolver.class);
resolver.registerProxyRule(rule);

Now with this rule registered any requests to /foo will be proxied to the upstream server. So therefore:

/foo/bar/baz -> http://www.example.org/bar/baz

Registering interceptors

Rules also support interceptors. Let's say you want to block all requests to the path /foo/bar/qux and return a 403 without hitting the upstream server.

Expanding on the code in our injection configuration above we can create a new ProxyInterceptor to intercept those calls and modify the response. For this purpose we will extend the BaseProxyInterceptor which provides noop stubs for the ProxyInterceptor interface so we only have to implement the interceptor method we're interested in:

ProxyInterceptor interceptor = new BaseProxyInterceptor() {
  /* Here we use the 'before' method which intercepts the request before it has been 
   * proxied to the upstream server. */
  public Response before(Request inboundRequest, Request proxyRequest) {
    if (inboundRequest.path().startsWith("/foo/bar/qux")) {
      return new Response().status(403);  // terminate proxying immediately and return 403 response to user
    }
    return null;  // null response signals that we should continue proxying request
  }
};
rule.addInterceptor(interceptor);

Interceptor events

The interceptor framework supports 3 events.

  • before - intercepts request before being proxied to the upstream server
  • after - intercepts response from upstream server before it has been proxied back to the requestor
  • exception - intercepts exceptions occurring in any rule or interceptor

Custom rule classes

If the SimpleProxyRule class just isn't cutting it then creating your own is easy. Just extend BaseProxyRule or implement the ProxyRule interface.

Версии библиотеки

Версия
0.1.0