Wysyłanie i parsowanie odpowiedzi przy użyciu klienta HTTP dla listy JSON

W moim kodzie java muszę wysłać żądanie http do określonego adresu URL z 3 nagłówkami:

URL: http://localhost/something
Referer: http://localhost/something 
Authorization: Basic (with a username and password)
Content-type: application/json

Zwraca to odpowiedź z parą JSON „klucz”: „wartość”, którą następnie muszę jakoś przeanalizować, aby zapisać klucz / wartość (Alan / 72) w MAP. Odpowiedź brzmi (gdy używasz SOAPUI lub Postman Rest):

    {
    "analyzedNames": [
        {
            "alternate": false               
        }
    ],
    "nameResults": [
        {
            "alternate": false,            
            "givenName": "John",           
            "nameCategory": "PERSONAL",
            "originalGivenName": "",
            "originalSurname": "",           
            "score": 72,
            "scriptType": "NOSCRIPT",            
        }
    ]
}

Mogę to zrobić za pomocą SOAPUI lub Postman Rest, ale jak mogę to zrobić w Javie, ponieważ pojawia się błąd:

****DEBUG main org.apache.http.impl.conn.DefaultClientConnection - Receiving response: HTTP/1.1 500 Internal Server Error****

Mój kod to:

    public class NameSearch {

        /**
         * @param args
         * @throws IOException 
         * @throws ClientProtocolException 
         */
        public static void main(String[] args) throws ClientProtocolException, IOException {
            // TODO Auto-generated method stub
            DefaultHttpClient defaultHttpClient = new DefaultHttpClient();          
            StringWriter writer = new StringWriter();

            //Define a postRequest request
            HttpPost postRequest = new HttpPost("http://127.0.0.1:1400/dispatcher/api/rest/search");

            //Set the content-type header
            postRequest.addHeader("content-type", "application/json");
 postRequest.addHeader("Authorization", "Basic ZW5zYWRtaW46ZW5zYWRtaW4=");

            try {               

                //Set the request post body
                StringEntity userEntity = new StringEntity(writer.getBuffer().toString());
                postRequest.setEntity(userEntity);

                //Send the request; return the response in HttpResponse object if any
                HttpResponse response = defaultHttpClient.execute(postRequest);

                //verify if any error code first
                int statusCode = response.getStatusLine().getStatusCode();                
            }
            finally
            {
                //Important: Close the connect
                defaultHttpClient.getConnectionManager().shutdown();
            }    
        }    
    }

Każda pomoc (z przykładowym kodem, w tym bibliotekami do zaimportowania) będzie najbardziej doceniana.

DZIĘKI

questionAnswers(2)

yourAnswerToTheQuestion