您将要使用@Produces、@ Consumes注释和JAXB创建并运行JAX-RS的简单示例。
@Stateless
@LocalBean
@path(/hotel ) ) )。
公共类rest main {
@GET
@ produces (media type.application _ XML )。
@path () hotelid () ) )
publichotelrestinforead (@ path param ) ' hotelid ' ) long hotelId )。
hoteldatasourcefakehoteldatasourcefake=newhoteldatasourcefake (;
hotelrestinfohotelinfo=hoteldatasourcefake.getfakeplacebyid (hotelid );
返回酒店信息;
}
}
在web.xml中:
REST App
com.sun.jersey.SPI.container.servlet容器
1
jersey网络APP
/rest/*
第二个APP应用程序是客户端
现在有以下客户端代码。
import com.sun.jersey.API.client.client;
import com.sun.jersey.API.client.client response;
import com.sun.jersey.API.client.webresource;
.
客户端客户端=client.create (;
string uri=' http://localhost :8080/rest JEE/rest/hotel/' hotelid;
webresource resource=client.resource (uri;
clientresponseresponse=resource.accept (application/XML ).get (客户端响应. class );
hotelrestinfohotelrestinfo=response.get entity (hotelrestinfo.class );
但是,我不想使用jersey的客户端、客户端响应和WebResource。
我想在@Consumes上做这个。
客户端appliaction web.xml是否需要包含其他参数?
双方(客户端和服务器)都包含HotelRESTInfo类。
@ XML路由
公共类热点
.
}