Package hirondelle.web4j.model

Examples of hirondelle.web4j.model.AppException


    File file = new File(imageFilePath);
    try {
      fFileItem.write(file);
    }
    catch(Exception ex){
      throw new AppException("Cannot save file.", ex);
    }
  }
View Full Code Here


        //close streams, clean up resources
        out.close();
      }
    }
    catch (IOException ex) {
      throw new AppException("Cannot generate binary output.", ex);
    }
    return getResponsePage();
  }
View Full Code Here

      Preferences prefs = dao.fetch(SafeText.from(userName));
      fLogger.fine("Adding language/locale preference to session: " + prefs.getLocale());
      aSession.setAttribute(Controller.LOCALE, prefs.getLocale());
    }
    catch (DAOException ex){
      throw new AppException("Cannot fetch language preference from database.", ex);
    }
  }
View Full Code Here

      fLogger.fine("Adding user id and screen name to session");
      aSession.setAttribute(ActionImpl.USER_ID, prefs.getUserId());
      aSession.setAttribute(Preferences.SCREEN_NAME, prefs.getScreenName());
    }
    catch (DAOException ex){
      throw new AppException("Cannot fetch Preferences from database.", ex);
    }
  }
View Full Code Here

   <P>Extract the <a href="#URIMappingString">URI Mapping String</a> from the underlying request, and
   map it to an {@link Action}.
  */
  @Override public final Action getWebAction() {
    Action result = null;
    AppException problem = new AppException();
    Class webAction = fUriToActionMapping.get(fURIMappingString);
    if ( webAction == null ) {
      throw new RuntimeException("Cannot map URI to an Action class : " + Util.quote(fURIMappingString));
    }
   
    Class[] ctorArgs = {RequestParser.class};
    try {
      Constructor ctor = webAction.getConstructor(ctorArgs);
      result = (Action)ctor.newInstance(new Object[]{this});
    }
    catch(NoSuchMethodException ex){
      problem.add("Action does not have public constructor having single argument of type 'RequestParser'.");
    }
    catch(InstantiationException ex){
      problem.add("Cannot call Action constructor using reflection (class is abstract). " + ex);
    }
    catch(IllegalAccessException ex){
      problem.add("Cannot call Action constructor using reflection (constructor not public). " + ex);
    }
    catch(IllegalArgumentException ex){
      problem.add("Cannot call Action constructor using reflection. " + ex);
    }
    catch(InvocationTargetException ex){
      String message = ex.getCause() == null ? ex.toString() : ex.getCause().getMessage();
      problem.add("Cannot call Action constructor using reflection (constructor threw exception). " + message);
    }
   
    if( problem.isNotEmpty() ){
      throw new RuntimeException("Problem constructing Action for URI " + Util.quote(fURIMappingString) + " " + Util.logOnePerLine(problem.getMessages()));
    }
    fLogger.info("URI " + Util.quote(fURIMappingString) + " successfully mapped to an instance of " + webAction);
   
    return result;
  }
View Full Code Here

  private static final Logger fLogger = Util.getLogger(RequestParserImpl.class);
 
  private static void scanMappings(){
    fUriToActionMapping.clear(); //needed for reloading application : reloading app does not reload this class.
    Set<Class<Action>> actionClasses = ConfigReader.fetchConcreteClassesThatImplement(Action.class);
    AppException problems = new AppException();
    for(Class<Action> actionClass: actionClasses){
      Field explicitMappingField = null;
      try {
        explicitMappingField = actionClass.getField(EXPLICIT_URI_MAPPING);
      }
      catch (NoSuchFieldException ex){
        addMapping(actionClass,  getImplicitURI(actionClass), problems);
        continue;
      }
      addExplicitMapping(actionClass, explicitMappingField, problems);
    }
    //ensure that any problems will cause a failure to startup
    //thus, runtime exception are replaced with startup time exceptions
    if ( problems.isNotEmpty() ) {
      throw new RuntimeException("Problem(s) occurred while creating mapping of URIs to WebActions. " + Util.logOnePerLine(problems.getMessages()));
    }
  }
View Full Code Here

          try {
            T convertedItem  = fConvertUserInput.convert(filteredValue, aSupportedTargetClass, fLocale, fTimeZone);
            result.add(convertedItem);
          }
          catch (ModelCtorException ex){
            AppException conversionEx = fConversionError.get(aSupportedTargetClass, filteredValue, aReqParam);
            conversionExceptions.add(conversionEx);
          }
        }
        else {
          result.add(null);
View Full Code Here

  private String getWebmasterEmailAddress() {
    return WEBMASTER.getValue();
  }

  private void validateState(String aFrom, List<String> aToAddresses, String aSubject, String aBody) throws AppException {
    AppException ex = new AppException();
    if (!WebUtil.isValidEmailAddress(aFrom)) {
      ex.add("From-Address is not a valid email address.");
    }
    if (!Util.textHasContent(aSubject)) {
      ex.add("Email subject has no content");
    }
    if (!Util.textHasContent(aBody)) {
      ex.add("Email body has no content");
    }
    for(String email: aToAddresses){
      if (!WebUtil.isValidEmailAddress(email)) {
        ex.add("To-Address is not a valid email address: " + Util.quote(email));
      }
    }
    if (ex.isNotEmpty()) {
      fLogger.severe("Cannot send email : " + ex);
      throw ex;
    }
  }
View Full Code Here

      message.setText(aBody);
      Transport.send(message); // thread-safe?
    }
    catch (Throwable ex) {
      fLogger.severe("CANNOT SEND EMAIL: " + ex);
      throw new AppException("Cannot send email", ex);
    }
    fLogger.fine("Mail is sent.");
  }
View Full Code Here

    addLine("Web application Build Date: " + fAppInfo.getBuildDate());
    addLine("Web application Author : " + fAppInfo.getAuthor());
    addLine("Web application Link : " + fAppInfo.getLink());
    addLine("Web application Message : " + fAppInfo.getMessage());
    if ( fException instanceof AppException ) {
      AppException appEx = (AppException)fException;
      Iterator errorsIter = appEx.getMessages().iterator();
      while ( errorsIter.hasNext() ) {
        addLine( errorsIter.next().toString() );
      }
    }
  }
View Full Code Here

TOP

Related Classes of hirondelle.web4j.model.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.