[英]Java jax-rs server
在本地測試我制作的SOAP Web服務時,通常會這樣做:
MyServiceImpl service = new MyServiceImpl();
Endpoint endpoint=Endpoint.create(service);
endpoint.publish("http://localhost:8084/service") ;
現在,我也想將其擴展到REST服務。 我可以使用JBoss做到這一點,但我也想在本地進行測試。 有什么方法可以在Java中啟動Jax-RS Rest HTTP服務(並且沒有其他第三方庫,例如jersey等。)
不添加依賴項就無法做到。 簡單的方法是使用簡單框架和jersey-simple-server。 將它們添加到Maven的配置文件中,而沒有它們,您仍然可以部署到JBoss。
您可以手動打開http連接,有很多方法可以做到這一點
以下是更多示例之一。
import java.net.*;
import java.io.*;
public class URLConnectionReader {
public static void main(String[] args) throws Exception {
URL yahoo = new URL("http://www.sum.com/");
URLConnection yc = yahoo.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.