Axis,生於apache,死於apache。但由於其誕生時間早,現在仍佔一席之地。
由於工作需求,現需要將一個老舊的框架進行升級與重構。其中框架裏面的ws是由axis來完成的。
說實話,心裏有些抵觸,畢竟習慣了很多優雅的設計,再過來看Axis,有些難以適從。
所以在開發的工作當中,總會先入爲主的認爲錯誤是由於Axis導致的,而忽略了真正的原因。(這是個BUG呀)
下面簡單列兩條吧。共勉:
1。 axisclient連不通jax呀
package com.linpeng.ws;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService
public class Hello {
@WebMethod(operationName = "getRemindInfo")
public String getRemindInfo(String requestStr) {
System.out.println("From Client PT :" + requestStr);
return "Hello " + requestStr;
}
}
就這麼簡單的Service。
org.apache.axis.client.Service service = new org.apache.axis.client.Service();
Call call = (Call) service.createCall();
call.addParameter(new javax.xml.namespace.QName("", "requestStr"),
new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"),
javax.xml.rpc.ParameterMode.IN);
call.setReturnType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"));
call.setOperationName(new javax.xml.namespace.QName(request
.getParameter("namespace"), request
.getParameter("operationname")));
call.setTimeout(10000);
call.setTargetEndpointAddress(new java.net.URL(request.getParameter("wsdl")));
AuthenticatedUser user = SecurityUtil.getCurrentUser();
String requestStr = "Who";
result = call.invoke(new Object[] { requestStr });
調用也非常簡單。
可是在Endpoint那邊就是沒收到內容。爾後改用SoapUI進行測試,以及自己寫jax-client測試。發現都能拿到數據。
解決:加上@WebParam(name = "requestStr") 即可。