开发者社区> 问答> 正文

用Java开发WebService Axis,怎么把请求内容打印下来?

import java.rmi.RemoteException;
import javax.xml.rpc.ParameterMode;

import javax.xml.rpc.ServiceException;
import javax.xml.soap.SOAPException;
import org.apache.axis.client.Call;

import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.apache.axis.message.SOAPHeaderElement;
public class SOAPHepler {

    public static void main(String[] args) throws ServiceException, RemoteException {
        try {
            String endpointURL = "http://122.228.134.30:2121/EtoneWebService.asmx?WSDL";
            Service service = new Service();
            Call call = (Call) service.createCall();
            call.setTargetEndpointAddress(new java.net.URL(endpointURL));
            call.setSOAPActionURI("http://tempuri.org/" + "getPhoneArea");
            call.setOperationName("getPhoneArea"); 
            SOAPHeaderElement soapHeaderElement = new SOAPHeaderElement("http://tempuri.org/", "etoneSoapHeader");
            soapHeaderElement.setNamespaceURI("http://tempuri.org/");
            try {
                soapHeaderElement.addChildElement("UserName").setValue("admin");
                soapHeaderElement.addChildElement("Password").setValue("123");
            }
            catch (SOAPException e)    {
                e.printStackTrace();
            }
            call.addHeader(soapHeaderElement);
            call.setReturnType(XMLType.XSD_STRING);
            call.addParameter("mobile", XMLType.XSD_STRING, ParameterMode.IN);
            String ret = (String) call.invoke(new Object[] { "18268136200" });
            System.out.println(ret);
            
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}

我实质上是想打印请求报文的内容的,或者用什么工具捕获请求的报文

展开
收起
爵霸 2016-06-06 11:15:47 5080 0
1 条回答
写回答
取消 提交回答
  • 安装Eclipse-jee,下载Axis2的最新版本Axis2 1.4.1 Release,其内部结构为 开发前配置:在Eclipse的菜单栏中,Window --> Preferences --> Web Service --> Axis2 Perferences,在Axis2 runtime location中选择Axis2解压缩包的位置,设置好后,点"OK"即行。 新建一个Java Project,命名为"WS_01",在"WS_01"项目上new --> other,找到"Web Services"下面的"Web Service"; 在出现的Web Services对象框,在Service implementation中点击"Browse",进入Browse Classes对象框,查找到我们刚才写的写的CalculateService类。(如下图)。点击"ok",则回到 Web Service话框。 在Web Service对话框中,将Web Service type中的滑块,调到"start service“的位置,将Client type中的滑块调到"Test client"的位置。 在Web Service type滑块图的右边有个"Configuration",点击它下面的选项,进入Service Deployment Configuration对象框,在这里选择相应的Server(我这里用Tomcat6.0)和Web Service runtime(选择Apache Axis2) 点OK后,则返回到Web Service对话框,同理,Client type中的滑块右边也有"Configuration",也要进行相应的置,步骤同上。完成后,Next --> next即行。到了Server startup对话框,有个按键"start server",点击它,则可启动Tomcat服务器了。 等启完后,点击"next -- > next",一切默认即行,最后,点击完成。最后,出现如下界面:(Web Service Explorer),我们在这里便可测试我们的Web服务。 测试比较简单,例如,我们选择一个"plus"的Operation,出现下图,在x的输入框中输入2,在y的 输入框中输入3,点击"go",便会在status栏中显示结果5.0。其他方法的测试也类似。
    

    答案来源网络,供您参考

    2019-09-18 17:09:31
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载