简体   繁体   中英

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 ??

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
    public boolean register(String regFirstName, String regLastName, String regLoginName, String regPassword, String regAddress, String regPhone, String regEmail) {
        return false;
    }

this is my 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 ?)

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/ )

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.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)

restart apache tomcat and check the apache logs to make sure log4j isn't throwing any warnings or errors

If everything works fine, you should be able to see axis.log in apache tomcat's bin directory

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

References:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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