import java
io
IOException;
import javaioInputStream;
import URL;
import javaxservletServletConfig;
import javaxservletServletException;
import javaxservletServletOutputStream;
import javaxservlethttpHttpServlet;
import javaxservlethttpHttpServletRequest;
import javaxservlethttpHttpServletResponse;
/**
* Take any request and proxy it to the given REDIRECT_BASE
* For example if this servlet lives at
*
*
*
* and is inititialized with the REDIRECT_BASE
*
*
*
* then a GET request like
*
*
*
* will return the results of a GET from
*
*
*
* This is not robust and generalized; its simple and quick
*
* @author jdf
*
*/
public class ProxyServlet extends HttpServlet
{
private final static String COPYRIGHT = comibmdogearCopyrightSHORT;
public static final String REDIRECT_BASE = comibmblservletRedirectServletredirect_base;
private String redirectBase;
@Override
public void init(ServletConfig config) throws ServletException
{
superinit(config)
redirectBase = getRequiredParam(REDIRECT_BASE)
}
@Override
protected void doGet(HttpServletRequest req HttpServletResponse resp) throws IOException
{
String queryString = reqgetQueryString()
URL url = new URL(redirectBase + (queryString != null ? ? + queryString : ))
copyInputStreamToOutputStream(urlopenStream() respgetOutputStream())
}
private void copyInputStreamToOutputStream(InputStream in ServletOutputStream out)
throws IOException
{
try
{
try
{
byte[] buffer = new byte[];
int n;
while ((n = inread(buffer)) != )
outwrite(buffer n)
}
finally
{
outclose()
}
}
finally
{
inclose()
}
}
protected String getRequiredParam(String param) throws ServletException
{
String result = getServletConfig()getInitParameter(param)
if (result == null) {
throw new ServletException(getClass() + requires + param + param)
}
return result;
}
}