高手请指教!Axis2生成webservice客户端调用报错问题

xcs841202 2009-12-29 10:26:43
最近刚下载了axis2相关包(axis2.war)及Eclipse插件,axis2-eclipse-service-archiver-wizard.zip及axis2-eclipse-codegen-wizard.zip。通过wsdl文件自动生成客户端如下:
自动生成代码核心方法如下:
/**
* Auto generated method signature
* @see com.eii.webservices.user.GetUserInfo#getUser
* @param param2

*/
public com.eii.webservices.user.GetUserInfoStub.GetUserout getUser(

com.eii.webservices.user.GetUserInfoStub.GetUserin0 param2)
throws java.rmi.RemoteException

{
try{
org.apache.axis2.client.OperationClient _operationClient = _serviceClient.createClient(_operations[0].getName());
_operationClient.getOptions().setAction("");
_operationClient.getOptions().setExceptionToBeThrownOnSOAPFault(true);



// create SOAP envelope with that payload
org.apache.axiom.soap.SOAPEnvelope env = null;

//Style is Doc.


env = toEnvelope(getFactory(_operationClient.getOptions().getSoapVersionURI()),
param2,
optimizeContent(new javax.xml.namespace.QName("",
"getUser")));

//adding SOAP headers
_serviceClient.addHeadersToEnvelope(env);
// create message context with that soap envelope
org.apache.axis2.context.MessageContext _messageContext = new org.apache.axis2.context.MessageContext() ;
_messageContext.setEnvelope(env);

// add the message contxt to the operation client
_operationClient.addMessageContext(_messageContext);
//execute the operation client
_operationClient.execute(true);
//执行到此处报空指针

org.apache.axis2.context.MessageContext _returnMessageContext = _operationClient.getMessageContext(
org.apache.axis2.wsdl.WSDLConstants.MESSAGE_LABEL_IN_VALUE);
org.apache.axiom.soap.SOAPEnvelope _returnEnv = _returnMessageContext.getEnvelope();


java.lang.Object object = fromOM(
_returnEnv.getBody().getFirstElement() ,
com.eii.webservices.user.GetUserInfoStub.GetUserout.class,
getEnvelopeNamespaces(_returnEnv));
_messageContext.getTransportOut().getSender().cleanup(_messageContext);
return (com.eii.webservices.user.GetUserInfoStub.GetUserout)object;

}catch(org.apache.axis2.AxisFault f){
org.apache.axiom.om.OMElement faultElt = f.getDetail();
if (faultElt!=null){
if (faultExeptionNameMap.containsKey(faultElt.getQName())){
//make the fault by reflection
try{
java.lang.String exceptionClassName = (java.lang.String)faultExeptionClassNameMap.get(faultElt.getQName());
java.lang.Class exceptionClass = java.lang.Class.forName(exceptionClassName);
java.lang.Exception ex=
(java.lang.Exception) exceptionClass.newInstance();
//message class
java.lang.String messageClassName = (java.lang.String)faultMessageMap.get(faultElt.getQName());
java.lang.Class messageClass = java.lang.Class.forName(messageClassName);
java.lang.Object messageObject = fromOM(faultElt,messageClass,null);
java.lang.reflect.Method m = exceptionClass.getMethod("setFaultMessage",
new java.lang.Class[]{messageClass});
m.invoke(ex,new java.lang.Object[]{messageObject});


throw new java.rmi.RemoteException(ex.getMessage(), ex);
}catch(java.lang.ClassCastException e){
// we cannot intantiate the class - throw the original Axis fault
throw f;
} catch (java.lang.ClassNotFoundException e) {
// we cannot intantiate the class - throw the original Axis fault
throw f;
}catch (java.lang.NoSuchMethodException e) {
// we cannot intantiate the class - throw the original Axis fault
throw f;
} catch (java.lang.reflect.InvocationTargetException e) {
// we cannot intantiate the class - throw the original Axis fault
throw f;
} catch (java.lang.IllegalAccessException e) {
// we cannot intantiate the class - throw the original Axis fault
throw f;
} catch (java.lang.InstantiationException e) {
// we cannot intantiate the class - throw the original Axis fault
throw f;
}
}else{
throw f;
}
}else{
throw f;
}
}
}

自己写的调用测试代码如下:

package com.eii.webservices.user;

import org.apache.axis2.AxisFault;

import com.eii.webservices.user.GetUserInfoStub.GetUserArgs;

public class Test {

public static void main(String[] args) {
com.eii.webservices.user.GetUserInfoStub stub;
try {
stub = new com.eii.webservices.user.GetUserInfoStub();

com.eii.webservices.user.GetUserInfoStub.GetUserin0 param6=


(com.eii.webservices.user.GetUserInfoStub.GetUserin0)getTestObject

(com.eii.webservices.user.GetUserInfoStub.GetUserin0.class);
// todo Fill in the param6 here
GetUserArgs arg = new GetUserArgs();
arg.setSysCode("EII");
arg.setUserId("A0071142");
param6.setGetUserin0(arg);
String s= stub.getUser( param6).getGetUserout();
System.out.println(s);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//the default implementation should point to the right endpoint


}
public static org.apache.axis2.databinding.ADBBean getTestObject

(java.lang.Class type) throws Exception{
return (org.apache.axis2.databinding.ADBBean) type.newInstance();
}
}


结果在执行测试程序时,总是出错,错误信息如下:

java.lang.NullPointerException
at org.apache.axis2.description.ClientUtils.inferInTransport

(ClientUtils.java:85)
at org.apache.axis2.description.OutInAxisOperationClient.execute

(OutInAxisOperation.java:163)
at com.eii.webservices.user.GetUserInfoStub.getUser

(GetUserInfoStub.java:141)
at com.eii.webservices.user.Test.main(Test.java:21)

这个问题,不知道如何解决,也查不到为什么会出错,请高手指教!在线等
...全文
1224 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
等待 2012-09-27
  • 打赏
  • 举报
回复
有解决的吗?
沐之枫 2012-08-06
  • 打赏
  • 举报
回复
楼主你解决没?我现在也出现这个问题。
xcs841202 2009-12-29
  • 打赏
  • 举报
回复
附WSDL文件如下:GetUserInfo.wsdl
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc11="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://user.webservices.eii.com" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://eii.com/webservices/user" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soapenc12="http://www.w3.org/2003/05/soap-encoding" targetNamespace="http://eii.com/webservices/user">
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://user.webservices.eii.com">
<xsd:complexType name="GetUserArgs">
<xsd:sequence>
<xsd:element minOccurs="0" name="sysCode" nillable="true" type="xsd:string"/>
<xsd:element minOccurs="0" name="userId" nillable="true" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://eii.com/webservices/user">
<xsd:element name="getUserin0" type="ns1:GetUserArgs"/>
<xsd:element name="getUserout" type="xsd:string"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="getUserRequest">
<wsdl:part name="getUserin0" element="tns:getUserin0">
</wsdl:part>
</wsdl:message>
<wsdl:message name="getUserResponse">
<wsdl:part name="getUserout" element="tns:getUserout">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="GetUserInfoPortType">
<wsdl:operation name="getUser">
<wsdl:input name="getUserRequest" message="tns:getUserRequest">
</wsdl:input>
<wsdl:output name="getUserResponse" message="tns:getUserResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="GetUserInfoHttpBinding" type="tns:GetUserInfoPortType">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getUser">
<wsdlsoap:operation/>
<wsdl:input>
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="GetUserInfo">
<wsdl:port name="GetUserInfoHttpPort" binding="tns:GetUserInfoHttpBinding">
<wsdlsoap:address location="http://10.60.108.150:9080/EII/services/GetUserInfo"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

8,906

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧