Hi,
i try to upload an exported Report (export.zip) via the Java Rest_v2 API into my JRS. The Import via the Webinterface works.
But when i try to send the postrequest the server sends the answer "no response"
In the first step ein send a login-request an i get the response with a jSessionId.
Does anybody have a code Examlpe to do this?
greetings
Thomas Gärtner
2 Answers:
If your export.zip is large (>2 MB) and you're using Tomcat then it can reject the large POST. You'll need to increase the maxPostSize of the Tomcat HTTP connector.
It would also be quite useful to see how exactly you're forming the import request (method, headers, attachments, etc.)
Hi, the zip File is about 8 KB
the Login which works for the Session ID is like
List<NameValuePair> ce_qparams = new ArrayList<NameValuePair>();
ce_qparams.add(new BasicNameValuePair(PARAMETER_USERNAME, USER_NAME));
ce_qparams.add(new BasicNameValuePair(PARAM_PASSWORD, PASSWORD));
URI _uri = URIUtils.createURI(_scheme, _host, _port, _handle +_restUrl + _login,
URLEncodedUtils.format(ce_qparams, "UTF-8"), null);
HostConfiguration hc = new HostConfiguration();
hc.setHost(_uri.getHost(), _uri.getPort());
httpClient = new HttpClient();
httpClient.setHostConfiguration(hc);
httpClient.getParams().setParameter("http.tcp.nodelay", Boolean.TRUE);
httpClient.getParams().setParameter("http.socket.timeout", new Integer(120000));
if ("https".equals(_uri.getScheme())) {
ProtocolSocketFactory easyssl = new EasySSLProtocolSocketFactory();
// Protocol easyhttps = new Protocol("https", easyssl, 8443);
Protocol easyhttps = new Protocol("https", easyssl, 443);
hc.setHost(_uri.getHost(), _uri.getPort(), easyhttps);
} else {
hc.setHost(_uri.getHost(), _uri.getPort());
}
HttpRequestBase _httpReqCE;
_httpReqCE = new HttpPost();
_httpReqCE.setURI(_uri);
httpClient = new HttpClient();
PostMethod _postLogin = new PostMethod(_uri.toString());
int resultLogin = httpClient.executeMethod(_postLogin);
Header[] ah = _postLogin.getResponseHeaders();
Header cookie = _postLogin.getResponseHeader("Set-Cookie");
String jSessionId = cookie.getValue();
result = jSessionId.substring(jSessionId.indexOf("=") + 1, jSessionId.indexOf(";"));
Den Import führe ich über:
Die Uri ist aufgebaut https://localhost:8443/jasperserver/rest_v2/import
...
StringBuilder _buffer = new StringBuilder();
String context = uriUpload.getPath();
_buffer = new StringBuilder();
_buffer.append(context).append("?update=true");
String _filename = binaryFile.getName();
int _index = _filename.lastIndexOf(".");
String _filenameWithoutSuffix = _filename.substring(0, _index);
PostMethod _post = new PostMethod(_buffer.toString());
_post.setRequestHeader("COOKIE", jSessionId);
JSONObject _json = new JSONObject();
_json.element("filename", _filenameWithoutSuffix);
StringPart _partMetadata;
_partMetadata = new StringPart("metadata", _json.toString(), "UTF-8");
_partMetadata.setContentType("application/zip");
Part _partFiledata = new FilePart(_filenameWithoutSuffix, binaryFile);
Part[] parts = { _partMetadata, _partFiledata };
_post.setRequestEntity(new MultipartRequestEntity(parts, _post.getParams()));
System.out.println("Query: " + _post.getQueryString());
int result = httpClient.executeMethod(_post);
System.out.println("Result: " + result);
Die Fehler meldung ist
org.apache.commons.httpclient.NoHttpResponseException: The server localhost failed to respond