mvisman Posted November 27, 2008 Share Posted November 27, 2008 Hello everyone,I'm trying to get a report via web service from JasperServer (v3.0), using java client libraries of the iReport plugin; everything works well when I try to do it without passing parameters, but when I call a report with DATE input params, the server raises this exception:--------------------------------------------------------------------------------------java.lang.Exception: 1 - For input string: "Tue Jan 01 00:01:00 CET 2008"at com.jaspersoft.jasperserver.irplugin.wsclient.WSClient.runReport(WSClient.java:394)at com.jaspersoft.jasperserver.irplugin.wsclient.WSClient.runReport(WSClient.java:311)--------------------------------------------------------------------------------------I use the following code:--------------------------------------------------------------------------------------HashMap myParameters = new HashMap();myParameters.put("I_PARAM_STAT_DATE", new Date());JasperPrint myJasperPrint = runReport(reportUri,myParameters);--------------------------------------------------------------------------------------Anyone has any suggestion?Thanks in advanceMassimo Link to comment Share on other sites More sharing options...
ytsefofis Posted November 28, 2008 Share Posted November 28, 2008 I'm facing the same problem!Any news? Thanks a lot!Rafael Link to comment Share on other sites More sharing options...
ytsefofis Posted November 28, 2008 Share Posted November 28, 2008 Hey Massimo, problem solved!It happened that WSClient calls the toString() method of the Object parameter, and then JasperServers uses the value (now the String representation o the Date Object) to instantiate the Date. Add the Milliseconds representation of the Date Object instead of the Date Object itself. Didn't want to change my Domain model just because of that, so i had to extend WSClient to encapsulate it. And use it instead of getting the wsclient directly from JServer. The extended WSClient follows. Regards.RafaelCode:package br.com.visent.sicorp.test.jasperserver;import java.io.ByteArrayInputStream;import java.io.ByteArrayOutputStream;import java.io.InputStream;import java.util.ArrayList;import java.util.Collection;import java.util.Date;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import javax.activation.DataHandler;import net.sf.jasperreports.engine.JasperPrint;import net.sf.jasperreports.engine.util.JRLoader;import com.jaspersoft.jasperserver.api.metadata.xml.domain.impl.Argument;import com.jaspersoft.jasperserver.api.metadata.xml.domain.impl.ListItem;import com.jaspersoft.jasperserver.api.metadata.xml.domain.impl.OperationResult;import com.jaspersoft.jasperserver.api.metadata.xml.domain.impl.Request;import com.jaspersoft.jasperserver.api.metadata.xml.domain.impl.ResourceDescriptor;import com.jaspersoft.jasperserver.irplugin.JServer;import com.jaspersoft.jasperserver.irplugin.wsclient.FileContent;import com.jaspersoft.jasperserver.irplugin.wsclient.WSClient;import com.jaspersoft.jasperserver.ws.xml.Marshaller;import com.jaspersoft.jasperserver.ws.xml.Unmarshaller;public class SicorpWSClient extends WSClient { private Marshaller marshaller = new Marshaller(); private Unmarshaller unmarshaller = new Unmarshaller(); public SicorpWSClient(JServer arg0) throws Exception { super(arg0); } @Override public JasperPrint runReport(ResourceDescriptor descriptor, java.util.Map parameters) throws Exception { List args = new ArrayList(1); args.add(new Argument(Argument.RUN_OUTPUT_FORMAT, Argument.RUN_OUTPUT_FORMAT_JRPRINT)); Map attachments = this.runReport(descriptor, parameters, args); FileContent content = null; if (attachments != null && !attachments.isEmpty()) { content = (FileContent)(attachments.values().toArray()[0]); //attachments.get("jasperPrint"); } if (content == null) { throw new Exception("No JasperPrint"); } InputStream is = new ByteArrayInputStream(content.getData()); JasperPrint print = (JasperPrint) JRLoader.loadObject(is); return print; } @Override public Map runReport(ResourceDescriptor descriptor, java.util.Map parameters, List args) throws Exception { try { Request req = new Request(); req.setOperationName("runReport"); req.setLocale(getServer().getLocale()); ResourceDescriptor newRUDescriptor = new ResourceDescriptor(); newRUDescriptor.setUriString(descriptor.getUriString()); for (Iterator i = parameters.keySet().iterator(); i.hasNext();) { String key = "" + i.next(); Object value = parameters.get(key); if (value instanceof java.util.Collection) { Iterator cIter = ((Collection) value).iterator(); while (cIter.hasNext()) { Object item = cIter.next(); ListItem l = new ListItem(key + "", item); l.setIsListItem(true); newRUDescriptor.getParameters().add(l); } //If Date, add the Long representation instead of the Date Object itself } else if (value instanceof Date) { Long dateLong = ((Date) value).getTime(); newRUDescriptor.getParameters().add(new ListItem(key + "", dateLong)); }else newRUDescriptor.getParameters().add(new ListItem(key + "", parameters.get(key))); } req.setResourceDescriptor(newRUDescriptor); req.getArguments().addAll(args); String result = getManagementService().runReport(marshaller.marshal(req)); OperationResult or = (OperationResult) unmarshaller.unmarshal(result); if (or.getReturnCode() != 0) throw new Exception(or.getReturnCode() + " - " + or.getMessage()); Map results = new HashMap(); Object[] resAtts = ((org.apache.axis.client.Stub) getManagementService()).getAttachments(); boolean attachFound = false; for (int i = 0; resAtts != null && i < resAtts.length; ++i) { attachFound = true; DataHandler actualDH = (DataHandler) ((org.apache.axis.attachments.AttachmentPart) resAtts[i]) .getDataHandler(); String name = actualDH.getName(); //((org.apache.axis.attachments // . // AttachmentPart)resAtts[i] // ).getAttachmentFile(); String contentId = ((org.apache.axis.attachments.AttachmentPart) resAtts[i]).getContentId(); if (name == null) name = "attachment-" + i; if (contentId == null) contentId = "attachment-" + i; InputStream is = actualDH.getInputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] data = new byte[1000]; int bytesRead; while ((bytesRead = is.read(data)) != -1) { bos.write(data, 0, bytesRead); } data = bos.toByteArray(); String contentType = actualDH.getContentType(); FileContent content = new FileContent(); content.setData(data); content.setMimeType(contentType); content.setName(name); results.put(contentId, content); } if (!attachFound) { throw new Exception("Attachment not present!"); } return results; } catch (Exception ex) { ex.printStackTrace(); throw ex; } finally { } }}Post Edited by Rafael Dantas at 11/28/08 19:31 Link to comment Share on other sites More sharing options...
vpremkumar Posted December 8, 2009 Share Posted December 8, 2009 Hi Rafael,I'm trying to use this code you attached, and it works great for all types of parameter, except for comma seperated parameter. I have a sql like select * from employee where employee id in (12,52)My parameter $P{empId} from client will send the value 12,52 and iReport sql will have select * from employee where employee id in$P!{emplModifiedid}where $P{emplModifiedid} = "("+$P{empId}+")" The code runs fine for $P{empId} = 12 but fails for $P{empId} = 12,52 with return code 1 .Can you please help me out in this. Thank you,Vandana Link to comment Share on other sites More sharing options...
swood Posted December 18, 2009 Share Posted December 18, 2009 Try using the $X form of parameters. This automatically does the "column in (list)" for you. The input control should be a Collection. iReport converts input like 1,2,3 for a collection into a collection when running a report ShermanJaspersoft Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now