Package net.thegreshams.firebase4j.model

Examples of net.thegreshams.firebase4j.model.FirebaseResponse


    // create the firebase
    Firebase firebase = new Firebase( firebase_baseUrl );
   
   
    // "DELETE" (the fb4jDemo-root)
    FirebaseResponse response = firebase.delete();
 

    // "PUT" (test-map into the fb4jDemo-root)
    Map<String, Object> dataMap = new LinkedHashMap<String, Object>();
    dataMap.put( "PUT-root", "This was PUT into the fb4jDemo-root" );
View Full Code Here


    String url = this.buildFullUrlFromRelativePath( path );
    HttpGet request = new HttpGet( url );
    HttpResponse httpResponse = this.makeRequest( request );
   
    // process the response
    FirebaseResponse response = this.processResponse( FirebaseRestMethod.GET, httpResponse );
   
    return response;
  }
View Full Code Here

    HttpPut request = new HttpPut( url );
    request.setEntity( this.buildEntityFromDataMap( data ) );
    HttpResponse httpResponse = this.makeRequest( request );
   
    // process the response
    FirebaseResponse response = this.processResponse( FirebaseRestMethod.PUT, httpResponse );
   
    return response;
  }
View Full Code Here

    HttpPut request = new HttpPut( url );
    request.setEntity( this.buildEntityFromJsonData( jsonData ) );
    HttpResponse httpResponse = this.makeRequest( request );
   
    // process the response
    FirebaseResponse response = this.processResponse( FirebaseRestMethod.PUT, httpResponse );
   
    return response;   
  }
View Full Code Here

    HttpPost request = new HttpPost( url );
    request.setEntity( this.buildEntityFromDataMap( data ) );
    HttpResponse httpResponse = this.makeRequest( request );
   
    // process the response
    FirebaseResponse response = this.processResponse( FirebaseRestMethod.POST, httpResponse );
   
    return response;
  }
View Full Code Here

    HttpPost request = new HttpPost( url );
    request.setEntity( this.buildEntityFromJsonData( jsonData ) );
    HttpResponse httpResponse = this.makeRequest( request );
   
    // process the response
    FirebaseResponse response = this.processResponse( FirebaseRestMethod.POST, httpResponse );
   
    return response;
  }
View Full Code Here

    String url = this.buildFullUrlFromRelativePath( path );
    HttpDelete request = new HttpDelete( url );
    HttpResponse httpResponse = this.makeRequest( request );
   
    // process the response
    FirebaseResponse response = this.processResponse( FirebaseRestMethod.DELETE, httpResponse );
   
    return response;
  }
View Full Code Here

    return response;
  }
 
  private FirebaseResponse processResponse( FirebaseRestMethod method, HttpResponse httpResponse ) throws FirebaseException {
 
    FirebaseResponse response = null;

    // sanity-checks
    if( method == null ) {
     
      String msg = "method cannot be null";
      LOGGER.error( msg );
      throw new FirebaseException( msg );
    }
    if( httpResponse == null ) {
     
      String msg = "httpResponse cannot be null";
      LOGGER.error( msg );
      throw new FirebaseException( msg );
    }
   
    // get the response-entity
    HttpEntity entity = httpResponse.getEntity();
   
    // get the response-code
    int code = httpResponse.getStatusLine().getStatusCode();
   
    // set the response-success
    boolean success = false;
    switch( method ) {
      case DELETE:
        if( httpResponse.getStatusLine().getStatusCode() == 204
          && "No Content".equalsIgnoreCase( httpResponse.getStatusLine().getReasonPhrase() ) )
        {
          success = true;
        }
        break;
      case PUT:
      case POST:
      case GET:
        if( httpResponse.getStatusLine().getStatusCode() == 200
          && "OK".equalsIgnoreCase( httpResponse.getStatusLine().getReasonPhrase() ) )
        {
          success = true;
        }
        break;
      default:
        break;
       
    }
   
    // get the response-body
    Writer writer = new StringWriter();
    if( entity != null ) {
     
      try {
       
        InputStream is = entity.getContent();
        char[] buffer = new char[1024];
        Reader reader = new BufferedReader( new InputStreamReader( is, "UTF-8" ) );
        int n;
        while( (n=reader.read(buffer)) != -1 ) {
          writer.write( buffer, 0, n );
        }
       
      } catch( Throwable t ) {
       
        String msg = "unable to read response-content; read up to this point: '" + writer.toString() + "'";
        writer = new StringWriter(); // don't want to later give jackson partial JSON it might choke on
        LOGGER.error( msg );
        throw new FirebaseException( msg, t );
       
      }
    }
   
    // convert response-body to map
    Map<String, Object> body = null;
    try {
     
      body = JacksonUtility.GET_JSON_STRING_AS_MAP( writer.toString() );
     
    } catch( JacksonUtilityException jue ) {
     
      String msg = "unable to convert response-body into map; response-body was: '" + writer.toString() + "'";
      LOGGER.error( msg );
      throw new FirebaseException( msg, jue );
    }
   
    // build the response
    response = new FirebaseResponse( success, code, body, writer.toString() );
   
    return response;
  }
View Full Code Here

TOP

Related Classes of net.thegreshams.firebase4j.model.FirebaseResponse

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.