I've got a Jax-RS server which is supposed to keep a list of files accessible via ssh that I can then download or stream via HTTP.
I've been trying to read the files with JSch's SFTP channel, but I keep receiving a NullPointerException.
Here's the MessageBodyWriter I wrote:
#Provider
#Produces("video/*")
public class MediaBodyWriter implements MessageBodyWriter<MediaFile> {
#Override
public long getSize(MediaFile mFile, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4) {
return mFile.getFileSize();
}
#Override
public boolean isWriteable(Class<?> type, Type arg1, Annotation[] arg2, MediaType arg3) {
return type.equals(MediaFile.class);
}
#Override
public void writeTo(MediaFile mFile,
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
OutputStream entityStream) throws IOException, WebApplicationException {
mFile.streamFile(entityStream); //line 41
}
}
Here's MediaFile class minus the getters and setters:
#Entity
#XmlRootElement
public class MediaFile {
#Id
#GeneratedValue
Long id;
#JsonIgnore
#ManyToOne(cascade=CascadeType.ALL)
#PrimaryKeyJoinColumn
MediaRepo repo;
String filePath;
String fileName;
transient JSch jsch;
transient Session session;
transient ChannelSftp sftp;
public MediaFile(){}
public void prepForDownload(){
if(sftp != null)
return;
try{
jsch = new JSch();
session = jsch.getSession(repo.getUsername(), repo.getHost(), repo.getPort());
session.setPassword(repo.getPassword());
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
sftp = (ChannelSftp)session.openChannel("sftp");
}catch(Exception e){
e.printStackTrace();
}
}
public long getFileSize(){
prepForDownload();
try {
return sftp.lstat(getCompletePath()).getSize();
} catch (SftpException e) {
e.printStackTrace();
}
return 0;
}
private String getCompletePath(){
return repo.getBasePath()+filePath+fileName;
}
public void streamFile(OutputStream output){
prepForDownload();
try {
sftp.get(getCompletePath(), output);
} catch (SftpException e) {
e.printStackTrace();
}
}
}
And here's the error I'm receiving:
13:50:05,260 ERROR [stderr] (default task-5) 4:
13:50:05,260 ERROR [stderr] (default task-5) at com.jcraft.jsch.ChannelSftp.get(ChannelSftp.java:1011)
13:50:05,260 ERROR [stderr] (default task-5) at com.jcraft.jsch.ChannelSftp.get(ChannelSftp.java:984)
13:50:05,261 ERROR [stderr] (default task-5) at model.MediaFile.streamFile(MediaFile.java:75)
13:50:05,261 ERROR [stderr] (default task-5) at MediaBodyWriter.writeTo(MediaBodyWriter.java:41)
13:50:05,261 ERROR [stderr] (default task-5) at MediaBodyWriter.writeTo(MediaBodyWriter.java:1)
13:50:05,261 ERROR [stderr] (default task-5) at MediaBodyWriter$Proxy$_$$_WeldClientProxy.writeTo(Unknown Source)
13:50:05,261 ERROR [stderr] (default task-5) at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.writeTo(AbstractWriterInterceptorContext.java:131)
13:50:05,261 ERROR [stderr] (default task-5) at org.jboss.resteasy.core.interception.ServerWriterInterceptorContext.writeTo(ServerWriterInterceptorContext.java:60)
13:50:05,262 ERROR [stderr] (default task-5) at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:120)
13:50:05,262 ERROR [stderr] (default task-5) at org.jboss.resteasy.security.doseta.DigitalSigningInterceptor.aroundWriteTo(DigitalSigningInterceptor.java:145)
13:50:05,262 ERROR [stderr] (default task-5) at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:124)
13:50:05,262 ERROR [stderr] (default task-5) at org.jboss.resteasy.plugins.interceptors.encoding.GZIPEncodingInterceptor.aroundWriteTo(GZIPEncodingInterceptor.java:100)
13:50:05,262 ERROR [stderr] (default task-5) at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:124)
13:50:05,262 ERROR [stderr] (default task-5) at org.jboss.resteasy.core.ServerResponseWriter.writeNomapResponse(ServerResponseWriter.java:98)
13:50:05,262 ERROR [stderr] (default task-5) at org.jboss.resteasy.core.SynchronousDispatcher.writeResponse(SynchronousDispatcher.java:466)
13:50:05,263 ERROR [stderr] (default task-5) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:415)
13:50:05,263 ERROR [stderr] (default task-5) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:202)
13:50:05,263 ERROR [stderr] (default task-5) at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:221)
13:50:05,263 ERROR [stderr] (default task-5) at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
13:50:05,263 ERROR [stderr] (default task-5) at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
13:50:05,263 ERROR [stderr] (default task-5) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
13:50:05,263 ERROR [stderr] (default task-5) at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
13:50:05,263 ERROR [stderr] (default task-5) at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
13:50:05,264 ERROR [stderr] (default task-5) at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
13:50:05,264 ERROR [stderr] (default task-5) at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
13:50:05,264 ERROR [stderr] (default task-5) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
13:50:05,264 ERROR [stderr] (default task-5) at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
13:50:05,264 ERROR [stderr] (default task-5) at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
13:50:05,264 ERROR [stderr] (default task-5) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
13:50:05,265 ERROR [stderr] (default task-5) at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
13:50:05,265 ERROR [stderr] (default task-5) at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
13:50:05,265 ERROR [stderr] (default task-5) at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
13:50:05,265 ERROR [stderr] (default task-5) at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
13:50:05,265 ERROR [stderr] (default task-5) at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
13:50:05,266 ERROR [stderr] (default task-5) at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
13:50:05,266 ERROR [stderr] (default task-5) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
13:50:05,266 ERROR [stderr] (default task-5) at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
13:50:05,266 ERROR [stderr] (default task-5) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
13:50:05,266 ERROR [stderr] (default task-5) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
13:50:05,266 ERROR [stderr] (default task-5) at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:284)
13:50:05,267 ERROR [stderr] (default task-5) at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:263)
13:50:05,267 ERROR [stderr] (default task-5) at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
13:50:05,267 ERROR [stderr] (default task-5) at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:174)
13:50:05,267 ERROR [stderr] (default task-5) at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
13:50:05,267 ERROR [stderr] (default task-5) at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:793)
13:50:05,267 ERROR [stderr] (default task-5) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
13:50:05,268 ERROR [stderr] (default task-5) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
13:50:05,268 ERROR [stderr] (default task-5) at java.lang.Thread.run(Thread.java:745)
13:50:05,268 ERROR [stderr] (default task-5) Caused by: java.lang.NullPointerException
13:50:05,268 ERROR [stderr] (default task-5) at com.jcraft.jsch.ChannelSftp.get(ChannelSftp.java:994)
13:50:05,269 ERROR [stderr] (default task-5) ... 47 more
You have to call the .connect() on the ChannelSftp, before you can use it, as all JSch SFTP examples show.
For example, see the official JSch SFTP example:
Channel channel=session.openChannel("sftp");
channel.connect();
ChannelSftp c=(ChannelSftp)channel;
Related
I'm using Java11 and httpclient 4.5.11 to make request to APIs, and so far everything works. But more than a week ago payments to https://api.moip.com.br started giving intermitent errors (Connection reset).
I know that they require TLSv1.2 and Java11 supports it, furthermore the errors are intermitent (somethimes it works, sometimes it doesn't). I contacted them and they said that they made a migration of their codebase, but that their configuration to process requests is the same, which I doubt, but in any case, considering that they process payments of several organizations, I assume that there is something that I can do to avoid these errors. As a side note, I can make requests without problems to PayPal, Stripe, Google Recaptcha, among other services.
How I create a connection:
try (CloseableHttpClient httpClient = createHttpClientBuilder().build()) {
HttpUriRequest httpMethod = createHttpUriRequest(request);
HttpResponse httpResponse = httpClient.execute(httpMethod);
SimpleHttpClientResponse response = createResponse(httpResponse);
return response;
} catch (Exception e) {
throw new HTTPException(request, e);
}
And the following are how I create the connection manager, the client builder and the request itself:
private static HttpClientBuilder createHttpClientBuilder() throws KeyManagementException, NoSuchAlgorithmException {
CookieStore httpCookieStore = new BasicCookieStore();
RequestConfig defaultRequestConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES).build();
HttpClientBuilder builder = HttpClients.custom()
.setConnectionManager(connectionManager)
.setConnectionManagerShared(true)
.setDefaultCookieStore(httpCookieStore)
.setDefaultRequestConfig(defaultRequestConfig);
return builder;
}
private static PoolingHttpClientConnectionManager createConnectionManager() {
try {
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
SSLContext.getDefault(),
new String[] {"TLSv1.2"},
null,
SSLConnectionSocketFactory.getDefaultHostnameVerifier());
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.INSTANCE)
.register("https", socketFactory)
.build();
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(registry);
cm.setMaxTotal(200);
cm.setDefaultMaxPerRoute(20);
return cm;
} catch (NoSuchAlgorithmException | RuntimeException e) {
LogUtils.error(e);
return null;
}
}
private static HttpUriRequest createHttpUriRequest(SimpleHttpClientRequest request) throws ParseException, IOException, URISyntaxException {
HttpUriRequest httpUriRequest;
if (request.getMethod().equals(HTTPMethod.POST)) {
HttpPost httpPost = new HttpPost(request.getUrl());
HttpEntity entity = createEntity(request);
httpPost.setEntity(entity);
httpUriRequest = httpPost;
} else if (request.getMethod().equals(HTTPMethod.HEAD)) {
httpUriRequest = new HttpHead(getUrlWithParameters(request));
} else if (request.getMethod().equals(HTTPMethod.DELETE)) {
httpUriRequest = new HttpDelete(getUrlWithParameters(request));
} else {
httpUriRequest = new HttpGet(getUrlWithParameters(request));
}
Map<String, String> headers = request.getHeaders();
if (headers != null) {
for (String key : headers.keySet()) {
String value = headers.get(key);
httpUriRequest.setHeader(key, value);
}
}
return httpUriRequest;
}
The SimpleHttpClientRequest is just a class of mine that defines the uri, headers, and other data to be used when making the request, but the request itself is done by apache HttpClient.
Like, I said, the errors are intermitent, if I try to make the same request several times it works.
I defined -Djavax.net.debug=all to know what could be the case, and the logs are like the following:
Obs: I've removed lines like ERROR [stderr] (default task-2) 0000: D2 A3 F4 C9 87 BF 23 89 65 F7 50 B6 90 8C 9D 8B ......#.e.P..... because I don't think they add anything usefult in this case
When I receive the error:
10:03:16,752 ERROR [stderr] (default task-2) javax.net.ssl|DEBUG|DC|default task-2|2020-06-23
10:03:16.750 GMT-03:00|SSLSocketInputRecord.java:249|READ: TLSv1.1 application_data, length = 2160
10:03:16,756 ERROR [stderr] (default task-2) javax.net.ssl|DEBUG|DC|default task-2|2020-06-23 10:03:16.755 GMT-03:00|SSLCipher.java:1329|Padded plaintext after DECRYPTION (
10:03:16,775 ERROR [stderr] (default task-2) )
10:03:16,793 ERROR [stderr] (default task-2) javax.net.ssl|WARNING|DC|default task-2|2020-06-23 10:03:16.792 GMT-03:00|SSLSocketImpl.java:1280|handling exception (
10:03:16,793 ERROR [stderr] (default task-2) "throwable" : {
10:03:16,793 ERROR [stderr] (default task-2) java.net.SocketTimeoutException: Read timed out
10:03:16,793 ERROR [stderr] (default task-2) at java.base/java.net.SocketInputStream.socketRead0(Native Method)
10:03:16,794 ERROR [stderr] (default task-2) at java.base/java.net.SocketInputStream.socketRead(SocketInputStream.java:115)
10:03:16,794 ERROR [stderr] (default task-2) at java.base/java.net.SocketInputStream.read(SocketInputStream.java:168)
10:03:16,802 ERROR [stderr] (default task-2) at java.base/java.net.SocketInputStream.read(SocketInputStream.java:140)
...
10:03:16,812 ERROR [stderr] (default task-2) at java.base/java.lang.Thread.run(Thread.java:834)}
10:03:16,812 ERROR [stderr] (default task-2)
10:03:16,813 ERROR [stderr] (default task-2) )
10:03:16,820 ERROR [stderr] (default task-2) javax.net.ssl|DEBUG|DC|default task-2|2020-06-23 10:03:16.813 GMT-03:00|SSLSocketOutputRecord.java:309|WRITE: TLS12 application_data, length = 329
10:03:16,821 ERROR [stderr] (default task-2) javax.net.ssl|DEBUG|DC|default task-2|2020-06-23 10:03:16.821 GMT-03:00|SSLCipher.java:1743|Plaintext before ENCRYPTION (
10:03:16,827 ERROR [stderr] (default task-2) )
10:03:16,828 ERROR [stderr] (default task-2) javax.net.ssl|DEBUG|DC|default task-2|2020-06-23 10:03:16.827 GMT-03:00|SSLSocketOutputRecord.java:323|Raw write (
10:03:16,829 ERROR [stderr] (default task-2) )
10:03:16,990 ERROR [stderr] (default task-2) javax.net.ssl|WARNING|DC|default task-2|2020-06-23 10:03:16.989 GMT-03:00|SSLSocketImpl.java:1280|handling exception (
10:03:16,990 ERROR [stderr] (default task-2) "throwable" : {
10:03:16,991 ERROR [stderr] (default task-2) java.net.SocketException: Connection reset
10:03:16,991 ERROR [stderr] (default task-2) at java.base/java.net.SocketInputStream.read(SocketInputStream.java:186)
10:03:16,991 ERROR [stderr] (default task-2) at java.base/java.net.SocketInputStream.read(SocketInputStream.java:140)
...
10:03:17,022 ERROR [stderr] (default task-2) at java.base/java.lang.Thread.run(Thread.java:834)}
10:03:17,022 ERROR [stderr] (default task-2)
10:03:17,022 ERROR [stderr] (default task-2) )
10:03:17,025 ERROR [stderr] (default task-2) javax.net.ssl|ERROR|DC|default task-2|2020-06-23 10:03:17.024 GMT-03:00|TransportContext.java:318|Fatal (UNEXPECTED_MESSAGE): Connection reset (
10:03:17,025 ERROR [stderr] (default task-2) "throwable" : {
10:03:17,025 ERROR [stderr] (default task-2) java.net.SocketException: Connection reset
10:03:17,026 ERROR [stderr] (default task-2) at java.base/java.net.SocketInputStream.read(SocketInputStream.java:186)
10:03:17,026 ERROR [stderr] (default task-2) at java.base/java.net.SocketInputStream.read(SocketInputStream.java:140)
10:03:17,026 ERROR [stderr] (default task-2) at java.base/sun.security.ssl.SSLSocketInputRecord.read(SSLSocketInputRecord.java:448)
...
10:03:17,052 ERROR [stderr] (default task-2) at java.base/java.lang.Thread.run(Thread.java:834)}
10:03:17,052 ERROR [stderr] (default task-2)
10:03:17,052 ERROR [stderr] (default task-2) )
10:03:17,053 ERROR [stderr] (default task-2) javax.net.ssl|ALL|DC|default task-2|2020-06-23 10:03:17.053 GMT-03:00|SSLSessionImpl.java:784|Invalidated session: Session(1592917276199|TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
10:03:17,055 ERROR [stderr] (default task-2) javax.net.ssl|DEBUG|DC|default task-2|2020-06-23 10:03:17.054 GMT-03:00|SSLSocketOutputRecord.java:71|WRITE: TLS12 alert(unexpected_message), length = 10
10:03:17,056 ERROR [stderr] (default task-2) javax.net.ssl|DEBUG|DC|default task-2|2020-06-23 10:03:17.055 GMT-03:00|SSLCipher.java:1743|Plaintext before ENCRYPTION (
10:03:17,056 ERROR [stderr] (default task-2) )
10:03:17,059 ERROR [stderr] (default task-2) javax.net.ssl|WARNING|DC|default task-2|2020-06-23 10:03:17.059 GMT-03:00|TransportContext.java:360|Fatal: failed to send fatal alert UNEXPECTED_MESSAGE (
10:03:17,060 ERROR [stderr] (default task-2) "throwable" : {
10:03:17,060 ERROR [stderr] (default task-2) java.net.SocketException: Broken pipe (Write failed)
10:03:17,060 ERROR [stderr] (default task-2) at java.base/java.net.SocketOutputStream.socketWrite0(Native Method)
10:03:17,061 ERROR [stderr] (default task-2) at java.base/java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:110)
...
10:03:17,076 ERROR [stderr] (default task-2) at java.base/java.lang.Thread.run(Thread.java:834)}
10:03:17,076 ERROR [stderr] (default task-2)
10:03:17,076 ERROR [stderr] (default task-2) )
10:03:17,077 ERROR [stderr] (default task-2) javax.net.ssl|DEBUG|DC|default task-2|2020-06-23 10:03:17.077 GMT-03:00|SSLSocketImpl.java:1353|close the underlying socket
10:03:17,077 ERROR [stderr] (default task-2) javax.net.ssl|DEBUG|DC|default task-2|2020-06-23 10:03:17.077 GMT-03:00|SSLSocketImpl.java:1372|close the SSL connection (initiative)
10:03:17,078 ERROR [stderr] (default task-2) javax.net.ssl|DEBUG|DC|default task-2|2020-06-23 10:03:17.078 GMT-03:00|SSLSocketImpl.java:663|close outbound of SSLSocket
10:03:17,078 ERROR [stderr] (default task-2) javax.net.ssl|DEBUG|DC|default task-2|2020-06-23 10:03:17.078 GMT-03:00|SSLSocketImpl.java:629|close inbound of SSLSocket
10:03:17,079 ERROR [stderr] (default task-2) javax.net.ssl|WARNING|DC|default task-2|2020-06-23 10:03:17.079 GMT-03:00|TransportContext.java:284|Closed transport, general or untracked problem
10:03:17,105 WARN [my.company.util.LogUtils] (default task-2)
at my.deployment//my.company.util.ExceptionUtils.wrap(ExceptionUtils.java:26)
at my.deployment//my.company.util.PagamentoUtil.consultarRespostaHttpPagamento(PagamentoUtil.java:618)
at my.deployment//my.company.controller.admin.verification.VerifyPaymentApiController.doGet(VerifyPaymentApiController.java:61)
... 58 more
Caused by: my.company.exceptions.HTTPException: javax.net.ssl.SSLException: Connection reset - 'GET': 'https://api.moip.com.br/v2/orders/ORD-KC1CSM2SVPMX'
at my.deployment//my.company.util.HttpClientUtils.send(HttpClientUtils.java:63)
at my.deployment//my.company.util.URIUtils.getResponseObjectFromRequest(URIUtils.java:315)
at my.deployment//my.company.util.PagamentoUtil.accessMoipV2(PagamentoUtil.java:2060)
at my.deployment//my.company.util.PagamentoUtil.lambda$consultarRespostaHttpPagamento$0(PagamentoUtil.java:597)
at my.deployment//my.company.util.PagamentoUtil.getResponseResultFromApi(PagamentoUtil.java:806)
at my.deployment//my.company.util.PagamentoUtil.consultarRespostaHttpPagamento(PagamentoUtil.java:597)
... 59 more
Caused by: javax.net.ssl.SSLException: Connection reset
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:127)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:326)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:269)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:264)
at java.base/sun.security.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1306)
at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.read(SSLSocketImpl.java:832)
at my.deployment//org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:137)
at my.deployment//org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:153)
at my.deployment//org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:280)
at my.deployment//org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:138)
at my.deployment//org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:56)
at my.deployment//org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:259)
at my.deployment//org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:163)
at my.deployment//org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:157)
at my.deployment//org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:273)
at my.deployment//org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125)
at my.deployment//org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:272)
at my.deployment//org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)
at my.deployment//org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
at my.deployment//org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at my.deployment//org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
at my.deployment//org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
at my.deployment//org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108)
at my.deployment//my.company.util.HttpClientUtils.send(HttpClientUtils.java:59)
... 64 more
Suppressed: java.net.SocketException: Broken pipe (Write failed)
at java.base/java.net.SocketOutputStream.socketWrite0(Native Method)
at java.base/java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:110)
at java.base/java.net.SocketOutputStream.write(SocketOutputStream.java:150)
at java.base/sun.security.ssl.SSLSocketOutputRecord.encodeAlert(SSLSocketOutputRecord.java:81)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:357)
... 86 more
Caused by: java.net.SocketException: Connection reset
at java.base/java.net.SocketInputStream.read(SocketInputStream.java:186)
at java.base/java.net.SocketInputStream.read(SocketInputStream.java:140)
at java.base/sun.security.ssl.SSLSocketInputRecord.read(SSLSocketInputRecord.java:448)
at java.base/sun.security.ssl.SSLSocketInputRecord.bytesInCompletePacket(SSLSocketInputRecord.java:68)
at java.base/sun.security.ssl.SSLSocketImpl.readApplicationRecord(SSLSocketImpl.java:1096)
at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.read(SSLSocketImpl.java:816)
... 82 more
When it errors, it doesn't reach the part in the successful request that logs:
10:01:13,234 ERROR [stderr] (default task-2) javax.net.ssl|DEBUG|DC|default task-2|2020-06-23 10:01:13.233 GMT-03:00|TrustStoreManager.java:161|Inaccessible trust store: /usr/lib/jvm/java-11-openjdk-11.0.7.10-4.el7_8.x86_64/lib/security/jssecacerts
10:01:13,234 ERROR [stderr] (default task-2) javax.net.ssl|DEBUG|DC|default task-2|2020-06-23 10:01:13.234 GMT-03:00|TrustStoreManager.java:112|trustStore is: /usr/lib/jvm/java-11-openjdk-11.0.7.10-4.el7_8.x86_64/lib/security/cacerts
10:01:13,234 ERROR [stderr] (default task-2) trustStore type is: pkcs12
10:01:13,234 ERROR [stderr] (default task-2) trustStore provider is:
10:01:13,235 ERROR [stderr] (default task-2) the last modified time is: Thu Jun 11 13:31:42 GMT-03:00 2020
10:01:13,553 ERROR [stderr] (default task-2) javax.net.ssl|DEBUG|DC|default task-2|2020-06-23 10:01:13.551 GMT-03:00|X509TrustManagerImpl.java:79|adding as trusted certificates (
10:01:13,554 ERROR [stderr] (default task-2) "certificate" : {
10:01:13,554 ERROR [stderr] (default task-2) "version" : "v3",
I saw the SocketTimeoutException (even tough it happens only 200ms after the request begins) and tried to increase the socket timeout either in the connection manager as well as in the client builder, and also in the request, but it didn't work. I also tried to remove the keepalive and make it so that the connections aren't reused, but it also didn't work. I also looked at other questions here in SO with a similar problem and none worked. The following are the changes I tried:
In the connection manager:
SocketConfig socketConfig = SocketConfig.custom()
.setSoKeepAlive(false)
.setSoTimeout(600000)
.setSoReuseAddress(false)
.build();
cm.setDefaultSocketConfig(socketConfig);
In the client:
RequestConfig requestConfig = RequestConfig.custom()
.setSocketTimeout(15000)
.setConnectTimeout(15000)
.setCookieSpec(CookieSpecs.IGNORE_COOKIES).build();
builder = builder.setDefaultRequestConfig(requestConfig);
builder = builder.setConnectionReuseStrategy((response, context) -> {
LogUtils.info("**** connectionReuse strategy returning false");
return false;
});
builder = builder.setKeepAliveStrategy((response, context) -> {
LogUtils.info("**** keepAlive strategy returning -1");
return -1l;
});
In the request:
RequestConfig requestConfig = RequestConfig.custom()
.setSocketTimeout(15000)
.setConnectTimeout(15000)
.setCookieSpec(CookieSpecs.IGNORE_COOKIES).build();
httpUriRequest.setConfig(requestConfig);
I tried the above together, as well as individually, and none worked.
Something I realized is that I never received the exception right after started the java application when testing locally (could be a coincidence, tough), and when a request works, the following requests work for 1 minute or so, but even when I defined to not reuse connections it continued the same way, with intermittent errors, and working for a time if one request is successful (although maybe that configuration didn't disabled the reuse of connections, but I think it disabled because I saw the logs with connectionReuse strategy returning false), so I ended up out of options.
For now I included them in a while loop that executes at most 4 times (when it errors) to make the request to that specific endpoint work seamlessly to the users, but this is a very hack approach and I would like to fix this problem, if possible.
I hope someone can help me with this.
HEELP!!
I have a problem running the code, it does not execute the Sql statement and I cannot locate the error between the DAO class and the rest service.
I already added the exceptions of SQLException and ClassNotFound in the DAO class but I still cannot locate the error, and I already executed the code in a separate class and if the request of the BD returns, which means that the driver is well configured.
package com.DAO;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
//import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import com.connection.ConexionPSQL;
import com.IDAO.EmployeIDAO;
import com.model.EmployeObject;
public class EmployeDAO implements EmployeIDAO {
#Override
public List<EmployeObject> obtener() {
Connection co = null;
Statement stm = null;
ResultSet rs = null;
String sql = "SELECT * FROM TABLE_EMPLOYES";
List<EmployeObject> listaCliente = new
ArrayList<EmployeObject>();
try {
co = ConexionPSQL.crearConexion();
stm = co.createStatement();
rs = stm.executeQuery(sql);
while (rs.next()) {
EmployeObject e = new EmployeObject();
e.setId(rs.getInt(1));
e.setNombre(rs.getString(2));
e.setApellido(rs.getString(3));
listaCliente.add(e);
}
stm.close();
rs.close();
co.close();
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
return listaCliente;
}
}
`` ``` ``` ``` ``` ``` ``` ``` ``` ``` ``` ``` ``` ``` ``` `
package com.IDAO;
import java.util.List;
import com.model.EmployeObject;
public interface EmployeIDAO {
public boolean registrar(EmployeObject employe);
public List<EmployeObject> obtener();
public boolean actualizar(EmployeObject employe);
public boolean eliminar(EmployeObject employe);
}
`` ``` ``` ``` ``` ``` ``` ``` ``` ```
package REST;
import java.util.List;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.MediaType;
import com.DAO.EmployeDAO;
import com.model.EmployeObject;
import javax.ws.rs.Produces;
// http://localhost:8080/RestService/resources/MyRestService/verEmpleados
#GET
#Path("/verEmpleados")
#Produces(MediaType.APPLICATION_JSON)
public List<EmployeObject> VerEmpleado() {
List<EmployeObject> verEmpleados = empleados.obtener();
return verEmpleados;
}
`` ``` ``` ``` ``` ``` ``` ``` ``` ```
I hope I can help, thank you very much
Here are the error messages
10:55:27,125 ERROR [stderr] (default task-2) at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198)
10:55:27,125 ERROR [stderr] (default task-2) at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:412)
10:55:27,125 ERROR [stderr] (default task-2) at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:400)
10:55:27,125 ERROR [stderr] (default task-2) at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)
10:55:27,126 ERROR [stderr] (default task-2) at java.lang.Class.forName0(Native Method)
10:55:27,126 ERROR [stderr] (default task-2) at java.lang.Class.forName(Unknown Source)
10:55:27,126 ERROR [stderr] (default task-2) at com.connection.ConexionPSQL.crearConexion(ConexionPSQL.java:17)
10:55:27,126 ERROR [stderr] (default task-2) at com.DAO.EmployeDAO.obtener(EmployeDAO.java:55)
10:55:27,127 ERROR [stderr] (default task-2) at REST.RestService.VerEmpleado(RestService.java:46)
10:55:27,127 ERROR [stderr] (default task-2) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
10:55:27,127 ERROR [stderr] (default task-2) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
10:55:27,127 ERROR [stderr] (default task-2) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
10:55:27,127 ERROR [stderr] (default task-2) at java.lang.reflect.Method.invoke(Unknown Source)
10:55:27,127 ERROR [stderr] (default task-2) at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:140)
10:55:27,128 ERROR [stderr] (default task-2) at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:295)
10:55:27,128 ERROR [stderr] (default task-2) at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:249)
10:55:27,128 ERROR [stderr] (default task-2) at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:236)
10:55:27,128 ERROR [stderr] (default task-2) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:406)
10:55:27,129 ERROR [stderr] (default task-2) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:213)
10:55:27,129 ERROR [stderr] (default task-2) at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:228)
10:55:27,129 ERROR [stderr] (default task-2) at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
10:55:27,129 ERROR [stderr] (default task-2) at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
10:55:27,130 ERROR [stderr] (default task-2) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
10:55:27,130 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
10:55:27,130 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
10:55:27,130 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
10:55:27,130 ERROR [stderr] (default task-2) at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
10:55:27,131 ERROR [stderr] (default task-2) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
10:55:27,131 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
10:55:27,131 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
10:55:27,131 ERROR [stderr] (default task-2) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
10:55:27,131 ERROR [stderr] (default task-2) at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
10:55:27,132 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
10:55:27,132 ERROR [stderr] (default task-2) at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
10:55:27,132 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
10:55:27,132 ERROR [stderr] (default task-2) at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
10:55:27,134 ERROR [stderr] (default task-2) at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
10:55:27,134 ERROR [stderr] (default task-2) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
10:55:27,134 ERROR [stderr] (default task-2) at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
10:55:27,135 ERROR [stderr] (default task-2) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
10:55:27,135 ERROR [stderr] (default task-2) at org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
10:55:27,135 ERROR [stderr] (default task-2) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
10:55:27,135 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
10:55:27,136 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
10:55:27,136 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
10:55:27,136 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
10:55:27,136 ERROR [stderr] (default task-2) at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
10:55:27,137 ERROR [stderr] (default task-2) at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
10:55:27,137 ERROR [stderr] (default task-2) at org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
10:55:27,137 ERROR [stderr] (default task-2) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
10:55:27,137 ERROR [stderr] (default task-2) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
10:55:27,138 ERROR [stderr] (default task-2) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
10:55:27,138 ERROR [stderr] (default task-2) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
10:55:27,138 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
10:55:27,138 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
10:55:27,138 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
10:55:27,139 ERROR [stderr] (default task-2) at io.undertow.server.Connectors.executeRootHandler(Connectors.java:326)
10:55:27,139 ERROR [stderr] (default task-2) at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:812)
10:55:27,139 ERROR [stderr] (default task-2) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
10:55:27,139 ERROR [stderr] (default task-2) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
10:55:27,139 ERROR [stderr] (default task-2) at java.lang.Thread.run(Unknown Source)
well i created a restful webservice wi th a get method that returns a list of bank transactions based on an account id. the service works fine when i test.
Then i created a restful client in my managedBean. this exceptions pops out when i invoke my webservice.
i tried this method already with a list of all clients (without parameters) and it worked but when i add a parameter to my transactions method the id could not be extracted from my request.
this is my webservice
#Stateless
#Path("/transactions")
public class TransactionWebService {
#EJB
private GestionAccountsLocal local1;
#EJB
private GestionTransactionsLocal local2;
#GET
#Path("/{id}")
#Produces(MediaType.APPLICATION_JSON)
public List<Transaction> getTransactionById(#PathParam(value="id") Integer id)
{
Account account=local1.findAccountByid(id);
return local2.showTransactionByAccount(account);
}
}
this is my restful client
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.json.JsonException;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import org.json.JSONArray;
#ManagedBean
#SessionScoped
public class WebServiceTransaction {
private WebTarget webtarget;
private Client client;
private entities.Account account;
private Transaction transaction;
private List<Transaction> transactions;
private static final String base_url= "http://localhost:8383/ebankingWEB/rest/transactions" ;
public WebTarget getWebtarget() {
return webtarget;
}
public void setWebtarget(WebTarget webtarget) {
this.webtarget = webtarget;
}
public Transaction getTransaction() {
return transaction;
}
public void setTransaction(Transaction transaction) {
this.transaction = transaction;
}
public static String getBaseUrl() {
return base_url;
}
public Client getClient() {
return client;
}
public void setClient(Client client) {
this.client = client;
}
public WebServiceTransaction() {
client= ClientBuilder.newClient();
webtarget=client.target(base_url).path("id");
}
public List<Transaction> getTransactions() {
return transactions;
}
public void setTransactions(List<Transaction> transactions) {
this.transactions = transactions;
}
public List<Transaction> convertToList (String jsonListString) throws JsonException{
try{
JSONArray jsonList = new JSONArray(jsonListString);
transactions = new ArrayList<Transaction>();
for (int i=0 ; i < jsonList.length();i++){
Transaction transaction = new Transaction(jsonList.get(i).toString());
transactions.add(transaction);
}
return transactions;
}
catch (Exception e) {
throw new JsonException(e.getMessage());
}
}
public List<Transaction> getTransactionsByAccount (Integer id){
try{
WebTarget ressource = webtarget;
ressource.path(MessageFormat.format("{0}" , new Object[]{id}));
String jsonListString = ressource.request(MediaType.APPLICATION_JSON).get(String.class);
return convertToList(jsonListString);
}
catch (Exception e){
String message = "non existant transactions ";
FacesContext.getCurrentInstance()
.addMessage(
null,
new FacesMessage(FacesMessage.SEVERITY_INFO,
message, null));
e.printStackTrace();
return new ArrayList<Transaction>();
}
}
public entities.Account getAccount() {
return account;
}
public void setAccount(entities.Account account) {
this.account = account;
}
}
and this is my log
15:51:05,177 WARN [org.jboss.resteasy.core.ExceptionHandler] (default task-26) failed to execute: javax.ws.rs.NotFoundException: Unable to extract parameter from http request: javax.ws.rs.PathParam("id") value is 'id' for public java.util.List webServices.TransactionWebService.getTransactionById(java.lang.Integer)
at org.jboss.resteasy.core.PathParamInjector$1.throwProcessingException(PathParamInjector.java:54) [resteasy-jaxrs-3.0.8.Final.jar:]
at org.jboss.resteasy.core.StringParameterInjector.extractValue(StringParameterInjector.java:336) [resteasy-jaxrs-3.0.8.Final.jar:]
at org.jboss.resteasy.core.PathParamInjector.inject(PathParamInjector.java:131) [resteasy-jaxrs-3.0.8.Final.jar:]
at org.jboss.resteasy.core.MethodInjectorImpl.injectArguments(MethodInjectorImpl.java:89) [resteasy-jaxrs-3.0.8.Final.jar:]
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:112) [resteasy-jaxrs-3.0.8.Final.jar:]
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:296) [resteasy-jaxrs-3.0.8.Final.jar:]
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:250) [resteasy-jaxrs-3.0.8.Final.jar:]
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:237) [resteasy-jaxrs-3.0.8.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356) [resteasy-jaxrs-3.0.8.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179) [resteasy-jaxrs-3.0.8.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220) [resteasy-jaxrs-3.0.8.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56) [resteasy-jaxrs-3.0.8.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51) [resteasy-jaxrs-3.0.8.Final.jar:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:177) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:727) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_75]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_75]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_75]
Caused by: java.lang.NumberFormatException: For input string: "id"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) [rt.jar:1.7.0_75]
at java.lang.Integer.parseInt(Integer.java:492) [rt.jar:1.7.0_75]
at java.lang.Integer.<init>(Integer.java:677) [rt.jar:1.7.0_75]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.7.0_75]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) [rt.jar:1.7.0_75]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [rt.jar:1.7.0_75]
at java.lang.reflect.Constructor.newInstance(Constructor.java:526) [rt.jar:1.7.0_75]
at org.jboss.resteasy.core.StringParameterInjector.extractValue(StringParameterInjector.java:319) [resteasy-jaxrs-3.0.8.Final.jar:]
... 38 more
15:51:05,191 ERROR [stderr] (default task-25) javax.ws.rs.NotFoundException: HTTP 404 Not Found
15:51:05,191 ERROR [stderr] (default task-25) at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.handleErrorStatus(ClientInvocation.java:181)
15:51:05,191 ERROR [stderr] (default task-25) at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(ClientInvocation.java:154)
15:51:05,191 ERROR [stderr] (default task-25) at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:444)
15:51:05,192 ERROR [stderr] (default task-25) at org.jboss.resteasy.client.jaxrs.internal.ClientInvocationBuilder.get(ClientInvocationBuilder.java:165)
15:51:05,192 ERROR [stderr] (default task-25) at tn.esprit.webServiceData.WebServiceTransaction.getTransactionsByAccount(WebServiceTransaction.java:89)
15:51:05,192 ERROR [stderr] (default task-25) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
15:51:05,192 ERROR [stderr] (default task-25) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
15:51:05,192 ERROR [stderr] (default task-25) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
15:51:05,192 ERROR [stderr] (default task-25) at java.lang.reflect.Method.invoke(Method.java:606)
15:51:05,193 ERROR [stderr] (default task-25) at javax.el.ELUtil.invokeMethod(ELUtil.java:308)
15:51:05,193 ERROR [stderr] (default task-25) at javax.el.BeanELResolver.invoke(BeanELResolver.java:537)
15:51:05,193 ERROR [stderr] (default task-25) at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:256)
15:51:05,193 ERROR [stderr] (default task-25) at com.sun.el.parser.AstValue.invoke(AstValue.java:269)
15:51:05,193 ERROR [stderr] (default task-25) at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
15:51:05,193 ERROR [stderr] (default task-25) at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
15:51:05,194 ERROR [stderr] (default task-25) at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
15:51:05,194 ERROR [stderr] (default task-25) at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
15:51:05,194 ERROR [stderr] (default task-25) at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
15:51:05,194 ERROR [stderr] (default task-25) at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
15:51:05,194 ERROR [stderr] (default task-25) at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
15:51:05,194 ERROR [stderr] (default task-25) at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
15:51:05,194 ERROR [stderr] (default task-25) at javax.faces.component.UICommand.broadcast(UICommand.java:315)
15:51:05,195 ERROR [stderr] (default task-25) at javax.faces.component.UIData.broadcast(UIData.java:1108)
15:51:05,195 ERROR [stderr] (default task-25) at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
15:51:05,195 ERROR [stderr] (default task-25) at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
15:51:05,195 ERROR [stderr] (default task-25) at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
15:51:05,195 ERROR [stderr] (default task-25) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
15:51:05,195 ERROR [stderr] (default task-25) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
15:51:05,196 ERROR [stderr] (default task-25) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
15:51:05,196 ERROR [stderr] (default task-25) at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
15:51:05,196 ERROR [stderr] (default task-25) at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61)
15:51:05,196 ERROR [stderr] (default task-25) at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
15:51:05,196 ERROR [stderr] (default task-25) at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
15:51:05,196 ERROR [stderr] (default task-25) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
15:51:05,197 ERROR [stderr] (default task-25) at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113)
15:51:05,197 ERROR [stderr] (default task-25) at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56)
15:51:05,197 ERROR [stderr] (default task-25) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
15:51:05,197 ERROR [stderr] (default task-25) at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45)
15:51:05,197 ERROR [stderr] (default task-25) at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61)
15:51:05,197 ERROR [stderr] (default task-25) at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)
15:51:05,198 ERROR [stderr] (default task-25) at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70)
15:51:05,198 ERROR [stderr] (default task-25) at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)
15:51:05,198 ERROR [stderr] (default task-25) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
15:51:05,198 ERROR [stderr] (default task-25) at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
15:51:05,198 ERROR [stderr] (default task-25) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
15:51:05,198 ERROR [stderr] (default task-25) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
15:51:05,198 ERROR [stderr] (default task-25) at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240)
15:51:05,198 ERROR [stderr] (default task-25) at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227)
15:51:05,198 ERROR [stderr] (default task-25) at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73)
15:51:05,198 ERROR [stderr] (default task-25) at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146)
15:51:05,198 ERROR [stderr] (default task-25) at io.undertow.server.Connectors.executeRootHandler(Connectors.java:177)
15:51:05,198 ERROR [stderr] (default task-25) at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:727)
15:51:05,198 ERROR [stderr] (default task-25) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
15:51:05,198 ERROR [stderr] (default task-25) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
15:51:05,198 ERROR [stderr] (default task-25) at java.lang.Thread.run(Thread.java:745)
PS:
i think this line is the issue since it gets the base url but the id is not extracted correctly webtarget=client.target(base_url).path("id");
if you need anything else please let me know.
You configured your Service with
#Path("/{id}")
So you should not mention the path fragment "/id" in your webtaregt in the constructor :
webtarget=client.target(base_url).path("id"); // wrong
webtarget=client.target(base_url); // OK
Ex : considering transaction id=1 exists, check on your webbrowser :
../transactions/id/1 //wrong
../transactions/1 // OK
i corrected my rest client and it worked like a charm.
webtarget=client.target(base_url);
and
WebTarget ressource = webtarget;
ressource = ressource.path(MessageFormat.format("{0}" , new Object[]{id}));
before that , i didn't affect a ressource to my parameter.
I set up a project to Inject bean
But when you try to start getting a null pointer error
Can you tell that I did not ?
public_html\WEB-INF\faces-config.xml
<?xml version='1.0' encoding='UTF-8'?>
<faces-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.2"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
<application>
<locale-config>
<default-locale>ru</default-locale>
</locale-config>
<resource-bundle>
<base-name>by.softclub.abank.admin.ui.resources.Labels</base-name>
<var>lbl</var>
</resource-bundle>
<resource-bundle>
<base-name>by.softclub.abank.admin.ui.resources.Regexp</base-name>
<var>regexp</var>
</resource-bundle>
<action-listener>org.primefaces.application.DialogActionListener</action-listener>
<navigation-handler>org.primefaces.application.DialogNavigationHandler</navigation-handler>
<!-- <view-handler>org.primefaces.application.DialogViewHandler</view-handler> -->
<el-resolver>
org.primefaces.application.exceptionhandler.PrimeExceptionHandlerELResolver
</el-resolver>
</application>
<factory>
<exception-handler-factory>
org.primefaces.application.exceptionhandler.PrimeExceptionHandlerFactory
</exception-handler-factory>
</factory>
<lifecycle>
<phase-listener>by.softclub.abank.admin.ui.faces.UniqueSessionPhaseListener</phase-listener>
</lifecycle>
</faces-config>
public_html\WEB-INF\beans.xml
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
version="1.2" bean-discovery-mode="annotated">
<!-- some content -->
</beans>
UniqueSessionPhaseListener
public class UniqueSessionPhaseListener implements PhaseListener {
#Inject
ApplicationBean applicationBean;
public PhaseId getPhaseId() {
return PhaseId.RENDER_RESPONSE;
}
public void afterPhase(PhaseEvent phaseEvent) {
}
public void beforePhase(PhaseEvent phaseEvent) {
if (applicationBean.sessionIntercepted(FacesUtils.getSession())) {
SessionBean sessionBean = (SessionBean) FacesUtils.getSession().getAttribute("sessionBean");
if (sessionBean.isAuthenticated()) {
sessionBean.logoutAction();
}
}
}
}
ApplicationBean
#ApplicationScoped
#Named("applicationBean")
public class ApplicationBean implements Serializable {
public ApplicationBean() {
}
}
Error log
09:35:58,189 ERROR [stderr] (default task-35) java.lang.NullPointerException
09:35:58,189 ERROR [stderr] (default task-35) at by.softclub.abank.admin.ui.faces.UniqueSessionPhaseListener.beforePhase(UniqueSessionPhaseListener.java:26)
09:35:58,189 ERROR [stderr] (default task-35) at com.sun.faces.lifecycle.Phase.handleBeforePhase(Phase.java:228)
09:35:58,190 ERROR [stderr] (default task-35) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:99)
09:35:58,190 ERROR [stderr] (default task-35) at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
09:35:58,190 ERROR [stderr] (default task-35) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:659)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130)
09:35:58,190 ERROR [stderr] (default task-35) at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:98)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)
09:35:58,190 ERROR [stderr] (default task-35) at com.github.zhanhb.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:55)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)
09:35:58,190 ERROR [stderr] (default task-35) at by.softclub.abank.admin.ui.faces.UrlFilter.doFilter(UrlFilter.java:118)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
09:35:58,190 ERROR [stderr] (default task-35) at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)
09:35:58,190 ERROR [stderr] (default task-35) at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:72)
09:35:58,193 ERROR [stderr] (default task-35) at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
09:35:58,193 ERROR [stderr] (default task-35) at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)
09:35:58,193 ERROR [stderr] (default task-35) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
09:35:58,193 ERROR [stderr] (default task-35) at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
09:35:58,193 ERROR [stderr] (default task-35) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
09:35:58,193 ERROR [stderr] (default task-35) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
09:35:58,193 ERROR [stderr] (default task-35) at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:282)
09:35:58,193 ERROR [stderr] (default task-35) at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:261)
09:35:58,193 ERROR [stderr] (default task-35) at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:80)
09:35:58,193 ERROR [stderr] (default task-35) at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:172)
09:35:58,193 ERROR [stderr] (default task-35) at io.undertow.server.Connectors.executeRootHandler(Connectors.java:199)
09:35:58,193 ERROR [stderr] (default task-35) at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:774)
09:35:58,193 ERROR [stderr] (default task-35) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
09:35:58,193 ERROR [stderr] (default task-35) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
09:35:58,193 ERROR [stderr] (default task-35) at java.lang.Thread.run(Thread.java:745)
09:35:58,193 SEVERE [org.primefaces.application.exceptionhandler.PrimeExceptionHandler] (default task-35) null: java.lang.NullPointerException
at by.softclub.abank.admin.ui.faces.UniqueSessionPhaseListener.beforePhase(UniqueSessionPhaseListener.java:26) [classes:]
at com.sun.faces.lifecycle.Phase.handleBeforePhase(Phase.java:228) [jsf-impl-2.2.12-jbossorg-2.jar:2.2.12-jbossorg-2]
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:99) [jsf-impl-2.2.12-jbossorg-2.jar:2.2.12-jbossorg-2]
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219) [jsf-impl-2.2.12-jbossorg-2.jar:2.2.12-jbossorg-2]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:659) [jboss-jsf-api_2.2_spec-2.2.12.jar:2.2.12]
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:98) [primefaces-5.0.jar:5.0]
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at com.github.zhanhb.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:55) [character-encoding-filter-2.1.6.4.jar:]
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at by.softclub.abank.admin.ui.faces.UrlFilter.doFilter(UrlFilter.java:118) [classes:]
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46) [undertow-core-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) [undertow-core-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:72) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50) [undertow-core-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.2.9.Final.jar:1.2.9.Final]
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:282) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:261) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:80) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:172) [undertow-servlet-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:199) [undertow-core-1.2.9.Final.jar:1.2.9.Final]
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:774) [undertow-core-1.2.9.Final.jar:1.2.9.Final]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_102]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_102]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_102]
I try
How to #Inject in a PhaseListener
But also null pointer
public static ApplicationBean getApplicationBean() {
FacesContext context = FacesContext.getCurrentInstance();
return context.getApplication()
.evaluateExpressionGet(context, "#{applicationBean}", ApplicationBean.class);
}
Whee ApplicationBean was annotated #ManagedBean all work fine
Change PhaseListener
import javax.el.ELContext;
import javax.enterprise.context.ApplicationScoped;
import javax.faces.application.Application;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;
import javax.naming.InitialContext;
import javax.naming.NamingException;
#ApplicationScoped
public class UniqueSessionPhaseListener implements PhaseListener {
public PhaseId getPhaseId() {
return PhaseId.RENDER_RESPONSE;
}
public void afterPhase(PhaseEvent phaseEvent) {
}
public void beforePhase(PhaseEvent phaseEvent) {
FacesContext context = FacesContext.getCurrentInstance();
ELContext elContext = context.getELContext();
Object object = context.getApplication().evaluateExpressionGet(context, "#{applicationBean}", Object.class);
Application application = context.getApplication();
ApplicationBean applicationBean0 = application.evaluateExpressionGet(context, "#{applicationBean}", ApplicationBean.class);
ApplicationBean applicationBean00 = (ApplicationBean) application.getExpressionFactory().createValueExpression(elContext, "#{applicationBean}", ApplicationBean.class).getValue(elContext);
ApplicationBean applicationBean000 = (ApplicationBean) elContext.getELResolver().getValue(elContext, null, "applicationBean");
ApplicationBean applicationBean = (ApplicationBean) FacesContext.getCurrentInstance().getApplication().getELResolver().getValue(elContext, null, "#{applicationBean}");
ApplicationBean applicationBean1 = context.getApplication().evaluateExpressionGet(context, "#{applicationBean}", ApplicationBean.class);
InitialContext initialContext = null;
try {
initialContext = new InitialContext();
ApplicationBean beanManager = (ApplicationBean) initialContext.lookup("java:comp/applicationBean");
} catch (NamingException e) {
e.printStackTrace();
}
ApplicationBean bean = FacesUtils.getApplicationBean();
if (bean.sessionIntercepted(FacesUtils.getSession())) {
SessionBean sessionBean = (SessionBean) FacesUtils.getSession().getAttribute("sessionBean");
if (sessionBean.isAuthenticated()) {
sessionBean.logoutAction();
}
}
}
}
Updated 21.09.2016
Add questions:
1) How can I find is on the right path lies beans.xml (faces-config is in the WEB-INF), so I think unlikely but still there is the idea that with the beans.xml that something is wrong.
2) Server Settings, his library (I WildFly 9) can not be to influence the CDI application?
I want the payload of my HTTP request to be converted into a JSON string and I am using Jackson library for it. First I convert it to a Map and then to a JSON string.
try {
ObjectMapper mapper = new ObjectMapper();
JsonParser jsonParser = mapper.getFactory().createParser(httpRequest.getInputStream());
System.out.println("JSON PARSER: " + jsonParser +
" TOKEN: " + jsonParser.getCurrentToken());
Map<String, Object> jsonMap = mapper.readValue(jsonParser, Map.class);
} catch (IOException e) {
e.printStackTrace();
}
I get exception:
com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input ERROR [stderr] (default task-2) at [Source: io.undertow.servlet.spec.ServletInputStreamImpl#4b68bbaa; line: 1, column: 1]
ERROR [stderr] (default task-2) at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:164)
ERROR [stderr] (default task-2) at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:3029)
ERROR [stderr] (default task-2) at com.fasterxml.jackson.databind.ObjectMapper._readValue(ObjectMapper.java:2944)
ERROR [stderr] (default task-2) at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:1587)
ERROR [stderr] (default task-2)
ERROR [stderr] (default task-2) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2016-07-18 11:52:15,973 ERROR [stderr] (default task-2) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
2016-07-18 11:52:15,973 ERROR [stderr] (default task-2) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2016-07-18 11:52:15,973 ERROR [stderr] (default task-2) at java.lang.reflect.Method.invoke(Method.java:606)
2016-07-18 11:52:15,973 ERROR [stderr] (default task-2) at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:137)
2016-07-18 11:52:15,973 ERROR [stderr] (default task-2) at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:280)
2016-07-18 11:52:15,974 ERROR [stderr] (default task-2) at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:234)
2016-07-18 11:52:15,974 ERROR [stderr] (default task-2) at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:221)
2016-07-18 11:52:15,974 ERROR [stderr] (default task-2) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356)
2016-07-18 11:52:15,974 ERROR [stderr] (default task-2) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179)
2016-07-18 11:52:15,974 ERROR [stderr] (default task-2) at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220)
2016-07-18 11:52:15,974 ERROR [stderr] (default task-2) at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
2016-07-18 11:52:15,975 ERROR [stderr] (default task-2) at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
2016-07-18 11:52:15,975 ERROR [stderr] (default task-2) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
2016-07-18 11:52:15,975 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
2016-07-18 11:52:15,975 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61)
2016-07-18 11:52:15,975 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
2016-07-18 11:52:15,975 ERROR [stderr] (default task-2) at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
2016-07-18 11:52:15,975 ERROR [stderr] (default task-2) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
2016-07-18 11:52:15,976 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113)
2016-07-18 11:52:15,976 ERROR [stderr] (default task-2) at io.undertow.security.handlers.AuthenticationCallHandler.handleRequest(AuthenticationCallHandler.java:52)
2016-07-18 11:52:15,976 ERROR [stderr] (default task-2) at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45)
2016-07-18 11:52:15,976 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61)
2016-07-18 11:52:15,976 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70)
2016-07-18 11:52:15,976 ERROR [stderr] (default task-2) at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)
2016-07-18 11:52:15,976 ERROR [stderr] (default task-2) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
2016-07-18 11:52:15,977 ERROR [stderr] (default task-2) at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
2016-07-18 11:52:15,977 ERROR [stderr] (default task-2) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
2016-07-18 11:52:15,977 ERROR [stderr] (default task-2) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
2016-07-18 11:52:15,977 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240)
2016-07-18 11:52:15,977 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227)
2016-07-18 11:52:15,977 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73)
2016-07-18 11:52:15,978 ERROR [stderr] (default task-2) at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146)
2016-07-18 11:52:15,978 ERROR [stderr] (default task-2) at io.undertow.server.Connectors.executeRootHandler(Connectors.java:168)
2016-07-18 11:52:15,978 ERROR [stderr] (default task-2) at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:687)
2016-07-18 11:52:15,978 ERROR [stderr] (default task-2) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
2016-07-18 11:52:15,978 ERROR [stderr] (default task-2) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
2016-07-18 11:52:15,978 ERROR [stderr] (default task-2) at java.lang.Thread.run(Thread.java:724)
The following line:
System.out.println("JSON PARSER: " + jsonParser +
" TOKEN: " + jsonParser.getCurrentToken());
Prints:
JSON PARSER: com.fasterxml.jackson.core.json.UTF8StreamJsonParser#6634789d TOKEN: null
My token is coming null.
Am I missing something? What is the corrcet way to extract data from HTTP request stream?
The following should do the trick:
// Read the request payload into a String
StringBuilder buffer = new StringBuilder();
BufferedReader reader = request.getReader();
String line;
while ((line = reader.readLine()) != null) {
buffer.append(line);
}
String data = buffer.toString();
// If the String is not empty, parses the payload into a map
Map<String, Object> jsonMap = null;
if (!data.isEmpty()) {
ObjectMapper mapper = new ObjectMapper();
jsonMap = mapper.readValue(data, Map.class);
}
I do it like this:
BufferedReader bufReader = new BufferedReader(new InputStreamReader
(new URL(myUrlString).openStream()));
StringBuilder myStrBuilder = new StringBuilder();
while((builderLine = bufReader.readLine()) != null) {
myStrBuilder.append(builderLine);
}
JSONArray myJsonArry = new JSONArray(myStrBuilder.toString());
List<Object> myArrayList = new ArrayList<Object>(toList(myJsonArry));
Collection<Map<String,String>> mapsCol = new HashSet<Map<String,String>>();
for (int i=0; i < myArrayList.size(); i++) {
mapsCol.add((HashMap<String, String>)myArrayList.get(i));
}