2015-10-02 58 views
0

我在將掃描器輸入到我的Web服務框架中時遇到了一些問題。當我使用輸入掃描儀命令時,它不顯示我想要的結果。嘗試在我的WebService中輸入掃描器輸入以顯示用戶輸入的輸出

我想要發生的是當爲mySponsorID字符串輸入值時,我希望它顯示在響應或else語句中。例如,如果用戶提示SponsorOrganizationalIdentifier並且他們進入SOI,我希望他們輸入的內容顯示在響應中。

我是新來的Java和Web服務,所以任何幫助,你可以給我我真的很感激它。下面是代碼:

package org.example.www.newwsdlfile3; 


/** 
* ExchangeInformationServiceSkeleton java skeleton for the axisService 
*/ 
public class ExchangeInformationServiceSkeleton { 
import java.util.Scanner; 

    /** 
    * Auto generated method signature 
    * 
    * @param hRCtoIRSUpdate 
    * @return hRCtoIRSUpdateResponse 
    */ 

    public org.example.www.newwsdlfile3.HRCtoIRSUpdateResponse hRCtoIRSUpdate(
      org.example.www.newwsdlfile3.HRCtoIRSUpdate hRCtoIRSUpdate0) { 

     HRCtoIRSUpdateResponse hRCtoIRSUpdateResponse = null; 

     hRCtoIRSUpdateResponse = new HRCtoIRSUpdateResponse(); 

     // get string 
     String mySponsorID = ""; 
     mySponsorID = hRCtoIRSUpdate0.getSponsorOrganizationalIdentifier(); 
     // check if null 
     if (mySponsorID == null || mySponsorID.isEmpty()) { 
      hRCtoIRSUpdateResponse.setErrorCode("The update isn't complete"); 
      hRCtoIRSUpdateResponse.setErrorDescription("SponsorOrganizationIdentifier must have a value"); 
      hRCtoIRSUpdateResponse.setProcessStatus("Update Failed! Please try again!"); 
     // display entry for SponsorOrganizationalIdentifier 
     } else { 
      Scanner scan = new Scanner(System.in); 
     mySponsorID = scan.nextLine(); 
     System.out.println("You have entered " + mySponsorID); 
     hRCtoIRSUpdateResponse.setProcessStatus("Update Complete!"); 
     hRCtoIRSUpdateResponse.setErrorCode(null); 
     hRCtoIRSUpdateResponse.setErrorDescription(null); 
     scan.close(); 
     } 

     return hRCtoIRSUpdateResponse; 
    } 

} 
+0

我看不到你想要的東西:Web服務是在服務器中運行並處理由客戶端發送給它的請求的東西。通常服務器和客戶端是兩個不同的JVM。用戶會在客戶端輸入一些東西。你想在哪裏使用[掃描儀](http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html)以及用於何種目的?來自客戶端的任何數據應該是請求的一部分(在你的情況下是'org.example.www.newwsdlfile3.HRCtoIRSUpdate'對象)。 – hotzst

+0

我想使用else語句中的掃描器。因此,如果mySponsorID不爲null,請寫出用戶在else語句旁邊輸入的內容以及hRCtoIRSUpdateResponse(「更新完成」)。 – barnyak10

+0

我編輯了一段代碼,讓你知道我想做什麼。 – barnyak10

回答

0

添加記錄到您的代碼:

public class ExchangeInformationServiceSkeleton { 
    // define the logger 
    private final Logger logger = Logger.getLogger(getClass().getName()); 

    public org.example.www.newwsdlfile3.HRCtoIRSUpdateResponse hRCtoIRSUpdate(
      org.example.www.newwsdlfile3.HRCtoIRSUpdate hRCtoIRSUpdate0) { 
     ... 
     } else { 
      logger.warn("User has not supplied required SponsorOrganizationalIdentifier")  
      hRCtoIRSUpdateResponse.setProcessStatus("Update Complete!"); 
      hRCtoIRSUpdateResponse.setErrorCode(null); 
      hRCtoIRSUpdateResponse.setErrorDescription(null); 
     } 
     ...   
} 

還需要採取哪些措施是配置記錄器(日誌級別,其中記錄到)。通常最好在單獨的配置文件中執行此操作,並在初始化應用程序時使用該文件,從而在整個代碼中爲所有記錄器使用相同的配置。

+0

你能給我一個關於如何將這個記錄到其他響應中的例子。我只是想向客戶展示迴應。我可以補充說,「你已經進入 - 例子」或類似的東西。有沒有辦法可以做到這一點? – barnyak10

+0

在if-else子句的情況下,你已經完成了你的自我。如果'SponsorOrganizationalIdentifier'是必填字段,則不應該可以向服務器發送缺少'SponsorOrganizationalIdentifier'的請求。 – hotzst