I am trying to create a small application that uses OpenID4Java for openId auth.
I am able to successfully redirect user to OpenID provider site to login, but on returning to URL its verification fails.
Method that process response from openID Provider is,
public HashMap<String, String> verifyResponse(HttpServletRequest httpReq){
HashMap<String, String> values = new HashMap<String, String>();
try{
ParameterList response = new ParameterList(httpReq.getParameterMap());
// retrieve the previously stored discovery information
DiscoveryInformation discovered = (DiscoveryInformation)httpReq.getSession().getAttribute("openid-disc");
// extract the receiving URL from the HTTP request
StringBuffer receivingURL = httpReq.getRequestURL();
String queryString = httpReq.getQueryString();
if (queryString != null && queryString.length() > 0)
receivingURL.append("?").append(httpReq.getQueryString());
// verify the response; ConsumerManager needs to be the same
// (static) instance used to place the authentication request
VerificationResult verification = manager.verify(receivingURL.toString(), response, discovered);
// examine the verification result and extract the verified identifier
Identifier verified = verification.getVerifiedId();
if (verified != null){
AuthSuccess authSuccess = (AuthSuccess) verification.getAuthResponse();
if (authSuccess.hasExtension(AxMessage.OPENID_NS_AX)){
FetchResponse fetchResp = (FetchResponse) authSuccess.getExtension(AxMessage.OPENID_NS_AX);
values.put("GUID", (String)fetchResp.getAttributeValues("GUID").get(0));
values.put("Email", (String)fetchResp.getAttributeValues("Email").get(0));
values.put("FirstName", (String)fetchResp.getAttributeValues("FirstName").get(0));
values.put("LastName", (String)fetchResp.getAttributeValues("LastName").get(0));
values.put("Gender", (String)fetchResp.getAttributeValues("Gender").get(0));
values.put("Country", (String)fetchResp.getAttributeValues("Country").get(0));
values.put("Company", (String)fetchResp.getAttributeValues("Company").get(0));
values.put("VerifiedUserId", verified.getIdentifier());
values.put("Verified", verified.toString());
}
return values; // success
}else{
values.put("VerifiedUserId", "nun");
// values.put("Verified", verified.toString());
return values; // success
}
}
catch (OpenIDException e){
// present error to the user
}
return null;
}
on returning, following failure messages are there in console.
31573 [http-bio-8080-exec-9] DEBUG org.apache.http.headers - << Set-Cookie: ephemeral_session_id=56f872bb71a5f4feae404d3f391f9d51833d50b51c13ddbcdac6a1fc058e5269; domain=myopenid.com; path=/
31573 [http-bio-8080-exec-9] DEBUG org.apache.http.headers - << Set-Cookie: ephemeral_session_id=56f872bb71a5f4feae404d3f391f9d51833d50b51c13ddbcdac6a1fc058e5269; domain=myopenid.com; path=/
31573 [http-bio-8080-exec-9] DEBUG org.apache.http.headers - << Set-Cookie: browser_id=5e3bfb0c08da19a59e8445e624637c261aee10e65a6b672ed642cb9201e5d8e4; domain=myopenid.com; path=/; expires=Sat, 16-Mar-2013 21:40:09 GMT
31573 [http-bio-8080-exec-9] DEBUG org.apache.http.headers - << Set-Cookie: browser_id=5e3bfb0c08da19a59e8445e624637c261aee10e65a6b672ed642cb9201e5d8e4; domain=myopenid.com; path=/; expires=Sat, 16-Mar-2013 21:40:09 GMT
31573 [http-bio-8080-exec-9] DEBUG org.apache.http.headers - << Set-Cookie: session_id=8aef51436d464910daaa1ef8eb5c661e6fa45c134c0969a1f7048ef5f23707c6; domain=myopenid.com; path=/; expires=Sat, 16-Mar-2013 21:40:09 GMT
31573 [http-bio-8080-exec-9] DEBUG org.apache.http.headers - << Set-Cookie: session_id=8aef51436d464910daaa1ef8eb5c661e6fa45c134c0969a1f7048ef5f23707c6; domain=myopenid.com; path=/; expires=Sat, 16-Mar-2013 21:40:09 GMT
31573 [http-bio-8080-exec-9] DEBUG org.apache.http.headers - << P3P: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"
31573 [http-bio-8080-exec-9] DEBUG org.apache.http.headers - << P3P: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"
31573 [http-bio-8080-exec-9] DEBUG org.apache.http.headers - << Connection: close
31573 [http-bio-8080-exec-9] DEBUG org.apache.http.headers - << Connection: close
31574 [http-bio-8080-exec-9] DEBUG org.apache.http.client.protocol.ResponseProcessCookies - Cookie accepted: "[version: 0][name: ephemeral_session_id][value: 56f872bb71a5f4feae404d3f391f9d51833d50b51c13ddbcdac6a1fc058e5269][domain: myopenid.com][path: /][expiry: null]".
31574 [http-bio-8080-exec-9] DEBUG org.apache.http.client.protocol.ResponseProcessCookies - Cookie accepted: "[version: 0][name: ephemeral_session_id][value: 56f872bb71a5f4feae404d3f391f9d51833d50b51c13ddbcdac6a1fc058e5269][domain: myopenid.com][path: /][expiry: null]".
31574 [http-bio-8080-exec-9] DEBUG org.apache.http.client.protocol.ResponseProcessCookies - Cookie accepted: "[version: 0][name: browser_id][value: 5e3bfb0c08da19a59e8445e624637c261aee10e65a6b672ed642cb9201e5d8e4][domain: myopenid.com][path: /][expiry: Sun Mar 17 02:40:09 PKT 2013]".
31574 [http-bio-8080-exec-9] DEBUG org.apache.http.client.protocol.ResponseProcessCookies - Cookie accepted: "[version: 0][name: browser_id][value: 5e3bfb0c08da19a59e8445e624637c261aee10e65a6b672ed642cb9201e5d8e4][domain: myopenid.com][path: /][expiry: Sun Mar 17 02:40:09 PKT 2013]".
31575 [http-bio-8080-exec-9] DEBUG org.apache.http.client.protocol.ResponseProcessCookies - Cookie accepted: "[version: 0][name: session_id][value: 8aef51436d464910daaa1ef8eb5c661e6fa45c134c0969a1f7048ef5f23707c6][domain: myopenid.com][path: /][expiry: Sun Mar 17 02:40:09 PKT 2013]".
31575 [http-bio-8080-exec-9] DEBUG org.apache.http.client.protocol.ResponseProcessCookies - Cookie accepted: "[version: 0][name: session_id][value: 8aef51436d464910daaa1ef8eb5c661e6fa45c134c0969a1f7048ef5f23707c6][domain: myopenid.com][path: /][expiry: Sun Mar 17 02:40:09 PKT 2013]".
31575 [http-bio-8080-exec-9] DEBUG org.apache.http.impl.client.ClientParamsStack - 'http.protocol.handle-redirects': false
31575 [http-bio-8080-exec-9] DEBUG org.apache.http.impl.client.ClientParamsStack - 'http.protocol.handle-redirects': false
31575 [http-bio-8080-exec-9] DEBUG org.apache.http.wire - << "is_valid:false[\n]"
31575 [http-bio-8080-exec-9] DEBUG org.apache.http.wire - << "is_valid:false[\n]"
31575 [http-bio-8080-exec-9] DEBUG org.apache.http.wire - << "ns:http://specs.openid.net/auth/2.0[\n]"
31575 [http-bio-8080-exec-9] DEBUG org.apache.http.wire - << "ns:http://specs.openid.net/auth/2.0[\n]"
31575 [http-bio-8080-exec-9] DEBUG org.apache.http.impl.conn.DefaultClientConnection - Connection shut down
31575 [http-bio-8080-exec-9] DEBUG org.apache.http.impl.conn.DefaultClientConnection - Connection shut down
31576 [http-bio-8080-exec-9] DEBUG org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager - Released connection is not reusable.
31576 [http-bio-8080-exec-9] DEBUG org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager - Released connection is not reusable.
31576 [http-bio-8080-exec-9] DEBUG org.apache.http.impl.conn.tsccm.ConnPoolByRoute - Releasing connection [HttpRoute[{}->http://www.myopenid.com]][null]
31576 [http-bio-8080-exec-9] DEBUG org.apache.http.impl.conn.tsccm.ConnPoolByRoute - Releasing connection [HttpRoute[{}->http://www.myopenid.com]][null]
31576 [http-bio-8080-exec-9] DEBUG org.apache.http.impl.conn.tsccm.ConnPoolByRoute - Notifying no-one, there are no waiting threads
31576 [http-bio-8080-exec-9] DEBUG org.apache.http.impl.conn.tsccm.ConnPoolByRoute - Notifying no-one, there are no waiting threads
31576 [http-bio-8080-exec-9] DEBUG org.openid4java.util.HttpCache - Read 51 bytes.
31576 [http-bio-8080-exec-9] DEBUG org.openid4java.util.HttpCache - Read 51 bytes.
31576 [http-bio-8080-exec-9] DEBUG org.openid4java.message.ParameterList - Creating parameter list from key-value form:
is_valid:false
ns:http://specs.openid.net/auth/2.0
31576 [http-bio-8080-exec-9] DEBUG org.openid4java.message.ParameterList - Creating parameter list from key-value form:
is_valid:false
ns:http://specs.openid.net/auth/2.0
31576 [http-bio-8080-exec-9] DEBUG org.openid4java.message.ParameterList - Created empty parameter list.
31576 [http-bio-8080-exec-9] DEBUG org.openid4java.message.ParameterList - Created empty parameter list.
31581 [http-bio-8080-exec-9] DEBUG org.openid4java.message.ParameterList - Copying parameter list:
is_valid:false
ns:http://specs.openid.net/auth/2.0
31581 [http-bio-8080-exec-9] DEBUG org.openid4java.message.ParameterList - Copying parameter list:
is_valid:false
ns:http://specs.openid.net/auth/2.0
31581 [http-bio-8080-exec-9] DEBUG org.openid4java.consumer.ConsumerManager - Retrived response:
is_valid:false
ns:http://specs.openid.net/auth/2.0
31581 [http-bio-8080-exec-9] DEBUG org.openid4java.consumer.ConsumerManager - Retrived response:
is_valid:false
ns:http://specs.openid.net/auth/2.0
31582 [http-bio-8080-exec-9] DEBUG org.openid4java.message.ParameterList - Created empty parameter list.
31582 [http-bio-8080-exec-9] DEBUG org.openid4java.message.ParameterList - Created empty parameter list.
31582 [http-bio-8080-exec-9] DEBUG org.openid4java.message.VerifyResponse - Created verification response:
is_valid:false
ns:http://specs.openid.net/auth/2.0
31582 [http-bio-8080-exec-9] DEBUG org.openid4java.message.VerifyResponse - Created verification response:
is_valid:false
ns:http://specs.openid.net/auth/2.0
31582 [http-bio-8080-exec-9] DEBUG org.openid4java.consumer.ConsumerManager - Direct signature verification failed with OP: http://www.myopenid.com/server
31582 [http-bio-8080-exec-9] DEBUG org.openid4java.consumer.ConsumerManager - Direct signature verification failed with OP: http://www.myopenid.com/server
31582 [http-bio-8080-exec-9] ERROR org.openid4java.consumer.ConsumerManager - Verification failed for: http://aaaqif.myopenid.com/ reason: Direct signature verification failed.
31582 [http-bio-8080-exec-9] ERROR org.openid4java.consumer.ConsumerManager - Verification failed for: http://aaaqif.myopenid.com/ reason: Direct signature verification failed.
Related
I have enabled feign logging andgot some thing like that:
15:27:15.420 [ForkJoinPool-1-worker-229] DEBUG feign.Logger - [UserEndpoint#postUser] Authorization: Bearer test
15:27:15.420 [ForkJoinPool-1-worker-229] DEBUG feign.Logger - [UserEndpoint#postUser] Content-Length: 19
15:27:15.420 [ForkJoinPool-1-worker-229] DEBUG feign.Logger - [UserEndpoint#postUser] Content-Type: application/json
15:27:15.420 [ForkJoinPool-1-worker-229] DEBUG feign.Logger - [UserEndpoint#postUser]
15:27:15.420 [ForkJoinPool-1-worker-229] DEBUG feign.Logger - [UserEndpoint#postUser] {"attributes":null}
15:27:15.420 [ForkJoinPool-1-worker-229] DEBUG feign.Logger - [UserEndpoint#postUser] ---> END HTTP (19-byte body)
15:27:16.585 [ForkJoinPool-1-worker-117] DEBUG feign.Logger - [UserEndpoint#getUserById] <--- HTTP/1.1 500 Internal Server Error (1223ms)
15:27:16.585 [ForkJoinPool-1-worker-117] DEBUG feign.Logger - [UserEndpoint#getUserById] apigw-requestid: RpKPuhaFPHcESkA=
15:27:16.585 [ForkJoinPool-1-worker-117] DEBUG feign.Logger - [UserEndpoint#getUserById] connection: keep-alive
15:27:16.585 [ForkJoinPool-1-worker-117] DEBUG feign.Logger - [UserEndpoint#getUserById] content-length: 35
15:27:16.585 [ForkJoinPool-1-worker-117] DEBUG feign.Logger - [UserEndpoint#getUserById] content-type: application/json
15:27:16.585 [ForkJoinPool-1-worker-117] DEBUG feign.Logger - [UserEndpoint#getUserById] date: Thu, 05 May 2022 08:27:16 GMT
15:27:16.585 [ForkJoinPool-1-worker-117] DEBUG feign.Logger - [UserEndpoint#getUserById]
Ishtere a way to output like that:
GET https://myhost/api/users/eac92ab2-682b-45d9-8aa2-435f933b2661
Authorization: mytoken
E.g. one request - one piece of output in one place (not line by header)
Ideally there request and response should be output tohether, idealy in single line with escaped line breaks
Isit possible with feign?
I want to use CloseableHttpAsyncClient to send a http request in Async mode. But the request is not send out. When enable comment HttpResponse response = future.get(). It works. But I'd like to know why I need future.get() even I didn't care about the response.
Code is here
public class CloseableHttpAsyncClientTest {
#Test
public void whenUseHttpAsyncClient_thenCorrect() throws Exception {
CloseableHttpAsyncClient client = HttpAsyncClients.createDefault();
client.start();
HttpDelete request = new HttpDelete("http://www.bing.com");
Future<HttpResponse> future = client.execute(request, null);
// The delete request will send out if we remove comment here. We just want to send out delete http
// request but not care about the response
// HttpResponse response = future.get();
client.close();
}
}
The console like this
20:28:48.930 [main] DEBUG org.apache.http.impl.nio.client.MainClientExec - [exchange: 1] start execution
20:28:48.941 [main] DEBUG org.apache.http.client.protocol.RequestAddCookies - CookieSpec selected: default
20:28:48.950 [main] DEBUG org.apache.http.client.protocol.RequestAuthCache - Auth cache not set in the context
20:28:48.951 [main] DEBUG org.apache.http.impl.nio.client.InternalHttpAsyncClient - [exchange: 1] Request connection for {}->http://www.bing.com:80
20:28:48.953 [main] DEBUG org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager - Connection request: [route: {}->http://www.bing.com:80][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]
20:28:48.976 [main] DEBUG org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager - Connection manager is shutting down
20:28:49.003 [main] DEBUG org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager - Connection manager shut down
After I enable the comments. Like this. It works.
public class CloseableHttpAsyncClientTest {
#Test
public void whenUseHttpAsyncClient_thenCorrect() throws Exception {
CloseableHttpAsyncClient client = HttpAsyncClients.createDefault();
client.start();
HttpDelete request = new HttpDelete("http://www.bing.com");
Future<HttpResponse> future = client.execute(request, null);
// The delete request will send out if we remove comment here. We just want to send out delete http
// request but not care about the response
HttpResponse response = future.get();
client.close();
}
}
From the log, we can see. The http delete has been send out.
20:39:15.998 [main] DEBUG org.apache.http.impl.nio.client.MainClientExec - [exchange: 1] start execution
......
......
20:39:16.137 [I/O dispatcher 1] DEBUG org.apache.http.headers - http-outgoing-0 >> DELETE / HTTP/1.1
20:39:16.137 [I/O dispatcher 1] DEBUG org.apache.http.headers - http-outgoing-0 >> Host: www.bing.com
......
......
20:39:16.142 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 >> "DELETE / HTTP/1.1[\r][\n]"
20:39:16.142 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Host: www.bing.com[\r][\n]"
20:39:16.142 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
20:39:16.142 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 >> "User-Agent: Apache-HttpAsyncClient/4.1.4 (Java/1.8.0_202)[\r][\n]"
20:39:16.143 [I/O dispatcher 1] DEBUG org.apache.http.wire - http-outgoing-0 >> "[\r][\n]"
20:39:16.143 [I/O dispatcher 1] DEBUG org.apache.http.impl.nio.client.InternalIODispatch - http-outgoing-0 [ACTIVE] Request ready
20:39:16.143 [I/O dispatcher 1] DEBUG
......
20:39:16.209 [main] DEBUG org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager - Connection manager shut down
Future<HttpResponse> future = client.execute(request, null);
client.execute will send out http request in Async way. It will take another thread to complete the http request.
HttpResponse response = future.get();
future.get() will block the main thread until client.execute complete and fill the response into future. Without this, the client will be close before http request send out. Cos http request send out by one thread, but client close be closed by main thread. So, main thread need be blocked until future.get() get the result by another thread.
In short: I want to test some http proxies. I have run into a single proxy that seems to be unresponsive, however HttpClient is does not timeout like it should. Stacktrace shows that app is blocked on read method. It should timeout IMHO but it is not. In general code is tested and works fine in plenty of other cases (including timeouts, exceptions etc.)
How I configure my request (yes, I use those on request execution):
requestConfig = RequestConfig.custom()
.setSocketTimeout(2000)
.setConnectionRequestTimeout(1000)
.setConnectTimeout(5000);
RequestConfig config = requestConfig.setProxy(proxyHost).build();
context.setRequestConfig(config);
What HttpClient is doing - request is sent but no response:
09:55:06.719 [ProxyPool-ScheduledWorkers-pool-3-thread-1] DEBUG o.a.h.c.protocol.RequestAddCookies - CookieSpec selected: default
09:55:06.720 [ProxyPool-ScheduledWorkers-pool-3-thread-1] DEBUG o.a.h.c.protocol.RequestAuthCache - Auth cache not set in the context
09:55:06.721 [ProxyPool-ScheduledWorkers-pool-3-thread-1] DEBUG o.a.h.i.c.PoolingHttpClientConnectionManager - Connection request: [route: {tls}->http://84.28.86.73:80->https://api.ipify.org:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]
09:55:06.722 [ProxyPool-ScheduledWorkers-pool-3-thread-1] DEBUG o.a.h.i.c.PoolingHttpClientConnectionManager - Connection leased: [id: 19][route: {tls}->http://84.28.86.73:80->https://api.ipify.org:443][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 20]
09:55:06.723 [ProxyPool-ScheduledWorkers-pool-3-thread-1] DEBUG o.a.h.impl.execchain.MainClientExec - Opening connection {tls}->http://84.28.86.73:80->https://api.ipify.org:443
09:55:06.723 [ProxyPool-ScheduledWorkers-pool-3-thread-1] DEBUG o.a.h.i.c.DefaultHttpClientConnectionOperator - Connecting to /84.28.86.73:80
09:55:06.786 [ProxyPool-ScheduledWorkers-pool-3-thread-1] DEBUG o.a.h.i.c.DefaultHttpClientConnectionOperator - Connection established 192.168.2.144:31914<->84.28.86.73:80
09:55:06.787 [ProxyPool-ScheduledWorkers-pool-3-thread-1] DEBUG org.apache.http.headers - http-outgoing-19 >> CONNECT api.ipify.org:443 HTTP/1.1
09:55:06.787 [ProxyPool-ScheduledWorkers-pool-3-thread-1] DEBUG org.apache.http.headers - http-outgoing-19 >> Host: api.ipify.org
09:55:06.788 [ProxyPool-ScheduledWorkers-pool-3-thread-1] DEBUG org.apache.http.headers - http-outgoing-19 >> User-Agent: Apache-HttpClient/4.5.2 (Java/1.8.0_66)
09:55:06.788 [ProxyPool-ScheduledWorkers-pool-3-thread-1] DEBUG org.apache.http.wire - http-outgoing-19 >> "CONNECT api.ipify.org:443 HTTP/1.1[\r][\n]"
09:55:06.788 [ProxyPool-ScheduledWorkers-pool-3-thread-1] DEBUG org.apache.http.wire - http-outgoing-19 >> "Host: api.ipify.org[\r][\n]"
09:55:06.789 [ProxyPool-ScheduledWorkers-pool-3-thread-1] DEBUG org.apache.http.wire - http-outgoing-19 >> "User-Agent: Apache-HttpClient/4.5.2 (Java/1.8.0_66)[\r][\n]"
09:55:06.789 [ProxyPool-ScheduledWorkers-pool-3-thread-1] DEBUG org.apache.http.wire - http-outgoing-19 >> "[\r][\n]"
Here is the stackrace where connection is blocked
Thread [ProxyPool-ScheduledWorkers-pool-3-thread-1] (Suspended)
SocketInputStream.socketRead0(FileDescriptor, byte[], int, int, int) line: not available [native method]
SocketInputStream.socketRead(FileDescriptor, byte[], int, int, int) line: not available
SocketInputStream.read(byte[], int, int, int) line: not available
SocketInputStream.read(byte[], int, int) line: not available
LoggingInputStream.read(byte[], int, int) line: 87
SessionInputBufferImpl.streamRead(byte[], int, int) line: 139
SessionInputBufferImpl.fillBuffer() line: 155
SessionInputBufferImpl.readLine(CharArrayBuffer) line: 284
DefaultHttpResponseParser.parseHead(SessionInputBuffer) line: 140
DefaultHttpResponseParser.parseHead(SessionInputBuffer) line: 57
DefaultHttpResponseParser(AbstractMessageParser<T>).parse() line: 261
LoggingManagedHttpClientConnection(DefaultBHttpClientConnection).receiveResponseHeader() line: 165
CPoolProxy.receiveResponseHeader() line: 167
HttpRequestExecutor.doReceiveResponse(HttpRequest, HttpClientConnection, HttpContext) line: 272
HttpRequestExecutor.execute(HttpRequest, HttpClientConnection, HttpContext) line: 124
MainClientExec.createTunnelToTarget(AuthState, HttpClientConnection, HttpRoute, HttpRequest, HttpClientContext) line: 472
MainClientExec.establishRoute(AuthState, HttpClientConnection, HttpRoute, HttpRequest, HttpClientContext) line: 397
MainClientExec.execute(HttpRoute, HttpRequestWrapper, HttpClientContext, HttpExecutionAware) line: 236
ProtocolExec.execute(HttpRoute, HttpRequestWrapper, HttpClientContext, HttpExecutionAware) line: 184
RedirectExec.execute(HttpRoute, HttpRequestWrapper, HttpClientContext, HttpExecutionAware) line: 110
InternalHttpClient.doExecute(HttpHost, HttpRequest, HttpContext) line: 184
InternalHttpClient(CloseableHttpClient).execute(HttpUriRequest, HttpContext) line: 82
InternalHttpClient(CloseableHttpClient).execute(HttpUriRequest, HttpContext) line: 55
Ipify.getExternalIp(HttpClient, RequestConfig, HttpContext) line: 48
Ipify.getExternalIp(HttpClient, HttpContext) line: 33
<obsolete method in<unknown declaring type>>
ProxyTester.isHttpsProxyValidQuiet(HttpsProxyHost) line: 105
FetchProxiesFromSourceTask.run() line: 72
Executors$RunnableAdapter<T>.call() line: not available
ScheduledThreadPoolExecutor$ScheduledFutureTask<V>(FutureTask<V>).runAndReset() line: not available
ScheduledThreadPoolExecutor$ScheduledFutureTask<V>.access$301(ScheduledThreadPoolExecutor$ScheduledFutureTask) line: not available
ScheduledThreadPoolExecutor$ScheduledFutureTask<V>.run() line: not available
ScheduledThreadPoolExecutor(ThreadPoolExecutor).runWorker(ThreadPoolExecutor$Worker) line: not available
ThreadPoolExecutor$Worker.run() line: not available
Thread.run() line: not available
EDIT: Honorable mention:
setting socket timeout in both RequestConfig and SocketConfig works differently for HTTP and HTTPS
Looks like a design flaw to me as there is no way to set soTimeout prior SSL handshake on request basis.
And reported bug here: https://issues.apache.org/jira/browse/HTTPCLIENT-1478
My AWS Java Client is throwing
javax.net.ssl.SSLException: Connection has been shutdown: javax.net.ssl.SSLException: java.net.SocketException: Connection reset
at sun.security.ssl.SSLSocketImpl.checkEOF(SSLSocketImpl.java:1541) ~[na:1.8.0_60]
at sun.security.ssl.SSLSocketImpl.checkWrite(SSLSocketImpl.java:1553) ~[na:1.8.0_60]
at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:71) ~[na:1.8.0_60]
at org.apache.http.impl.io.AbstractSessionOutputBuffer.flushBuffer(AbstractSessionOutputBuffer.java:159) ~[httpcore-4.3.3.jar:4.3.3]
My code is
public void save(String name, byte[] file) {
ObjectMetadata metaData = new ObjectMetadata();
String streamMD5 = new String(Base64.encodeBase64(file));
metaData.setContentMD5(streamMD5);
metaData.setContentLength(file.length);
InputStream stream = new ByteArrayInputStream(file);
try {
PutObjectRequest put = new PutObjectRequest(
configuration.getBucketName(), name, stream, metaData);
s3client.putObject(put);
} finally {
IOUtils.closeQuietly(stream);
}
}
The s3client is a spring bean and is not garbage collected before the stream has finished uploading. I've tried without specifying MD5 and/or content length but still has the same exception thrown.
Logging through AWS library shows:
10:09:15.540 [http-nio-8080-exec-1] DEBUG o.a.h.c.protocol.RequestAddCookies - CookieSpec selected: best-match
10:09:15.540 [http-nio-8080-exec-1] DEBUG o.a.h.c.protocol.RequestAuthCache - Auth cache not set in the context
10:09:15.540 [http-nio-8080-exec-1] DEBUG o.a.h.c.p.RequestProxyAuthentication - Proxy auth state: UNCHALLENGED
10:09:15.540 [http-nio-8080-exec-1] DEBUG c.a.http.impl.client.SdkHttpClient - Attempt 1 to execute request
10:09:15.540 [http-nio-8080-exec-1] DEBUG o.a.h.i.conn.DefaultClientConnection - Sending request: PUT /documeent.pdf HTTP/1.1
10:09:15.540 [http-nio-8080-exec-1] DEBUG org.apache.http.wire - >> "PUT /document.pdf HTTP/1.1[\r][\n]"
10:09:15.540 [http-nio-8080-exec-1] DEBUG org.apache.http.wire - >> "Host: bucket.s3.amazonaws.com[\r][\n]"
10:09:15.540 [http-nio-8080-exec-1] DEBUG org.apache.http.wire - >> "Authorization: AWS 123445667788=[\r][\n]"
10:09:15.540 [http-nio-8080-exec-1] DEBUG org.apache.http.wire - >> "User-Agent: aws-sdk-java/1.10.21 Linux/3.13.0-65-generic Java_HotSpot(TM)_Server_VM/25.60-b23/1.8.0_60[\r][\n]"
10:09:15.540 [http-nio-8080-exec-1] DEBUG org.apache.http.wire - >> "Date: Tue, 06 Oct 2015 09:09:15 GMT[\r][\n]"
10:09:15.663 [http-nio-8080-exec-1] DEBUG com.amazonaws.internal.SdkSSLSocket - closing bucket.s3.amazonaws.com/12.34.56.78:443
10:09:15.665 [http-nio-8080-exec-1] DEBUG o.a.h.i.conn.DefaultClientConnection - I/O error closing connection
I've checked that the file size (3.2M) does not exceed the max file siez for this bucket.
Get/List requests work fine and I can copy files into the S3 bucket using the s3 client tools.
Does anyone know of anything else I should check?
Thanks.
I have configured a project with Log4j. I have configured log4j using log4.properties file.
While the test runs it creates the myLog.log file but nothing is written to the log file.
Appender we are using as RollingFileAppender and log4j.rootLogger=DEBUG.
Can any one suggest what might be causing this problem?
Here is log4j.properties for the project.
log4j.rootLogger= DEBUG, ConsoleAppender, Rolling
log4j.appender.ConsoleAppender=org.apache.log4j.ConsoleAppender
log4j.appender.ConsoleAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.ConsoleAppender.layout.ConversionPattern=%d %-2p %c.%M(): %m%n
log4j.appender.Rolling=org.apache.log4j.RollingFileAppender
log4j.appender.Rolling.MaxFileSize=5MB
log4j.appender.Rolling.MaxBackupIndex=2
log4j.appender.Rolling.File=D:\Logs\myProj.log
log4j.appender.Rolling.layout = org.apache.log4j.PatternLayout
log4j.appender.Rolling.layout.ConversionPattern=%d %-4p %c.%M(): %m%n
## Following two lines have been removed now.
log4j.logger.com=WARN
log4j.logger.org=WARN
Received Log in the log file :
2012-01-16 22:02:08,534 DEBUG org.apache.http.headers.receiveResponseHeader(): << content-type: application/json; charset=UTF-8
2012-01-16 22:02:08,534 DEBUG org.apache.http.headers.receiveResponseHeader(): << connection: close
2012-01-16 22:02:08,534 DEBUG org.apache.http.headers.receiveResponseHeader(): << content-length: 236
2012-01-16 22:02:08,550 DEBUG org.apache.http.headers.receiveResponseHeader(): << server: httpd.js
2012-01-16 22:02:08,550 DEBUG org.apache.http.headers.receiveResponseHeader(): << date: Tue, 17 Jan 2012 03:02:06 GMT
2012-01-16 22:02:08,566 DEBUG org.apache.http.wire.wire(): << "{"name":"clickElement","sessionId":"2fad55cf-670e-44f3-ab60-7d2f76f641e6","status":0,"value":"This action is final and cannot be undone?"}"
2012-01-16 22:02:08,566 DEBUG org.apache.http.impl.conn.DefaultClientConnection.shutdown(): Connection shut down
2012-01-16 22:02:08,566 DEBUG org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager.releaseConnection(): Released connection is not reusable.
2012-01-16 22:02:08,566 DEBUG org.apache.http.impl.conn.tsccm.ConnPoolByRoute.freeEntry(): Releasing connection [HttpRoute[{}->http://127.0.0.1:7055]][null]
2012-01-16 22:02:08,566 DEBUG org.apache.http.impl.conn.tsccm.ConnPoolByRoute.notifyWaitingThread(): Notifying no-one, there are no waiting threads
2012-01-16 22:02:10,566 DEBUG org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager.getConnection(): Get connection: HttpRoute[{}->http://127.0.0.1:7055], timeout = 120000
2012-01-16 22:02:10,566 DEBUG org.apache.http.impl.conn.tsccm.ConnPoolByRoute.getEntryBlocking(): [HttpRoute[{}->http://127.0.0.1:7055]] total kept alive: 0, total issued: 0, total allocated: 0 out of 2000
2012-01-16 22:02:10,566 DEBUG org.apache.http.impl.conn.tsccm.ConnPoolByRoute.getFreeEntry(): No free connections [HttpRoute[{}->http://127.0.0.1:7055]][null]
2012-01-16 22:02:10,566 DEBUG org.apache.http.impl.conn.tsccm.ConnPoolByRoute.getEntryBlocking(): Available capacity: 2000 out of 2000 [HttpRoute[{}->http://127.0.0.1:7055]][null]
2012-01-16 22:02:10,581 DEBUG org.apache.http.impl.conn.tsccm.ConnPoolByRoute.createEntry(): Creating new connection [HttpRoute[{}->http://127.0.0.1:7055]]
2012-01-16 22:02:10,597 DEBUG org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(): Connecting to 127.0.0.1:7055
2012-01-16 22:02:10,597 DEBUG org.apache.http.client.protocol.RequestAddCookies.process(): CookieSpec selected: best-match
2012-01-16 22:02:10,597 DEBUG org.apache.http.client.protocol.RequestAuthCache.process(): Auth cache not set in the context
2012-01-16 22:02:10,597 DEBUG org.apache.http.impl.client.DefaultHttpClient.tryExecute(): Attempt 1 to execute request
2012-01-16 22:02:10,597 DEBUG org.apache.http.impl.conn.DefaultClientConnection.sendRequestHeader(): Sending request: GET /hub/session/2fad55cf-670e-44f3-ab60-7d2f76f641e6/alert_text HTTP/1.1
2012-01-16 22:02:10,597 DEBUG org.apache.http.wire.wire(): >> "GET /hub/session/2fad55cf-670e-44f3-ab60-7d2f76f641e6/alert_text HTTP/1.1[\r][\n]"
2012-01-16 22:02:10,597 DEBUG org.apache.http.wire.wire(): >> "Accept: application/json, image/png[\r][\n]"
2012-01-16 22:02:10,597 DEBUG org.apache.http.wire.wire(): >> "Host: 127.0.0.1:7055[\r][\n]"
2012-01-16 22:02:10,597 DEBUG org.apache.http.wire.wire(): >> "Connection: Keep-Alive[\r][\n]"
2012-01-16 22:02:10,597 DEBUG org.apache.http.wire.wire(): >> "[\r][\n]"
2012-01-16 22:02:10,597 DEBUG org.apache.http.headers.sendRequestHeader(): >> GET /hub/session/2fad55cf-670e-44f3-ab60-7d2f76f641e6/alert_text HTTP/1.1
2012-01-16 22:02:10,597 DEBUG org.apache.http.headers.sendRequestHeader(): >> Accept: application/json, image/png
2012-01-16 22:02:10,597 DEBUG org.apache.http.headers.sendRequestHeader(): >> Host: 127.0.0.1:7055
2012-01-16 22:02:10,597 DEBUG org.apache.http.headers.sendRequestHeader(): >> Connection: Keep-Alive
2012-01-16 22:02:10,612 DEBUG org.apache.http.wire.wire(): << "HTTP/1.1 200 OK[\r][\n]"
2012-01-16 22:02:10,612 DEBUG org.apache.http.wire.wire(): << "content-type: application/json; charset=UTF-8[\r][\n]"
2012-01-16 22:02:10,612 DEBUG org.apache.http.wire.wire(): << "connection: close[\r][\n]"
2012-01-16 22:02:10,612 DEBUG org.apache.http.wire.wire(): << "content-length: 236[\r][\n]"
2012-01-16 22:02:10,612 DEBUG org.apache.http.wire.wire(): << "server: httpd.js[\r][\n]"
2012-01-16 22:02:10,612 DEBUG org.apache.http.wire.wire(): << "date: Tue, 17 Jan 2012 03:02:10 GMT[\r][\n]"
2012-01-16 22:02:10,612 DEBUG org.apache.http.wire.wire(): << "[\r][\n]"
2012-01-16 22:02:10,612 DEBUG org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(): Receiving response: HTTP/1.1 200 OK
First of all, make sure your log4j.properties is loaded in classpath. I assume that the file can also be found inside the WEB-INF/classes directory if it is a webapp. But because you say that the file is getting created, I think that is not a problem.
So, try with this
log4j.rootLogger= DEBUG, Console, Rolling
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d %-2p %c.%M(): %m%n
log4j.appender.Rolling=org.apache.log4j.RollingFileAppender
log4j.appender.Rolling.MaxFileSize=5MB
log4j.appender.Rolling.MaxBackupIndex=2
log4j.appender.Rolling.File=D:\Logs\myProj.log
log4j.appender.Rolling.layout = org.apache.log4j.PatternLayout
log4j.appender.Rolling.layout.ConversionPattern=%d %-4p %c.%M(): %m%n
Note that I have removed the last two lines.
Basically, those lines set the log level to WARN to all packages starting with com and org. So, unless you have any WARN messages being logged, you won't see anything at all on the log files.
You can experiment with levels by doing something like
log4j.logger.com.foo.bar=DEBUG
log4j.logger.com.foo.bar.MyClass=TRACE
The above will print log all com.foo.bar logs in DEBUG whereas will print com.foo.bar.MyClass logs in the TRACE level.
Or more detailed: No logging-request from com or org-packages with log-level < WARN will be enabled. So it wont be forwarded to your rootLogger.
Quote:
A log request of level p in a logger with (either assigned or inherited, whichever is
appropriate) level q, is enabled if p >= q.
and
Each enabled logging request for a given logger will be forwarded to all the appenders in
that logger as well as the appenders higher in the hierarchy.
See: http://logging.apache.org/log4j/1.2/manual.html