Java Программа которая слушает 7000 порт Битрикс24

Привет всем.

Хочу поделиться JAVA программой которая бы слушала 7000 порт на ответ от REST API Битрикс24.

Те кто в теме поймут зачем это нужно.

Есть 2 класса:

первый:

import java.io.IOException;

/**
 * Created by ruslan on 13.11.2014.
 */
public class mainClass {
    public static void main(String args[]) throws Throwable {

        mHttpServer Server = new mHttpServer();
        System.out.println("Program start");
        Server.Start();

    }
}
 и второй:

import com.sun.jndi.toolkit.url.Uri;
import org.apache.commons.io.IOUtils;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

import java.io.*;
import java.net.*;
import java.util.HashMap;
import java.util.List;

/**
 * Created by yar 09.09.2009
 */
public class mHttpServer {

    public void Start() throws Throwable  {
        ServerSocket ss = new ServerSocket(7000);
        while (true) {
           Socket s = ss.accept();
           SocketProcessor sp = new  SocketProcessor(s);
           boolean flag = sp.run();
            if (flag){
                break;
            }
        }
    }

    private static class SocketProcessor  {

        private Socket s;
        private InputStream is;
        private OutputStream os;
        private String code;

        private SocketProcessor(Socket s) throws Throwable {
            this.s = s;
            this.is = s.getInputStream();
            this.os = s.getOutputStream();
        }

        public boolean run() throws IOException {

            boolean flag = false;
            try {
                flag =  readInputHeaders();
                writeResponse("<html><body><h1><center>Запрос успешно выполнен</center></h1></body></html>");
            } catch (Exception e) {
                flag =  false;
               e.printStackTrace();
            } catch (Throwable throwable) {
                throwable.printStackTrace();
            } finally {
                    s.close();
            }

            return flag;
        }

        private void writeResponse(String s) throws Throwable {
            String response = "HTTP/1.1 200 OK\r\n" +
                    "Server: YarServer/2009-09-09\r\n" +
                    "Content-Type: text/html\r\n" +
                    "Content-Length: " + s.length() + "\r\n" +
                    "Connection: close\r\n\r\n";
            String result = response + s;
            os.write(result.getBytes());
            os.flush();
        }

        private boolean readInputHeaders() throws Throwable {
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
//            while(true) {
                String ss = br.readLine();

                ss= "http://localhost:7000"+ss.substring(4);

            URL url = new URL(ss);
            String[] mass;
            String[] subMass;
            HashMap<String, String> hm = new HashMap<String, String>();
            String s = url.getQuery();
            mass = s.split("&");
            for (String t : mass) {
                subMass = t.split("=");
                hm.put(subMass[0], (subMass[1]));
            }
            String code = hm.get("code");
            String domain = hm.get("domain");

            System.out.println("code = " + code);
            System.out.println("domain = " + domain);

            write("c:/1.txt","code="+code+"\n");

            HttpGet req = new HttpGet("http://Ваш_портал.bitrix24.ru/oauth/token/?client_id=Клиент_ID&grant_type=authorization_code&client_secret=Секретный_Ключ&redirect_uri=http%3A%2F%2Flocalhost%3A70005&code="+code+"&scope=user,task,crm");
            req.setHeader("User-Agent", "Chrome");
            CloseableHttpClient client = HttpClients.createDefault();
            CloseableHttpResponse response = client.execute(req);
            InputStream inputStream = response.getEntity().getContent();
            String result = IOUtils.toString(inputStream, "UTF-8");

            System.out.println(result);
            System.out.println(result.length());

            if (result.length()>28) {
                write("c:/2.txt",result);

            }else{

            }
            return true;
        }
    }

    public static void write(String fileName, String text) {
        //Определяем файл
        File file = new File(fileName);

        try {
            //проверяем, что если файл не существует то создаем его
            if(!file.exists()){
                file.createNewFile();
            }

            //PrintWriter обеспечит возможности записи в файл
            PrintWriter out = new PrintWriter(file.getAbsoluteFile());

            try {
                //Записываем текст у файл
                out.print(text);
            } finally {
                //После чего мы должны закрыть файл
                //Иначе файл не запишется
                out.close();
            }
        } catch(IOException e) {
            throw new RuntimeException(e);
        }
}
}

ну вот в все.
Для тех кто не разберется мой мейл:heczua@gmail.com

И кликните на google рекламу как благодарность)