Преглед изворни кода

上传文件至 'edu-api-weixin'

fanjie пре 7 година
родитељ
комит
d524fb82ef

+ 5 - 0
edu-api-weixin/MANIFEST.MF

@@ -0,0 +1,5 @@
+Manifest-Version: 1.0
+Built-By: Administrator
+Build-Jdk: 1.8.0_111
+Created-By: Maven Integration for Eclipse
+

+ 23 - 0
edu-api-weixin/dubbo-boss.xml

@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
+	xsi:schemaLocation="http://www.springframework.org/schema/beans 
+			classpath:org/springframework/beans/factory/xml/spring-beans-3.1.xsd 
+            http://code.alibabatech.com/schema/dubbo  
+            classpath:dubbo.xsd">    
+	<!-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 -->
+	<dubbo:application name="efunbox-api-weixin" />       <!-- 使用multicast广播注册中心暴露发现服务地址 -->
+	<dubbo:registry  protocol="zookeeper"  address="${dubbo.registry.address}"/>         <!-- 生成远程服务代理,可以和本地bean一样使用demoService -->
+	<!-- behavior -->
+	<dubbo:reference id="favoritesService" interface="cn.efunbox.service.FavoritesService" check="false" version="${consumer.behavior.dubbo.version}"/>
+	<dubbo:reference id="subscribeService" interface="cn.efunbox.service.SubscribeService" check="false" version="${consumer.behavior.dubbo.version}"/>
+	<dubbo:reference id="postsService" interface="cn.efunbox.service.PostsService" check="false" version="${consumer.behavior.dubbo.version}"/>
+	<dubbo:reference id="replyService" interface="cn.efunbox.service.ReplyService" check="false" version="${consumer.behavior.dubbo.version}"/>
+	<dubbo:reference id="coursePlayLogService" interface="cn.efunbox.service.CoursePlayLogService" check="false" version="${consumer.behavior.dubbo.version}"/>
+	<dubbo:reference id="coursewareService" interface="cn.efunbox.service.CoursewareService" check="false" version="${consumer.resource.dubbo.version}"/>
+	<dubbo:reference id="courseService" interface="cn.efunbox.service.CourseService" check="false" version="${consumer.resource.dubbo.version}"/>
+
+	<!-- user -->
+	<dubbo:reference id="userInfoService" interface="cn.efunbox.service.UserInfoService" check="false" version="${consumer.user.dubbo.version}"/>
+
+</beans>

+ 73 - 0
edu-api-weixin/index.jsp

@@ -0,0 +1,73 @@
+<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
+<%
+    String path = request.getContextPath();
+    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
+%>
+
+<!DOCTYPE HTML>
+<html>
+<head>
+    <title>My WebSocket</title>
+</head>
+
+<body>
+Welcome<br/>
+<input id="text" type="text" /><button onclick="send()">Send</button>    <button onclick="closeWebSocket()">Close</button>
+<div id="message">
+</div>
+</body>
+
+<script type="text/javascript">
+    var websocket = null;
+
+    //判断当前浏览器是否支持WebSocket
+    if('WebSocket' in window){
+        websocket = new WebSocket("ws://localhost:8081/websocket/1");
+//        websocket = new WebSocket("wss://wxapi.ai160.com/efunbox-edu-api-weixin/websocket/1111");
+    }
+    else{
+        alert('Not support websocket')
+    }
+
+    //连接发生错误的回调方法
+    websocket.onerror = function(){
+        setMessageInnerHTML("error");
+    };
+
+    //连接成功建立的回调方法
+    websocket.onopen = function(event){
+        setMessageInnerHTML("open");
+    }
+
+    //接收到消息的回调方法
+    websocket.onmessage = function(event){
+        setMessageInnerHTML(event.data);
+    }
+
+    //连接关闭的回调方法
+    websocket.onclose = function(){
+        setMessageInnerHTML("close");
+    }
+
+    //监听窗口关闭事件,当窗口关闭时,主动去关闭websocket连接,防止连接还没断开就关闭窗口,server端会抛异常。
+    window.onbeforeunload = function(){
+        websocket.close();
+    }
+
+    //将消息显示在网页上
+    function setMessageInnerHTML(innerHTML){
+        document.getElementById('message').innerHTML += innerHTML + '<br/>';
+    }
+
+    //关闭连接
+    function closeWebSocket(){
+        websocket.close();
+    }
+
+    //发送消息
+    function send(){
+        var message = document.getElementById('text').value;
+        websocket.send(message);
+    }
+</script>
+</html>

+ 65 - 0
edu-api-weixin/spring-dao.xml

@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
+	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
+	xmlns:p="http://www.springframework.org/schema/p" xmlns:task="http://www.springframework.org/schema/task"
+	xsi:schemaLocation="http://www.springframework.org/schema/beans 
+	classpath:org/springframework/beans/factory/xml/spring-beans-3.1.xsd
+		http://www.springframework.org/schema/aop 
+		classpath:org/springframework/aop/config/spring-aop-3.1.xsd
+		http://www.springframework.org/schema/tx 
+		classpath:org/springframework/transaction/config/spring-tx-3.1.xsd
+		http://www.springframework.org/schema/context 
+		classpath:org/springframework/context/config/spring-context-3.1.xsd
+		">
+		
+	<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="clone">
+		<!-- 基本属性driverClassName、 url、user、password -->
+		<property name="driverClassName" value="${jdbc.driverClassName}" />
+		<property name="url" value="${edu.jdbc.url}" />
+		<property name="username" value="${edu.jdbc.username}" />
+		<property name="password" value="${edu.jdbc.password}" />
+		
+		<!-- 配置初始化大小、最小、最大 -->
+		<!-- 通常来说,只需要修改initialSize、minIdle、maxActive -->
+		<!-- 初始化时建立物理连接的个数,缺省值为0 -->
+		<property name="initialSize" value="2" />
+		<!-- 最小连接池数量 -->
+		<property name="minIdle" value="2" />
+		<!-- 最大连接池数量,缺省值为8 -->
+		<property name="maxActive" value="10" />
+
+		<!-- 获取连接时最大等待时间,单位毫秒。配置了maxWait之后,缺省启用公平锁,并发效率会有所下降,如果需要可以通过配置useUnfairLock属性为true使用非公平锁。 -->
+		<property name="maxWait" value="60000" />
+		
+		<!-- 
+			有些数据库连接的时候有超时限制(MySQL连接在8小时后断开),或者由于网络中断等原因,连接池的连接会出现失效的情况,这时候可以设置一个testWhileIdle参数为true,
+			如果检测到当前连接不活跃的时间超过了timeBetweenEvictionRunsMillis,则去手动检测一下当前连接的有效性,在保证确实有效后才加以使用。
+			在检测活跃性时,如果当前的活跃时间大于minEvictableIdleTimeMillis,则认为需要关闭当前连接。当
+			然,为了保证绝对的可用性,你也可以使用testOnBorrow为true(即在每次获取Connection对象时都检测其可用性),不过这样会影响性能。
+		-->
+		<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒(3600000:为1小时) -->
+		<property name="timeBetweenEvictionRunsMillis" value="3600000" />
+		<!-- 配置一个连接在池中最小生存的时间,单位是毫秒(300000:为5分钟) -->
+		<property name="minEvictableIdleTimeMillis" value="300000" />
+		<!-- 用来检测连接是否有效的sql,要求是一个查询语句。如果validationQuery为null,testOnBorrow、testOnReturn、testWhileIdle都不会其作用。 -->
+		<property name="validationQuery" value="${jdbc.pool.validationQuery}" />
+		<!-- 申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。建议配置为true,不影响性能,并且保证安全性。-->
+      	<property name="testWhileIdle" value="true" />
+      	<!-- 申请连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。缺省值:true -->
+      	<property name="testOnBorrow" value="false" />
+      	<!-- 归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。缺省值:false -->
+      	<property name="testOnReturn" value="false" />
+      	
+      	<!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
+		<!-- 是否缓存preparedStatement,也就是PSCache。PSCache对支持游标的数据库性能提升巨大,比如说oracle。在mysql5.5以下的版本中没有PSCache功能,建议关闭掉。5.5及以上版本有PSCache,建议开启。缺省值:false -->
+		<property name="poolPreparedStatements" value="true" />
+		<!-- 要启用PSCache,必须配置大于0,当大于0时,poolPreparedStatements自动触发修改为true。在Druid中,不会存在Oracle下PSCache占用内存过多的问题,可以把这个数值配置大一些,比如说100。 -->
+		<property name="maxPoolPreparedStatementPerConnectionSize" value="20" />
+	</bean>
+	
+	<!-- 配置Jdbc模板 -->
+	<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
+		<property name="dataSource" ref="dataSource"></property>
+	</bean>
+</beans>

+ 71 - 0
edu-api-weixin/web.xml

@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xmlns="http://java.sun.com/xml/ns/javaee"
+         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+         id="WebApp_ID" version="3.0">
+    <display-name>edu-api-weixin Web Application</display-name>
+
+    <filter>
+        <filter-name>ajax</filter-name>
+        <filter-class>cn.efunbox.filter.YunosApiFilter</filter-class>
+        <init-param>
+            <param-name>encoding</param-name>
+            <param-value>utf-8</param-value>
+        </init-param>
+    </filter>
+    <filter-mapping>
+        <filter-name>ajax</filter-name>
+        <url-pattern>/*</url-pattern>
+    </filter-mapping>
+
+
+    <context-param>
+        <param-name>contextConfigLocation</param-name>
+        <param-value>classpath:spring.xml</param-value>
+    </context-param>
+    <filter>
+        <description>字符集过滤器</description>
+        <filter-name>encodingFilter</filter-name>
+        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
+        <init-param>
+            <description>字符集编码</description>
+            <param-name>encoding</param-name>
+            <param-value>UTF-8</param-value>
+        </init-param>
+        <init-param>
+            <param-name>forceEncoding</param-name>
+            <param-value>true</param-value>
+        </init-param>
+    </filter>
+    <filter-mapping>
+        <filter-name>encodingFilter</filter-name>
+        <url-pattern>/*</url-pattern>
+    </filter-mapping>
+    <listener>
+        <description>spring Listener</description>
+        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
+    </listener>
+    <servlet>
+        <servlet-name>springMvc</servlet-name>
+        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
+        <init-param>
+            <param-name>contextConfigLocation</param-name>
+            <param-value>classpath:spring-mvc.xml</param-value>
+        </init-param>
+        <load-on-startup>1</load-on-startup>
+    </servlet>
+    <servlet-mapping>
+        <servlet-name>springMvc</servlet-name>
+        <url-pattern>/</url-pattern>
+    </servlet-mapping>
+    <servlet-mapping>
+        <servlet-name>default</servlet-name>
+        <url-pattern>*.html</url-pattern>
+    </servlet-mapping>
+    <listener>
+        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
+    </listener>
+    <welcome-file-list>
+        <welcome-file>index.jsp</welcome-file>
+    </welcome-file-list>
+</web-app>