Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is no JSESSIONID in the content of HTTP response after a bad request. #318

Open
aaaakun opened this issue Oct 17, 2017 · 2 comments
Open

Comments

@aaaakun
Copy link

aaaakun commented Oct 17, 2017

Hello,
thanks for your great work to apply such an useful API.
I found an issue when using the API.
Firstly I used the API to make a mistake on purpose, for example, I added a role which already exsited on the server.
After that whatever API I used, there is no JSESSIONID in the content of HTTP response.
So that I cann't use SPRING authenticate type to connect with sever after a http error.

In the JasperserverRestClient class, if AuthenticationType is SPRING, the follwing codes will work:

String sessionId;
if (!location.matches("[^?]+\?([^&]&)error=1(&[^&])$")) {
sessionId = response.getCookies().get("JSESSIONID").getValue();
storage.setSessionId(sessionId);
} else {
throw new AuthenticationFailedException("Invalid credentials supplied. Could not login to JasperReports Server.");
}

This will cause NullPointerException.

HTTP Logs :
2017-10-17 14:50:36.195 INFO SessionStorage:155 - 1 * Sending client request on thread Thread-12
1 > PUT http://localhost:8080/jasperserver-pro/rest_v2/roles/1112
1 > Accept: application/json
1 > Content-Type: application/json
{"name":"1112","externallyDefined":false}

2017-10-17 14:50:36.266 INFO SessionStorage:155 - 1 * Client response received on thread Thread-12
1 < 400
1 < Cache-Control: private
1 < Connection: close
1 < Content-Type: application/json
1 < Date: Tue, 17 Oct 2017 06:50:36 GMT
1 < Expires: Thu, 01 Jan 1970 08:00:00 CST
1 < P3P: CP="ALL"
1 < Server: Apache-Coyote/1.1
1 < Transfer-Encoding: chunked
{"message":"resource 1112 already exists。","errorCode":"resource.already.exists","parameters":["1112"]}

2017-10-17 14:50:36.311 INFO SessionStorage:155 - 1 * Sending client request on thread Thread-12
1 > GET http://localhost:8080/jasperserver-pro/rest_v2/organizations?includeParents=true
1 > Accept: application/json

2017-10-17 14:50:36.321 INFO SessionStorage:155 - 1 * Client response received on thread Thread-12
1 < 200
1 < Cache-Control: private
1 < Content-Type: application/json
1 < Date: Tue, 17 Oct 2017 06:50:36 GMT
1 < Expires: Thu, 01 Jan 1970 08:00:00 CST
1 < P3P: CP="ALL"
1 < Result-Count: 5
1 < Server: Apache-Coyote/1.1
1 < Start-Index: 0
1 < Total-Count: 5
1 < Transfer-Encoding: chunked

Could you please tell me what's the reason of this problem?
Looking forward for your reply.

@TanyaEf
Copy link
Contributor

TanyaEf commented Oct 17, 2017

Could you provide us with your code? from HTTP is not completely clear, what is going on. in short words, you can not get JSESSIONID from any request, you have to get object "session" after login. Or attach Base64 encoded credentials as header, but in this case you don't need JSESSIONID at all(each request works in separate session).

@aaaakun
Copy link
Author

aaaakun commented Oct 18, 2017

Thank you for you reply.
We found that the API seems like to have a conflict with javafx.scene.web.WebView.
And the conflict causes JSESSIONID's missing.

Code(1112 is an exsiting role):

public static void test() {
new Thread(() -> {
try {
ClientRole roleCreate = new ClientRole().setName("1112");
client.authenticate("superuser", "superuser")
.rolesService()
.roleName("1112").createOrUpdate(roleCreate);
} catch(Exception e) {
String detailHTML = "";
Platform.runLater(() -> {
WebView webView = new WebView();
webView.getEngine().loadContent(detailHTML);
webView.setMaxHeight(400);
webView.setMinHeight(100);
});

			client.authenticate("superuser", "superuser")
	        .organizationsService()
	        .allOrganizations()
	        .parameter(OrganizationParameter.INCLUDE_PARENTS, "true")
	        .get();
			try {
				Thread.sleep(5000);
			} catch (InterruptedException ex) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			client.authenticate("superuser", "superuser")
	        .organizationsService()
	        .allOrganizations()
	        .parameter(OrganizationParameter.INCLUDE_PARENTS, "true")
	        .get();
		}
	}).start();
}

HTTP log:
2017-10-18 12:29:47.310 INFO SessionStorage:155 - 1 * Sending client request on thread Thread-9
1 > PUT http://localhost:8080/jasperserver-pro/rest_v2/roles/1112
1 > Accept: application/json
1 > Content-Type: application/json
{"name":"1112","externallyDefined":false}

2017-10-18 12:29:47.356 INFO SessionStorage:155 - 1 * Client response received on thread Thread-9
1 < 400
1 < Cache-Control: private
1 < Connection: close
1 < Content-Type: application/json
1 < Date: Wed, 18 Oct 2017 04:29:47 GMT
1 < Expires: Thu, 01 Jan 1970 08:00:00 CST
1 < P3P: CP="ALL"
1 < Server: Apache-Coyote/1.1
1 < Set-Cookie: userLocale=ja_JP;Expires=Thu, 19-Oct-2017 04:29:47 GMT;HttpOnly,JSESSIONID=C9CDF9623B37D05348811C21B8F820C4; Path=/jasperserver-pro/; HttpOnly
1 < Transfer-Encoding: chunked
{"message":"resource 1112 already exists。","errorCode":"resource.already.exists","parameters":["1112"]}

2017-10-18 12:29:47.495 INFO SessionStorage:155 - 1 * Sending client request on thread Thread-9
1 > GET http://localhost:8080/jasperserver-pro/rest_v2/organizations?includeParents=true
1 > Accept: application/json

2017-10-18 12:29:47.535 INFO SessionStorage:155 - 1 * Client response received on thread Thread-9
1 < 200
1 < Cache-Control: private
1 < Content-Type: application/json
1 < Date: Wed, 18 Oct 2017 04:29:47 GMT
1 < Expires: Thu, 01 Jan 1970 08:00:00 CST
1 < P3P: CP="ALL"
1 < Result-Count: 5
1 < Server: Apache-Coyote/1.1
1 < Set-Cookie: userLocale=ja_JP;Expires=Thu, 19-Oct-2017 04:29:47 GMT;HttpOnly,JSESSIONID=8CF4E03E3C51A7456C9AEA11F2311F54; Path=/jasperserver-pro/; HttpOnly
1 < Start-Index: 0
1 < Total-Count: 5
1 < Transfer-Encoding: chunked
{"organization":[{"id":"organization_1","alias":"organization_1","parentId":"organizations","tenantName":"Organization","tenantDesc":" ","tenantNote":" ","tenantUri":"/organization_1","tenantFolderUri":"/organizations/organization_1","theme":"default"},{"id":"organization_2","alias":"organization_2","parentId":"organizations","tenantName":"organization_2","tenantDesc":" ","tenantUri":"/organization_2","tenantFolderUri":"/organizations/organization_2","theme":"default"},{"id":"test","alias":"test","parentId":"organization_1","tenantName":"test","tenantDesc":" test","tenantUri":"/organization_1/test","tenantFolderUri":"/organizations/organization_1/organizations/test","theme":"default"},{"id":"dummy","alias":"dummy","parentId":"organizations","tenantName":"dummy","tenantDesc":" ","tenantUri":"/dummy","tenantFolderUri":"/organizations/dummy","theme":"default"},{"id":"13dummy","alias":"13dummy","parentId":"dummy","tenantName":"13dummy","tenantDesc":" ","tenantUri":"/dummy/13dummy","tenantFolderUri":"/organizations/dummy/organizations/13dummy","theme":"default"}]}

2017-10-18 12:29:52.589 INFO SessionStorage:155 - 1 * Sending client request on thread Thread-9
1 > GET http://localhost:8080/jasperserver-pro/rest_v2/organizations?includeParents=true
1 > Accept: application/json

2017-10-18 12:29:52.890 INFO SessionStorage:155 - 1 * Client response received on thread Thread-9
1 < 200
1 < Cache-Control: private
1 < Content-Type: application/json
1 < Date: Wed, 18 Oct 2017 04:29:52 GMT
1 < Expires: Thu, 01 Jan 1970 08:00:00 CST
1 < P3P: CP="ALL"
1 < Result-Count: 5
1 < Server: Apache-Coyote/1.1
1 < Set-Cookie: ,
1 < Start-Index: 0
1 < Total-Count: 5
1 < Transfer-Encoding: chunked
{"organization":[{"id":"organization_1","alias":"organization_1","parentId":"organizations","tenantName":"Organization","tenantDesc":" ","tenantNote":" ","tenantUri":"/organization_1","tenantFolderUri":"/organizations/organization_1","theme":"default"},{"id":"organization_2","alias":"organization_2","parentId":"organizations","tenantName":"organization_2","tenantDesc":" ","tenantUri":"/organization_2","tenantFolderUri":"/organizations/organization_2","theme":"default"},{"id":"test","alias":"test","parentId":"organization_1","tenantName":"test","tenantDesc":" test","tenantUri":"/organization_1/test","tenantFolderUri":"/organizations/organization_1/organizations/test","theme":"default"},{"id":"dummy","alias":"dummy","parentId":"organizations","tenantName":"dummy","tenantDesc":" ","tenantUri":"/dummy","tenantFolderUri":"/organizations/dummy","theme":"default"},{"id":"13dummy","alias":"13dummy","parentId":"dummy","tenantName":"13dummy","tenantDesc":" ","tenantUri":"/dummy/13dummy","tenantFolderUri":"/organizations/dummy/organizations/13dummy","theme":"default"}]}

Looking forward for your reply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants