public static DepartmentRemoteService getServicePort() { try { URL wsdlLocation = new URL( "http://localhost:8080/com.mobilebulletin.remote.service/MobileBulletin/DepartmentRemoteBean?wsdl"); QName qName = new QName("mobilebulletin", "MobileBulletin"); Service service = null; service = Service.create(wsdlLocation, qName); /** * HeaderHandlerResolve will pass this information to a HeaderHandler implementation class * which will embed the user name and password passed in to the ws-security header within the * soap header element */ HeaderHandlerResolver handlerResolver = new HeaderHandlerResolver( ReadProperties.getUsernameProperty(), ReadProperties.getPasswordProperty()); service.setHandlerResolver(handlerResolver); DepartmentRemoteService servicePort = service.getPort(DepartmentRemoteService.class); return servicePort; } catch (MalformedURLException mue) { Logger.getLogger(DepartmentServiceConnector.class) .warn("An error occurred while getting the wsdl location.", mue); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
/** * DB Connection ��ü�� ��ȯ�Ѵ�. * * @return */ public static Connection getDB(String key) { ReadPropertiesAble rp = ReadProperties.getInstance(); Connection conn = null; try { if (rp.getValue("was").equals("weblogic")) { try { conn = ConnectionFactory.getInstance().getConnectionWeblogic(rp.getValue(key)); } catch (Exception e) { errorLog("weblogic DB ���ῡ�� :" + e.toString()); } } else if (rp.getValue("was").equals("tomcat")) { try { conn = ConnectionFactory.getInstance() .getConnectionTomcat(rp.getValue("JNDI"), rp.getValue(key)); conn.setAutoCommit(true); } catch (Exception e) { errorLog("tomcat DB ���ῡ�� :" + e.toString()); } } } catch (Exception e) { errorLog("��d���� ���� ���� :" + e.toString()); } return conn; }
public static Map<String, String> login( HttpServletRequest req, HttpServletResponse res, String username, String password) throws Exception { String url = ReadProperties.getByName("login.ip") + "/login"; Map<String, String> datas = new HashMap<String, String>(); Map<String, String> cookies = new HashMap<String, String>(); Connection con = Jsoup.connect(url).timeout(120000); // 获取连接 con.header( "User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0"); // 配置模拟浏览器 Response rs; rs = con.execute(); cookies = rs.cookies(); Document doc = Jsoup.parse(rs.body()); // 转换为Dom树 List<Element> et = doc.select("form"); // 获取form表单,可以通过查看页面源码代码得知 for (Element e : et.get(0).getAllElements()) { if (e.attr("name").equals("username")) { e.attr("value", username); // 设置用户名 } if (e.attr("name").equals("password")) { e.attr("value", password); // 设置用户密码 } if (e.attr("name").length() > 0) { // 排除空值表单属性 datas.put(e.attr("name"), e.attr("value")); } } // 设置cookie和post上面的map数据 Response login = null; login = con.data(datas).cookies(cookies).method(Method.POST).execute(); url = ReadProperties.getByName("common.ip") + req.getContextPath() + "/user/getUser"; con = Jsoup.connect(url) .cookies(login.cookies()) .ignoreContentType(true) .method(Method.GET); // 获取连接 rs = con.execute(); for (Entry<String, String> entry : rs.cookies().entrySet()) { Cookie cookie = new Cookie(entry.getKey(), entry.getValue()); cookie.setPath(req.getContextPath() + "/"); res.addCookie(cookie); } return JsonUtil.jsonToObject(rs.body(), Map.class); }
public static String[] getEncodeFromProperties() { String[] arrEncode = null; try { String rslt = ReadProperties.getInstance().getValue("propertiesEncode"); arrEncode = rslt.split("\\>"); } catch (Exception e) { } return arrEncode; }
/** * common.properties * * @param key * @param value */ public static void setProperties(String key, String value) { String[] arrEncode = getEncodeFromProperties(); String rslt = ""; if (arrEncode.length == 2) { try { rslt = new String(value.getBytes(arrEncode[1]), arrEncode[0]); ReadProperties.getInstance().setProperties(key, rslt); } catch (Exception e) { } } }
/** * sql.properties ������ key �� ��; ��ȯ * * @param key * @return */ public static String getSQL(String key) { String[] arrEncode = getDecodeFromProperties(); String rslt = ReadProperties.getInstance().getSQL(key); if (arrEncode.length == 2) { try { rslt = new String(rslt.getBytes(arrEncode[0]), arrEncode[1]); } catch (Exception e) { } } return rslt; }
/** * ���� �α� ��� �Ѵ�. * * @param log */ public static void debugLog(String log) { String[] arrEncode = getValue("logDecode").split("\\>"); try { ReadPropertiesAble rp = ReadProperties.getInstance(); if (rp.getValue("debugLog").equals("Y")) { String path = rp.getValue("debugLogPath"); if (path == null || path.equals("")) path = rp.getPath(); log = (arrEncode.length == 2) ? new String(log.getBytes(arrEncode[0]), arrEncode[1]) : log; // System.out.println(Log.getInstance().logDate()+" : "+log); Log.getInstance().println(path + "degug.log", log); } } catch (Exception e) { } }
public static void accessMwLog(String log) { String[] arrEncode = getValue("logDecode").split("\\>"); try { ReadPropertiesAble rp = ReadProperties.getInstance(); if (rp.getValue("accessMwLog").equals("Y")) { Calendar cal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern("yyyy-MM-dd"); String path = rp.getValue("accessMwLogPath"); if (path == null || path.equals("")) path = rp.getPath(); log = (arrEncode.length == 2) ? new String(log.getBytes(arrEncode[0]), arrEncode[1]) : log; // System.out.println(Log.getInstance().logDate()+" : "+log); Log.getInstance() .println(path + "access_mw_" + sdf.format(cal.getTime()).toString() + ".log", log); } } catch (Exception e) { } }