Bład serwera HTTPServer wysyłającego własne zapytania

0

Witam,

Probacje napisać serwer, który nasłuchuje requestu, a jak takowy się pojawi to wysyła reguest do nowego hosta, czeka na odpowiedź i odpowiada na pierwszy request kodem statusu połaczenia jak tekst strony (brzmi trochę bezsensownie, ale to zaledwie mały kawałek większej budowy :)). Mój kod:

import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.util.Scanner;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;

public class ServerHTTP{

    public static void main(String[] args) throws Exception {
        HttpServer server = HttpServer.create(new InetSocketAddress(8000), 0);
        server.createContext("/", new MyHandler());
        server.setExecutor(null); // creates a default executor
        server.start();
    }

    static class MyHandler implements HttpHandler {
        @Override
        public void handle(HttpExchange t) throws IOException {
        	CloseableHttpClient httpclient = HttpClients.createDefault();

            //Creating a HttpGet object
            HttpGet httpget = new HttpGet("https://www.google.com/ ");

            //Printing the method used
            System.out.println("Request Type: "+httpget.getMethod());

            //Executing the Get request
            HttpResponse httpresponse = httpclient.execute(httpget);

            Scanner sc = new Scanner(httpresponse.getEntity().getContent());

            //Printing the status line
            System.out.println(httpresponse.getStatusLine());
            
            while(sc.hasNext()) {
               System.out.println(sc.nextLine());
            }
            
            String response = ""+ httpresponse.getStatusLine().getStatusCode();
            
            t.sendResponseHeaders(200, response.length());
            OutputStream os = t.getResponseBody();
            os.write(response.getBytes());
            os.close();
        }
    }

}

Niestety jest zwracany błąd dla linii

CloseableHttpClient httpclient = HttpClients.createDefault();

o treści:

Exception in thread "Thread-2" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory

W czym tkwi problem i jak to naprawić?

1 użytkowników online, w tym zalogowanych: 0, gości: 1