Modifier and Type | Method and Description |
---|---|
static String |
getMatchingPathPart(HttpServletRequest request)
Returns the part of the request URL that was not used to match the URL to the RequestMapping annotations on
your code.
|
static String |
parseUrl(HttpServletRequest request,
String targetUrlTemplate)
Parses the HTTP Request URL to something else, using a Groovy String template.
|
static String |
parseUrl(HttpServletRequest request,
String targetUrlTemplate,
Map variables)
Parses the HTTP Request URL to something else, using a Groovy String template.
|
static String |
parseUrl(String targetUrlTemplate,
HttpServletRequest request)
Parses the HTTP Request URL to something else, using a Groovy String template.
|
static String |
parseUrl(String targetUrlTemplate,
HttpServletRequest request,
Map variables)
Parses the HTTP Request URL to something else, using a Groovy String template.
|
static HttpServletRequest |
proxy(HttpServletRequest request,
HttpServletResponse response,
String targetUrl)
A method used to proxy an incoming HTTP request to another server.
|
static HttpServletRequest |
proxy(HttpServletRequest request,
HttpServletResponse response,
String targetUrl,
boolean followRedirects)
A method used to proxy an incoming HTTP request to another server.
|
static HttpServletRequest |
proxy(String targetUrl,
HttpServletRequest request,
HttpServletResponse response)
A method used to proxy an incoming HTTP request to another server.
|
static HttpServletRequest |
proxy(String targetUrl,
HttpServletRequest request,
HttpServletResponse response,
boolean followRedirects)
A method used to proxy an incoming HTTP request to another server.
|
static HttpServletRequest |
proxy(String targetUrl,
HttpServletRequest request,
HttpServletResponse response,
boolean followRedirect,
Closure<HttpServletRequest> requestClosure)
A method used to proxy an incoming HTTP request to another server.
|
public static HttpServletRequest proxy(HttpServletRequest request, HttpServletResponse response, String targetUrl) throws Exception
A method used to proxy an incoming HTTP request to another server. Read more about the proxy feature here. Redirects here will be followed. Remember to pass in the target url parameter with single quotes in groovy.
Example usage:
request.proxy( response, 'http://internal-api-server.com/$matchingPath')
request
- The Original HTTP Requestresponse
- The Original HTTP responsetargetUrl
- The target URL. This URL can be a groovy template string that Martini Runtime will then use to
try and generate a new URL using runtime parameters from the original requestException
public static HttpServletRequest proxy(HttpServletRequest request, HttpServletResponse response, String targetUrl, boolean followRedirects) throws Exception
A method used to proxy an incoming HTTP request to another server. Read more about the proxy feature here.
Example usage:
request.proxy( response, 'http://internal-api-server.com/$matchingPath', false)
request
- The Original HTTP Requestresponse
- The Original HTTP responsetargetUrl
- The target URL. This URL can be a groovy template string that Martini Runtime will then use to
try and generate a new URL using runtime parameters from the original requestfollowRedirects
- A boolean stating whether the proxy will follow a redirect responseException
public static HttpServletRequest proxy(String targetUrl, HttpServletRequest request, HttpServletResponse response) throws Exception
A method used to proxy an incoming HTTP request to another server. Read more about the proxy feature here. Redirects here will be followed. Remember to pass in the target url parameter with single quotes in groovy.
Example usage:
'http://internal-api-server.com/$matchingPath'.proxy( request, response )
targetUrl
- The target URL. This URL can be a groovy template string that Martini Runtime will then use to
try and generate a new URL using runtime parameters from the original requestrequest
- The Original HTTP Requestresponse
- The Original HTTP responseException
public static HttpServletRequest proxy(String targetUrl, HttpServletRequest request, HttpServletResponse response, boolean followRedirects) throws Exception
A method used to proxy an incoming HTTP request to another server. Read more about the proxy feature here.
Example usage:
'http://internal-api-server.com/$matchingPath'.proxy( request, response, false )
The provided response body is automatically closed if and only if, the proxied
request receives a response from the server, regardless of the response code. Otherwise
if the underlying http client that proxies the request throws an exception (e.g., the
targeUrl
is down, or the remote server times out), the provided response body is
kept open to give control to the original caller.
Tip: If used with Gloop, declare an output property $requestHandled
to true
to prevent Martini from further writing to the response.
request
- The Original HTTP Requestresponse
- The Original HTTP responsetargetUrl
- The target URL. This URL can be a groovy template string that Martini Runtime will then use to
try and generate a new URL using runtime parameters from the original requestfollowRedirects
- A boolean stating whether the proxy will follow a redirect responseException
public static HttpServletRequest proxy(String targetUrl, HttpServletRequest request, HttpServletResponse response, boolean followRedirect, Closure<HttpServletRequest> requestClosure) throws Exception
A method used to proxy an incoming HTTP request to another server. Read more about the proxy feature here.
Example usage:
'http://internal-api-server.com/$matchingPath'.proxy( request, response, false, { it.putHeader('Authorization', null) // removes 'Authorization' header } )
The provided response body is automatically closed if and only if, the proxied
request receives a response from the server, regardless of the response code. Otherwise
if the underlying http client that proxies the request throws an exception (e.g., the
targeUrl
is down, or the remote server times out), the provided response body is
kept open to give control to the original caller.
Tip: If used with Gloop, declare an output property $requestHandled
to true
to prevent Martini from further writing to the response.
request
- The Original HTTP Requestresponse
- The Original HTTP responsetargetUrl
- The target URL. This URL can be a groovy template string that Martini Runtime will then use to
try and generate a new URL using runtime parameters from the original requestfollowRedirect
- A boolean stating whether the proxy will follow a redirect responserequestClosure
- Used for modifying the original request before sentException
public static String getMatchingPathPart(HttpServletRequest request)
Returns the part of the request URL that was not used to match the URL to the RequestMapping annotations on your code. Read more here.
Example usage:
def urlPart = request.getMatchingPathPart()
request
- The Original HTTP Requestpublic static String parseUrl(HttpServletRequest request, String targetUrlTemplate, Map variables) throws Exception
Parses the HTTP Request URL to something else, using a Groovy String template. Read more here.
Example usage:
def newUrl = request.parseUrl('http://internal-$serverName?$queryString&test=$test', [ test : 'Hello'] )
request
- The Original HTTP RequesttargetUrlTemplate
- The target Groovy template stringvariables
- An optional list of additional variables to pass to the string template engineException
public static String parseUrl(HttpServletRequest request, String targetUrlTemplate) throws Exception
Parses the HTTP Request URL to something else, using a Groovy String template. Read more here.
Example usage:def newUrl = request.parseUrl('http://internal-$serverName?$queryString' )
request
- The Original HTTP RequesttargetUrlTemplate
- The target Groovy template stringException
public static String parseUrl(String targetUrlTemplate, HttpServletRequest request, Map variables) throws Exception
Parses the HTTP Request URL to something else, using a Groovy String template. Read more here.
Example usage:
def newUrl = 'http://internal-$serverName?$queryString&test=$test'.parseUrl( request, [ test : 'Hello'] )
request
- The Original HTTP RequesttargetUrlTemplate
- The target Groovy template stringvariables
- An optional list of additional variables to pass to the string template engineException
public static String parseUrl(String targetUrlTemplate, HttpServletRequest request) throws Exception
Parses the HTTP Request URL to something else, using a Groovy String template. Read more here.
Example usage:
def newUrl = 'http://internal-$serverName?$queryString'.parseUrl( request )
request
- The Original HTTP RequesttargetUrlTemplate
- The target Groovy template stringException
Copyright © 2019. All rights reserved.