I want to schedule a single report for multiple JS users through java using jasperserver web services(rest_v2).

I've done it through rest_v2 API but, I want to get it done through Java.

jigar.patel's picture
Joined: Jan 30 2015 - 12:21am
Last seen: 2 years 4 months ago

2 Answers:

Have you tried the client availble on Github?

https://github.com/Jaspersoft/jrs-rest-java-client

nuno-miguel-lourenco's picture
Joined: Feb 23 2015 - 10:21am
Last seen: 7 years 7 months ago

Thanks

jigar.patel - 8 years 2 weeks ago
I created simplest version...
 
import java.io.BufferedReader;
import java.io.InputStreamReader;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
 
public class Restv2 {
public static void main(String[] args) {
DefaultHttpClient httpclient = new DefaultHttpClient(); //session
try {
HttpHost target = new HttpHost("localhost", 8080, "http"); // specify the host, protocol, and port
HttpGet getRequest = new HttpGet("/jasperserver/rest/login?j_username=jasperadmin&j_password=jasperadmin"); // specify the get request
HttpResponse objResponse = httpclient.execute(target, getRequest);
if(objResponse.getStatusLine().getStatusCode()==200){    //check status code in web service guide
System.out.println("Successfully logged in to JasperServer");
if(objResponse!=null)
EntityUtils.consumeQuietly(objResponse.getEntity()); //need to complete first response to send another request...
objResponse=null;
 
String xmlString=""; //set XML String over here.
HttpPut objHttpPut = new HttpPut("/jasperserver/rest_v2/jobs");
objHttpPut.setHeader("Content-Type", "application/xml");     //send put request after login.
objHttpPut.setEntity(new StringEntity(xmlString));
objResponse = httpclient.execute(target, objHttpPut);
System.out.println(objResponse);
BufferedReader rd = new BufferedReader(new InputStreamReader(objResponse.getEntity().getContent()));
String line = "";
 while ((line = rd.readLine()) != null) {
  System.out.println(line);
 }
}
else
System.out.println("Failed to login to JasperServer");
 
 
} catch (Exception e) {
e.printStackTrace();
} finally {
// When HttpClient instance is no longer needed, shut down the connection manager to ensure immediate deallocation of all system resources
httpclient.getConnectionManager().shutdown();
}
}
}

 

jigar.patel's picture
Joined: Jan 30 2015 - 12:21am
Last seen: 2 years 4 months ago
Feedback
randomness