开发者社区> 问答> 正文

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

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();
		}
	}
}
我实质上是想打印请求报文的内容的,或者用什么工具捕获请求的报文

展开
收起
kun坤 2020-05-29 22:53:18 725 0
1 条回答
写回答
取消 提交回答
  • 用SOAPUI 工具试试..这个工具主要调试webservice的

    或者在提供服务的程序里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

    ######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 设置完后,没有打印出来呀?######

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

    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
    设置完后,没有打印出来啊? ###### 或者说我要发这样一个报文来请求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>

    2020-05-29 22:53:27
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

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