Package com.github.kevinsawicki.http

Examples of com.github.kevinsawicki.http.HttpRequest$CloseOperation


    mPassword = pPassword;
    return this;
  }

  protected HttpRequest createRequest(BankRequest pBankRequest, String pMethod) {
    HttpRequest vHttpRequest = null;
    if (HttpRequest.METHOD_POST.equals(pMethod)) {
      vHttpRequest = new HttpRequest(pBankRequest.getUri(), pMethod);
    } else {
      vHttpRequest = new HttpRequest(pBankRequest.generateUri(), pMethod);
    }
    vHttpRequest.userAgent(USER_AGENT);
    modifyRequest(pBankRequest);
    for (Entry<String, String> header : pBankRequest.getHeaders().entrySet()) {
      vHttpRequest.header(header.getKey(), header.getValue());
    }
    return vHttpRequest;
  }
View Full Code Here


    }

    if (getCache().exists(pBankRequest)) {
      return getCache().get(pBankRequest);
    }
    HttpRequest request = createRequest(pBankRequest, pMethod);
    if (HttpRequest.METHOD_POST.equals(pMethod)) {
      request.form(pBankRequest.getParams());
    }
    request.code();
    BankResponse response = new DefaultBankResponse(request);
    getCache().put(pBankRequest, response);
    return response;
  }
View Full Code Here

        JSONObject postData = new JSONObject();
        postData.put("session_id", JSONObject.NULL);
        postData.put("context", new JSONObject());

        HttpRequest firstConnection = this.JsonRpc(getURLForMethod("session", "get_session_info"), "call", postData );

        // We retrieve and store werkzeug session cookie
        String cookies = firstConnection.header("Set-Cookie");
        _cookies = HttpCookie.parse(cookies);

        // We retrieve and store OpenERP session_id
        JSONObject body = new JSONObject(firstConnection.body());
        this._sessionId = (String) body.getJSONObject("result").get("session_id");
    }
View Full Code Here

        _defaultContext.put("lang", language);
    }

    public HttpRequest JsonRpc( String url, String method, JSONObject args) {

        HttpRequest request = HttpRequest.post(url);

        // We re-inject sid cookie
        if( !this._cookies.isEmpty() ) {
            StringBuffer cookieHeader = new StringBuffer();
            for( HttpCookie cookie : this._cookies) {
                cookieHeader.append(cookie.toString());
                cookieHeader.append(';');
            }
            request.header("Cookie", cookieHeader.toString());
        };

        JSONObject postData = new JSONObject();
        postData.put("json-rpc", "2.0");
        postData.put("method", method);
        postData.put("params", args);
        postData.put("id", "r"+this._rid);

        this._rid++;

        // set content type to json
        request.contentType(HttpRequest.CONTENT_TYPE_JSON);
        request.acceptJson();
        request.send(postData.toString());

        // We force method call
        int statusCode = request.code();

        if( statusCode != 200 ) {
            // Here, user failed to provide a valid URL so either, method or service is incorrect
            throw new OpenERPServiceOrMethodException("URL="+url);
        };
View Full Code Here

        if(this._sessionId!=null) {
            params.put("session_id", this._sessionId);
        }

        HttpRequest request = JsonRpc( url, method, params);
        JSONObject jsonResponse = new JSONObject(request.body());

        if (logger.isTraceEnabled()) logger.trace("OpenERP Response: {} ", jsonResponse );

        try {
            Object result = jsonResponse.get("result");
View Full Code Here

  public void addAuthenticationInfo( AuthenticationInfo authentication ) {
    authentications.add( authentication );
  }

  public Response get() {
    HttpRequest request = HttpRequest.get( url );
    addContentType( request );
    addHeaders( request );
    addAuthentication( request );
    sendRequest( request );
    return new ResponseImpl( request );
View Full Code Here

    sendRequest( request );
    return new ResponseImpl( request );
  }

  public Response post() {
    HttpRequest request = HttpRequest.post( url );
    addContentType( request );
    addHeaders( request );
    addAuthentication( request );
    request.send( content );
    sendRequest( request );
    return new ResponseImpl( request );
  }
View Full Code Here

    sendRequest( request );
    return new ResponseImpl( request );
  }
 
  public Response delete() {
    HttpRequest request = HttpRequest.delete( url );
    addContentType( request );
    addHeaders( request );
    addAuthentication( request );
    sendRequest( request );
    return new ResponseImpl( request );
View Full Code Here

    sendRequest( request );
    return new ResponseImpl( request );
  }
 
  public Response put() {
    HttpRequest request = HttpRequest.put( url );
    addContentType( request );
    addHeaders( request );
    addAuthentication( request );
    request.send( content );
    sendRequest( request );
    return new ResponseImpl( request );
  }
View Full Code Here

    sendRequest( request );
    return new ResponseImpl( request );
  }
 
  public Response head() {
    HttpRequest request = HttpRequest.head( url );
    addContentType( request );
    addHeaders( request );
    addAuthentication( request );
    sendRequest( request );
    return new ResponseImpl( request );
View Full Code Here

TOP

Related Classes of com.github.kevinsawicki.http.HttpRequest$CloseOperation

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.