简体   繁体   English

从Web服务客户端访问Java Web服务

[英]accessing a java webservice from the webservice client

I am trying to access a java webservice by sending a soap request to the service the strange part is that until recently it worked fine, and now it gives me an internal server error what am i doing wrong ?? 我正在尝试通过向服务发送肥皂请求来访问Java Web服务,奇怪的是直到最近它都能正常工作,现在它给了我一个内部服务器错误,我在做什么错?

this is my soap message: 这是我的肥皂信息:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0="http://webservice.lenabru.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soapenv:Body> <q0:register><q0:regFirstName></q0:regFirstName><q0:regLastName></q0:regLastName><q0:regLoginName></q0:regLoginName><q0:regPassword></q0:regPassword><q0:regAddress></q0:regAddress><q0:regEmail></q0:regEmail><q0:regPhone></q0:regPhone></q0:register></soapenv:Body></soapenv:Envelope> 

and this is the response i get from the server 这是我从服务器得到的响应

"<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <soapenv:Body>
  <soapenv:Fault>
   <faultcode>soapenv:Server.userException</faultcode>
   <faultstring>java.lang.reflect.InvocationTargetException</faultstring>
   <detail>
    <ns1:hostname xmlns:ns1="http://xml.apache.org/axis/">Lena</ns1:hostname>
   </detail>
  </soapenv:Fault>
 </soapenv:Body>
</soapenv:Envelope>"

this is the contents of the webmethod i am trying to reach: 这是我尝试达到的webmethod的内容:

@WebMethod
    public boolean register(String regFirstName, String regLastName, String regLoginName, String regPassword, String regAddress, String regPhone, String regEmail) {
        return false;
    }

this is my wsdl: 这是我的wsdl:

<wsdl:definitions xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://webservice.lenabru.com" xmlns:intf="http://webservice.lenabru.com" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://webservice.lenabru.com">
<!--
WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)
-->
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://webservice.lenabru.com">
<element name="register">
<complexType>
<sequence>
<element name="regFirstName" type="xsd:string"/>
<element name="regLastName" type="xsd:string"/>
<element name="regLoginName" type="xsd:string"/>
<element name="regPassword" type="xsd:string"/>
<element name="regAddress" type="xsd:string"/>
<element name="regPhone" type="xsd:string"/>
<element name="regEmail" type="xsd:string"/>
</sequence>
</complexType>
</element>
<element name="registerResponse">
<complexType>
<sequence>
<element name="registerReturn" type="xsd:boolean"/>
</sequence>
</complexType>
</element>
<element name="isUserExists">
<complexType>
<sequence>
<element name="userName" type="xsd:string"/>
</sequence>
</complexType>
</element>
<element name="isUserExistsResponse">
<complexType>
<sequence>
<element name="isUserExistsReturn" type="xsd:boolean"/>
</sequence>
</complexType>
</element>
</schema>
</wsdl:types>
<wsdl:message name="isUserExistsResponse">
<wsdl:part element="impl:isUserExistsResponse" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="registerRequest">
<wsdl:part element="impl:register" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="isUserExistsRequest">
<wsdl:part element="impl:isUserExists" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="registerResponse">
<wsdl:part element="impl:registerResponse" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:portType name="ElectronicArenaWebService">
<wsdl:operation name="register">
<wsdl:input message="impl:registerRequest" name="registerRequest"></wsdl:input>
<wsdl:output message="impl:registerResponse" name="registerResponse"></wsdl:output>
</wsdl:operation>
<wsdl:operation name="isUserExists">
<wsdl:input message="impl:isUserExistsRequest" name="isUserExistsRequest"></wsdl:input>
<wsdl:output message="impl:isUserExistsResponse" name="isUserExistsResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ElectronicArenaWebServiceSoapBinding" type="impl:ElectronicArenaWebService">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="register">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="registerRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="registerResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="isUserExists">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="isUserExistsRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="isUserExistsResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ElectronicArenaWebServiceService">
<wsdl:port binding="impl:ElectronicArenaWebServiceSoapBinding" name="ElectronicArenaWebService">
<wsdlsoap:address location="http://localhost:8080/ElectronicArenaLena/services/ElectronicArenaWebService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

First a note: if you're using Tomcat 7 (why not use Axis 2 ?) 首先请注意:如果您使用的是Tomcat 7(为什么不使用Axis 2?)

Setup for Log4j (at the time axis 1 was still there there was log4j, now there is a better alternatives from the same author of Log4j it's called logback - however there is a new Log4j 2 now but I haven't tested it for this setup only the one that comes with axis downloaded here http://archive.apache.org/dist/ws/axis/1_4/ ) Log4j的设置(在时间轴1上仍然有log4j,现在有来自Log4j的同一作者的更好的替代品 ,称为logback-但是现在有一个新的Log4j 2,但我尚未对此设置进行过测试只有随轴附带的一个在这里下载http://archive.apache.org/dist/ws/axis/1_4/

create a log4j.properties file and put it in your WEB-INF/classes folder (I created a sample content so that you can get going, might need to look at log4j's documentation to modify the logs as you need - the below creates multiple log files(max 5) whenever one's size reaches 100k it creates another, you might need to change the size or number as needed or just use one) 创建一个log4j.properties文件并将其放在您的WEB-INF / classes文件夹中(我创建了一个示例内容,以便您可以开始使用,可能需要查看log4j的文档以根据需要修改日志-以下创建了多个日志个文件(最多5个),只要一个人的大小达到100k,它就会创建另一个文件,您可能需要根据需要更改大小或数字,或者只使用其中一个)

log4j.rootLogger=DEBUG, R

log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.MaxFileSize=100KB
log4j.appender.R.File=axis.log 
log4j.appender.R.MaxBackupIndex=5
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} – %m%n

# below line might not be needed, but I just had it there
log4j.R.org.apache.axis=DEBUG

now open axis.jar and remove whatever properties file you have directly in the folder structure (next to MANIFEST and org folders - I had simplelog.properties so I deleted it) 现在打开axis.jar并删除直接在文件夹结构中的所有属性文件(MANIFEST和org文件夹旁边-我有simplelog.properties,因此将其删除)

restart apache tomcat and check the apache logs to make sure log4j isn't throwing any warnings or errors 重新启动apache tomcat并检查apache日志以确保log4j不会引发任何警告或错误

If everything works fine, you should be able to see axis.log in apache tomcat's bin directory 如果一切正常,您应该能够在apache tomcat的bin目录中看到axis.log

Note: you might notice a lot of useless debug logs, however when an exception occurs or some issue happens it might be handy to have this level of details in your logs, plus you can disable it anytime you need, just replace rootLogger DEBUG into INFO or comment log4j.properties all together 注意:您可能会注意到很多无用的调试日志,但是,当发生异常或某些问题时,在日志中包含此级别的详细信息可能很方便,而且您可以在需要时随时禁用它,只需将rootLogger DEBUG替换为INFO或一起评论log4j.properties

References: 参考文献:

http://osdir.com/ml/text.xml.axis.user/2002-08/msg00436.html http://osdir.com/ml/text.xml.axis.user/2002-08/msg00436.html

http://axis.apache.org/axis/java/developers-guide.html#LoggingTracing http://axis.apache.org/axis/java/developers-guide.html#LoggingTracing

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM