java-wns icon indicating copy to clipboard operation
java-wns copied to clipboard

Use in wildfly

Open a-ferrari opened this issue 7 years ago • 1 comments

Thanks for your code I use it in my j2ee application in Wildfly 10 I did few changes the most important is close the response after using it ( otherwise this exception is thrown 'Caused by: java.lang.IllegalStateException: Invalid use of BasicClientConnManager: connection still allocated. Make sure to release the connection before allocating another one.' )

My snippet of WnsClient push method

	Response response = webResourceBuilder
			.buildPost(Entity.entity(resourceBuilder.getEntityToSendWithNotification(notification), type)).invoke();
	WnsNotificationResponse notificationResponse = null;
	try {
		notificationResponse = new WnsNotificationResponse(channelUri, response.getStatus(),
				response.getStringHeaders());
		if (notificationResponse.code == 200) {
			return notificationResponse;
		}

		if (notificationResponse.code == 401 && retriesLeft > 0) {
			retriesLeft--;
			// Access token may have expired
			refreshAccessToken();
			// Retry
			return this.push(resourceBuilder, channelUri, notification, retriesLeft, optional);
		}
	} finally {
		if (response != null) {
			// EntityUtils.consume((HttpEntity) response.getEntity());
			//EntityUtils.consumeQuietly((HttpEntity) response.getEntity());
			response.close();
		}
	}

best regards Alberto

a-ferrari avatar Mar 21 '17 11:03 a-ferrari

Thanks. Instead of opening and closing connections, please also bear in mind the possibility of using a pooled connection, check this and if you can submit a PR I'll be happy to merge it.

fernandospr avatar Mar 21 '17 13:03 fernandospr