Package net.virtalabs.auth.exceptions

Examples of net.virtalabs.auth.exceptions.AppException


          + cnf.get(ClientSecret) + "&" + RedirectUri + "="
          + cnf.get(RedirectUri) + "&" + GrantType + "="
          + cnf.get(GrantType);

    } catch (FileNotFoundException fileEx) {
      throw new AppException(
          "Cannot find config file. Did you copy it to server?",
          C.CONFIG_ERROR);
    } catch (JsonParseException jpe) {
      throw new AppException("Cannot parse Config. Check it manually",
          C.CONFIG_ERROR);
    }
  }
View Full Code Here


      }
      writer.close();
      reader.close();
      return result;
    } catch (MalformedURLException e) {
      throw new AppException("Got Network-related error: wrong URL",
          C.NET_ERROR);
    } catch (IOException e) {
      StringBuffer errBuffer = new StringBuffer();
      try {
        System.err.println("Code: " + conn.getResponseCode());
        InputStream is = conn.getErrorStream();
        byte[] data = new byte[is.available()];
        is.read(data);
        String body = new String(data);
        System.err.println("Google said: " + body);
        // close flows
        if (is != null) {
          is.close();
        }
        if (writer != null) {
          writer.close();
        }
        if (reader != null) {
          reader.close();
        }
        // make meanful reply in AppException
        Gson gson = new Gson();
        GoogleErrStruct jsonWithError = gson.fromJson(reader,
            GoogleErrStruct.class);
        errBuffer.append(jsonWithError.getError());
        System.err.println("Request was: " + payload);
      } catch (IOException e1) {
        throw new AppException(
            "Got Network-related error: Net I/O while reading response",
            C.NET_ERROR);
      } catch (NullPointerException npe) {
        throw new AppException(
            "Got Network-related error: Net I/O while reading response aka NPE",
            C.NET_ERROR);
      }
      throw new AppException("Got " + errBuffer.toString()
          + " error from google", C.NET_ERROR);
    }

  }
View Full Code Here

        result = result + buffer;
      }
      reader.close();
      return result;
    } catch (MalformedURLException e) {
      throw new AppException("Got Network-related error: wrong URL",
          C.NET_ERROR);
    } catch (IOException e) {
      StringBuffer errBuffer = new StringBuffer();
      try {
        System.err.println("Code: " + conn.getResponseCode());
        InputStream is = conn.getErrorStream();
        byte[] data = new byte[is.available()];
        is.read(data);
        String body = new String(data);
        System.err.println("Google said: " + body);
        // close flows
        if (is != null) {
          is.close();
        }
        if (reader != null) {
          reader.close();
        }
        // make meanful reply in AppException
        /*
         * Gson gson = new Gson(); GoogleErrStruct jsonWithError =
         * gson.fromJson(reader, GoogleErrStruct.class);
         * errBuffer.append(jsonWithError.getError());
         */
        System.err.println("Header sent was: " + payload);
      } catch (IOException e1) {
        throw new AppException(
            "Got Network-related error: Net I/O while reading response",
            C.NET_ERROR);
      } catch (NullPointerException npe) {
        throw new AppException(
            "Got Network-related error: Net I/O while reading response aka NPE",
            C.NET_ERROR);
      }
      throw new AppException("Got " + errBuffer.toString()
          + " error from google", C.NET_ERROR);
    }

    // return "";
  }
View Full Code Here

    String code = appData.getCode();
    // 1)make request to Google Server (POST)
    String postBody = NetWork.makeLink(code);
    String tokenJson = NetWork.getAccessToken(postBody);
    if (tokenJson == null) {
      throw new AppException("Google is silent", C.GENERAL_ERROR);
    }
    // 2)handle Reply (access_token, expires_in)

    GoogleTokenStruct tokenStruct = gson.fromJson(tokenJson,
        GoogleTokenStruct.class);
View Full Code Here

  static GoogleAuthStruct read(String input) throws AppException{
    try{
      GoogleAuthStruct data = gson.fromJson(input, GoogleAuthStruct.class);
      return data;
    }catch (JsonParseException jpe){
      throw new AppException("Failed to parse json",C.WRONG_JSON);
    }
  }
View Full Code Here

      return net.virtalabs.auth.mod.auth.self.SelfAuth.run(modData);
    } else if(provider.equals("google")){
      GoogleAuthStruct modData = (GoogleAuthStruct) StdRx.read(rawData, GoogleAuthStruct.class);
      return net.virtalabs.auth.mod.auth.google.GoogleAuth.run(modData);
    } else {
      throw new AppException("Provider unsupported yet",C.NO_SUCH_PROVIDER);
    }
  }
View Full Code Here

 
   public static StdRxStruct read(String json,Type type) throws AppException{
     try{
     return gson.fromJson(json,type);
     }catch(JsonParseException jpe){
       throw new AppException("Param must be valid JSON. See API",C.WRONG_JSON);
     }
   }
View Full Code Here

public class Router {

  public static String route(String json) throws AppException {
      //test if json if not empty
      if(json.length()==0){
        throw new AppException("Provided JSON is empty",C.EMPTY_JSON);
      }
      //Rx
      String action = Router.getAction(json);

      if(action.equals("auth")){
        //auth
        return Auth.run(json);
      } else if(action.equals("register")){
        //register
        RegisterStruct modData = (RegisterStruct) StdRx.read(json,RegisterStruct.class);
        //TODO data checker
        return net.virtalabs.auth.mod.register.Register.run(modData);
      } else if(action.equals("checkToken")) {
        //checkToken
        CheckTokenStruct modData = (CheckTokenStruct) StdRx.read(json, CheckTokenStruct.class);
        return net.virtalabs.auth.mod.checkToken.CheckToken.run(modData);
      } else {
        throw new AppException("No such action here",C.NO_SUCH_ACTION);
      }
  }
View Full Code Here

      if(action == null){
        throw new NullPointerException();
      }
      return action;
    }catch (NullPointerException npe) {
      throw new AppException("There is no action key in JSON. See API",C.WRONG_JSON);
    }
   }
View Full Code Here

TOP

Related Classes of net.virtalabs.auth.exceptions.AppException

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.