微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Java – XMLGregorianCalendar异常

我正在开发一个Web服务程序,它以XML的形式来回调用.然而,我的问题不在于此.当我在我的机器上本地(在Eclipse中)运行它时,它似乎工作.但是,当我的同事运行它/如果我尝试在服务器上运行它时,他甚至在调用Web服务之前得到此异常:

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.Nown 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
           {
              ArrayListstem.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
最佳答案
问题是你从strRunType.substring(2,strRunType.length())获得的’date’不是日期的有效lexicalRepresentation.

您需要正确格式化输入值,以便解析为XMLGregorianCalendar对象.

错误是您错过了:在您日期的-04:00中.

你必须知道的是因为sRunType = sRunType.replaceAll(“ – 0500”,“ – 05:00”);代码……除了你使用的是5而不是4?

原文地址:https://www.jb51.cc/java/438131.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐