Identical request timing out in Java Apache, working fine in postman





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







8















I'm trying to register a Office365 Api webhook per official api docs. I tried it in postman, all works as expected.



Java Version: 1.7 (I know...)



I am working with the Play framework version 1.2.7.2



HttpClient: org.apache.http.client.HttpClient



Relevant documentation:




The subscription process goes as follows:



A client app makes a subscription request (POST) for a specific resource. It includes a notification URL, among other properties.



The Outlook notifications service tries to validate the notification URL with the listener service. It includes a validation token in the validation request.



If the listener service successfully validates the URL, it returns a success response within 5 seconds as follows:



Sets the content type in the response header to textplain.
Includes the same validation token in the response body.
Returns an HTTP 200 response code. The listener can discard the validation token subsequently.
Depending on the URL validation result, the Outlook notifications service sends a response to the client app:



If URL validation was successful, the service creates the subscription with a unique subscription ID and sends the response to the client.
If URL validation was unsuccessful, the service sends an error response with an error code and other details.
Upon receiving a successful response, the client app stores the subscription ID to correlate future notifications with this subscription.




Postman request:



Both requests intercepted with wireshark:



Postman:



Ý`!Ë2@ʸ1cÊþßV:
ðîPOST /api/v2.0/me/subscriptions HTTP/1.1
Content-Type: application/json
cache-control: no-cache
Postman-Token: a24df796-c49e-4245-a1cf-0949cd6538b6
Authorization: Bearer ###
User-Agent: PostmanRuntime/7.4.0
Accept: */*
Host: localhost:3000
accept-encoding: gzip, deflate
content-length: 430
Connection: keep-alive

{
"@odata.type":"#Microsoft.OutlookServices.PushSubscription",
"ChangeType": "Created, Deleted, Updated",
"ClientState": "some-token",
"NotificationURL": "https://###/office365/receive.php?subId=5",
"Resource": "https://outlook.office.com/api/v2.0/me/Calendars('###')/events"
}


(captured in wireshark) (the ### parts are removed info, I made sure that auth and ids match up)



At ###/office365/receive.php lies a php script which just echoes back $_GET['validationtoken']. This works perfectly in Postman.



In Java, I create a request with the same headers and the same body



E/@@5â$¸³zêð-gÄV$
Là¼Là¼POST /api/v2.0/me/subscriptions HTTP/1.1
Accept: */*
Content-Type: application/json
Authorization: Bearer ###
Content-Length: 476
Host: localhost:3000
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.2 (Java/1.7.0_80)
Accept-Encoding: gzip,deflate

{
"@odata.type":"#Microsoft.OutlookServices.PushSubscription",
"ChangeType": "Created, Deleted, Updated",
"ClientState": "1fdb3e372212622e0b7e68abe09e1201a81a8bcc040cce9a6f013f71a09bfbe1",
"NotificationURL": "https://###/office365/receive.php",
"Resource": "https://outlook.office.com/api/v2.0/me/Calendars('###')/events"
}


I verified that all (important) parts of the request are exactly the same.



My code in java is a little to complex to share fully here, however the important bits are:



// build url
private final RequestBuilder getRequest (String url) {
RequestBuilder req = RequestBuilder.create(getMethod()); // e.g. POST
req.setUri(overwriteBaseUrl(url) + getPath());

// headers is a hashmap<String, String>
for (String key: headers.keySet()) {
req.setHeader(key, headers.get(key));
}

// set body (handle empty cases)
String body = getBody();
if (body == null) {
body = "";
}

req.setEntity(new StringEntity(body, "UTF-8"));

return req;
}

public void send (HttpClient client, Office365Credentials cred, String url) throws IOException, InvalidCrmCredentialsException, MalformedResponseException {
// creates request (with headers, body, etc)
RequestBuilder req = getRequest(url);
// adds auth
addAuthHeaderToRequest(cred, req);

// execute the request
Response response;
try {
response = new Response(client.execute(req.build()));
} catch (ConnectionPoolTimeoutException e) {
// The 10 second limit has passed
throw new MalformedResponseException("Response missing (response timed out)!", e);
}

// check for 401, not authorized
if (response.getStatus() == 401) {
throw new InvalidCrmCredentialsException("401 - Not authorized! " + req.getUri().toString());
}

// process response
processResponse(response);
}


The HttpClient is constructed like this:



    int CONNECTION_TIMEOUT_MS = 10 * 1000; // 10 second timeout
RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout(CONNECTION_TIMEOUT_MS)
.setConnectTimeout(CONNECTION_TIMEOUT_MS)
.setSocketTimeout(CONNECTION_TIMEOUT_MS)
.build();

client = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build();


No matter how high I set the limit, I never get a response, the office api. Not even an error response.



TL;DR: My request works fine in postman, exact same request in Java times out (no matter the timeout length)










share|improve this question

























  • Do you use a proxy server?

    – declension
    Nov 16 '18 at 14:54











  • @declension no proxy used

    – Le 'nton
    Nov 16 '18 at 14:57











  • POST /api/v2.0/me/subscriptions HTTP/1.1 vs. POST /me/subscriptions HTTP/1.1. There are some further changes actually notable so the requests are similar but NOT identical. Maybe one of the differences is causing the problems. Have you even received the request sent from your client and were the processed by the same server logic?

    – Roman Vottner
    Nov 16 '18 at 15:22













  • Is it correct that you were using different versions of API from Java and Postman?

    – Dmitry Surin
    Nov 16 '18 at 15:23











  • @DmitrySurin sorry no, this was a unrelated mistake from when I was trying different ways to capture the requests. Updated

    – Le 'nton
    Nov 16 '18 at 15:42


















8















I'm trying to register a Office365 Api webhook per official api docs. I tried it in postman, all works as expected.



Java Version: 1.7 (I know...)



I am working with the Play framework version 1.2.7.2



HttpClient: org.apache.http.client.HttpClient



Relevant documentation:




The subscription process goes as follows:



A client app makes a subscription request (POST) for a specific resource. It includes a notification URL, among other properties.



The Outlook notifications service tries to validate the notification URL with the listener service. It includes a validation token in the validation request.



If the listener service successfully validates the URL, it returns a success response within 5 seconds as follows:



Sets the content type in the response header to textplain.
Includes the same validation token in the response body.
Returns an HTTP 200 response code. The listener can discard the validation token subsequently.
Depending on the URL validation result, the Outlook notifications service sends a response to the client app:



If URL validation was successful, the service creates the subscription with a unique subscription ID and sends the response to the client.
If URL validation was unsuccessful, the service sends an error response with an error code and other details.
Upon receiving a successful response, the client app stores the subscription ID to correlate future notifications with this subscription.




Postman request:



Both requests intercepted with wireshark:



Postman:



Ý`!Ë2@ʸ1cÊþßV:
ðîPOST /api/v2.0/me/subscriptions HTTP/1.1
Content-Type: application/json
cache-control: no-cache
Postman-Token: a24df796-c49e-4245-a1cf-0949cd6538b6
Authorization: Bearer ###
User-Agent: PostmanRuntime/7.4.0
Accept: */*
Host: localhost:3000
accept-encoding: gzip, deflate
content-length: 430
Connection: keep-alive

{
"@odata.type":"#Microsoft.OutlookServices.PushSubscription",
"ChangeType": "Created, Deleted, Updated",
"ClientState": "some-token",
"NotificationURL": "https://###/office365/receive.php?subId=5",
"Resource": "https://outlook.office.com/api/v2.0/me/Calendars('###')/events"
}


(captured in wireshark) (the ### parts are removed info, I made sure that auth and ids match up)



At ###/office365/receive.php lies a php script which just echoes back $_GET['validationtoken']. This works perfectly in Postman.



In Java, I create a request with the same headers and the same body



E/@@5â$¸³zêð-gÄV$
Là¼Là¼POST /api/v2.0/me/subscriptions HTTP/1.1
Accept: */*
Content-Type: application/json
Authorization: Bearer ###
Content-Length: 476
Host: localhost:3000
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.2 (Java/1.7.0_80)
Accept-Encoding: gzip,deflate

{
"@odata.type":"#Microsoft.OutlookServices.PushSubscription",
"ChangeType": "Created, Deleted, Updated",
"ClientState": "1fdb3e372212622e0b7e68abe09e1201a81a8bcc040cce9a6f013f71a09bfbe1",
"NotificationURL": "https://###/office365/receive.php",
"Resource": "https://outlook.office.com/api/v2.0/me/Calendars('###')/events"
}


I verified that all (important) parts of the request are exactly the same.



My code in java is a little to complex to share fully here, however the important bits are:



// build url
private final RequestBuilder getRequest (String url) {
RequestBuilder req = RequestBuilder.create(getMethod()); // e.g. POST
req.setUri(overwriteBaseUrl(url) + getPath());

// headers is a hashmap<String, String>
for (String key: headers.keySet()) {
req.setHeader(key, headers.get(key));
}

// set body (handle empty cases)
String body = getBody();
if (body == null) {
body = "";
}

req.setEntity(new StringEntity(body, "UTF-8"));

return req;
}

public void send (HttpClient client, Office365Credentials cred, String url) throws IOException, InvalidCrmCredentialsException, MalformedResponseException {
// creates request (with headers, body, etc)
RequestBuilder req = getRequest(url);
// adds auth
addAuthHeaderToRequest(cred, req);

// execute the request
Response response;
try {
response = new Response(client.execute(req.build()));
} catch (ConnectionPoolTimeoutException e) {
// The 10 second limit has passed
throw new MalformedResponseException("Response missing (response timed out)!", e);
}

// check for 401, not authorized
if (response.getStatus() == 401) {
throw new InvalidCrmCredentialsException("401 - Not authorized! " + req.getUri().toString());
}

// process response
processResponse(response);
}


The HttpClient is constructed like this:



    int CONNECTION_TIMEOUT_MS = 10 * 1000; // 10 second timeout
RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout(CONNECTION_TIMEOUT_MS)
.setConnectTimeout(CONNECTION_TIMEOUT_MS)
.setSocketTimeout(CONNECTION_TIMEOUT_MS)
.build();

client = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build();


No matter how high I set the limit, I never get a response, the office api. Not even an error response.



TL;DR: My request works fine in postman, exact same request in Java times out (no matter the timeout length)










share|improve this question

























  • Do you use a proxy server?

    – declension
    Nov 16 '18 at 14:54











  • @declension no proxy used

    – Le 'nton
    Nov 16 '18 at 14:57











  • POST /api/v2.0/me/subscriptions HTTP/1.1 vs. POST /me/subscriptions HTTP/1.1. There are some further changes actually notable so the requests are similar but NOT identical. Maybe one of the differences is causing the problems. Have you even received the request sent from your client and were the processed by the same server logic?

    – Roman Vottner
    Nov 16 '18 at 15:22













  • Is it correct that you were using different versions of API from Java and Postman?

    – Dmitry Surin
    Nov 16 '18 at 15:23











  • @DmitrySurin sorry no, this was a unrelated mistake from when I was trying different ways to capture the requests. Updated

    – Le 'nton
    Nov 16 '18 at 15:42














8












8








8


1






I'm trying to register a Office365 Api webhook per official api docs. I tried it in postman, all works as expected.



Java Version: 1.7 (I know...)



I am working with the Play framework version 1.2.7.2



HttpClient: org.apache.http.client.HttpClient



Relevant documentation:




The subscription process goes as follows:



A client app makes a subscription request (POST) for a specific resource. It includes a notification URL, among other properties.



The Outlook notifications service tries to validate the notification URL with the listener service. It includes a validation token in the validation request.



If the listener service successfully validates the URL, it returns a success response within 5 seconds as follows:



Sets the content type in the response header to textplain.
Includes the same validation token in the response body.
Returns an HTTP 200 response code. The listener can discard the validation token subsequently.
Depending on the URL validation result, the Outlook notifications service sends a response to the client app:



If URL validation was successful, the service creates the subscription with a unique subscription ID and sends the response to the client.
If URL validation was unsuccessful, the service sends an error response with an error code and other details.
Upon receiving a successful response, the client app stores the subscription ID to correlate future notifications with this subscription.




Postman request:



Both requests intercepted with wireshark:



Postman:



Ý`!Ë2@ʸ1cÊþßV:
ðîPOST /api/v2.0/me/subscriptions HTTP/1.1
Content-Type: application/json
cache-control: no-cache
Postman-Token: a24df796-c49e-4245-a1cf-0949cd6538b6
Authorization: Bearer ###
User-Agent: PostmanRuntime/7.4.0
Accept: */*
Host: localhost:3000
accept-encoding: gzip, deflate
content-length: 430
Connection: keep-alive

{
"@odata.type":"#Microsoft.OutlookServices.PushSubscription",
"ChangeType": "Created, Deleted, Updated",
"ClientState": "some-token",
"NotificationURL": "https://###/office365/receive.php?subId=5",
"Resource": "https://outlook.office.com/api/v2.0/me/Calendars('###')/events"
}


(captured in wireshark) (the ### parts are removed info, I made sure that auth and ids match up)



At ###/office365/receive.php lies a php script which just echoes back $_GET['validationtoken']. This works perfectly in Postman.



In Java, I create a request with the same headers and the same body



E/@@5â$¸³zêð-gÄV$
Là¼Là¼POST /api/v2.0/me/subscriptions HTTP/1.1
Accept: */*
Content-Type: application/json
Authorization: Bearer ###
Content-Length: 476
Host: localhost:3000
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.2 (Java/1.7.0_80)
Accept-Encoding: gzip,deflate

{
"@odata.type":"#Microsoft.OutlookServices.PushSubscription",
"ChangeType": "Created, Deleted, Updated",
"ClientState": "1fdb3e372212622e0b7e68abe09e1201a81a8bcc040cce9a6f013f71a09bfbe1",
"NotificationURL": "https://###/office365/receive.php",
"Resource": "https://outlook.office.com/api/v2.0/me/Calendars('###')/events"
}


I verified that all (important) parts of the request are exactly the same.



My code in java is a little to complex to share fully here, however the important bits are:



// build url
private final RequestBuilder getRequest (String url) {
RequestBuilder req = RequestBuilder.create(getMethod()); // e.g. POST
req.setUri(overwriteBaseUrl(url) + getPath());

// headers is a hashmap<String, String>
for (String key: headers.keySet()) {
req.setHeader(key, headers.get(key));
}

// set body (handle empty cases)
String body = getBody();
if (body == null) {
body = "";
}

req.setEntity(new StringEntity(body, "UTF-8"));

return req;
}

public void send (HttpClient client, Office365Credentials cred, String url) throws IOException, InvalidCrmCredentialsException, MalformedResponseException {
// creates request (with headers, body, etc)
RequestBuilder req = getRequest(url);
// adds auth
addAuthHeaderToRequest(cred, req);

// execute the request
Response response;
try {
response = new Response(client.execute(req.build()));
} catch (ConnectionPoolTimeoutException e) {
// The 10 second limit has passed
throw new MalformedResponseException("Response missing (response timed out)!", e);
}

// check for 401, not authorized
if (response.getStatus() == 401) {
throw new InvalidCrmCredentialsException("401 - Not authorized! " + req.getUri().toString());
}

// process response
processResponse(response);
}


The HttpClient is constructed like this:



    int CONNECTION_TIMEOUT_MS = 10 * 1000; // 10 second timeout
RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout(CONNECTION_TIMEOUT_MS)
.setConnectTimeout(CONNECTION_TIMEOUT_MS)
.setSocketTimeout(CONNECTION_TIMEOUT_MS)
.build();

client = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build();


No matter how high I set the limit, I never get a response, the office api. Not even an error response.



TL;DR: My request works fine in postman, exact same request in Java times out (no matter the timeout length)










share|improve this question
















I'm trying to register a Office365 Api webhook per official api docs. I tried it in postman, all works as expected.



Java Version: 1.7 (I know...)



I am working with the Play framework version 1.2.7.2



HttpClient: org.apache.http.client.HttpClient



Relevant documentation:




The subscription process goes as follows:



A client app makes a subscription request (POST) for a specific resource. It includes a notification URL, among other properties.



The Outlook notifications service tries to validate the notification URL with the listener service. It includes a validation token in the validation request.



If the listener service successfully validates the URL, it returns a success response within 5 seconds as follows:



Sets the content type in the response header to textplain.
Includes the same validation token in the response body.
Returns an HTTP 200 response code. The listener can discard the validation token subsequently.
Depending on the URL validation result, the Outlook notifications service sends a response to the client app:



If URL validation was successful, the service creates the subscription with a unique subscription ID and sends the response to the client.
If URL validation was unsuccessful, the service sends an error response with an error code and other details.
Upon receiving a successful response, the client app stores the subscription ID to correlate future notifications with this subscription.




Postman request:



Both requests intercepted with wireshark:



Postman:



Ý`!Ë2@ʸ1cÊþßV:
ðîPOST /api/v2.0/me/subscriptions HTTP/1.1
Content-Type: application/json
cache-control: no-cache
Postman-Token: a24df796-c49e-4245-a1cf-0949cd6538b6
Authorization: Bearer ###
User-Agent: PostmanRuntime/7.4.0
Accept: */*
Host: localhost:3000
accept-encoding: gzip, deflate
content-length: 430
Connection: keep-alive

{
"@odata.type":"#Microsoft.OutlookServices.PushSubscription",
"ChangeType": "Created, Deleted, Updated",
"ClientState": "some-token",
"NotificationURL": "https://###/office365/receive.php?subId=5",
"Resource": "https://outlook.office.com/api/v2.0/me/Calendars('###')/events"
}


(captured in wireshark) (the ### parts are removed info, I made sure that auth and ids match up)



At ###/office365/receive.php lies a php script which just echoes back $_GET['validationtoken']. This works perfectly in Postman.



In Java, I create a request with the same headers and the same body



E/@@5â$¸³zêð-gÄV$
Là¼Là¼POST /api/v2.0/me/subscriptions HTTP/1.1
Accept: */*
Content-Type: application/json
Authorization: Bearer ###
Content-Length: 476
Host: localhost:3000
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.2 (Java/1.7.0_80)
Accept-Encoding: gzip,deflate

{
"@odata.type":"#Microsoft.OutlookServices.PushSubscription",
"ChangeType": "Created, Deleted, Updated",
"ClientState": "1fdb3e372212622e0b7e68abe09e1201a81a8bcc040cce9a6f013f71a09bfbe1",
"NotificationURL": "https://###/office365/receive.php",
"Resource": "https://outlook.office.com/api/v2.0/me/Calendars('###')/events"
}


I verified that all (important) parts of the request are exactly the same.



My code in java is a little to complex to share fully here, however the important bits are:



// build url
private final RequestBuilder getRequest (String url) {
RequestBuilder req = RequestBuilder.create(getMethod()); // e.g. POST
req.setUri(overwriteBaseUrl(url) + getPath());

// headers is a hashmap<String, String>
for (String key: headers.keySet()) {
req.setHeader(key, headers.get(key));
}

// set body (handle empty cases)
String body = getBody();
if (body == null) {
body = "";
}

req.setEntity(new StringEntity(body, "UTF-8"));

return req;
}

public void send (HttpClient client, Office365Credentials cred, String url) throws IOException, InvalidCrmCredentialsException, MalformedResponseException {
// creates request (with headers, body, etc)
RequestBuilder req = getRequest(url);
// adds auth
addAuthHeaderToRequest(cred, req);

// execute the request
Response response;
try {
response = new Response(client.execute(req.build()));
} catch (ConnectionPoolTimeoutException e) {
// The 10 second limit has passed
throw new MalformedResponseException("Response missing (response timed out)!", e);
}

// check for 401, not authorized
if (response.getStatus() == 401) {
throw new InvalidCrmCredentialsException("401 - Not authorized! " + req.getUri().toString());
}

// process response
processResponse(response);
}


The HttpClient is constructed like this:



    int CONNECTION_TIMEOUT_MS = 10 * 1000; // 10 second timeout
RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout(CONNECTION_TIMEOUT_MS)
.setConnectTimeout(CONNECTION_TIMEOUT_MS)
.setSocketTimeout(CONNECTION_TIMEOUT_MS)
.build();

client = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build();


No matter how high I set the limit, I never get a response, the office api. Not even an error response.



TL;DR: My request works fine in postman, exact same request in Java times out (no matter the timeout length)







java apache






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 15:42







Le 'nton

















asked Nov 7 '18 at 16:45









Le 'ntonLe 'nton

175117




175117













  • Do you use a proxy server?

    – declension
    Nov 16 '18 at 14:54











  • @declension no proxy used

    – Le 'nton
    Nov 16 '18 at 14:57











  • POST /api/v2.0/me/subscriptions HTTP/1.1 vs. POST /me/subscriptions HTTP/1.1. There are some further changes actually notable so the requests are similar but NOT identical. Maybe one of the differences is causing the problems. Have you even received the request sent from your client and were the processed by the same server logic?

    – Roman Vottner
    Nov 16 '18 at 15:22













  • Is it correct that you were using different versions of API from Java and Postman?

    – Dmitry Surin
    Nov 16 '18 at 15:23











  • @DmitrySurin sorry no, this was a unrelated mistake from when I was trying different ways to capture the requests. Updated

    – Le 'nton
    Nov 16 '18 at 15:42



















  • Do you use a proxy server?

    – declension
    Nov 16 '18 at 14:54











  • @declension no proxy used

    – Le 'nton
    Nov 16 '18 at 14:57











  • POST /api/v2.0/me/subscriptions HTTP/1.1 vs. POST /me/subscriptions HTTP/1.1. There are some further changes actually notable so the requests are similar but NOT identical. Maybe one of the differences is causing the problems. Have you even received the request sent from your client and were the processed by the same server logic?

    – Roman Vottner
    Nov 16 '18 at 15:22













  • Is it correct that you were using different versions of API from Java and Postman?

    – Dmitry Surin
    Nov 16 '18 at 15:23











  • @DmitrySurin sorry no, this was a unrelated mistake from when I was trying different ways to capture the requests. Updated

    – Le 'nton
    Nov 16 '18 at 15:42

















Do you use a proxy server?

– declension
Nov 16 '18 at 14:54





Do you use a proxy server?

– declension
Nov 16 '18 at 14:54













@declension no proxy used

– Le 'nton
Nov 16 '18 at 14:57





@declension no proxy used

– Le 'nton
Nov 16 '18 at 14:57













POST /api/v2.0/me/subscriptions HTTP/1.1 vs. POST /me/subscriptions HTTP/1.1. There are some further changes actually notable so the requests are similar but NOT identical. Maybe one of the differences is causing the problems. Have you even received the request sent from your client and were the processed by the same server logic?

– Roman Vottner
Nov 16 '18 at 15:22







POST /api/v2.0/me/subscriptions HTTP/1.1 vs. POST /me/subscriptions HTTP/1.1. There are some further changes actually notable so the requests are similar but NOT identical. Maybe one of the differences is causing the problems. Have you even received the request sent from your client and were the processed by the same server logic?

– Roman Vottner
Nov 16 '18 at 15:22















Is it correct that you were using different versions of API from Java and Postman?

– Dmitry Surin
Nov 16 '18 at 15:23





Is it correct that you were using different versions of API from Java and Postman?

– Dmitry Surin
Nov 16 '18 at 15:23













@DmitrySurin sorry no, this was a unrelated mistake from when I was trying different ways to capture the requests. Updated

– Le 'nton
Nov 16 '18 at 15:42





@DmitrySurin sorry no, this was a unrelated mistake from when I was trying different ways to capture the requests. Updated

– Le 'nton
Nov 16 '18 at 15:42












1 Answer
1






active

oldest

votes


















6














The problem is, that org.apache.http.client.HttpClient is not thread safe (at least for play framework 1.2.7). Since the play framework reuses threads, my best guess is, that it never received the answer (since the webhook register request takes a little longer than normal requests).



I switched to WS, the http client supplied by the play framework itself. This come with the disadvantage, that it only has limited support for all the http verbs.



The new methods look like this:



private final WS.WSRequest getRequest (String url) {
WS.WSRequest req = WS.url(overwriteBaseUrl(url) + getPath());

for (String key: headers.keySet()) {
req.setHeader(key, headers.get(key));
}

String body = getBody();
if (body == null) {
body = "";
}

req.body(body);

return req;
}

public void send (WSMockableSender client, Office365Credentials cred, String url) throws IOException, InvalidCrmCredentialsException, MalformedResponseException {

WS.WSRequest req = getRequest(url);
addAuthHeaderToRequest(cred, req);

// execute the request
WSResponse response;
response = new WSResponse(client.post(req));

System.out.println("Response received!");

// check for 401, not authorized
if (response.getStatus() == 401) {
throw new InvalidCrmCredentialsException("401 - Not authorized! " + req.url);
}

processResponse(response);
}





share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53194046%2fidentical-request-timing-out-in-java-apache-working-fine-in-postman%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    6














    The problem is, that org.apache.http.client.HttpClient is not thread safe (at least for play framework 1.2.7). Since the play framework reuses threads, my best guess is, that it never received the answer (since the webhook register request takes a little longer than normal requests).



    I switched to WS, the http client supplied by the play framework itself. This come with the disadvantage, that it only has limited support for all the http verbs.



    The new methods look like this:



    private final WS.WSRequest getRequest (String url) {
    WS.WSRequest req = WS.url(overwriteBaseUrl(url) + getPath());

    for (String key: headers.keySet()) {
    req.setHeader(key, headers.get(key));
    }

    String body = getBody();
    if (body == null) {
    body = "";
    }

    req.body(body);

    return req;
    }

    public void send (WSMockableSender client, Office365Credentials cred, String url) throws IOException, InvalidCrmCredentialsException, MalformedResponseException {

    WS.WSRequest req = getRequest(url);
    addAuthHeaderToRequest(cred, req);

    // execute the request
    WSResponse response;
    response = new WSResponse(client.post(req));

    System.out.println("Response received!");

    // check for 401, not authorized
    if (response.getStatus() == 401) {
    throw new InvalidCrmCredentialsException("401 - Not authorized! " + req.url);
    }

    processResponse(response);
    }





    share|improve this answer




























      6














      The problem is, that org.apache.http.client.HttpClient is not thread safe (at least for play framework 1.2.7). Since the play framework reuses threads, my best guess is, that it never received the answer (since the webhook register request takes a little longer than normal requests).



      I switched to WS, the http client supplied by the play framework itself. This come with the disadvantage, that it only has limited support for all the http verbs.



      The new methods look like this:



      private final WS.WSRequest getRequest (String url) {
      WS.WSRequest req = WS.url(overwriteBaseUrl(url) + getPath());

      for (String key: headers.keySet()) {
      req.setHeader(key, headers.get(key));
      }

      String body = getBody();
      if (body == null) {
      body = "";
      }

      req.body(body);

      return req;
      }

      public void send (WSMockableSender client, Office365Credentials cred, String url) throws IOException, InvalidCrmCredentialsException, MalformedResponseException {

      WS.WSRequest req = getRequest(url);
      addAuthHeaderToRequest(cred, req);

      // execute the request
      WSResponse response;
      response = new WSResponse(client.post(req));

      System.out.println("Response received!");

      // check for 401, not authorized
      if (response.getStatus() == 401) {
      throw new InvalidCrmCredentialsException("401 - Not authorized! " + req.url);
      }

      processResponse(response);
      }





      share|improve this answer


























        6












        6








        6







        The problem is, that org.apache.http.client.HttpClient is not thread safe (at least for play framework 1.2.7). Since the play framework reuses threads, my best guess is, that it never received the answer (since the webhook register request takes a little longer than normal requests).



        I switched to WS, the http client supplied by the play framework itself. This come with the disadvantage, that it only has limited support for all the http verbs.



        The new methods look like this:



        private final WS.WSRequest getRequest (String url) {
        WS.WSRequest req = WS.url(overwriteBaseUrl(url) + getPath());

        for (String key: headers.keySet()) {
        req.setHeader(key, headers.get(key));
        }

        String body = getBody();
        if (body == null) {
        body = "";
        }

        req.body(body);

        return req;
        }

        public void send (WSMockableSender client, Office365Credentials cred, String url) throws IOException, InvalidCrmCredentialsException, MalformedResponseException {

        WS.WSRequest req = getRequest(url);
        addAuthHeaderToRequest(cred, req);

        // execute the request
        WSResponse response;
        response = new WSResponse(client.post(req));

        System.out.println("Response received!");

        // check for 401, not authorized
        if (response.getStatus() == 401) {
        throw new InvalidCrmCredentialsException("401 - Not authorized! " + req.url);
        }

        processResponse(response);
        }





        share|improve this answer













        The problem is, that org.apache.http.client.HttpClient is not thread safe (at least for play framework 1.2.7). Since the play framework reuses threads, my best guess is, that it never received the answer (since the webhook register request takes a little longer than normal requests).



        I switched to WS, the http client supplied by the play framework itself. This come with the disadvantage, that it only has limited support for all the http verbs.



        The new methods look like this:



        private final WS.WSRequest getRequest (String url) {
        WS.WSRequest req = WS.url(overwriteBaseUrl(url) + getPath());

        for (String key: headers.keySet()) {
        req.setHeader(key, headers.get(key));
        }

        String body = getBody();
        if (body == null) {
        body = "";
        }

        req.body(body);

        return req;
        }

        public void send (WSMockableSender client, Office365Credentials cred, String url) throws IOException, InvalidCrmCredentialsException, MalformedResponseException {

        WS.WSRequest req = getRequest(url);
        addAuthHeaderToRequest(cred, req);

        // execute the request
        WSResponse response;
        response = new WSResponse(client.post(req));

        System.out.println("Response received!");

        // check for 401, not authorized
        if (response.getStatus() == 401) {
        throw new InvalidCrmCredentialsException("401 - Not authorized! " + req.url);
        }

        processResponse(response);
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 16 '18 at 15:39









        Le 'ntonLe 'nton

        175117




        175117
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53194046%2fidentical-request-timing-out-in-java-apache-working-fine-in-postman%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Xamarin.iOS Cant Deploy on Iphone

            Glorious Revolution

            Dulmage-Mendelsohn matrix decomposition in Python