public Object invokeMethod ( String method , Object [ ] params ) { log . debug ( "invokeMethod url: {}" , ( url + appendToUrl ) ) ; IoBuffer resultBuffer = null ; IoBuffer data = encodeInvoke ( method , params ) ; //setup POST HttpPost post = null ; try { post = new HttpPost ( url + appendToUrl ) ; post . addHeader ( "Content-Type" , CONTENT_TYPE ) ; post . setEntity ( new InputStreamEntity ( data . asInputStream ( ) , data . limit ( ) ) ) ; // execute the method HttpResponse response = client . execute ( post ) ; int code = response . getStatusLine ( ) . getStatusCode ( ) ; log . debug ( "HTTP response code: {}" , code ) ; if ( code / 100 != 2 ) { throw new RuntimeException ( "Didn't receive success from remoting server" ) ; } else { HttpEntity entity = response . getEntity ( ) ; if ( entity != null ) { //fix for Trac #676 int contentLength = ( int ) entity . getContentLength ( ) ; //default the content length to 16 if post doesn't contain a good value if ( contentLength < 1 ) { contentLength = 16 ; } // get the response as bytes byte [ ] bytes = EntityUtils . toByteArray ( entity ) ; resultBuffer = IoBuffer . wrap ( bytes ) ; Object result = decodeResult ( resultBuffer ) ; if ( result instanceof RecordSet ) { // Make sure we can retrieve paged results ( ( RecordSet ) result ) . setRemotingClient ( this ) ; } return result ; } } } catch ( Exception ex ) { log . error ( "Error while invoking remoting method: {}" , method , ex ) ; post . abort ( ) ; } finally { if ( resultBuffer != null ) { resultBuffer . free ( ) ; resultBuffer = null ; } data . free ( ) ; data = null ; } return null ; }
Invoke a method synchronously on the remoting server .