wadl2java 系统找不到_『阿男的Java社区指南』*02*Jersey的WADL功能
本节课视频:http://v.youku.com/v_show/id_XMTYwOTM3NzUxNg==.htmlJersey内置WADL动态生成的功能,为WebService提供WADL描述文件,本文简单介绍它的使用方法。首先使用maven命令生成Jersey项目:mvn archetype:generate -DarchetypeArtifactId=jersey-quickstart-grizzly2 \-DarchetypeGroupId=org.glassfish.jersey.archetypes -DinteractiveMode=false \-DgroupId=org.weli -DartifactId=wadl-service -Dpackage=org.weli \-DarchetypeVersion=2.23.1生成的项目目录结构如下:cute:wadl-service weli$ tree.├── pom.xml└── src
├── main
│
└── java
│
└── org
│
└── weli
│
├── Main.java
│
└── MyResource.java
└── test
└── java
└── org
└── weli
└── MyResourceTest.java9 directories, 4 files运行代码:mvn exec:java生成的资源如下:package org.weli;import javax.ws.rs.GET;import javax.ws.rs.Path;import javax.ws.rs.Produces;import javax.ws.rs.core.MediaType;/** * Root resource (exposed at "myresource" path) */@Path("myresource")public class MyResource {
/**
* Method handling HTTP GET requests. The returned object will be sent
* to the client as "text/plain" media type.
*
* @return String that will be returned as a text/plain response.
*/
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getIt() {
return "Got it!";
}}生成的测试代码如下:package org.weli;import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder;import javax.ws.rs.client.WebTarget;import org.glassfish.grizzly.http.server.HttpServer;import org.junit.After;import org.junit.Before;import org.junit.Test;import static org.junit.Assert.assertEquals;public class MyResourceTest {
private HttpServer server;
private WebTarget target;
@Before
public void setUp() throws Exception {
// start the server
server = Main.startServer();
// create the client
Client c = ClientBuilder.newClient();
// uncomment the following line if you want to enable
// support for JSON in the client (you also have to uncomment
// dependency on jersey-media-json module in pom.xml and Main.startServer())
// --
// c.configuration().enable(new org.glassfish.jersey.media.json.JsonJaxbFeature());
target = c.target(Main.BASE_URI);
}
@After
public void tearDown() throws Exception {
server.stop();
}
/**
* Test to see that the message "Got it!" is sent in the response.
*/
@Test
public void testGetIt() {
String responseMsg = target.path("myresource").request().get(String.class);
assertEquals("Got it!", responseMsg);
}}测试代码中使用轻量级的Grizzly容器。此外,生成的Main类里面包含了一个main方法可以启动服务器:package org.weli;import org.glassfish.grizzly.http.server.HttpServer;import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;import org.glassfish.jersey.server.ResourceConfig;import java.io.IOException;import java.net.URI;/** * Main class. * */public class Main {
// Base URI the Grizzly HTTP server will listen on
public static final String BASE_URI = "http://localhost:8080/myapp/";
/**
* Starts Grizzly HTTP server exposing JAX-RS resources defined in this application.
* @return Grizzly HTTP server.
*/
public static HttpServer startServer() {
// create a resource config that scans for JAX-RS resources and providers
// in org.weli package
final ResourceConfig rc = new ResourceConfig().packages("org.weli");
// create and start a new instance of grizzly http server
// exposing the Jersey application at BASE_URI
return GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
}
/**
* Main method.
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
final HttpServer server = startServer();
System.out.println(String.format("Jersey app started with WADL available at "
+ "%sapplication.wadl\nHit enter to stop it...", BASE_URI));
System.in.read();
server.stop();
}}启动这个服务后的日志输出:Jersey app started with WADL available at http://localhost:8080/myapp/application.wadl访问WADL输出如下:cute:Desktop weli$ curl http://localhost:8080/myapp/application.wadl<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
参考资料:[1] https://jersey.java.net/documentation/latest/getting-started.html#new-from-archetype
wadl2java 系统找不到_『阿男的Java社区指南』*02*Jersey的WADL功能相关推荐
- Git和Github介绍,294页『Git与Github学习使用指南』分享
1 前言 相信大家写代码的时候,心里肯定想找一个别人写好的,可以直接上手的代码,再做相应的修改和改进.那哪里有这些代码呢? 答案自然是Github了,那GitHub又是啥? GitHub是世界上最大的 ...
- java调用打印预览_急求一个用Java实现的打印及打印预览功能的Demo
展开全部 package com.szallcom.tools; import java.awt.BorderLayout; import java.awt.Color; import java.aw ...
- 使用ImageIO.write上传二维码文件时候,提示系统找不到指定路径
报错如图所示: java.io.FileNotFoundException: E:\SF\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtp ...
- idea报错:系统找不到指定路径
idea报错展示: Error:Internal error: (java.io.FileNotFoundException) C:\Users\鐜嬫旦娉�\.IntelliJIdea2017.3\s ...
- java.io.IOException: Cannot run program “***.exe“ CreateProcess error=2, 系统找不到指定的文件,java调用可执行程序
通过java调用命令行 java.io.IOException: Cannot run program ""C:\Users\yzx\Desktop\C4Photosynthesi ...
- phantomjs异常:Can not run program “phantomjs“: CreateProcess error=2, 系统找不到指定的文件
异常信息: java.io.IOException: Cannot run program "phantomjs": CreateProcess error=2, 系统找不到指定的 ...
- 【Java报错找不到指定文件】Exception in thread “main“ java.io.FileNotFoundException:...... (系统找不到指定的文件。)
出错代码 (这段代码位于Src_exp2_3.java中) public static String getValue(String key) throws IOException{Propertie ...
- Caused by: java.io.IOException: CreateProcess error=5, 拒绝访问 。 CreateProcess error=2, 系统找不到指定的文件
解决Intellij IDEA错误:" Caused by: java.io.IOException: CreateProcess error=5, 拒绝访问 " 和 " ...
- 文件上传:FileNotFoundException(系统找不到指定的路径)
环境搭建 目的:在工程下创建文件夹并接收上传的文件 UploadServlet public class UploadServlet extends HttpServlet {protected vo ...
最新文章
- Caused by: org.apache.ibatis.reflection.ReflectionException我碰到的情况,原因不唯一
- python用于什么-Python用于哪些领域
- 【Android NDK 开发】JNI 引用 ( 局部引用 | 局部引用作用域 | 局部引用产生 | 局部引用释放 | 代码示例)
- MTK 鼠标在列表界面选不到最后的选项 Patch
- 2009年SOA七大预测:SOA借力云计算
- java.lang.System
- 页面传值的方法 和JSON与字符串和对象之间的转换
- Alpha 冲刺 (1/10)
- J2EE 快速开发框架 Wabacus 3.3 版功能列表
- eclipse清理无用import(一次性清理整个项目所有)
- 【图像压缩】基于matlab GUI DCT图像压缩(压缩率可调)【含Matlab源码 1049期】
- vcpkg Ubuntu安装
- shell脚本合集2
- 无人机协同搜索matlab,一种多无人机协同目标搜索方法与流程
- Gxlcms有声小说系统/小说听书系统源码
- win10专业版激活工具很不错!
- C语言编程入门训练(一)
- 冯扬文:船用燃料油价格大涨对我省航运企业的影响
- jQuery实战读书笔记(第一章至第四章)
- [几何画板]正十七边形的做法
热门文章
- 虚拟内存越大越好吗_手机如何选择屏幕分辩率?720p、1080P,数值越大越好吗?...
- 简述web服务器的性能指标,web性能指标
- Spring Boot底层原理详解及整合
- Mac配置Tomcat环境变量
- IntelliJ IDEA注释模板设置
- C++ 使用folly的异步回调功能时出现的错误处理
- Avalon 总线 时序 介绍
- 华南师范计算机复试试题,复试全接触——记我的复试(附教育史复试真题)(华南师范大学)...
- ios底部栏设计规范_2018最新iOS端界面UI设计规范整理
- 微软时间源服务器,Windows的Internet时间服务器使时间同步 – 运维那些事