Exemplo n.º 1
0
    /**
     * @param href
     * @param base
     * @return
     * @throws TransformerException
     */
    public Source resolve(String href, String base) throws TransformerException {
      Resolver resolver = ResolverWrapper.getInstance();
      CatalogResolver catResolver = resolver.getCatalogResolver();
      if (Log.isDebugEnabled(Log.XML_RESOLVER)) {
        Log.debug(Log.XML_RESOLVER, "Trying to resolve " + href + ":" + base);
      }
      String decodedBase;
      try {
        decodedBase = URLDecoder.decode(base, Jeeves.ENCODING);
      } catch (UnsupportedEncodingException e1) {
        decodedBase = base;
      }
      String decodedHref;
      try {
        decodedHref = URLDecoder.decode(href, Jeeves.ENCODING);
      } catch (UnsupportedEncodingException e1) {
        decodedHref = href;
      }
      Source s = catResolver.resolve(decodedHref, decodedBase);
      // If resolver has a blank XSL file to replace non existing resolved file ...
      String blankXSLFile = resolver.getBlankXSLFile();
      if (blankXSLFile != null && s.getSystemId().endsWith(".xsl")) {
        // The resolved resource does not exist, set it to blank file path to not trigger
        // FileNotFound Exception
        try {
          if (Log.isDebugEnabled(Log.XML_RESOLVER)) {
            Log.debug(Log.XML_RESOLVER, "  Check if exist " + s.getSystemId());
          }
          File f;
          if (SystemUtils.IS_OS_WINDOWS) {
            String path = s.getSystemId();
            // fxp
            path = path.replaceAll("file:\\/", "");
            // heikki
            path = path.replaceAll("file:", "");

            f = new File(path);
          } else {
            f = new File(new URI(s.getSystemId()));
          }
          if (!(f.exists())) {
            if (Log.isDebugEnabled(Log.XML_RESOLVER)) {
              Log.debug(
                  Log.XML_RESOLVER,
                  "  Resolved resource "
                      + s.getSystemId()
                      + " does not exist. blankXSLFile returned instead.");
            }
            s.setSystemId(blankXSLFile);
          }
        } catch (URISyntaxException e) {
          e.printStackTrace();
        }
      }

      if (Log.isDebugEnabled(Log.XML_RESOLVER) && s != null) {
        Log.debug(Log.XML_RESOLVER, "Resolved as " + s.getSystemId());
      }
      return s;
    }
Exemplo n.º 2
0
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
      long startTime = 0;
      if (LOG.isDebugEnabled()) {
        startTime = Time.now();
      }

      ObjectWritable value =
          (ObjectWritable)
              client.call(RPC.RpcKind.RPC_WRITABLE, new Invocation(method, args), remoteId);
      if (LOG.isDebugEnabled()) {
        long callTime = Time.now() - startTime;
        LOG.debug("Call: " + method.getName() + " " + callTime);
      }
      return value.get();
    }
Exemplo n.º 3
0
    public Writable call(Class<?> protocol, Writable param, long receivedTime) throws IOException {
      try {
        Invocation call = (Invocation) param;
        if (verbose) log("Call: " + call);

        Method method = protocol.getMethod(call.getMethodName(), call.getParameterClasses());
        method.setAccessible(true);

        int qTime = (int) (System.currentTimeMillis() - receivedTime);
        long startNanoTime = System.nanoTime();
        Object value = method.invoke(instance, call.getParameters());
        long processingMicroTime = (System.nanoTime() - startNanoTime) / 1000;
        if (LOG.isDebugEnabled()) {
          LOG.debug(
              "Served: "
                  + call.getMethodName()
                  + " queueTime (millisec)= "
                  + qTime
                  + " procesingTime (microsec)= "
                  + processingMicroTime);
        }
        rpcMetrics.rpcQueueTime.inc(qTime);
        rpcMetrics.rpcProcessingTime.inc(processingMicroTime);

        MetricsTimeVaryingRate m =
            (MetricsTimeVaryingRate) rpcMetrics.registry.get(call.getMethodName());
        if (m == null) {
          try {
            m = new MetricsTimeVaryingRate(call.getMethodName(), rpcMetrics.registry);
          } catch (IllegalArgumentException iae) {
            // the metrics has been registered; re-fetch the handle
            LOG.debug("Error register " + call.getMethodName(), iae);
            m = (MetricsTimeVaryingRate) rpcMetrics.registry.get(call.getMethodName());
          }
        }
        // record call time in microseconds
        m.inc(processingMicroTime);

        if (verbose) log("Return: " + value);

        return new ObjectWritable(method.getReturnType(), value);

      } catch (InvocationTargetException e) {
        Throwable target = e.getTargetException();
        if (target instanceof IOException) {
          throw (IOException) target;
        } else {
          IOException ioe = new IOException(target.toString());
          ioe.setStackTrace(target.getStackTrace());
          throw ioe;
        }
      } catch (Throwable e) {
        if (!(e instanceof IOException)) {
          LOG.error("Unexpected throwable object ", e);
        }
        IOException ioe = new IOException(e.toString());
        ioe.setStackTrace(e.getStackTrace());
        throw ioe;
      }
    }
  /**
   * コード一覧作成用メソッド。<br>
   * 領域番号と領域名称の一覧を取得する。 領域番号順にソートする。
   *
   * @param connection コネクション
   * @return
   * @throws ApplicationException
   */
  public static List selectRyoikiInfoList(Connection connection, String kubun)
      throws ApplicationException {

    // -----------------------
    // SQL文の作成
    // -----------------------
    String select =
        "SELECT"
            + " RYOIKI_NO," // 領域番号
            + " RYOIKI_RYAKU" // 領域名称
            + " FROM MASTER_RYOIKI";

    if ("1".equals(kubun)) {
      select = select + " WHERE KEIKAKU_FLG = '1'";
    } else {
      select = select + " WHERE KOUBO_FLG = '1'";
    }
    select = select + " GROUP BY RYOIKI_NO, RYOIKI_RYAKU" + " ORDER BY RYOIKI_NO";

    if (log.isDebugEnabled()) {
      log.debug("query:" + select);
    }

    // -----------------------
    // リスト取得
    // -----------------------
    try {
      return SelectUtil.select(connection, select);
    } catch (DataAccessException e) {
      throw new ApplicationException("領域情報検索中にDBエラーが発生しました。", new ErrorInfo("errors.4004"), e);
    } catch (NoDataFoundException e) {
      throw new SystemException("領域マスタに1件もデータがありません。", e);
    }
  }
  /**
   * コード一覧(新規領域)作成用メソッド。<br>
   * 領域番号と領域名称の一覧を取得する。 領域番号順にソートする。
   *
   * @param connection コネクション
   * @return  List
   * @throws ApplicationException
   */
  public static List selectRyoikiSinnkiInfoList(Connection connection) throws ApplicationException {

    // -----------------------
    // SQL文の作成
    // -----------------------
    StringBuffer select = new StringBuffer();

    select.append("SELECT DISTINCT");
    select.append(" RYOIKI_NO,"); // 領域番号
    select.append(" RYOIKI_RYAKU,"); // 領域名称
    select.append(" SETTEI_KIKAN"); // 設定期間
    select.append(" FROM MASTER_RYOIKI");
    select.append(" WHERE ZENNENDO_OUBO_FLG = '1'");
    select.append(" ORDER BY RYOIKI_NO");

    if (log.isDebugEnabled()) {
      log.debug("query:" + select);
    }

    // -----------------------
    // リスト取得
    // -----------------------
    try {
      return SelectUtil.select(connection, select.toString());
    } catch (DataAccessException e) {
      throw new ApplicationException("領域情報検索中にDBエラーが発生しました。", new ErrorInfo("errors.4004"), e);
    } catch (NoDataFoundException e) {
      throw new SystemException("領域マスタに1件もデータがありません。", e);
    }
  }
  /**
   * 領域の一覧(コンポボックス用)を取得する。
   *
   * @param connection コネクション
   * @return 事業情報
   * @throws ApplicationException
   */
  public static List selectRyouikiKubunInfoList(Connection connection)
      throws ApplicationException, NoDataFoundException {

    // -----------------------
    // SQL文の作成
    // -----------------------
    String select =
        "SELECT"
            + " A.RYOIKI_NO"
            + ",A.RYOIKI_RYAKU"
            + " FROM MASTER_RYOIKI A"
            + " ORDER BY RYOIKI_NO";
    StringBuffer query = new StringBuffer(select);

    if (log.isDebugEnabled()) {
      log.debug("query:" + query);
    }

    // -----------------------
    // リスト取得
    // -----------------------
    try {
      return SelectUtil.select(connection, query.toString());
    } catch (DataAccessException e) {
      throw new ApplicationException("領域情報検索中にDBエラーが発生しました。", new ErrorInfo("errors.4004"), e);
    } catch (NoDataFoundException e) {
      throw new NoDataFoundException("領域マスタに1件もデータがありません。", e);
    }
  }
Exemplo n.º 7
0
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
      final boolean logDebug = LOG.isDebugEnabled();
      long startTime = 0;
      if (logDebug) {
        startTime = System.currentTimeMillis();
      }

      ObjectWritable value = null;
      try {
        value =
            (ObjectWritable)
                client.call(
                    new Invocation(method, args), getAddress(), protocol, ticket, rpcTimeout);
      } catch (RemoteException re) {
        throw re;
      } catch (ConnectException ce) {
        needCheckDnsUpdate = true;
        throw ce;
      } catch (NoRouteToHostException nrhe) {
        needCheckDnsUpdate = true;
        throw nrhe;
      } catch (PortUnreachableException pue) {
        needCheckDnsUpdate = true;
        throw pue;
      } catch (UnknownHostException uhe) {
        needCheckDnsUpdate = true;
        throw uhe;
      }
      if (logDebug) {
        long callTime = System.currentTimeMillis() - startTime;
        LOG.debug("Call: " + method.getName() + " " + callTime);
      }
      return value.get();
    }
  /**
   * 領域マスタの1レコードをMap形式で返す。 引数には主キー値を渡す。
   *
   * @param connection
   * @param labelKubun
   * @param value
   * @return
   * @throws NoDataFoundException
   * @throws DataAccessException
   */
  public static Map selectRecord(Connection connection, String ryouikiNo)
      throws NoDataFoundException, DataAccessException {
    // -----------------------
    // SQL文の作成
    // -----------------------
    String select =
        "SELECT"
            + " A.RYOIKI_NO"
            + ",A.RYOIKI_RYAKU"
            + ",A.KOMOKU_NO"
            // 2006/06/26 苗 修正ここから
            + ",A.SETTEI_KIKAN" // 設定期間
            + ",A.SETTEI_KIKAN_KAISHI" // 設定期間(開始年度)
            + ",A.SETTEI_KIKAN_SHURYO" // 設定期間(終了年度)
            // 2006/06/26 苗 修正ここまで
            + ",A.BIKO"
            + " FROM MASTER_RYOIKI A"
            + " WHERE RYOIKI_NO = ? ";

    if (log.isDebugEnabled()) {
      log.debug("query:" + select);
    }

    // -----------------------
    // レコード取得
    // -----------------------
    List result = SelectUtil.select(connection, select, new String[] {ryouikiNo});
    if (result.isEmpty()) {
      throw new NoDataFoundException("当該レコードは存在しません。領域No=" + ryouikiNo);
    }
    return (Map) result.get(0);
  }
Exemplo n.º 9
0
  @Test
  @SuppressWarnings("deprecation")
  public void testOurLogLogging() {
    final Log logger = new Log();

    logger.trace("Foobar TRACE");
    AppenderForTests.hasNoLastEvent("at Trace level");
    assertFalse(logger.isTraceEnabled());

    logger.debug("Foobar DEBUG");
    AppenderForTests.hasNoLastEvent("at Debug level");
    assertFalse(logger.isDebugEnabled());

    logger.info("Foobar INFO");
    AppenderForTests.hasNoLastEvent("at Info level");
    assertFalse(logger.isInfoEnabled());

    logger.warn("Foobar WARN");
    AppenderForTests.hasLastEvent("at Warn level");
    assertTrue(logger.isWarnEnabled());

    logger.error("Foobar ERROR");
    AppenderForTests.hasLastEvent("at Error level");
    assertTrue(logger.isErrorEnabled());
  }
Exemplo n.º 10
0
 private void logSomething(boolean expectedDebug) {
   Log log = LogFactory.getLog(Object.class);
   log.warn("Warning message.");
   log.debug("Debug message.");
   log.error("Error message.");
   log.error("Error with Exception.", new Exception("Test exception."));
   assertEquals(expectedDebug, log.isDebugEnabled());
 }
Exemplo n.º 11
0
 /**
  * Shuts down the {@link CachingServiceFactory}.
  *
  * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
  */
 public void stop(final BundleContext context) {
   if (cachingServiceFactoryRegistration != null) {
     cachingServiceFactory.stop();
     cachingServiceFactoryRegistration.unregister();
   }
   if (Log.isDebugEnabled()) {
     Log.debug("Shut down and unregistered SingletonCachingService."); // $NON-NLS-1$
   }
 }
Exemplo n.º 12
0
 private void registerCachingServiceFactory(final BundleContext bundleContext) {
   cachingServiceFactory = new CachingServiceFactory(bundleContext);
   cachingServiceFactoryRegistration =
       bundleContext.registerService(
           ICachingServiceFactory.class.getName(), cachingServiceFactory, null);
   if (Log.isDebugEnabled()) {
     Log.debug("Created and registered SingletonCachingService."); // $NON-NLS-1$
   }
 }
Exemplo n.º 13
0
  protected void doCommon(HttpServletRequest httpRequest, HttpServletResponse httpResponse) {
    try {
      if (log.isDebugEnabled()) log.debug(HttpUtils.fmtRequest(httpRequest));

      // getRequestURL is the exact string used by the caller in the request.
      // Internally, it's the "request URI" that names the service

      // String requestURL = httpRequest.getRequestURL().toString() ;
      String uri = httpRequest.getRequestURI();

      if (uri.length() > urlLimit) {
        httpResponse.setStatus(HttpServletResponse.SC_REQUEST_URI_TOO_LONG);
        return;
      }

      String serviceURI = chooseServiceURI(uri, httpRequest);
      serviceURI = Service.canonical(serviceURI);

      String sender = httpRequest.getRemoteAddr();
      log.info("[" + sender + "] Service URI = <" + serviceURI + ">");

      // MIME-Type
      String contentType = httpRequest.getContentType();

      //            if ( Joseki.contentSPARQLUpdate.equals(contentType) ||
      //                Joseki.contentSPARQLUpdate_X.equals(contentType) )
      //            {}

      Request request = setupRequest(serviceURI, httpRequest);
      request.setParam(Joseki.VERB, httpRequest.getMethod());

      Response response = new ResponseHttp(request, httpRequest, httpResponse);
      Dispatcher.dispatch(serviceURI, request, response);
    } catch (Exception ex) {
      try {
        log.warn("Internal server error", ex);
        //                httpResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR) ;
        //                httpResponse.flushBuffer() ;
        //                httpResponse.getWriter().close() ;
        httpResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      } catch (Exception e) {
      }
    }
  }
  /**
   * 領域マスタの1レコードをMap形式で返す。 引数には主キー値を渡す。
   *
   * @param connection
   * @param labelKubun
   * @param value
   * @return
   * @throws NoDataFoundException
   * @throws DataAccessException
   */
  public static Map selectRecord(Connection connection, RyouikiInfoPk pkInfo, String ryoikiKbn)
      throws NoDataFoundException, DataAccessException {
    // -----------------------
    // SQL文の作成
    // -----------------------
    String select =
        "SELECT"
            + " A.RYOIKI_NO"
            + ",A.RYOIKI_RYAKU"
            + ",A.KOMOKU_NO"
            // 2006/07/04 苗 修正ここから
            + ",A.SETTEI_KIKAN" // 設定期間
            + ",A.SETTEI_KIKAN_KAISHI" // 設定期間(開始年度)
            + ",A.SETTEI_KIKAN_SHURYO" // 設定期間(終了年度)
            // 2006/07/04 苗 修正ここまで
            + " FROM MASTER_RYOIKI A"
            + " WHERE RYOIKI_NO = ? "
            + " AND KOMOKU_NO = ? ";

    // 計画研究の場合
    if ("1".equals(ryoikiKbn)) {
      select = select + " AND KEIKAKU_FLG = '1'";
    }
    // 公募研究の場合
    else if ("2".equals(ryoikiKbn)) {
      select = select + " AND KOUBO_FLG = '1'";
    }

    if (log.isDebugEnabled()) {
      log.debug("query:" + select);
    }

    // -----------------------
    // レコード取得
    // -----------------------
    List result =
        SelectUtil.select(
            connection, select, new String[] {pkInfo.getRyoikiNo(), pkInfo.getKomokuNo()});
    if (result.isEmpty()) {
      throw new NoDataFoundException("当該レコードは存在しません。");
    }
    return (Map) result.get(0);
  }
Exemplo n.º 15
0
  private void servletEnv() {
    if (!log.isDebugEnabled()) return;

    try {
      java.net.URL url = servletContext.getResource("/");
      log.trace("Joseki base directory: " + url);
    } catch (Exception ex) {
    }

    if (servletConfig != null) {
      String tmp = servletConfig.getServletName();
      log.trace("Servlet = " + (tmp != null ? tmp : "<null>"));
      @SuppressWarnings("unchecked")
      Enumeration<String> en = servletConfig.getInitParameterNames();

      for (; en.hasMoreElements(); ) {
        String s = en.nextElement();
        log.trace("Servlet parameter: " + s + " = " + servletConfig.getInitParameter(s));
      }
    }
    if (servletContext != null) {
      // Name of webapp
      String tmp = servletContext.getServletContextName();
      // msg(Level.FINE, "Webapp = " + (tmp != null ? tmp : "<null>"));
      log.debug("Webapp = " + (tmp != null ? tmp : "<null>"));

      // NB This servlet may not have been loaded as part of a web app
      @SuppressWarnings("unchecked")
      Enumeration<String> en = servletContext.getInitParameterNames();
      for (; en.hasMoreElements(); ) {
        String s = en.nextElement();
        log.debug("Webapp parameter: " + s + " = " + servletContext.getInitParameter(s));
      }
    }
    /*
    for ( Enumeration enum = servletContext.getAttributeNames() ;  enum.hasMoreElements() ; )
    {
        String s = (String)enum.nextElement() ;
        logger.log(LEVEL, "Webapp attribute: "+s+" = "+context.getAttribute(s)) ;
    }
     */
  }
Exemplo n.º 16
0
  // ------------------------------------------
  public static String chooseServiceURI(String uri, HttpServletRequest httpRequest) {
    String serviceURI = uri;
    String contextPath = httpRequest.getContextPath();

    if (contextPath != null && contextPath.length() > 0)
      serviceURI = serviceURI.substring(contextPath.length());

    String servletPath = httpRequest.getServletPath();

    // Suggested by Frank Hartman: helps make conf files more portable
    // between /joseki/myModel and /myModel but if the servlet is
    // explicitly named in web.xml, it strips that off
    //        if ( servletPath != null && servletPath.length() > 0 )
    //            dispatchURI = dispatchURI.substring(servletPath.length()) ;

    // Suggested by damien_coraboeuf
    // TODO Test and verify
    //        if ( servletPath != null && servletPath.length() > 0 )
    //            serviceURI = serviceURI.substring(servletPath.length()) ;

    // Example:
    //    <servlet-mapping>
    //        <servlet-name>JosekiServlet</servlet-name>
    //        <url-pattern>/ws/joseki/*</url-pattern>
    //    </servlet-mapping>

    if (log.isDebugEnabled()) {
      if (servletPath == null) servletPath = "";
      if (contextPath == null) contextPath = "";
      log.debug(
          "DispatchURI: "
              + uri
              + " => "
              + serviceURI
              + " (ContextPath = "
              + contextPath
              + ", ServletPath = "
              + servletPath
              + ")");
    }
    return serviceURI;
  }
Exemplo n.º 17
0
 VerProtocolImpl getHighestSupportedProtocol(RpcKind rpcKind, String protocolName) {
   Long highestVersion = 0L;
   ProtoClassProtoImpl highest = null;
   if (LOG.isDebugEnabled()) {
     LOG.debug("Size of protoMap for " + rpcKind + " =" + getProtocolImplMap(rpcKind).size());
   }
   for (Map.Entry<ProtoNameVer, ProtoClassProtoImpl> pv :
       getProtocolImplMap(rpcKind).entrySet()) {
     if (pv.getKey().protocol.equals(protocolName)) {
       if ((highest == null) || (pv.getKey().version > highestVersion)) {
         highest = pv.getValue();
         highestVersion = pv.getKey().version;
       }
     }
   }
   if (highest == null) {
     return null;
   }
   return new VerProtocolImpl(highestVersion, highest);
 }
  /**
   * 領域番号の件数を取得する。 領域番号順にソートする。
   *
   * @param connection コネクション
   * @param ryoikoNo 領域番号
   * @return
   * @throws ApplicationException
   * @throws DataAccessException
   */
  public String selectRyoikiNoCount(Connection connection, String ryoikoNo)
      throws ApplicationException, DataAccessException {

    String strCount = null;
    ResultSet recordSet = null;
    PreparedStatement preparedStatement = null;

    // -----------------------
    // SQL文の作成
    // -----------------------

    StringBuffer select = new StringBuffer();
    select.append("SELECT COUNT(RYOIKI_NO) ");
    select.append(ISystemServise.STR_COUNT);
    select.append(" FROM");
    select.append(" (SELECT MR.RYOIKI_NO FROM MASTER_RYOIKI MR WHERE MR.ZENNENDO_OUBO_FLG = '1' ");
    select.append("  AND MR.RYOIKI_NO = '");
    select.append(EscapeUtil.toSqlString(ryoikoNo));
    select.append("')");

    if (log.isDebugEnabled()) {
      log.debug("query:" + select.toString());
    }
    try {
      preparedStatement = connection.prepareStatement(select.toString());
      recordSet = preparedStatement.executeQuery();

      if (recordSet.next()) {
        strCount = recordSet.getString(ISystemServise.STR_COUNT);
      } else {
        throw new NoDataFoundException("領域マスタデータテーブルに該当するデータが見つかりません。");
      }
    } catch (SQLException ex) {
      throw new DataAccessException("領域マスタデータテーブルの検索中に例外が発生しました。", ex);
    } catch (NoDataFoundException ex) {
      throw new NoDataFoundException("該当する領域番号が存在しません。", ex);
    }

    return strCount;
  }
Exemplo n.º 19
0
 /**
  * Returns true, if the log level allows debug messages to be printed.
  *
  * @return true, if messages with an log level of DEBUG are allowed.
  */
 public boolean isDebugEnabled() {
   return Log.isDebugEnabled();
 }