2010-02-20 48 views
0

我需要通過https從xfire客戶端調用帶有ws-security(用戶名令牌)的axis2 Web服務。我可以通過xfire dynamic client來做這個練習,但是沒有wsdl base客戶端的運氣(即從wsdl生成java stub)。任何人都可以指出什麼可能是錯的(存根,ws-安全別的東西)?從xfire客戶端調用axis2 Web服務:找不到Operation的端點引用(EPR)

例外:螺紋

異常 「主」 org.codehaus.xfire.XFireRuntimeException: 無法調用服務..嵌套 例外是 org.codehaus.xfire.fault.XFireFault: 對於沒有找到 操作端點引用(EPR)是 https://localhost/services/DataServiceSample2 和WSA動作= org.codehaus.xfire.fault.XFireFault: 爲端點引用(EPR)沒有找到0操作是 https://localhost/services/DataServiceSample2 和WSA行動=

代碼:

public static void main(String[] args) throws MalformedURLException { 
    ProtocolSocketFactory easy = new EasySSLProtocolSocketFactory(); 
    Protocol protocol = new Protocol("https", easy, 9443); 
    Protocol.registerProtocol("https", protocol); 

    ObjectServiceFactory serviceFactory = new ObjectServiceFactory(); 
    serviceFactory.setStyle("message"); 
    Service serviceModel = serviceFactory.create(DataServiceSample2PortType.class); 
    XFireProxyFactory factory = new XFireProxyFactory(); 
    DataServiceSample2PortType service = (DataServiceSample2PortType) factory.create(serviceModel, "https://localhost:9443/services/DataServiceSample2"); 
    Client client = Client.getInstance(service); 
client.addOutHandler(new DOMOutHandler()); 

    Properties properties = new Properties(); 
    properties.setProperty(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN); 
    properties.setProperty(WSHandlerConstants.USER, "admin"); 
    properties.setProperty(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT); 
    properties.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, PasswordHandler.class.getName()); 
    client.addOutHandler(new WSS4JOutHandler(properties)); 

    sab.TopCustomerResponse topCustomersInCalifornia = service.topCustomersInCalifornia(null); 
} 
+0

是您的服務器在同一臺機器作爲你的客戶端上運行? – 2010-02-22 09:17:19

+0

否 – FoxyBOA 2010-02-22 14:12:38

回答

0

我在HTTP標題中缺少「SOAPAction」參數。你可以直接將其設置爲在Xfire客戶端

HttpsURLConnection conn; 
... 
conn.setRequestProperty("SOAPAction", "urn:executeXml"); 

AFAIK它可以在這樣的方式歸檔:

Map m = new HashMap(); 
    m.put("SOAPAction", "urn:executeXml"); 
    client.setProperty(CommonsHttpMessageSender.HTTP_HEADERS, m); 
0

請嘗試使用您的服務正在運行的機器的IP地址更換本地主機。取而代之的

factory.create(serviceModel,"https://localhost:9443/services/DataServiceSample2"); 

你可以試着指定IP地址這樣

factory.create(serviceModel,"https://192.168.2.18:9443/services/DataServiceSample2"); 

請注意,它被認爲是不好的做法,船舶代碼曖昧參數。所以在測試之後,你需要用一些易於配置的變量替換硬編碼的IP地址。

+0

通常,您可能希望從特定於環境的屬性文件加載端點地址。 – 2010-03-04 13:00:33