2015-10-05 113 views
0

我知道這是另一個類似主題的主題,但我搜索了stackoverflow,並且找不到我的問題的答案。 情況如下: 我有一個web服務讓我們用很多方法調用它testservice。最近我不得不添加一個又一個,所以我所做的:Java Stub類型中的方法不適用於參數

public int addPayments_p24(String sessionId, int pos_id, String amount, String currency, String title, String client, String address, String postal, String city, String country, String email, String language, String p24_sign) throws Exception { 
    int last_inserted_id=0; 
try { 
    PreparedStatement statement = null; 
    int timestamp = (int)(System.currentTimeMillis()/1000L); 
    statement = connection 
       .prepareStatement(
         "Insert into p24_strefa(pos_id,session_id,amount,currency,title,client,address,postal,city,country,email,language,p24_sign,timestamp)" + 
           "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?);", statement.RETURN_GENERATED_KEYS); 
     statement.setInt(1, pos_id); 
     statement.setString(2, sessionId); 
     statement.setString(3, amount); 
     statement.setString(4, currency); 
     statement.setString(5, title); 
     statement.setString(6, client); 
     statement.setString(7, address); 
     statement.setString(8, postal); 
     statement.setString(9, city); 
     statement.setString(10, country); 
     statement.setString(11, email); 
     statement.setString(12, language); 
     statement.setString(13, p24_sign); 
     statement.setInt(14, timestamp); 
     statement.executeUpdate(); 
     ResultSet rs = statement.getGeneratedKeys(); 
      if(rs.next()) 
      { 
       last_inserted_id = rs.getInt(1); 
      } 
    } catch (Exception ex) { 
     _log.error("addpayments_p24", ex); 
     throw ex; 
    } 
    finally { 
     dispose(); 
    } 

    return last_inserted_id; 
} 

然後我試圖調用從JSP文件中這個方法是這樣的:

String sessionId = request.getParameter("p24_session_id"); 
String amount = request.getParameter("p24_amount"); 
String currencys = request.getParameter("p24_currency"); 
String title = request.getParameter("p24_description"); 
String client = request.getParameter("p24_client"); 
String address = request.getParameter("p24_address"); 
String postal = request.getParameter("p24_zip"); 
String city = request.getParameter("p24_city"); 
String country = request.getParameter("p24_country"); 
String email = request.getParameter("p24_email"); 
String language = request.getParameter("p24_language"); 
String sign = get_sign_str(sessionId,amount,currencys); 
int pos_id = 2414; 
int testResponse; 
    try { 
     if (test== null) { 
     inittest(); 
    } 
    testResponse = test.addPayments_p24("test",2,"test","test","test","test","test","test","test","test","test","test","test"); 
    } 
    catch (testWebServicesExceptionException e) 
    { 
     e.printStackTrace(); 
    } 

到web服務的連接是通過這個函數來完成:

private static testWebServicesStub test; 
private synchronized void inittest() throws AxisFault { 
     if (test == null) { 
      String testWebServicesEndpoint = Settings 
        .gettestWebServicesEndpoint(); 
      test= new testWebServicesStub(testWebServicesEndpoint); 
     } 
    } 

正如你所看到的我使用Axis2。 而且ofcourse我得到了錯誤:

The method addPayments_p24(AddPayments_p24) in the type TestWebServicesStub is not applicable for the arguments (String, int, String, String, String, String, String, String, String, String, String, String, String) 

我在這個問題第三天現在坐在我實在不明白它。如果任何人有任何想法發生了什麼...

我差點忘了應用程序運行在apache-tomcat 7.0.34如果這改變了什麼,但我已經在另一個版本上測試過。 Ofcourse一切都編譯了多次,編譯後我甚至反編譯一切,以檢查變量類型是否正確,當然他們是...

+0

你可以發佈'addPayments_p24'的服務器端代碼嗎?您爲Web服務客戶端使用什麼框架?你可以在調用Web服務之前發佈代碼。 – Simon

+0

是否有可能由於webservice函數體中的錯誤而返回該錯誤? – Tomaszeek

+0

要測試問題出在服務器還是客戶端上,您可以使用某個REST客戶端並直接向Web服務發出請求,以找出問題的出處。您可以使用郵遞員(Chrome)或海報(Firefox)等瀏覽器插件或獨立客戶端,如SoapUI – Simon

回答

0

我沒有使用網絡服務一段時間,所以我不確定這一點,但是,看起來你正在混合兩種方法,就像錯誤所暗示的那樣,恰巧你正在調用方法

addPayments_p24(String, int, String, String, String, String, String, String, String, String, String, String, String)

其不存在於所述客戶端,既不它的界面(至少呼叫的可見範圍)。在調用範圍內(在客戶端)的方法是addPayments_p24(AddPayments_p24),所以你需要實例化一個對象AddPayments_p24可能與你想要的參數(String, int, String, String, String, String, String, String, String, String, String, String, String),不知道這個,但它似乎是真的。

+0

稀釋那些自動生成的wsdl,我不連有這樣的對象c reated,但我會嘗試,它使很多感覺:) – Tomaszeek

0

我會嘗試刪除「throw ex;」並從addPayments_p24中「拋出異常」。

相關問題