/** * 領域の一覧(コンポボックス用)を取得する。 * * @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); } }
/** * コード一覧(新規領域)作成用メソッド。<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); } }
/** * コード一覧作成用メソッド。<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); } }
/** * 領域マスタの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); }
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); }
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)) ; } */ }
// ------------------------------------------ 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; }
/** * 領域番号の件数を取得する。 領域番号順にソートする。 * * @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; }
/** * Makes a rest request of any type at the specified urlSuffix. The urlSuffix should be of the * form /userService/users. If CS throws an exception it handled and transalated to a Openfire * exception if possible. This is done using the check fault method that tries to throw the best * maching exception. * * @param type Must be GET or DELETE * @param urlSuffix The url suffix of the rest request * @param xmlParams The xml with the request params, must be null if type is GET or DELETE only * @return The response as a xml doc. * @throws ConnectionException Thrown if there are issues perfoming the request. * @throws Exception Thrown if the response from Clearspace contains an exception. */ public Element executeRequest(HttpType type, String urlSuffix, String xmlParams) throws ConnectionException, Exception { if (Log.isDebugEnabled()) { Log.debug("Outgoing REST call [" + type + "] to " + urlSuffix + ": " + xmlParams); } String wsUrl = getConnectionURI() + WEBSERVICES_PATH + urlSuffix; String secret = getSharedSecret(); HttpClient client = new HttpClient(); HttpMethod method; // Configures the authentication client.getParams().setAuthenticationPreemptive(true); Credentials credentials = new UsernamePasswordCredentials(OPENFIRE_USERNAME, secret); AuthScope scope = new AuthScope(host, port, AuthScope.ANY_REALM); client.getState().setCredentials(scope, credentials); // Creates the method switch (type) { case GET: method = new GetMethod(wsUrl); break; case POST: PostMethod pm = new PostMethod(wsUrl); StringRequestEntity requestEntity = new StringRequestEntity(xmlParams); pm.setRequestEntity(requestEntity); method = pm; break; case PUT: PutMethod pm1 = new PutMethod(wsUrl); StringRequestEntity requestEntity1 = new StringRequestEntity(xmlParams); pm1.setRequestEntity(requestEntity1); method = pm1; break; case DELETE: method = new DeleteMethod(wsUrl); break; default: throw new IllegalArgumentException(); } method.setRequestHeader("Accept", "text/xml"); method.setDoAuthentication(true); try { // Executes the request client.executeMethod(method); // Parses the result String body = method.getResponseBodyAsString(); if (Log.isDebugEnabled()) { Log.debug("Outgoing REST call results: " + body); } // Checks the http status if (method.getStatusCode() != 200) { if (method.getStatusCode() == 401) { throw new ConnectionException( "Invalid password to connect to Clearspace.", ConnectionException.ErrorType.AUTHENTICATION); } else if (method.getStatusCode() == 404) { throw new ConnectionException( "Web service not found in Clearspace.", ConnectionException.ErrorType.PAGE_NOT_FOUND); } else if (method.getStatusCode() == 503) { throw new ConnectionException( "Web service not avaible in Clearspace.", ConnectionException.ErrorType.SERVICE_NOT_AVAIBLE); } else { throw new ConnectionException( "Error connecting to Clearspace, http status code: " + method.getStatusCode(), new HTTPConnectionException(method.getStatusCode()), ConnectionException.ErrorType.OTHER); } } else if (body.contains("Clearspace Upgrade Console")) { // TODO Change CS to send a more standard error message throw new ConnectionException( "Clearspace is in an update state.", ConnectionException.ErrorType.UPDATE_STATE); } Element response = localParser.get().parseDocument(body).getRootElement(); // Check for exceptions checkFault(response); // Since there is no exception, returns the response return response; } catch (DocumentException e) { throw new ConnectionException( "Error parsing the response of Clearspace.", e, ConnectionException.ErrorType.OTHER); } catch (HttpException e) { throw new ConnectionException( "Error performing http request to Clearspace", e, ConnectionException.ErrorType.OTHER); } catch (UnknownHostException e) { throw new ConnectionException( "Unknown Host " + getConnectionURI() + " trying to connect to Clearspace", e, ConnectionException.ErrorType.UNKNOWN_HOST); } catch (IOException e) { throw new ConnectionException( "Error peforming http request to Clearspace.", e, ConnectionException.ErrorType.OTHER); } finally { method.releaseConnection(); } }
private void init() { // Register the trust manager to use when using HTTPS Protocol easyhttps = new Protocol("https", (ProtocolSocketFactory) new SSLProtocolSocketFactory(this), 443); Protocol.registerProtocol("https", easyhttps); // Convert XML based provider setup to Database based JiveGlobals.migrateProperty("clearspace.uri"); JiveGlobals.migrateProperty("clearspace.sharedSecret"); // Make sure that all Clearspace components are set up, unless they were overridden // Note that the auth provider is our way of knowing that we are set up with Clearspace, // so don't bother checking to set it. if (isEnabled()) { if (JiveGlobals.getProperty("provider.user.className") == null) { JiveGlobals.setProperty( "provider.user.className", "org.jivesoftware.openfire.clearspace.ClearspaceUserProvider"); } if (JiveGlobals.getProperty("provider.group.className") == null) { JiveGlobals.setProperty( "provider.group.className", "org.jivesoftware.openfire.clearspace.ClearspaceGroupProvider"); } if (JiveGlobals.getProperty("provider.vcard.className") == null) { JiveGlobals.setProperty( "provider.vcard.className", "org.jivesoftware.openfire.clearspace.ClearspaceVCardProvider"); } if (JiveGlobals.getProperty("provider.lockout.className") == null) { JiveGlobals.setProperty( "provider.lockout.className", "org.jivesoftware.openfire.clearspace.ClearspaceLockOutProvider"); } if (JiveGlobals.getProperty("provider.securityAudit.className") == null) { JiveGlobals.setProperty( "provider.securityAudit.className", "org.jivesoftware.openfire.clearspace.ClearspaceSecurityAuditProvider"); } if (JiveGlobals.getProperty("provider.admin.className") == null) { JiveGlobals.setProperty( "provider.admin.className", "org.jivesoftware.openfire.clearspace.ClearspaceAdminProvider"); } } this.uri = properties.get("clearspace.uri"); if (uri != null) { if (!this.uri.endsWith("/")) { this.uri = this.uri + "/"; } // Updates the host/port attributes based on the uri updateHostPort(); } sharedSecret = properties.get("clearspace.sharedSecret"); // Creates the cache maps userIDCache = new DefaultCache<String, Long>("clearspace.userid", 1000, JiveConstants.DAY); groupIDCache = new DefaultCache<String, Long>("clearspace.groupid", 1000, JiveConstants.DAY); usernameCache = new DefaultCache<Long, String>("clearspace.username", 1000, JiveConstants.DAY); if (Log.isDebugEnabled()) { StringBuilder buf = new StringBuilder(); buf.append("Created new ClearspaceManager() instance, fields:\n"); buf.append("\t URI: ").append(uri).append("\n"); buf.append("\t sharedSecret: ").append(sharedSecret).append("\n"); Log.debug("ClearspaceManager: " + buf.toString()); } // Init nonce cache nonceCache = CacheFactory.createCache("Clearspace SSO Nonce"); // Init nonce generator nonceGenerator = new Random(); }