Page 1 of 1

About Question enthuware.ocejws.v6.2.203 :

Posted: Sat Nov 01, 2014 12:54 pm
by austinor
There's another approach for Java SE clients of web services (one of my favorites):

Sockets.

Code: Select all

    Socket socket = new Socket(); 
    socket.connect( new InetSocketAddress(InetAddress.getByName(host),port), timeout );

    BufferedWriter reqWrtr = new BufferedWriter( 
                                                   new OutputStreamWriter( socket.getOutputStream(),"UTF-8" )); 
    ... 

    BufferedReader respRdr = new BufferedReader( 
                                                    new InputStreamReader( socket.getInputStream() ) ); 
    ... 


Re: About Question enthuware.ocejws.v6.2.203 :

Posted: Sun Nov 02, 2014 3:06 am
by fjwalraven
That is a nice one!

... but you won't find that one on the exam.

Regards,
Frits

Re: About Question enthuware.ocejws.v6.2.203 :

Posted: Mon Nov 14, 2016 2:27 pm
by johnlong
Isn't necessary to do the following :

Code: Select all

connection.setDoInput(true);

Re: About Question enthuware.ocejws.v6.2.203 :

Posted: Mon Nov 14, 2016 2:45 pm
by fjwalraven
Isn't necessary to do the following :
Yes, you are right that isn't necessary as the input flag is true by default.

Regards,
Frits

Re: About Question enthuware.ocejws.v6.2.203 :

Posted: Wed Nov 23, 2016 12:01 pm
by johnlong
URLConnection connection = (URLConnection) restURL.openConnection();

Is cast necessary here?

Re: About Question enthuware.ocejws.v6.2.203 :

Posted: Wed Nov 23, 2016 12:29 pm
by fjwalraven
No, you are right that is not necessary.

Regards,
Frits

Re: About Question enthuware.ocejws.v6.2.203 :

Posted: Thu Jun 14, 2018 2:19 pm
by witek_m
Hello, in the second answer:

Code: Select all

public static void main(String[]args)throwsIOException
        {  
    
            URLrestURL = newURL("http://localhost:8080/SimpleRS/jax/rs/add/5/8");      
            HttpURLConnectionconnection = (HttpURLConnection) restURL.openConnection();      
            connection.setRequestMethod("GET");      
            connection.setReadTimeout(10000);      
            connection.connect();          
            InputStreamReaderins = newInputStreamReader(connection.getInputStream());      
            BufferedReaderin = newBufferedReader(ins);      StringinputLine;      
            while ((inputLine = in.readLine()) != null) {         
                System.out.println(inputLine);      
            }      
            in.close();   
        }
is it not required to add a connection.setDoOutput(true)?

Re: About Question enthuware.ocejws.v6.2.203 :

Posted: Thu Jun 14, 2018 2:31 pm
by fjwalraven
is it not required to add a connection.setDoOutput(true)?
No, with a GET you will only read from the connection (DoOutput is for a POST)

Regards,
Frits

Re: About Question enthuware.ocejws.v6.2.203 :

Posted: Fri Jun 15, 2018 12:17 pm
by witek_m
Yes, my mistake.