1 package com.eviware.soapui.impl.wsdl.monitor.jettyproxy;
2
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.io.OutputStream;
6 import java.net.InetSocketAddress;
7 import java.net.Socket;
8 import java.nio.channels.SocketChannel;
9
10 import javax.servlet.ServletException;
11
12 import org.mortbay.jetty.Request;
13 import org.mortbay.jetty.Response;
14 import org.mortbay.util.IO;
15
16 public class Server extends org.mortbay.jetty.Server
17 {
18
19 @Override
20 public void handle(final org.mortbay.jetty.HttpConnection connection) throws IOException, ServletException
21 {
22 final Request request = connection.getRequest();
23
24 if (!request.getMethod().equals("CONNECT"))
25 {
26 super.handle(connection);
27 return;
28 }
29
30 final String uri = request.getUri().toString();
31
32 final int c = uri.indexOf(':');
33 final String port = uri.substring(c + 1);
34 final String host = uri.substring(0, c);
35
36 final InetSocketAddress inetAddress = new InetSocketAddress(host, Integer.parseInt(port));
37
38 final Socket clientSocket = connection.getEndPoint().getTransport() instanceof Socket ? (Socket) connection
39 .getEndPoint().getTransport() : ((SocketChannel) connection.getEndPoint().getTransport()).socket();
40 final InputStream in = clientSocket.getInputStream();
41 final OutputStream out = clientSocket.getOutputStream();
42
43 final Socket socket = new Socket(inetAddress.getAddress(), inetAddress.getPort());
44
45 final Response response = connection.getResponse();
46 response.setStatus(200);
47
48 response.flushBuffer();
49
50 IO.copyThread(socket.getInputStream(), out);
51
52 IO.copyThread(in, socket.getOutputStream());
53
54 }
55
56 }