/**
   * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest,
   *     javax.servlet.http.HttpServletResponse)
   */
  protected void service(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    if (!initParams.getEnabled()) {
      response.sendError(HttpServletResponse.SC_NOT_FOUND);
      return;
    }

    long startTime = 0;
    if (logger.isTraceEnabled()) {
      startTime = System.currentTimeMillis();
    }

    FileFilterMode.setClient(Client.webdav);

    try {
      // Create the appropriate WebDAV method for the request and execute it
      final WebDAVMethod method = createMethod(request, response);

      if (method == null) {
        if (logger.isErrorEnabled())
          logger.error("WebDAV method not implemented - " + request.getMethod());

        // Return an error status

        response.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED);
        return;
      } else if (method.getRootNodeRef() == null) {
        if (logger.isDebugEnabled()) {
          logger.debug(
              "No root node for request ["
                  + request.getMethod()
                  + " "
                  + request.getRequestURI()
                  + "]");
        }

        // Return an error status
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return;
      }

      // Execute the WebDAV request, which must take care of its own transaction
      method.execute();
    } catch (Throwable e) {
      ExceptionHandler exHandler = new ExceptionHandler(e, request, response);
      exHandler.handle();
    } finally {
      if (logger.isTraceEnabled()) {
        logger.trace(
            request.getMethod()
                + " took "
                + (System.currentTimeMillis() - startTime)
                + "ms to execute ["
                + request.getRequestURI()
                + "]");
      }

      FileFilterMode.clearClient();
    }
  }
Exemplo n.º 2
0
  /**
   * Ask our exception handler to handle the exception. Return the <code>ActionForward</code>
   * instance (if any) returned by the called <code>ExceptionHandler</code>.
   *
   * @param request The servlet request we are processing
   * @param response The servlet response we are processing
   * @param exception The exception being handled
   * @param form The ActionForm we are processing
   * @param mapping The ActionMapping we are using
   * @return The <code>ActionForward</code> instance (if any) returned by the called <code>
   *     ExceptionHandler</code>.
   * @throws IOException if an input/output error occurs
   * @throws ServletException if a servlet exception occurs
   */
  protected ActionForward processException(
      HttpServletRequest request,
      HttpServletResponse response,
      Exception exception,
      ActionForm form,
      ActionMapping mapping)
      throws IOException, ServletException {
    // Is there a defined handler for this exception?
    ExceptionConfig config = mapping.findException(exception.getClass());

    if (config == null) {
      log.warn(getInternal().getMessage("unhandledException", exception.getClass()));

      if (exception instanceof IOException) {
        throw (IOException) exception;
      } else if (exception instanceof ServletException) {
        throw (ServletException) exception;
      } else {
        throw new ServletException(exception);
      }
    }

    // Use the configured exception handling
    try {
      ExceptionHandler handler =
          (ExceptionHandler) RequestUtils.applicationInstance(config.getHandler());

      return (handler.execute(exception, config, mapping, form, request, response));
    } catch (Exception e) {
      throw new ServletException(e);
    }
  }
Exemplo n.º 3
0
  public void onException(ErrorMessage msg) throws MuleException {
    Class eClass = null;
    ExceptionHandler eh = null;

    try {
      eClass = msg.getException().toException().getClass();
      eh = getHandler(eClass);
      eh.onException(msg);
    } catch (Exception e) {
      logger.error(e);

      if (eh instanceof DefaultHandler) {
        logger.error(LocaleMessage.defaultFatalHandling(FatalHandler.class));
        handleFatal(e);

      } else if (eh instanceof FatalHandler) {
        logger.fatal(LocaleMessage.fatalHandling(e));
        MuleServer.getMuleContext().dispose();
        System.exit(-1);
      } else {
        logger.error(LocaleMessage.defaultHandling(DefaultHandler.class, eh, e));
        handleDefault(msg, e);
      }
    }
  }
Exemplo n.º 4
0
 // Returns instance of required class. It checks package access (security)
 // unless it is defaultClassname. It means if you are trying to instantiate
 // default implementation (fallback), pass the class name to both first and second parameter.
 static <T extends Exception> Object newInstance(
     String className, String defaultImplClassName, final ExceptionHandler<T> handler) throws T {
   try {
     return safeLoadClass(className, defaultImplClassName, contextClassLoader(handler))
         .newInstance();
   } catch (ClassNotFoundException x) {
     throw handler.createException(x, "Provider " + className + " not found");
   } catch (Exception x) {
     throw handler.createException(
         x, "Provider " + className + " could not be instantiated: " + x);
   }
 }
 /**
  * Generate handler info for exception with the generated instructions.
  *
  * @param insts the generated instructions.
  * @return handlers of exception for classfile.
  */
 public HandlerInfo[] getHandlerInfos(Instruction[] insts) {
   HandlerInfo[] handlers = info.getHandlers();
   for (int i = 0; i < handlers.length; ++i) {
     HandlerInfo handler = handlers[i];
     ExceptionHandler eh = exceptionHandlers[i];
     eh.searchIndex();
     handler.setStart(insts[eh.getStart()]);
     handler.setEnd(insts[eh.getEnd()]);
     handler.setHandler(insts[eh.getHandle()]);
   }
   return handlers;
 }
Exemplo n.º 6
0
  /**
   * Running Maven under JDK7 may cause connection issues because IPv6 is used by default.
   *
   * <p>e.g running mvn site:run will cause Jetty to fail.
   *
   * <p>The resolution is to add -Djava.net.preferIPv4Stack=true to the command line as documented
   * in http://cwiki.apache.org/confluence/display/MAVEN/ConnectException
   */
  public void testJdk7ipv6() {
    ConnectException connEx = new ConnectException("Connection refused: connect");
    IOException ioEx = new IOException("Unable to establish loopback connection");
    ioEx.initCause(connEx);
    MojoExecutionException mojoEx =
        new MojoExecutionException(
            "Error executing Jetty: Unable to establish loopback connection", ioEx);

    ExceptionHandler exceptionHandler = new DefaultExceptionHandler();
    ExceptionSummary exceptionSummary = exceptionHandler.handleException(mojoEx);

    String expectedReference = "http://cwiki.apache.org/confluence/display/MAVEN/ConnectException";
    assertEquals(expectedReference, exceptionSummary.getReference());
  }
Exemplo n.º 7
0
 static ClassLoader contextClassLoader(ExceptionHandler exceptionHandler) throws Exception {
   try {
     return Thread.currentThread().getContextClassLoader();
   } catch (Exception x) {
     throw exceptionHandler.createException(x, x.toString());
   }
 }
  public PagerBean<T> findByPage2(PagerBean<T> bean, T obj) {
    Logger.SERVICE.ldebug(
        "查询[" + obj.getClass().getAnnotation(Table.class).name() + "]数据", obj.toString());
    try {
      SelectEntity selectEntity = new SelectEntity();
      selectEntity.init(obj);
      CountEntity countEntity = new CountEntity();
      countEntity.init(obj);

      return setBeanValue(
          bean,
          //					getDao().findByPage2(selectEntity, bean.getPage(), bean.getPageSize(), "id"),
          getDao()
              .findByPage2(
                  obj.getClass(),
                  selectEntity.getFullSql(),
                  obj.getClass().getAnnotation(Table.class).name(),
                  selectEntity.getCriteria().getIdname(),
                  bean.getPage(),
                  bean.getPageSize(),
                  obj.getPrefix(),
                  selectEntity.getSmap(),
                  selectEntity.getCriteria().getParamList()),
          getDao().findCount2(countEntity));
    } catch (Exception e) {
      exceptionHandler.onDatabaseException(
          "查询" + obj.getClass().getAnnotation(Table.class).name() + "错误", e);
      bean.setException(e);
      return bean;
    }
  }
Exemplo n.º 9
0
 public static void runGame() {
   try {
     engine.run();
   } catch (InvalidMoveException e) {
     ExceptionHandler.handle(e);
   }
 }
Exemplo n.º 10
0
 @Override
 public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
   LOG.debug("Error ", cause);
   DefaultHttpResponse resp = ExceptionHandler.exceptionCaught(cause);
   resp.headers().set(CONNECTION, CLOSE);
   ctx.writeAndFlush(resp).addListener(ChannelFutureListener.CLOSE);
 }
Exemplo n.º 11
0
 @SuppressWarnings("unchecked")
 @Override
 public void run() {
   try {
     ListeningSocket.setSoTimeout(ListeningTimeout);
     // .
     try {
       while (!Canceller.flCancel) {
         Socket ClientSocket;
         try {
           ClientSocket = ListeningSocket.accept();
           // . start new session
           new TClientSession(this, ClientSocket);
         } catch (SocketTimeoutException E) {
         }
       }
     } finally {
       ArrayList<TClientSession> _ClientSessions;
       synchronized (ClientSessions) {
         _ClientSessions = (ArrayList<TClientSession>) ClientSessions.clone();
       }
       for (int I = 0; I < _ClientSessions.size(); I++) _ClientSessions.get(I).Finalize();
     }
   } catch (Throwable T) {
     if (!Canceller.flCancel) {
       if (ExceptionHandler != null) ExceptionHandler.DoOnException(T);
     }
   }
 }
Exemplo n.º 12
0
 /** Notifies the EventHandler immediately prior to this processor shutting down */
 private void notifyShutdown() {
   if (eventHandler instanceof LifecycleAware) {
     try {
       ((LifecycleAware) eventHandler).onShutdown();
     } catch (final Throwable ex) {
       exceptionHandler.handleOnShutdownException(ex);
     }
   }
 }
Exemplo n.º 13
0
 private void notifyTimeout(final long availableSequence) {
   try {
     if (timeoutHandler != null) {
       timeoutHandler.onTimeout(availableSequence);
     }
   } catch (Throwable e) {
     exceptionHandler.handleEventException(e, availableSequence, null);
   }
 }
 public int addAndReturnKey(T po) {
   Logger.SERVICE.ldebug(
       "导入[" + po.getClass().getAnnotation(Table.class).name() + "]数据", po.toString());
   try {
     return getDao().addAndReturnKey(po);
   } catch (Exception e) {
     exceptionHandler.onDatabaseException("导入记录错误", e);
     return -1;
   }
 }
Exemplo n.º 15
0
 public void setPlainText(String text) {
   try {
     resetDocument();
     StringReader stringReader = new StringReader(text);
     HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
     htmlEditorKit.read(stringReader, document, 0);
   } catch (Exception e) {
     ExceptionHandler.log(e);
   }
 }
 public ResultBean update(T po) {
   Logger.SERVICE.ldebug(
       "更新[" + po.getClass().getAnnotation(Table.class).name() + "]数据", po.toString());
   try {
     getDao().update(po);
     return ResultBean.RESULT_SUCCESS(po);
   } catch (Exception e) {
     exceptionHandler.onDatabaseException("更新记录错误", e);
     return ResultBean.RESULT_ERR(e.getMessage(), po);
   }
 }
Exemplo n.º 17
0
 public void saveDocument() {
   try {
     view.selectHtmlTab();
     if (currentFile != null) {
       try (FileWriter writer = new FileWriter(currentFile)) {
         new HTMLEditorKit().write(writer, document, 0, document.getLength());
       }
     } else saveDocumentAs();
   } catch (Exception e) {
     ExceptionHandler.log(e);
   }
 }
Exemplo n.º 18
0
  public String getPlainText() {

    try {
      StringWriter stringWriter = new StringWriter();
      HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
      htmlEditorKit.write(stringWriter, document, 0, document.getLength());
      return stringWriter.toString();
    } catch (Exception e) {
      ExceptionHandler.log(e);
    }
    return null;
  }
Exemplo n.º 19
0
 final void rejectAsyncResults(@NotNull ExceptionHandler exceptionHandler) {
   if (!messageCallbackMap.isEmpty()) {
     Enumeration<AsyncPromise<Object>> elements = messageCallbackMap.elements();
     while (elements.hasMoreElements()) {
       try {
         elements.nextElement().setError(REJECTED);
       } catch (Throwable e) {
         exceptionHandler.exceptionCaught(e);
       }
     }
   }
 }
 public ResultBean update2(T obj) {
   Logger.SERVICE.ldebug(
       "更新[" + obj.getClass().getAnnotation(Table.class).name() + "]数据", obj.toString());
   try {
     UpdateEntity entity = new UpdateEntity();
     entity.init(obj, false);
     getDao().update2(entity);
     return ResultBean.RESULT_SUCCESS(obj);
   } catch (Exception e) {
     exceptionHandler.onDatabaseException("更新记录错误", e);
     return ResultBean.RESULT_ERR(e.getMessage(), obj);
   }
 }
Exemplo n.º 21
0
 /**
  * Return a label for the given point on the graph axis
  *
  * @param value the value on the graph
  * @return the label for the given value
  */
 private String getLeafLabel(double value) {
   String label = Double.toString(value);
   try {
     int v = (int) value;
     int r = idxMap.getSrc(v);
     if (r < 0 || r >= tm.getRowCount()) {
       return "";
     }
     if (labelColumn >= 0 && labelColumn < tm.getColumnCount()) {
       Object o = tm.getValueAt(r, labelColumn);
       return o != null ? o.toString() : "";
     }
   } catch (Exception ex) {
     ExceptionHandler.popupException("" + ex);
   }
   try {
     label = Integer.toString((int) value);
   } catch (Exception ex) {
     ExceptionHandler.popupException("" + ex);
   }
   return label;
 }
Exemplo n.º 22
0
 protected void check() {
   if (reset == true || values == null) {
     try {
       values = getValues();
       reset = false;
       for (DynamicListListener<T> listener : listeners) {
         listener.valuesChanged(this);
       }
     } catch (Exception e) {
       if (exceptionHandler != null) {
         exceptionHandler.handleException(e);
       }
     }
   }
 }
 public PagerBean<T> find2(T obj) {
   Logger.SERVICE.ldebug(
       "查询[" + obj.getClass().getAnnotation(Table.class).name() + "]数据", obj.toString());
   PagerBean<T> bean = new PagerBean<T>();
   try {
     SelectEntity selectEntity = new SelectEntity();
     selectEntity.init(obj);
     bean.setDataList((List<T>) getDao().find2(selectEntity));
     return bean;
   } catch (Exception e) {
     exceptionHandler.onDatabaseException(
         "查询" + obj.getClass().getAnnotation(Table.class).name() + "错误", e);
     bean.setException(e);
     return bean;
   }
 }
 protected PagerBean<T> find(PagerBean<T> bean, Object obj, BaseDao dao, Class<T> clazz) {
   Logger.SERVICE.ldebug(
       "查询[" + obj.getClass().getAnnotation(Table.class).name() + "]数据",
       bean.getPage(),
       bean.getPageSize(),
       obj.toString());
   try {
     return setBeanValue(
         bean, dao.find(clazz, obj, bean.getPage(), bean.getPageSize(), "id"), dao.findCount(obj));
   } catch (Exception e) {
     bean.setException(e);
     exceptionHandler.onDatabaseException(
         "查询[" + obj.getClass().getAnnotation(Table.class).name() + "]时的错误", e);
     return bean;
   }
 }
  @Path("{email}")
  public UserResource getUser(@PathParam("email") String email) {
    try {
      if (SecurityHelper.hasRole(WindMobileAuthenticationProvider.roleAdmin) == false) {
        Error error = new Error();
        error.setCode(DataSourceException.Error.UNAUTHORIZED.getCode());
        throw new WebApplicationException(
            Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).entity(error).build());
      }

      return new UserResource(uriInfo, request, serviceLocator, email);
    } catch (Exception e) {
      ExceptionHandler.treatException(e);
      return null;
    }
  }
Exemplo n.º 26
0
 private void handleDefault(ErrorMessage msg, Throwable t) {
   ErrorMessage nestedMsg = null;
   // Try wrapping the exception and the Exception message that caused the
   // exception in a new message
   try {
     nestedMsg = new ErrorMessage(t);
   } catch (Exception e) {
     logger.fatal(LocaleMessage.defaultException(e), e);
     handleFatal(e);
   }
   try {
     defaultHandler.onException(nestedMsg);
   } catch (HandlerException e) {
     logger.fatal(LocaleMessage.defaultHandlerException(e), e);
     handleFatal(e);
   }
 }
Exemplo n.º 27
0
 public void saveDocumentAs() {
   try {
     view.selectHtmlTab();
     JFileChooser jFileChooser = new JFileChooser();
     jFileChooser.setFileFilter(new HTMLFileFilter());
     jFileChooser.setDialogTitle("Save File");
     int n = jFileChooser.showSaveDialog(view);
     if (n == JFileChooser.APPROVE_OPTION) {
       currentFile = jFileChooser.getSelectedFile();
       view.setTitle(currentFile.getName());
       try (FileWriter writer = new FileWriter(currentFile)) {
         new HTMLEditorKit().write(writer, document, 0, document.getLength());
       }
     }
   } catch (Exception e) {
     ExceptionHandler.log(e);
   }
 }
Exemplo n.º 28
0
  static <P, T extends Exception> P firstByServiceLoader(
      Class<P> spiClass, Logger logger, ExceptionHandler<T> handler) throws T {
    // service discovery
    try {
      ServiceLoader<P> serviceLoader = ServiceLoader.load(spiClass);

      for (P impl : serviceLoader) {
        logger.fine(
            "ServiceProvider loading Facility used; returning object ["
                + impl.getClass().getName()
                + "]");

        return impl;
      }
    } catch (Throwable t) {
      throw handler.createException(
          t, "Error while searching for service [" + spiClass.getName() + "]");
    }
    return null;
  }
 private void handleServletException(
     HttpServletRequest httpRequest, HttpServletResponse httpResponse, ServletException e)
     throws IOException, ServletException {
   EJBException ejbEx = ExceptionHandler.getEJBException(e);
   if (ejbEx != null
       && ejbEx.getCause() instanceof Exception
       && ejbEx.getCausedByException() instanceof AccessException) {
     String forwardErrorPage;
     if (BesServletRequestReader.isMarketplaceRequest(httpRequest)) {
       forwardErrorPage = Marketplace.MARKETPLACE_ROOT + Constants.INSUFFICIENT_AUTHORITIES_URI;
     } else {
       forwardErrorPage = Constants.INSUFFICIENT_AUTHORITIES_URI;
     }
     JSFUtils.sendRedirect(httpResponse, httpRequest.getContextPath() + forwardErrorPage);
   } else {
     // make sure we do not catch exceptions cause by
     // ViewExpiredException here, they'll be handled directly in the
     // doFilter()
     throw e;
   }
 }
Exemplo n.º 30
0
  /**
   * It is ok to have another thread rerun this method after a halt().
   *
   * @throws IllegalStateException if this object instance is already running in a thread
   */
  @Override
  public void run() {
    if (!running.compareAndSet(false, true)) {
      throw new IllegalStateException("Thread is already running");
    }
    sequenceBarrier.clearAlert();

    notifyStart();

    T event = null;
    long nextSequence = sequence.get() + 1L;
    while (true) {
      try {
        final long availableSequence = sequenceBarrier.waitFor(nextSequence);

        while (nextSequence <= availableSequence) {
          event = dataProvider.get(nextSequence);
          eventHandler.onEvent(event, nextSequence, nextSequence == availableSequence);
          nextSequence++;
        }

        sequence.set(availableSequence);
      } catch (final TimeoutException e) {
        notifyTimeout(sequence.get());
      } catch (final AlertException ex) {
        if (!running.get()) {
          break;
        }
      } catch (final Throwable ex) {
        exceptionHandler.handleEventException(ex, nextSequence, event);
        sequence.set(nextSequence);
        nextSequence++;
      }
    }

    notifyShutdown();

    running.set(false);
  }