2011-10-21 48 views
0

apache.axis2.AxisFault:傳輸錯誤:401錯誤:調用部署在Tomcat 6.0.13上的webservice時未經授權的異常請查找如下所示的堆棧跟蹤:log4j:WARN無法爲記錄器找到appender(org.apache.axis2.description.AxisService)。 log4j:WARN請正確初始化log4j系統。 HSYS:sysuser00:10.112.209.51:6500:null:80:null [SO_TIMEOUT,_NTLM_DIGEST_BASIC_AUTHENTICATION_] 300000 org.ap[email protected]fc9944 HSYS:sysuser00 org.apache.axis2.AxisFault:傳輸錯誤: 401錯誤:未授權的org.apache.axis2.transport.http.HTTPSender.handleResponse(HTTPSender.java:296)在org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:190)在org.apache .axis2.transport.http.HTTPSender.send(HTTPSender.java:75)at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:371)at org.apache.axis2.transport.http.CommonsHTTPTransportSender .invoke(CommonsHTTPTransportSender.java:209)在org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:435)在org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:402)在有機org.apa中的apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229) che.axis2.client.OperationClient.execute(OperationClient.java:165)at com.test.CmPersonUpServiceStub.cmPersonUp(CmPersonUpServiceStub.java:228)at com.test.CmPersonUpServiceTest.testcmPersonUp(CmPersonUpServiceTest.java:69)at com.test .CmPersonUpServiceTest.main(CmPersonUpServiceTest.java:85)--------------------------------------- -------------------------------------------------- -------------------------`請找我的測試調用類,如下:org.apache.axis2.AxisFault:傳輸錯誤:401錯誤:在Tomcat上調用webservice時未經授權

/** 
* CmPersonUpServiceTest.java 
* 
* This file was auto-generated from WSDL 
* by the Apache Axis2 version: 1.5 Built on : Apr 30, 2009 (06:07:24 EDT) 
*/ 
    package com.test; 

import java.util.ArrayList; 
import java.util.List; 

import org.apache.axis2.addressing.EndpointReference; 
import org.apache.axis2.client.Options; 
import org.apache.axis2.client.ServiceClient; 
import org.apache.axis2.transport.http.HTTPConstants; 
import org.apache.axis2.transport.http.HttpTransportProperties; 
import org.apache.axis2.transport.http.HttpTransportProperties.Authenticator; 

import com.oracle.cmpersonup_xsd.CmPersonUp; 

    /* 
    * CmPersonUpServiceTest Junit test case 
    */ 

    public class CmPersonUpServiceTest { 


     /** 
     * Auto generated test method 
     */ 
     public void testcmPersonUp() throws java.lang.Exception{ 

     com.test.CmPersonUpServiceStub stub = 
        new com.test.CmPersonUpServiceStub();//the default implementation should point to the right endpoint 




     Options opt = stub._getServiceClient().getOptions(); 
     EndpointReference epr = new EndpointReference("http://10.112.209.51:6500/spl/XAIApp/xaiserver/CmPersonUp"); 
     opt.setTo(epr); 
     opt.setProperty(HTTPConstants.SO_TIMEOUT, new Integer(300000)); 
     HttpTransportProperties.Authenticator authenticator = new HttpTransportProperties.Authenticator(); 
     List<String> auth = new ArrayList<String>(); 
     auth.add(Authenticator.BASIC); 
     authenticator.setAuthSchemes(auth); 
     authenticator.setUsername("HSYS"); 
     authenticator.setPassword("sysuser00"); 
     authenticator.setHost("10.112.209.51:6500"); 
     authenticator.setPort(80); 
     authenticator.setPreemptiveAuthentication(true); 
     opt.setProperty(HTTPConstants.AUTHENTICATE, authenticator); 
     stub._getServiceClient().setOptions(opt); 

     Options opt1 = stub._getServiceClient().getOptions(); 
     if(opt1.getProperty(HTTPConstants.AUTHENTICATE)!=null){ 
     Authenticator authenticator1=(Authenticator)opt1.getProperty(HTTPConstants.AUTHENTICATE); 
     System.out.println(authenticator1.getUsername()+" : "+authenticator1.getPassword()+" : "+authenticator1.getHost()+" : "+authenticator1.getDomain()+" : "+authenticator1.getPort()+" : "+authenticator1.getRealm()); 
     } 
     else System.out.println("opt1.getProperty(HTTPConstants.AUTHENTICATE); is null "); 
      com.oracle.cmpersonup_xsd.CmPersonUp cmPersonUp5= 
                 (com.oracle.cmpersonup_xsd.CmPersonUp)getTestObject(com.oracle.cmpersonup_xsd.CmPersonUp.class); 
        // TODO : Fill in the cmPersonUp5 here 
      cmPersonUp5.setPersonId("0272100000"); 
      cmPersonUp5.setPersonEmailId("[email protected]"); 
      cmPersonUp5.setFaultStyle("wsdl"); 
      CmPersonUp response=stub.cmPersonUp(cmPersonUp5); 
      System.out.println(response.getPersonEmailId()+" ------>>>>>> "+response.getPersonId()+" ------->>>>>>> "+response.getPersonBirthDay()); 

     } 

     //Create an ADBBean and provide it as the test object 
     public org.apache.axis2.databinding.ADBBean getTestObject(java.lang.Class type) throws java.lang.Exception{ 
      return (org.apache.axis2.databinding.ADBBean) type.newInstance(); 
     } 

     public static void main(String[] args) { 
      CmPersonUpServiceTest test = new CmPersonUpServiceTest(); 
      try { 
       test.testcmPersonUp(); 
      } catch (Exception e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
     } 


    } 

請提供您的協助。 `

回答

1

一個401錯誤意味着目標URL是受保護的,你需要提供用戶名/密碼認證。

需要設置,使得服務不保護客戶端的用戶名和密碼,或者調整你的服務器設置。

檢查TemperatureConverterStub類中是否允許您設置用戶名/密碼的方法,或者查看您正在使用哪種工具創建這些類的文檔以獲取更多信息。

相關問題