Package com.robustaweb.library.commons.exception

Examples of com.robustaweb.library.commons.exception.HttpException


                URL u;
                try {
                    u = new URL(url);
                } catch (MalformedURLException ex) {
                    throw new HttpException("malformedURI", ex);
                }

                try {
                    if (AsynchronousRestClientSun.proxy != null) {
                        http = (HttpURLConnection) u.openConnection(AsynchronousRestClientSun.proxy);
                    } else {
                        http = (HttpURLConnection) u.openConnection();
                    }
                    http.addRequestProperty("Content-type", contentType);
                    if (authorizationValue != null) {
                        http.addRequestProperty("Authorization", AsynchronousRestClientSun.authorizationValue);
                    }
                    http.setRequestMethod(method.toString());
                    http.setDoInput(true);
                    switch (method) {
                        case PUT:
                        case POST:
                            http.setDoOutput(true);
                            /* if there is something to put in the requestBody*/
                            if (requestBody != null && requestBody.length() >= 0) {
                                DataOutputStream wr = new DataOutputStream(http.getOutputStream());
                                wr.writeBytes(requestBody);
                                wr.flush();
                                wr.close();
                            }
                            break;
                    }
                    response = FileUtils.readInputStream(http.getInputStream());

                    //handling the callback
                    callCallback(callback, httpCode, response);

                } catch (IOException ex) {
                    ex.printStackTrace();
                    throw new HttpException(ex.getMessage(), ex);
                } finally {
                    clean();
                }
            }
        };
View Full Code Here


    @Override
    public void join() {
        try {
            requestThread.join();
        } catch (InterruptedException ex) {
            throw new HttpException("Can't join the client's thread : " + ex.getMessage(), ex);
        }
    }
View Full Code Here

        URL u;
        try {
            u = new URL(url);
        } catch (MalformedURLException ex) {
            throw new HttpException("malformedURI", ex);
        }

        try {

           
            if (SunRestClient.proxy != null){
                http = (HttpURLConnection) u.openConnection(SunRestClient.proxy);
            }else{
                http = (HttpURLConnection) u.openConnection();
            }
            

            http.addRequestProperty("Content-type", this.contentType);
            if (authorizationValue != null) {
                http.addRequestProperty("Authorization", SunRestClient.authorizationValue);
            }

            http.setRequestMethod(method.toString());
            http.setDoInput(true);
            switch (method) {
                case PUT:
                case POST:
                    http.setDoOutput(true);
                    /* if there is something to put in the requestBody*/
                    if (this.requestBody != null && this.requestBody.length() >= 0) {
                        DataOutputStream wr = new DataOutputStream(http.getOutputStream());
                        wr.writeBytes(requestBody);
                        wr.flush();
                        wr.close();
                    }
                    break;
            }
            this.response = FileUtils.readInputStream(http.getInputStream());
            this.responseHeaders = readHeaders(http);
           
           
          
            return this.response;
        } catch (IOException ex) {
            ex.printStackTrace();
            throw new HttpException(ex.getMessage(), ex);
        } finally {
            clean();
        }       
    }
View Full Code Here

         * @{@inheritDoc }
         */
        @Override
        public void onError(Request request, Throwable exception) {
            System.out.println("error:"+exception.getMessage());
            callback.onException(new HttpException("Unable to execute request : " + exception.getMessage(), exception));
        }
View Full Code Here

  @Override
  public void join() {
    try {
      requestThread.join();
    } catch (InterruptedException ex) {
      throw new HttpException("Can't join the client's thread : "
          + ex.getMessage(), ex);
    }
  }
View Full Code Here

            //Special case of forms && POST/PUT methods
            if (contentTypeIsForm() && (method == HttpMethod.POST || method == HttpMethod.PUT)) {
                //params will go in the requestBody
                if (requestBody != null && requestBody.length() > 0) {
                    throw new HttpException("Can't do a POST or PUT method with both parameters with 'x-www-form-urlencoded', and a non-null requestBody");
                } else {
                    //adding parameters to the requestBody
                    assert requestBody == null || requestBody.length() == 0;
                    body = encodeFormRequestBody(parameters);
                }
View Full Code Here

           
           
            return this.response;

        } catch (IOException ex) {
            throw new HttpException("IO Exception : "+ex.getMessage(), ex);
        }finally{
            clear();
        }
    }
View Full Code Here

TOP

Related Classes of com.robustaweb.library.commons.exception.HttpException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.