2014-06-13 105 views
0

我正在開發一個項目,我正在開發一個Web服務,使用谷歌翻譯API將英語翻譯成法語。我已經成功地創建了服務器。但是當我運行我的客戶端時出現錯誤。我正在爲項目使用Java,Eclipse,Axis2和Tomcat。 這是我的服務器代碼:Web服務錯誤(谷歌翻譯API)WSDL錯誤Java Eclipe Axis2

package com.GTWS; 
import com.gtranslate.Language; 
import com.gtranslate.Translator; 

public class GoogleTranslateClass { 

    public String toFrench(String sentence){ 
     Translator translate = Translator.getInstance(); 
     String textF = translate.translate(sentence, Language.ENGLISH, Language.FRENCH); 
     return textF; 
    } 


} 

請注意,我使用的是外部谷歌翻譯爲宗旨API JAR。然後我創建Web服務並讓它運行。 Eclipse將創建WSDL文件是:

<?xml version="1.0" encoding="UTF-8"?> 

-<wsdl:definitions targetNamespace="http://GTWS.com" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:ns="http://GTWS.com" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"> 

<wsdl:documentation> Please Type your service description here </wsdl:documentation> 


-<wsdl:types> 


-<xs:schema targetNamespace="http://GTWS.com" elementFormDefault="qualified" attributeFormDefault="qualified"> 


-<xs:element name="toFrench"> 


-<xs:complexType> 


-<xs:sequence> 

<xs:element name="sentence" type="xs:string" nillable="true" minOccurs="0"/> 

</xs:sequence> 

</xs:complexType> 

</xs:element> 


-<xs:element name="toFrenchResponse"> 


-<xs:complexType> 


-<xs:sequence> 

<xs:element name="return" type="xs:string" nillable="true" minOccurs="0"/> 

</xs:sequence> 

</xs:complexType> 

</xs:element> 

</xs:schema> 

</wsdl:types> 


-<wsdl:message name="toFrenchRequest"> 

<wsdl:part name="parameters" element="ns:toFrench"/> 

</wsdl:message> 


-<wsdl:message name="toFrenchResponse"> 

<wsdl:part name="parameters" element="ns:toFrenchResponse"/> 

</wsdl:message> 


-<wsdl:portType name="GoogleTranslateClassPortType"> 


-<wsdl:operation name="toFrench"> 

<wsdl:input wsaw:Action="urn:toFrench" message="ns:toFrenchRequest"/> 

<wsdl:output wsaw:Action="urn:toFrenchResponse" message="ns:toFrenchResponse"/> 

</wsdl:operation> 

</wsdl:portType> 


-<wsdl:binding name="GoogleTranslateClassSoap11Binding" type="ns:GoogleTranslateClassPortType"> 

<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> 


-<wsdl:operation name="toFrench"> 

<soap:operation style="document" soapAction="urn:toFrench"/> 


-<wsdl:input> 

<soap:body use="literal"/> 

</wsdl:input> 


-<wsdl:output> 

<soap:body use="literal"/> 

</wsdl:output> 

</wsdl:operation> 

</wsdl:binding> 


-<wsdl:binding name="GoogleTranslateClassSoap12Binding" type="ns:GoogleTranslateClassPortType"> 

<soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> 


-<wsdl:operation name="toFrench"> 

<soap12:operation style="document" soapAction="urn:toFrench"/> 


-<wsdl:input> 

<soap12:body use="literal"/> 

</wsdl:input> 


-<wsdl:output> 

<soap12:body use="literal"/> 

</wsdl:output> 

</wsdl:operation> 

</wsdl:binding> 


-<wsdl:binding name="GoogleTranslateClassHttpBinding" type="ns:GoogleTranslateClassPortType"> 

<http:binding verb="POST"/> 


-<wsdl:operation name="toFrench"> 

<http:operation location="toFrench"/> 


-<wsdl:input> 

<mime:content type="application/xml" part="parameters"/> 

</wsdl:input> 


-<wsdl:output> 

<mime:content type="application/xml" part="parameters"/> 

</wsdl:output> 

</wsdl:operation> 

</wsdl:binding> 


-<wsdl:service name="GoogleTranslateClass"> 


-<wsdl:port name="GoogleTranslateClassHttpSoap11Endpoint" binding="ns:GoogleTranslateClassSoap11Binding"> 

<soap:address location="http://localhost:8080/GoogleTranslateWebServer/services/GoogleTranslateClass.GoogleTranslateClassHttpSoap11Endpoint/"/> 

</wsdl:port> 


-<wsdl:port name="GoogleTranslateClassHttpSoap12Endpoint" binding="ns:GoogleTranslateClassSoap12Binding"> 

<soap12:address location="http://localhost:8080/GoogleTranslateWebServer/services/GoogleTranslateClass.GoogleTranslateClassHttpSoap12Endpoint/"/> 

</wsdl:port> 


-<wsdl:port name="GoogleTranslateClassHttpEndpoint" binding="ns:GoogleTranslateClassHttpBinding"> 

<http:address location="http://localhost:8080/GoogleTranslateWebServer/services/GoogleTranslateClass.GoogleTranslateClassHttpEndpoint/"/> 

</wsdl:port> 

</wsdl:service> 

</wsdl:definitions> 

然後我去創造僅僅使用軸基於Eclipse的Web客戶端並創建代理文件。我創建代理類的一個對象,並調用toFrench的方法,如:

package com.GTWS; 
import java.rmi.RemoteException; 

import com.GTWS.*; 
public class GTtester { 

    public static void main(String[] args) throws RemoteException { 
     // TODO Auto-generated method stub 
     GoogleTranslateClassPortTypeProxy gtp = new GoogleTranslateClassPortTypeProxy(); 
     System.out.println(gtp.toFrench("hi there")); 

    } 

} 

後來我得到的錯誤:

Jun 12, 2014 11:11:43 PM org.apache.axis.utils.JavaUtils isAttachmentSupported 
WARNING: Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled. 
Exception in thread "main" AxisFault 
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server 
faultSubcode: 
faultString: com/gtranslate/Translator 
faultActor: 
faultNode: 
faultDetail: 
    {http://xml.apache.org/axis/}stackTrace:com/gtranslate/Translator 
    at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222) 
    at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129) 
    at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087) 
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:606) 
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1742) 
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2900) 
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:607) 
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:116) 
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:489) 
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:835) 
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764) 
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123) 
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1210) 
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:568) 
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:302) 
    at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227) 
    at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696) 
    at org.apache.axis.Message.getSOAPEnvelope(Message.java:435) 
    at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62) 
    at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206) 
    at org.apache.axis.client.Call.invokeEngine(Call.java:2784) 
    at org.apache.axis.client.Call.invoke(Call.java:2767) 
    at org.apache.axis.client.Call.invoke(Call.java:2443) 
    at org.apache.axis.client.Call.invoke(Call.java:2366) 
    at org.apache.axis.client.Call.invoke(Call.java:1812) 
    at com.GTWS.GoogleTranslateClassSoap11BindingStub.toFrench(GoogleTranslateClassSoap11BindingStub.java:108) 
    at com.GTWS.GoogleTranslateClassPortTypeProxy.toFrench(GoogleTranslateClassPortTypeProxy.java:50) 
    at com.GTWS.GTtester.main(GTtester.java:10) 

    {http://xml.apache.org/axis/}hostname:Karan 

com/gtranslate/Translator 
    at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222) 
    at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129) 
    at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087) 
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:606) 
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1742) 
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2900) 
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:607) 
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:116) 
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:489) 
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:835) 
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764) 
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123) 
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1210) 
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:568) 
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:302) 
    at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227) 
    at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696) 
    at org.apache.axis.Message.getSOAPEnvelope(Message.java:435) 
    at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62) 
    at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206) 
    at org.apache.axis.client.Call.invokeEngine(Call.java:2784) 
    at org.apache.axis.client.Call.invoke(Call.java:2767) 
    at org.apache.axis.client.Call.invoke(Call.java:2443) 
    at org.apache.axis.client.Call.invoke(Call.java:2366) 
    at org.apache.axis.client.Call.invoke(Call.java:1812) 
    at com.GTWS.GoogleTranslateClassSoap11BindingStub.toFrench(GoogleTranslateClassSoap11BindingStub.java:108) 
    at com.GTWS.GoogleTranslateClassPortTypeProxy.toFrench(GoogleTranslateClassPortTypeProxy.java:50) 
    at com.GTWS.GTtester.main(GTtester.java:10) 

回答

0

您需要添加郵件1.4.jar和activation-1.1.jar到你的類路徑(WEB-INF/lib)。既然你有mime在wsdl文件中輸入。

WARNING: Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled.