public static Response call(String server, String service, boolean suppress, String... params) {
        try {
            URL url = new URL(server + '/' + service);
            URLConnection connection = url.openConnection();
            connection.setDoOutput(true);
            connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
            PrintWriter pw = new PrintWriter(new OutputStreamWriter(connection.getOutputStream(), "utf-8"));
            for (String param: params) {
                _logger.fine(param);
                pw.print(param); pw.print('&');
            }
            pw.close();
            InputStream in = connection.getInputStream();
            try {
                byte[] bytes = Bytes.read(in);
                try {
                    Response response = _mapper.readValue(bytes, Response.class).setResponseBody(bytes);
                    if (response.params == null) {
                        throw new ServiceException("***ProtocolErrorMissingParams");
                    } else if (!suppress) {
                        String message = response.params.get(Service.FAILURE_MESSAGE);
                        if (message != null && message.length() > 0) {
                            throw new RemoteServiceException(message);
                        }
                    }
                    return response;
                } catch (JsonProcessingException x) {
                    _logger.log(Level.WARNING, new String(bytes, "UTF-8"));
                    throw x;
                }
            } finally {
                in.close();
            }
        } catch (RuntimeException x) {
            throw x;
        } catch (Exception x) {
            throw new ServiceException("***RemoteServiceCallFailure", x);
        }
    }
public static Response call ( String server , String service , boolean suppress , String ... params ) { try { URL url = new URL ( server + '/' + service ) ; URLConnection connection = url . openConnection ( ) ; connection . setDoOutput ( true ) ; connection . setRequestProperty ( "Content-Type" , "application/x-www-form-urlencoded;charset=utf-8" ) ; PrintWriter pw = new PrintWriter ( new OutputStreamWriter ( connection . getOutputStream ( ) , "utf-8" ) ) ; for ( String param : params ) { _logger . fine ( param ) ; pw . print ( param ) ; pw . print ( '&' ) ; } pw . close ( ) ; InputStream in = connection . getInputStream ( ) ; try { byte [ ] bytes = Bytes . read ( in ) ; try { Response response = _mapper . readValue ( bytes , Response . class ) . setResponseBody ( bytes ) ; if ( response . params == null ) { throw new ServiceException ( "***ProtocolErrorMissingParams" ) ; } else if ( ! suppress ) { String message = response . params . get ( Service . FAILURE_MESSAGE ) ; if ( message != null && message . length ( ) > 0 ) { throw new RemoteServiceException ( message ) ; } } return response ; } catch ( JsonProcessingException x ) { _logger . log ( Level . WARNING , new String ( bytes , "UTF-8" ) ) ; throw x ; } } finally { in . close ( ) ; } } catch ( RuntimeException x ) { throw x ; } catch ( Exception x ) { throw new ServiceException ( "***RemoteServiceCallFailure" , x ) ; } }
Calls a remote service with a list of "name=value" string values as arguments.