2012-07-10 86 views
4

我正在研究以XML形式來回調用Web服務程序。然而,我的問題不在於此。當我在我的機器上本地運行(在Eclipse中)時,它似乎工作。然而,當我的同事運行它/如果我試圖在服務器上運行它,他甚至會在Web服務被調用之前得到此異常:Java - XMLGregorianCalendar異常

ClientMain.java中的異常#6 java.lang.IllegalArgumentException:2012-07 -09T08:19:44-0400

有沒有人有任何想法爲什麼它需要在一臺機器上的參數,而不是另一臺?構建不應該成爲問題,因爲我將我的整個Eclipse工作區複製到了一個拇指驅動器上(因此所有關聯的jar和構建路徑都應該繼續)。就服務器運行而言,我將整個程序作爲可運行的jar(運行Eclipse Indigo)導出,並得到類似的問題。

我會很感激任何見解!

堆棧跟蹤/輸出:

java.lang.IllegalArgumentException: 2012-07-09T09:19:42-0400 
     at com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl$Parser.skip(Unknown Source) 
     at com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl$Parser.parse(Unknown Source) 
     at com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl.<init>(Unknown Source) 
     at com.sun.org.apache.xerces.internal.jaxp.datatype.DatatypeFactoryImpl.newXMLGregorianCalendar(Unknown Source) 
     at com.travelport.worldspanimageserver.client.ClientMain.requestRun(ClientMain.java:231)****************************************************** 
Running by Yesterday's Date ... 
2012-07-09T09:19:42-0400 
Current date being used is 2012-07-09T09:19:42-0400 
Exception #6 in ClientMain.java java.lang.IllegalArgumentException: 2012-07-09T09:19:42-0400 

     at com.travelport.worldspanimageserver.client.ClientMain.runTypeCheck(ClientMain.java:161) 
     at com.travelport.worldspanimageserver.client.ClientMain.main(ClientMain.java:81) 
Exception #13 in ClientMain.java java.lang.NullPointerException 

方法造成例外:

import java.text.DateFormat; 
    import java.text.SimpleDateFormat; 
    import java.util.Calendar; 
    import java.util.Date; 
    import java.util.GregorianCalendar; 
    import java.util.List; 
    import java.util.Properties; 
    import java.util.TimeZone; 

    import javax.mail.Message; 
    import javax.mail.Session; 
    import javax.mail.Transport; 
    import javax.mail.internet.InternetAddress; 
    import javax.mail.internet.MimeMessage; 
    import javax.swing.text.Document; 
    import javax.xml.datatype.DatatypeConfigurationException; 
    import javax.xml.datatype.DatatypeFactory; 
    import javax.xml.datatype.XMLGregorianCalendar; 

    import org.joda.time.format.DateTimeFormatter; 
    import org.joda.time.format.ISODateTimeFormat; 

     public static void requestRun(String strRunType) throws DatatypeConfigurationException{ 
       //-TODO: determine how date is passed in/retrieved from database   
       GregorianCalendar c = new GregorianCalendar(); 

       XMLGregorianCalendar dateTime = null; 

       if (strRunType == "fullLoad") {dateTime = null;} 
       if (strRunType.substring(0,2).equals("OD")) 
       { 
        System.out.println("Current date being used is " + DatatypeFactory.newInstance().newXMLGregorianCalendar(strRunType.substring(2,strRunType.length()))); 
        dateTime = DatatypeFactory.newInstance().newXMLGregorianCalendar(strRunType.substring(2,strRunType.length())); 
       } 
       if (strRunType.substring(0,2).equals("DT")) 
       { 
        System.out.println("Current date being used is " + strRunType.substring(2,strRunType.length()));   
        dateTime = DatatypeFactory.newInstance().newXMLGregorianCalendar(strRunType.substring(2,strRunType.length())); 
       } 

String address = "http://vhligssas001:31860/services/ImageViewerService"; /**getServiceURL(sServer);**/ 

      try 
      { 
       ArrayList<PropertyType> propertyIdList = null;           
       ArrayList tempList = null; 

       if (strRunType.equals("properties")) 
       { 
        propertyIdList = getPropertiesFromFile(); //to fix later    
       } 
       else 
       { 
        propertyIdList = initialCall(dateTime, propertyIdList, address); 
       } 

       secondCall(propertyIdList, address); 

      } 
      catch(Exception e) 
      { 
       System.out.println("Exception #5 in ClientMain.java " + e); 
       try 
       { 
       postMail("Exception #5 in ClientMain.java " + e); 
       } 
       catch (Exception e1) 
       { 
        e1.printStackTrace(); 
       } 
       System.exit(16); 
      } 
     } 
     catch(Exception e) 
     { 
      System.out.println("Exception #6 in ClientMain.java " + e); 
      try 
      { 
      postMail("Exception #6 in ClientMain.java " + e); 
       e.printStackTrace(); //added 

      } 
      catch (Exception e1) 
      { 
      e1.printStackTrace(); 
      } 
      System.exit(16); 
     }   
    } 

主類:

public static void main(String args[]) throws Exception 
     { 
      String sRunType = new String(""); 
     try 
      {  
       File fPropertiesToLoad = new File("runType.txt"); 
       BufferedReader in = null; 
       String strRunType = new String(""); 

       if (!fPropertiesToLoad.exists()) 
       {   
        System.out.println("******************************************************"); 
        System.out.println("Exception #1 - Run Type file does not exist"); 
        System.out.println("******************************************************"); 
        postMail("Exception #1 - Run Type file does not exist"); 
        System.exit(16); 
       }   
       else 
       { 
        in = new BufferedReader(new FileReader("runType.txt")); 
        if ((strRunType = in.readLine()) != null) 
        { 
         sRunType = strRunType.trim(); 
        } 
        in.close();  
        runTypeCheck(sRunType); 
       } 
      }   
      catch (Exception e) 
      { 
       System.out.println("Exception #2 in ClientMain.java " + e); 
       postMail("Exception #2 in ClientMain.java " + e); 
       System.exit(16); 
      } 
     }  

runTypeCheck:

public static void runTypeCheck(String sRunType) 
     { 
      try 
      { 
      //Hard-coded in "yesterday" as the date 
      sRunType = "DT"; 

      System.out.println("******************************************************"); 
      DateTimeFormatter parser2 = ISODateTimeFormat.dateTimeNoMillis(); 

      if (sRunType.equals("DT")) 
      { 
       System.out.println("Running by Yesterday's Date ..."); 
       Calendar cal = Calendar.getInstance(); 
       cal.add(Calendar.DATE, -1); 
       DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); 
       sRunType = dateFormat.format(cal.getTime()); 
       System.out.println(sRunType); 
       sRunType = sRunType.replaceAll("-0500", "-05:00"); 
       sRunType = "DT" + sRunType; 
       requestRun(sRunType); 
      } 
System.out.println("******************************************************"); 

     } 
     catch(Exception e) 
     { 
      System.out.println("Exception #4 in ClientMain.java " + e); 
      try 
      { 
       postMail("Exception #4 in ClientMain.java " + e); 
      } 
      catch (Exception e1) 
      { 
       e1.printStackTrace(); 
      } 
      System.exit(16); 
     } 
    } 

只能輸出:

****************************************************** 

Running by Yesterday's Date ... 

2012-07-09T08:19:44-0400 

Current date being used is 2012-07-09T08:19:44-0400 

Exception #6 in ClientMain.java java.lang.IllegalArgumentException: 2012-07-09T08:19:44-0400 
+0

您的異常引用'ClientMain.java',但您尚未提供該代碼。 – Brad 2012-07-10 12:53:17

+0

添加了該信息。 – ns1 2012-07-10 13:03:51

+1

由於發佈的代碼和輸出之間沒有關聯,所以輸出具有誤導性。 – aviad 2012-07-10 13:06:53

回答

4

的問題是,你從strRunType.substring(2,strRunType.length())得到你的「日期」不是日期的有效lexicalRepresentation

您需要正確格式化輸入值才能解析爲XMLGregorianCalendar對象。

錯誤在於您在日期的-04:00中缺少:

你一定知道這是因爲sRunType = sRunType.replaceAll("-0500", "-05:00");代碼......除了你用的是5而不是4嗎?

+0

就是這樣。謝謝! – ns1 2012-07-10 17:14:50