-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Have OpenSearch not balk at empty keys (non EO opensearch clients wil…
…l send those by following the url template)
- Loading branch information
Showing
8 changed files
with
178 additions
and
13 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
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
105 changes: 105 additions & 0 deletions
105
src/community/oseo/oseo-core/src/main/java/org/geoserver/opensearch/eo/OSEOFilter.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,105 @@ | ||
/* (c) 2017 Open Source Geospatial Foundation - all rights reserved | ||
* This code is licensed under the GPL 2.0 license, available at the root | ||
* application directory. | ||
*/ | ||
package org.geoserver.opensearch.eo; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.Enumeration; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.logging.Level; | ||
|
||
import javax.servlet.FilterChain; | ||
import javax.servlet.FilterConfig; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletResponse; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletRequestWrapper; | ||
|
||
import org.apache.commons.collections.map.CaseInsensitiveMap; | ||
import org.geoserver.filters.GeoServerFilter; | ||
|
||
public class OSEOFilter implements GeoServerFilter { | ||
|
||
@Override | ||
public void init(FilterConfig filterConfig) throws ServletException { | ||
// nothing to do | ||
} | ||
|
||
@Override | ||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | ||
throws IOException, ServletException { | ||
if (request instanceof HttpServletRequest) { | ||
HttpServletRequest requestHTTP = (HttpServletRequest)request; | ||
if (requestNeedsWrapper(requestHTTP)) { | ||
request = new RequestWrapper(requestHTTP); | ||
} | ||
} | ||
chain.doFilter(request, response); | ||
|
||
} | ||
|
||
private boolean requestNeedsWrapper(HttpServletRequest requestHTTP) { | ||
return "GET".equalsIgnoreCase(requestHTTP.getMethod()) && !(new CaseInsensitiveMap(requestHTTP.getParameterMap()).containsKey("service")) | ||
&& (requestHTTP.getPathInfo().endsWith("search") || requestHTTP.getPathInfo().endsWith("description")); | ||
} | ||
|
||
@Override | ||
public void destroy() { | ||
// nothing to do | ||
} | ||
|
||
private static class RequestWrapper extends HttpServletRequestWrapper { | ||
private String request; | ||
|
||
private RequestWrapper(HttpServletRequest wrapped) { | ||
super(wrapped); | ||
if(wrapped.getPathInfo().endsWith("search")) { | ||
request = "search"; | ||
} else { | ||
request = "description"; | ||
} | ||
} | ||
|
||
@Override | ||
public Enumeration getParameterNames() { | ||
return Collections.enumeration(getParameterMap().keySet()); | ||
} | ||
|
||
@Override | ||
public Map<String,String[]> getParameterMap() { | ||
Map<String, String[]> original = super.getParameterMap(); | ||
Map filtered = new HashMap<String, String[]>(original); | ||
filtered.put("service", "OSEO"); | ||
filtered.put("version", "1.0.0"); | ||
filtered.put("request", request); | ||
return filtered; | ||
} | ||
|
||
@Override | ||
public String[] getParameterValues(String name) { | ||
if ("service".equalsIgnoreCase(name)) { | ||
return new String[] {"OSEO"}; | ||
} | ||
if ("request".equalsIgnoreCase(name)) { | ||
return new String[] {request}; | ||
} | ||
return super.getParameterValues(name); | ||
} | ||
|
||
@Override | ||
public String getParameter(String name) { | ||
if ("service".equalsIgnoreCase(name)) { | ||
return "OSEO"; | ||
} | ||
if ("request".equalsIgnoreCase(name)) { | ||
return request; | ||
} | ||
return super.getParameter(name); | ||
} | ||
} | ||
|
||
} |
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
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
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
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
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