Azure / azure-notificationhubs-java-backend

Azure Notification Hubs SDK for Java
https://docs.microsoft.com/en-us/azure/notification-hubs/
Apache License 2.0
35 stars 49 forks source link

[BUG] : java.lang.RuntimeException: org.apache.hc.core5.http.ParseException: Invalid protocol version; error at offset 0: <[0x2e][0x2f][0x30][0x31][0x32][0x33][0x34][0x35][0x36][0x37][0x38][0x39][0x3a][0x3b][0x3c][0x3d][0x3e]> #137

Closed moorthysara closed 1 year ago

moorthysara commented 2 years ago

Describe the bug A clear and concise description of what the bug is. package com.windowsazure.messaging; NotificationHub notificationHub = new NotificationHub(connUrl, hubPath); notificationHub.sendNotification(fcmNotification);

I am sending FCM notification using above lines of code, NotificationHub is the SDK class. which in turn call below HTTPS call.

SimpleHttpRequest post = this.createRequest(uri, Method.POST).setBody(notification.getBody(), notification.getContentType()).build();

this.executeRequest(post, callback, 201, (response) -> { this.sendNotificationOutcome(callback, post, response); });

In NotificationHubsService class -

HttpClientManager.getHttpAsyncClient().execute(SimpleRequestProducer.create(request), SimpleResponseConsumer.create(), new FutureCallback()

In HttpClientManager class - initializeHttpAsyncClient(); IOReactorConfig ioReactorConfig = IOReactorConfig.custom().setSoTimeout(Timeout.ofSeconds(5L)).build(); RequestConfig config = RequestConfig.custom().setConnectionRequestTimeout(Timeout.ofMilliseconds((long)connectionRequestTimeout)).setConnectTimeout(Timeout.ofMilliseconds((long)connectionTimeout)).build(); CloseableHttpAsyncClient client = HttpAsyncClients.custom().setIOReactorConfig(ioReactorConfig).setDefaultRequestConfig(config).setRetryStrategy(retryStrategy).build(); client.start(); httpAsyncClient = client;

then

HttpClientManager.getHttpAsyncClient().execute(SimpleRequestProducer.create(request), SimpleResponseConsumer.create(), new FutureCallback() { public void completed(SimpleHttpResponse simpleHttpResponse) { int statusCode = simpleHttpResponse.getCode(); if (Arrays.stream(statusCodes).noneMatch((x) -> { return x == statusCode; })) { callback.failed(NotificationHubsException.create(simpleHttpResponse, statusCode, NotificationHubsService.this.getTrackingId(request))); } else { consumer.accept(simpleHttpResponse); } }

This piece of code produce exception, instead it should call Notification Hub and produce http status code, as 200 etc.

OS: It is failing in Cent OS JDK Version: JDK 17

JDK 18 fails in Windows as well. Exception or Stack Trace java.lang.RuntimeException: org.apache.hc.core5.http.ParseException: Invalid protocol version; error at offset 0: <[0x2e][0x2f][0x30][0x31][0x32][0x33][0x34][0x35][0x36][0x37][0x38][0x39][0x3a][0x3b][0x3c][0x3d][0x3e]>

To Reproduce I have written sample POC code and it is with Microsoft Support Engg, in Secure FTP, you can use that. Mohsin Khan.

Code Snippet Added above.

Expected behavior HTTP Status Code - which are valid.

Screenshots NA

Setup (please complete the following information):

Additional context Add any other context about the problem here.

Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issue as an incomplete report. Please do not provide any private information in this bug report.

Gallaecio commented 1 year ago

Sounds like https://issues.apache.org/jira/browse/HTTPCLIENT-2219

dpozimski commented 1 year ago

libs.zip compiled version from https://github.com/Azure/azure-notificationhubs-java-backend/pull/149

dpozimski commented 1 year ago

you can install the file to your docker/local maven repository by executing: mvn install:install-file -Dfile=".\libs\Notification-Hubs-java-sdk-custom-1.0.4.jar" -DgroupId="com.windowsazure" -DartifactId="Notification-Hubs-java-sdk-custom" -Dversion="1.0.4" -Dpackaging=jar -DpomFile=".\libs\pom.xml"

jessHuh commented 1 year ago

The POC provided by the customer uses different library versions and has extra dependencies that Azure Notification Hub(ANH) SDK doesn't. The customer may remove libraries that ANH SDK doesn't use and use the same library versions to resolve the issue. Unfortunately, we will not be able to provide support on fixing the customer's written codebase.

Closing the ticket as it is tested and verified with JDK 17.

  1. Verified the fcm send test with ANH Java SDK 1.0.3 (https://github.com/Azure/azure-notificationhubs-java-backend/blob/main/NotificationHubs/test/com/windowsazure/messaging/e2e/RegistrationCrudsE2E.java#L837) works without errors.
  2. The customer may run the test to check their FCM Notification. Note that, the e2eSetup.properties file is needed to be updated with the connectionstring and gcmkey.