jigar.patel Posted March 4, 2015 Share Posted March 4, 2015 I've done it through rest_v2 API but, I want to get it done through Java. Link to comment Share on other sites More sharing options...
nuno-miguel-lourenco Posted March 5, 2015 Share Posted March 5, 2015 Have you tried the client availble on Github?https://github.com/Jaspersoft/jrs-rest-java-client Link to comment Share on other sites More sharing options...
jigar.patel Posted March 13, 2015 Author Share Posted March 13, 2015 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 portHttpGet getRequest = new HttpGet("/jasperserver/rest/login?j_username=jasperadmin&j_password=jasperadmin"); // specify the get requestHttpResponse objResponse = httpclient.execute(target, getRequest);if(objResponse.getStatusLine().getStatusCode()==200){ //check status code in web service guideSystem.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); }}elseSystem.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 resourceshttpclient.getConnectionManager().shutdown();}}} Link to comment Share on other sites More sharing options...
jigar.patel Posted March 13, 2015 Author Share Posted March 13, 2015 Thanks 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