Jump to content
JasperReports Library 7.0 is now available ×

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


jigar.patel

Recommended Posts

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

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();
}
}
}

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...