Skip to content

Commit

Permalink
Cors filter for /services
Browse files Browse the repository at this point in the history
  • Loading branch information
Samson committed Mar 14, 2018
1 parent 65cae51 commit c1204ca
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 98 deletions.
Binary file modified sm-shop/SALESMANAGER.h2.db
Binary file not shown.
2 changes: 1 addition & 1 deletion sm-shop/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>

<artifactId>sm-shop</artifactId>
<packaging>jar</packaging>
<packaging>war</packaging>

<name>sm-shop</name>
<url>http://www.shopizer.com</url>
Expand Down
30 changes: 15 additions & 15 deletions sm-shop/src/main/java/com/salesmanager/shop/filter/CorsFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CorsFilter implements Filter {
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

public class CorsFilter extends HandlerInterceptorAdapter {


@Override
public void destroy() {
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
// TODO Auto-generated method stub
public CorsFilter() {

}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {

/**
* Allows public web services to work from remote hosts
*/
public boolean preHandle(
HttpServletRequest request,
HttpServletResponse response,
Object handler) throws Exception {

HttpServletResponse httpResponse = (HttpServletResponse) response;

httpResponse.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS, DELETE");
httpResponse.setHeader("Access-Control-Allow-Headers", "X-Auth-Token, Content-Type");
//httpResponse.setHeader("Access-Control-Allow-Credentials", "false");
//httpResponse.setHeader("Access-Control-Max-Age", "4800");
//System.out.println("---CORS Configuration Completed---");
chain.doFilter(request, response);

return true;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -625,85 +625,6 @@ private void setTopCategories(MerchantStore store, Language language, HttpServle

}

/*@SuppressWarnings("unchecked")
private void getTopCategories(MerchantStore store, Language language, HttpServletRequest request) throws Exception {
*//**
* Top categories
* Top categories are implemented as Category entity
* CategoryDescription will provide attributes name for the
* label to be displayed and seUrl for the friendly url page
*//*
//build the key
*//**
* The categories is kept as a Map<String,Object>
* The key is <MERCHANT_ID>_CATEGORYLOCALE
* The value is a List of Category object
*//*
StringBuilder categoriesKey = new StringBuilder();
categoriesKey
.append(store.getId())
.append("_")
.append(Constants.CATEGORIES_CACHE_KEY)
.append("-")
.append(language.getCode());
StringBuilder categoriesKeyMissed = new StringBuilder();
categoriesKeyMissed
.append(categoriesKey.toString())
.append(Constants.MISSED_CACHE_KEY);
//Map<String, List<Category>> objects = null;
Map<String, List<ReadableCategory>> objects = null;
if(store.isUseCache()) {
//get from the cache
//objects = (Map<String, List<Category>>) cache.getFromCache(categoriesKey.toString());
objects = (Map<String, List<ReadableCategory>>) cache.getFromCache(categoriesKey.toString());
if(objects==null) {
//Boolean missedContent = (Boolean)cache.getFromCache(categoriesKeyMissed.toString());
//if(missedContent==null) {
//Get top categories from the database
objects = this.getCategories(store, language);
if(objects!=null) {
//put in cache
cache.putInCache(objects, categoriesKey.toString());
} else {
//put in missed cache
//cache.putInCache(new Boolean(true), categoriesKeyMissed.toString());
}
//}
}
} else {
objects = this.getCategories(store, language);
}
if(objects!=null && objects.size()>0) {
//List<Category> categories = objects.get(categoriesKey.toString());
List<ReadableCategory> categories = objects.get(categoriesKey.toString());
if(categories!=null) {
request.setAttribute(Constants.REQUEST_TOP_CATEGORIES, categories);
}
}
}
*/

private Map<String, List<ContentDescription>> getContentPagesNames(MerchantStore store, Language language) throws Exception {

Expand Down
9 changes: 8 additions & 1 deletion sm-shop/src/main/resources/spring/shopizer-controllers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,25 @@
<!-- Changes the locale when a 'locale' request parameter is sent; e.g. /?locale=de -->
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"/>

<!-- store web front filter -->
<mvc:interceptor>
<mvc:mapping path="/shop/**"/>
<bean class="com.salesmanager.shop.filter.StoreFilter"/>
</mvc:interceptor>

<!-- public services cors filter -->
<mvc:interceptor>
<mvc:mapping path="/services/**"/>
<bean class="com.salesmanager.shop.filter.CorsFilter"/>
</mvc:interceptor>

<!-- customer section filter -->
<mvc:interceptor>
<mvc:mapping path="/customer/**"/>
<bean class="com.salesmanager.shop.filter.StoreFilter"/>
</mvc:interceptor>


<!-- admin panel filter -->
<mvc:interceptor>
<mvc:mapping path="/admin/**"/>
<bean class="com.salesmanager.shop.filter.AdminFilter" />
Expand Down
3 changes: 1 addition & 2 deletions sm-shop/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">

<!--<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
-->

<!--Start UTF-8 Encoding needed.-->
<filter>
<filter-name>encodingFilter</filter-name>
Expand Down

0 comments on commit c1204ca

Please sign in to comment.