Package jeeves.config.springutil

Source Code of jeeves.config.springutil.JeevesNodeAwareRedirectStrategy

package jeeves.config.springutil;

import org.fao.geonet.NodeInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.security.web.DefaultRedirectStrategy;
import org.springframework.security.web.RedirectStrategy;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

import static jeeves.config.springutil.JeevesDelegatingFilterProxy.getApplicationContextFromServletContext;

/**
* Created by Jesse on 2/17/14.
*/
public class JeevesNodeAwareRedirectStrategy extends DefaultRedirectStrategy implements RedirectStrategy {
    @Autowired
    ServletContext context;

    @Override
    public void sendRedirect(HttpServletRequest request, HttpServletResponse response, String url) throws IOException {
        final ConfigurableApplicationContext applicationContext = getApplicationContextFromServletContext(context);

        NodeInfo nodeInfo = applicationContext.getBean(NodeInfo.class);

        String newUrl = url.replace("@@nodeId@@", nodeInfo.getId());

        super.sendRedirect(request, response, newUrl);
    }
}
TOP

Related Classes of jeeves.config.springutil.JeevesNodeAwareRedirectStrategy

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.