ehcache-server RESTful
2015-07-08 00:00
162 查看
摘要: ehcache-server RESTful
下载ehcache-server-1.0.0-distribution.tar.gz
http://tomcat.apache.org/download-60.cgi
下载tomcat6
文件夹名:ehcache
目录结构:
ehcache
--META-INF
--WEB-INF
在WEB-INF下的web.xml里disable SOAP Web Services
即注释掉
<servlet>
<servlet-name>EhcacheWebServiceEndpoint</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>EhcacheWebServiceEndpoint</servlet-name>
<url-pattern>/soap/EhcacheWebServiceEndpoint</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>60</session-timeout>
</session-config>
<listener>
<listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>
下载:slf4j-api-1.7.7.jar slf4j-jdk14-1.7.7.jar
放入:WEB-INF\lib,删除slf4j-api-1.5.8.jar
1.下载
http://ehcache.org/downloads/catalog下载ehcache-server-1.0.0-distribution.tar.gz
http://tomcat.apache.org/download-60.cgi
下载tomcat6
2.安装
安装tomcat6(安装路径里最好不要有空格)3.配置
解压ehcache-server-1.0.0-distribution.tar.gz文件夹名:ehcache
目录结构:
ehcache
--META-INF
--WEB-INF
在WEB-INF下的web.xml里disable SOAP Web Services
即注释掉
<servlet>
<servlet-name>EhcacheWebServiceEndpoint</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>EhcacheWebServiceEndpoint</servlet-name>
<url-pattern>/soap/EhcacheWebServiceEndpoint</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>60</session-timeout>
</session-config>
<listener>
<listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>
下载:slf4j-api-1.7.7.jar slf4j-jdk14-1.7.7.jar
放入:WEB-INF\lib,删除slf4j-api-1.5.8.jar
4.运行
将ehcache放到tomcat6的webapps,启动tomcat5.测试
用官网例子进行测试import java.io.InputStream; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; /** * A simple example Java client which uses the built-in java.net.URLConnection. * * @author BryantR * @author Greg Luck */ public class ExampleJavaClient { private static String TABLE_COLUMN_BASE = "http://localhost:8080/ehcache/rest/tableColumn"; private static String TABLE_COLUMN_ELEMENT = "http://localhost:8080/ehcache/rest/tableColumn/1"; /** * Creates a new instance of EHCacheREST */ public ExampleJavaClient() { } public static void main(String[] args) { URL url; HttpURLConnection connection = null; InputStream is = null; OutputStream os = null; int result = 0; try { //create cache URL u = new URL(TABLE_COLUMN_BASE); HttpURLConnection urlConnection = (HttpURLConnection) u.openConnection(); urlConnection.setRequestMethod("PUT"); int status = urlConnection.getResponseCode(); System.out.println("Status: " + status); urlConnection.disconnect(); //get cache url = new URL(TABLE_COLUMN_BASE); connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.connect(); is = connection.getInputStream(); byte[] response1 = new byte[4096]; result = is.read(response1); while (result != -1) { System.out.write(response1, 0, result); result = is.read(response1); } if (is != null) try { is.close(); } catch (Exception ignore) { } System.out.println("reading cache: " + connection.getResponseCode() + " " + connection.getResponseMessage()); if (connection != null) connection.disconnect(); //create entry url = new URL(TABLE_COLUMN_ELEMENT); connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("Content-Type", "text/plain"); connection.setDoOutput(true); connection.setRequestMethod("PUT"); connection.connect(); String sampleData = "Ehcache is way cool!!!"; byte[] sampleBytes = sampleData.getBytes(); os = connection.getOutputStream(); os.write(sampleBytes, 0, sampleBytes.length); os.flush(); System.out.println("result=" + result); System.out.println("creating entry: " + connection.getResponseCode() + " " + connection.getResponseMessage()); if (connection != null) connection.disconnect(); //get entry url = new URL(TABLE_COLUMN_ELEMENT); connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.connect(); is = connection.getInputStream(); byte[] response2 = new byte[4096]; result = is.read(response2); while (result != -1) { System.out.write(response2, 0, result); result = is.read(response2); } if (is != null) try { is.close(); } catch (Exception ignore) { } System.out.println("reading entry: " + connection.getResponseCode() + " " + connection.getResponseMessage()); if (connection != null) connection.disconnect(); } catch (Exception e) { e.printStackTrace(); } finally { if (os != null) try { os.close(); } catch (Exception ignore) { } if (is != null) try { is.close(); } catch (Exception ignore) { } if (connection != null) connection.disconnect(); } } }
相关文章推荐
- 我的第一台打印机-加电测试
- ZooKeeper典型应用场景一览
- 中大型移动互联网公司技术架构选择(转载)
- 多个相同属性的表单,获取不同表单的属性值
- android文档笔记(1)
- 敏捷管理是什么?
- 信息系统项目管理师挂靠方法及流程
- 执行一条sql语句update多条记录实现思路
- 几经辛苦,千医康健康网站终于上线
- View 事件传递,分发与拦截
- CSS 文本常用的换行方法
- 手机页面左右漂浮, PC端没有滚动条的抓狂问题
- boostrap 里的media的图片为什么会看不见
- Java程序员到架构师的推荐阅读书籍
- shell脚本利用Here Document ,打包C的源码并编译生成再执行。shell携代攻击程序
- 解决ssh登录后闲置时间过长而断开连接
- 上班的第五百二十二天
- Atom中文乱码字体大小设置
- msysgit之git bash方便的复制粘贴,默认工作目录,窗口大小,提高速度等小窍门
- Xposed (二) 深入Module