Java Jersey Rest Web服务客户端代码

时间:2015-07-15 14:00:08

标签: java date jersey

我正在编写一个使用Jersey调用Rest Web服务的Java代码。在这里,我想将日期设置为查询参数。但是我在线程“main”com.sun.jersey.api.client.UniformInterfaceException中得到了Exception。我不确定这是因为date参数。能帮我解决这个问题吗?这是我的代码:

DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");

    Calendar cal = Calendar.getInstance();
    System.out.println("Current Date Time : "
                    + dateFormat.format(cal.getTime()));
    cal.add(Calendar.HOUR, -1);
    System.out.println("Subtract one hour from current date : "
                    + dateFormat.format(cal.getTime()));
    String dateconverted = dateFormat.toString();       
    Client client = Client.create();
    WebResource webResource = client.resource("http://localhost/viewerportal/services/rest/vmds/programs");
    //String s = webResource.get(String.class);
    System.out.println("Got the web resource."+webResource);
    MultivaluedMap queryParams = new MultivaluedMapImpl();
    queryParams.add("availableDate", dateconverted);
       //queryParams.add("param2", "val2");
    String s = webResource.queryParams(queryParams).get(String.class);
    //System.out.println("Web resource string"+s);
    String response = webResource.get(String.class);
   System.out.println("Status ------->"+response);

这是我的例外:

Current Date Time : 2015-07-15T19:27:38Z
Subtract one hour from current date : 2015-07-15T18:27:38Z
Got the web resource.http://dpev827.innovate.ibm.com:8080/viewerportal  /services/rest/vmds/programs
Exception in thread "main" com.sun.jersey.api.client.UniformInterfaceException: GET http://dpev827.innovate.ibm.com:8080/viewerportal/services/rest/vmds/programs?availableDate=java.text.SimpleDateFormat@fe8ba6fa returned a response status of 500 Internal Server Error
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:688)
at com.sun.jersey.api.client.WebResource.get(WebResource.java:193)
at com.ibm.cio.mediahub.PushToW3Search.main(PushToW3Search.java:89)

0 个答案:

没有答案