Step1:
需要准备的文件:
axis.jar
axis-ant.jar
commons-discovery.jar
commons-logging.jar
jaxrpc.jar
log4j-1.2.4.jar
saaj.jar
wsdl4j.jar
xercesImpl.jar
可选:
(远程web service提供的类).jar
这2个是解析XML的类。以及支持使用Xpath解析XML的类,推荐使用,因为用xpath解析XML相当的方便。
dom4j-1.6.1.jar
jaxen-1.1.1.jar
准备好以上的文件一起COPY到(domino程序目录)/jvm/lib/ext/ 下面。
因为你肯定需要在客户端编译和调试,所以也复制一份到(你的Designer程序目录)/jvm/lib/ext/下面。
Step2:
配置Domino的Java.policy文件
这一步很重要。因为Axis里面的代码可能会在运行时受到policy的限制而报一些Permission的错。
编辑(Domino程序目录)/jvm/lib/security/java.policy
找到 grant {
};
这个区块。
在里面加上一行:
permission java.util.PropertyPermission "java.protocol.handler.pkgs", "write";
重起Domino之后。
Axis的环境就算配置OK了
Step3:
写代码:
拿一个例子说事,
这就是我要调的web service地址:
这个web service的作用就是我传一堆乱78糟的信息过去。然后它传一堆乱78糟的信息过来。我这次要做的事就是用Axis测试它提供的” HelloCtrip”方法
先在IE里面打开一下上面的web service地址,会列出该web service所支持的所有方法。查看一下HelloCtrip方法,看到以下信息:
SOAP 1.1
以下是
SOAP 1.2
请求和响应示例。所显示的
占位符
需替换为实际值。
POST /CorpExternalInterface/DomesticFlightService/DomesitFlights.asmx HTTP/1.1
Host: www.corporatetravel.ctrip.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.ctrip.com/webservice/flight/HelloCtrip"
?
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<HelloCtrip xmlns="http://www.ctrip.com/webservice/flight/" />
</soap:Body>
</soap:Envelope>
瞄一眼后,编写以下代码:
import lotus.domino.*;
import java.io.*;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
public class JavaAgent extends AgentBase {
private PrintWriter pw;
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Document curDoc = agentContext.getDocumentContext();
pw = getAgentOutput();
String endpoint=” https://www.corporatetravel.ctrip.com/CorpExternalInterface/DomesticFlightService/DomesitFlights.asmx”;
Service service = new Service();
Call call = (Call)service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName("HelloCtrip" );
call.setUseSOAPAction(true);
call.setSOAPActionURI("http://www.ctrip.com/webservice/flight/HelloCtrip");
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
String k = (String)call.invoke(new Object[]{});
printScript(k);
}
catch (Exception e) {System.err.println(e.toString());}
}
private void printScript(String str) throws Exception
{
if (str==null)
str="false";
pw.println("Cache-Control: NOCACHE");
pw.println("Pragma: no-cache");
pw.println("Content-type: text/html");
pw.println("<script>");
pw.println("alert(/""+str+"/")");
pw.println("</script>");
}
}
在网页上运行一下。
提示:Welcome to visit CTRIP DOMESTIC WEBSERVICE.
完了