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

javame 发布于 2014/09/23 21:35
阅读 1K+
收藏 0
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();
		}
	}
}

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

加载中
0
李星
李星
用SOAPUI 工具试试..这个工具主要调试webservice的
0
李星
李星

或者在提供服务的程序里service.xml 增加

<module ref="logging"/>

完整的例子如下:

<service name="myService"> 
     <description> 
         使用logging模块 
     </description> 
     <!--  引用logging模块  --> 
     <module ref="logging"/> 
     <parameter name="ServiceClass"> 
         service.MyService    
     </parameter> 
     <messageReceivers> 
         <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out" 
             class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" /> 
     </messageReceivers>



具体过程参考:  http://blog.csdn.net/thinkpadshi/article/details/8199027
0
我不说话
我不说话
axis框架本身用了Log4j吧,直接打印啊。把log4j.properties文件里级别改成debug
javame
javame
你好,我用了Axis框架里的Log4j, # Set root category priority to INFO and its only appender to CONSOLE. #log4j.rootCategory=INFO, CONSOLE log4j.rootCategory=DEBUG, CONSOLE 设置完后,没有打印出来呀?
0
javame
javame

引用来自“我不说话”的评论

axis框架本身用了Log4j吧,直接打印啊。把log4j.properties文件里级别改成debug

你好,我用了Axis框架里的Log4j,

# Set root category priority to INFO and its only appender to CONSOLE.

#log4j.rootCategory=INFO, CONSOLE

log4j.rootCategory=DEBUG, CONSOLE

设置完后,没有打印出来啊?

0
javame
javame

或者说我要发这样一个报文来请求WebService,程序中哪里错了,为什么一直请求不成功?

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">

   <soap:Header>
      <tem:etoneSoapHeader>
         <!--Optional:-->
         <tem:UserName>admin</tem:UserName>
         <!--Optional:-->
         <tem:Password>123</tem:Password>
         <!--Optional:-->
         <tem:StateLt>?</tem:StateLt>
         <!--Optional:-->
         <tem:StateYd>?</tem:StateYd>
         <!--Optional:-->
         <tem:StateDx>?</tem:StateDx>
         <!--Optional:-->
         <tem:Ydinterface>?</tem:Ydinterface>
      </tem:etoneSoapHeader>
   </soap:Header>
   <soap:Body>
      <tem:getPhoneArea>
         <!--Optional:-->
         <tem:mobile>18268136200</tem:mobile>
      </tem: getPhoneArea >
   </soap:Body>
</soap:Envelope>
返回顶部
顶部