Rest Import


i try to upload an exported Report ( 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?



Thomas Gärtner

tomm.g's picture
Joined: Mar 19 2018 - 12:35am
Last seen: 5 years 1 month ago

2 Answers:

If your 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.)

Friendly User's picture
Joined: Oct 8 2009 - 5:59am
Last seen: 4 days 3 hours ago

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

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

            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");

            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            


tomm.g's picture
Joined: Mar 19 2018 - 12:35am
Last seen: 5 years 1 month ago