java Web Services WSDL & restful
先用jdk的工具wsimport對wsdl url產生相關檔案, 接著可以呼叫wsdl,call soap wsdl example:
C:\Users\vm\Desktop>"C:\Program Files\Java\jdk1.7.0_51\bin\wsimport.exe" -d test -keep http://www.webservicex.net/CurrencyConvertor.asmx?WSDL
package clientweb.servlet;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import thsrwebserviceproj.order.Order;
import thsrwebserviceproj.order.OrderService;
import thsrwebserviceproj.order.OrderServiceService;
/**
* Servlet implementation class order
*/
@WebServlet("/order")
public class orderServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public orderServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String fromStation = request.getParameter("fromStation");
String toStation = request.getParameter("toStation");
String date = request.getParameter("date");
String trainid = request.getParameter("trainid");
OrderServiceService orderSvc = new OrderServiceService();
OrderService orderport = orderSvc.getOrderService();
String result = orderport.order(fromStation, toStation, date, trainid);
System.out.println(result);
request.setAttribute("result", result);
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/views/result.jsp");
dispatcher.forward(request, response);
}
}
wsdl soap
http://www.mkyong.com/webservices/jax-ws/jax-ws-hello-world-example/
http://www.mkyong.com/webservices/jax-ws/jax-ws-wsimport-tool-example/
https://www.youtube.com/watch?v=od6fNiegu-Q
https://jax-ws.java.net/jax-ws-ea3/docs/wsimport.html
http://www.oseye.net/user/kevin/blog/89
http://www.oseye.net/user/kevin/blog/90
http://www.java2blog.com/2013/03/jaxws-web-service-eclipse-tutorial.html
http://karrysu.blogspot.tw/2010/10/jax-ws-webservice.html
restful
http://crunchify.com/how-to-build-restful-service-with-java-using-jax-rs-and-jersey/
http://crunchify.com/how-to-create-restful-java-client-with-jersey-client-example/
http://crunchify.com/how-to-create-restful-java-client-using-apache-httpclient-example/
http://crunchify.com/how-to-create-restful-java-client-with-java-net-url-example/
http://www.java2blog.com/2013/04/create-restful-web-servicesjax-rs-using.html
http://www.java2blog.com/2015/10/restful-web-services-jaxrs-json-example.html
http://java.dzone.com/articles/restful-web-services-java
http://www.codedata.com.tw/java/java-restful-1-jersey-and-jax-rs
C:\Users\vm\Desktop>"C:\Program Files\Java\jdk1.7.0_51\bin\wsimport.exe" -d test -keep http://www.webservicex.net/CurrencyConvertor.asmx?WSDL
package clientweb.servlet;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import thsrwebserviceproj.order.Order;
import thsrwebserviceproj.order.OrderService;
import thsrwebserviceproj.order.OrderServiceService;
/**
* Servlet implementation class order
*/
@WebServlet("/order")
public class orderServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public orderServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String fromStation = request.getParameter("fromStation");
String toStation = request.getParameter("toStation");
String date = request.getParameter("date");
String trainid = request.getParameter("trainid");
OrderServiceService orderSvc = new OrderServiceService();
OrderService orderport = orderSvc.getOrderService();
String result = orderport.order(fromStation, toStation, date, trainid);
System.out.println(result);
request.setAttribute("result", result);
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/views/result.jsp");
dispatcher.forward(request, response);
}
}
wsdl soap
http://www.mkyong.com/webservices/jax-ws/jax-ws-hello-world-example/
http://www.mkyong.com/webservices/jax-ws/jax-ws-wsimport-tool-example/
https://www.youtube.com/watch?v=od6fNiegu-Q
https://jax-ws.java.net/jax-ws-ea3/docs/wsimport.html
http://www.oseye.net/user/kevin/blog/89
http://www.oseye.net/user/kevin/blog/90
http://www.java2blog.com/2013/03/jaxws-web-service-eclipse-tutorial.html
http://karrysu.blogspot.tw/2010/10/jax-ws-webservice.html
restful
http://crunchify.com/how-to-build-restful-service-with-java-using-jax-rs-and-jersey/
http://crunchify.com/how-to-create-restful-java-client-with-jersey-client-example/
http://crunchify.com/how-to-create-restful-java-client-using-apache-httpclient-example/
http://crunchify.com/how-to-create-restful-java-client-with-java-net-url-example/
http://www.java2blog.com/2013/04/create-restful-web-servicesjax-rs-using.html
http://www.java2blog.com/2015/10/restful-web-services-jaxrs-json-example.html
http://java.dzone.com/articles/restful-web-services-java
http://www.codedata.com.tw/java/java-restful-1-jersey-and-jax-rs
留言
張貼留言