Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Genesys Backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
19
Issues
19
List
Boards
Labels
Service Desk
Milestones
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Genesys PGR
Genesys Backend
Commits
ec86e60c
Commit
ec86e60c
authored
Aug 17, 2014
by
Matija Obreza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed ElasticsearchHelper, removed parsing client_id from URI
parent
e0634ecc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
116 deletions
+0
-116
src/main/java/org/genesys2/server/servlet/controller/webapi/ElasticsearchHelper.java
...server/servlet/controller/webapi/ElasticsearchHelper.java
+0
-100
src/main/java/org/genesys2/server/servlet/filter/WebApiFilter.java
...java/org/genesys2/server/servlet/filter/WebApiFilter.java
+0
-16
No files found.
src/main/java/org/genesys2/server/servlet/controller/webapi/ElasticsearchHelper.java
deleted
100644 → 0
View file @
e0634ecc
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package
org.genesys2.server.servlet.controller.webapi
;
import
java.io.IOException
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.client.HttpClient
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.client.methods.HttpPut
;
import
org.apache.http.client.methods.HttpRequestBase
;
import
org.apache.http.entity.InputStreamEntity
;
import
org.apache.http.impl.client.DefaultHttpClient
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.servlet.HandlerMapping
;
/**
* Relay /api/v0/veryelastic requests to elasticsearch
*/
@Controller
@PreAuthorize
(
"isAuthenticated()"
)
@RequestMapping
(
value
=
"/webapi"
)
public
class
ElasticsearchHelper
{
@Value
(
"${elasticsearch.url}"
)
private
String
elasticsearchUrl
;
public
static
final
Log
LOG
=
LogFactory
.
getLog
(
ElasticsearchHelper
.
class
);
@RequestMapping
(
"/{clientId}/es/**"
)
public
void
relay2
(
@PathVariable
(
"clientId"
)
String
clientId
,
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
IOException
{
String
foo
=
(
String
)
request
.
getAttribute
(
HandlerMapping
.
PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
);
foo
=
foo
.
substring
(
"/webapi"
.
length
()
+
1
+
clientId
.
length
()
+
1
+
"es"
.
length
()
+
1
);
String
queryString
=
request
.
getQueryString
();
String
method
=
request
.
getMethod
();
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"ES path: "
+
foo
);
LOG
.
debug
(
"ES qs: "
+
queryString
);
LOG
.
debug
(
"ES method: "
+
method
);
}
final
HttpClient
httpclient
=
new
DefaultHttpClient
();
HttpRequestBase
req
=
null
;
if
(
"POST"
.
equalsIgnoreCase
(
method
))
{
HttpPost
r
=
new
HttpPost
(
elasticsearchUrl
+
foo
);
HttpEntity
entity
=
new
InputStreamEntity
(
request
.
getInputStream
(),
request
.
getContentLength
());
r
.
setEntity
(
entity
);
req
=
r
;
}
else
if
(
"PUT"
.
equalsIgnoreCase
(
method
))
{
HttpPut
r
=
new
HttpPut
(
elasticsearchUrl
+
foo
);
HttpEntity
entity
=
new
InputStreamEntity
(
request
.
getInputStream
(),
request
.
getContentLength
());
r
.
setEntity
(
entity
);
req
=
r
;
}
else
if
(
"GET"
.
equalsIgnoreCase
(
method
))
{
req
=
new
HttpGet
(
elasticsearchUrl
+
foo
);
}
HttpResponse
esResponse
=
null
;
try
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Proxy "
+
req
);
}
esResponse
=
httpclient
.
execute
(
req
);
HttpEntity
e
=
esResponse
.
getEntity
();
response
.
setContentType
(
e
.
getContentType
().
getValue
());
response
.
setContentLengthLong
(
e
.
getContentLength
());
IOUtils
.
copy
(
e
.
getContent
(),
response
.
getOutputStream
());
response
.
flushBuffer
();
}
catch
(
final
IOException
e
)
{
LOG
.
error
(
e
.
getMessage
(),
e
);
throw
e
;
}
}
}
src/main/java/org/genesys2/server/servlet/filter/WebApiFilter.java
View file @
ec86e60c
...
...
@@ -18,8 +18,6 @@ package org.genesys2.server.servlet.filter;
import
java.io.IOException
;
import
java.util.Set
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
javax.servlet.FilterChain
;
import
javax.servlet.ServletException
;
...
...
@@ -42,8 +40,6 @@ import org.springframework.web.filter.OncePerRequestFilter;
public
class
WebApiFilter
extends
OncePerRequestFilter
{
private
static
final
Logger
_logger
=
LoggerFactory
.
getLogger
(
WebApiFilter
.
class
);
private
Pattern
webapiUri
=
Pattern
.
compile
(
"/webapi/([^@]+@[^/]+)/.+"
);
@Autowired
private
OAuth2ClientDetailsService
clientDetailsService
;
...
...
@@ -53,18 +49,6 @@ public class WebApiFilter extends OncePerRequestFilter {
String
clientSecret
=
request
.
getParameter
(
"client_secret"
);
String
referrer
=
request
.
getHeader
(
"Referer"
);
if
(
clientId
==
null
)
{
String
requestURI
=
request
.
getRequestURI
();
if
(
_logger
.
isDebugEnabled
())
_logger
.
debug
(
"PATH="
+
requestURI
);
Matcher
m
=
webapiUri
.
matcher
(
requestURI
);
if
(
m
.
matches
())
{
clientId
=
m
.
group
(
1
);
if
(
_logger
.
isDebugEnabled
())
_logger
.
debug
(
"client_id="
+
clientId
);
}
}
try
{
if
(
StringUtils
.
isBlank
(
clientId
))
{
throw
new
Exception
(
"client_id not provided"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment