0

I'm doing webService Call in java it's working well,but i need to SetTimout for the connection. Below is my requirement.

  • maximum time i need to set is 2 minutes. if that time is reached the connection should disconnect.

Here is my code for connection establish,getting response back.

ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
            String urlParameters = ow.writeValueAsString(something);
            urlParameters = "{ \"something\":" + urlParameters + "}" ;
            byte[] postData       = urlParameters.getBytes( StandardCharsets.UTF_8 );
            int    postDataLength = postData.length;
            String request        = "http://something.com";
            url = new URL( request );
            postConnection = (HttpURLConnection) url.openConnection();    
            postConnection.setDoOutput( true );
            postConnection.setInstanceFollowRedirects( false );
            postConnection.setRequestMethod( "POST" );
            postConnection.setRequestProperty( "Content-Type", "application/json"); 
                DataOutputStream wr = new DataOutputStream( postConnection.getOutputStream());
                    wr.write( postData );
                    wr.flush();
                    wr.close();


                BufferedReader in = new BufferedReader(
                        new InputStreamReader(postConnection.getInputStream()));

Thanx for help

0 Answers0