I created a proxy server (Fwd and Reverse) using Java sockets.
which will listen to the incoming request to 8080 configured in the browser and forward them to another proxy server2.
And read the response sent by server2 and write it in the browser.
Meanwhile, the code will register requests and respond, as well as block certain predefined types of requests from the browser.
Now I want to do this with Jetty and also support the HTTPS request.
I searched for an example but did not find it.
This starts the server on 8080, which I configured as a proxy port in the browser proxy settings.
import org.eclipse.jetty.server.Server;
import Handler.HelloHandler;
public class StartJetty
{
public static void main(String[] args) throws Exception
{
Server server = new Server(8080);
server.setHandler(new HelloHandler());
server.start();
server.join();
}
}
This is the handler that I use to listen to the request and send the response back to the browser.
package Handler;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
public class HelloHandler extends AbstractHandler
{
final String _greeting;
final String _body;
public HelloHandler()
{
_greeting="Hello World";
_body=null;
}
public HelloHandler(String greeting)
{
_greeting=greeting;
_body=null;
}
public HelloHandler(String greeting,String body)
{
_greeting=greeting;
_body=body;
}
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
response.setContentType("text/html;charset=utf-8");
response.setStatus(HttpServletResponse.SC_OK);
baseRequest.setHandled(true);
response.getWriter().println("<h1>"+_greeting+"</h1>");
if (_body!=null)
response.getWriter().println(_body);
}
}
, -, . .