How do I solve EncryptedStorage error when I make a https request? - codenameone

I try to encrypt my secure data with EncryptedStorage described in EncryptedStorage
I add the code below
EncryptedStorage.install("weejgrieqjgewgjwerrgjerwgmwe 9");
It shows error messages when my program makes a https request.
org.bouncycastle.crypto.DataLengthException: last block incomplete in decryption
[Network Thread] 0:0:0,2 - Exception: org.bouncycastle.crypto.DataLengthException - last block incomplete in decryption
[Network Thread] 0:0:0,648 - Exception: org.bouncycastle.crypto.DataLengthException - last block incomplete in decryption
[Network Thread] 0:0:0,749 - Exception: org.bouncycastle.crypto.DataLengthException - last block incomplete in decryption
[Network Thread] 0:0:1,252 - Exception: org.bouncycastle.crypto.DataLengthException - last block incomplete in decryption
at org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher.doFinal(PaddedBufferedBlockCipher.java:281)
at com.codename1.crypto.EncryptedStorage.createInputStream(EncryptedStorage.java:63)
at com.codename1.io.Storage.readObject(Storage.java:265)
at com.codename1.impl.CodenameOneImplementation.getCookiesForURL(CodenameOneImplementation.java:4700)
at com.codename1.io.ConnectionRequest.performOperationComplete(ConnectionRequest.java:830)
at com.codename1.io.NetworkManager$NetworkThread.run(NetworkManager.java:341)
How do I solve this problem?

The cookies file isn't encrypted. I'm assuming it was written before you applied the encryption everything.
So just before applying the encryption delete the cookies file:
deleteStorageFile("Cookies");

Related

Gatling check does not fail

I am trying to send a http request and fail if the request returns not 200:
exec(http("Get some html")
.get("${aggUrl}/somePath")
.check(status.is(200))
.check(regex("websocket=(.*?)&").saveAs("wsLink"))
)
The server sends the 401 response:
[HTTP/1.1 401 Unauthorized]{"errors":[{"code":"authentication.failure","message":"Failed to authenticate user details"}]}]
I expect in console something like "expecting code 200, but was 401"
But the actual error is:
[ERROR] i.g.c.a.b.SessionHookBuilder$$anon$1 - 'hook-38' crashed with 'j.u.NoSuchElementException: No attribute named 'wsLink' is defined', forwarding to the next one
[ERROR] i.g.h.a.HttpRequestAction - 'httpRequest-37' failed to execute: No attribute named 'wsLink' is defined
So I assume that the ".check(status.is(200))" is just ignored?
How then should I fail the test?
Thanks in advance,
Andrei Isakov
I think you're mistaken.
[ERROR] i.g.c.a.b.SessionHookBuilder$$anon$1 - 'hook-38' crashed with 'j.u.NoSuchElementException: No attribute named 'wsLink' is defined', forwarding to the next one
[ERROR] i.g.h.a.HttpRequestAction - 'httpRequest-37' failed to execute: No attribute named 'wsLink' is defined
Those errors happens happen AFTER the request you provided the code for, in an exec block you didn't mentioned where you're trying to inspect the Session's content and fetch the wsLink attribute that doesn't exist because the request failed.
Check failures are not logged with ERROR level. You have to either lower the logging level (see logback.xml) or check the HTML reports.

connection reset error while testing the App on simulator

I see the following error during the login process while calling REST methods with JSON response. Please advise what would be causing this issue in simulator.
java.net.SocketException: Connection reset
[Network Thread] 0:5:5,328 - Exception during JSON parsing at row: 1 column: 32593 buffer: /9j/4AAQSkZJRgABAQEAYABgAAD/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAEAAAAAAAD at java.net.SocketInputStream.read(SocketInputStream.java:210)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
SxZN3Hpvl3GnzbbeF920jPJ4wfXrUlxrU1/rkc1k0djqWMROQCOevtWJceIrGzidmVWjYcKGz81MHiXSXtoWv1mJjOUAUjP4ivr5YqkqTUmjxsLRqc6bTPuL/g3Lik0n/gr5pNtqzLdam+4rMowB+
at sun.security.ssl.InputRecord.readV3Record(InputRecord.java:593)
at sun.security.ssl.InputRecord.read(InputRecord.java:532)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:983)
at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:940)
at sun.security.ssl.AppInputStream.read(AppInputStream.java:105)
fD+TxB46uLjwiftXlGxu2aCfy8ZyFNfL5txNh6MXFSVz6rLMkqStKorH0B/wQT/4JUfCn9vn9hm81zxNDdLf2utGISwBdxATOCTX20/8AwbcfAkhfk1LKjByE5/Svoz/gnD+wZ4f/AOCeP7PFn4F0GSSRVYT3MjEZklxgmvoDdk
at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
at sun.net.www.MeteredStream.read(MeteredStream.java:134)
at java.io.FilterInputStream.read(FilterInputStream.java:133)
at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:3393)
at com.codename1.io.BufferedInputStream.read1(BufferedInputStream.java:338)
at com.codename1.io.BufferedInputStream.read(BufferedInputStream.java:445)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at com.codename1.io.JSONParser$ReaderClass.read(JSONParser.java:124)
/Xn4dkY6DZbuW+zx5PvtFVhsT7VXPHz7JXl1VUpF0fLnnNAfJpucE0K2UrqPCJK/MH/g6wH/ABrus/bWV/8AQDX6eb8ivzD/AODrP/lHfY5bH/E5X8fkNZ1PgZ15ev8AaYep/OXpQVdN0/d/zwU1aYrJJ7ZrNspN2k2OG+byV/K
at com.codename1.io.JSONParser.parse(JSONParser.java:194)

Aggregate after exception from ftp consumer: FatalFallbackErrorHandler

My camel route tries to pick up some files from sftp, transfer them to network, and delete them from sftp. If the sftp is unreachable after 3 attempts, I want the route to send an email warning the admin about the problem.
For this reason my sftp address has the following parameters:
maximumReconnectAttempts=2&throwExceptionOnConnectFailed=true&consumer.bridgeErrorHandler=true
In case the network location is not available, i want the route to notify the admin and not delete the files from sftp.
For this reason i have set .handled(false) in onException.
However, when connecting to sftp fails, aggregation also fails and no emails are coming. I have made a minimalist example below:
/configure
onException(Throwable.class)
.retryAttemptedLogLevel(LoggingLevel.WARN)
.redeliveryDelay(1000)
.handled(false)
.log(LoggingLevel.ERROR, LOG, "XXX - Error moving files")
.to(AGGREGATEROUTE)
.end();
from(downloadFrom)
.to(to)
.log(LoggingLevel.INFO, LOG, "XXX - Moving file OK")
.to(AGGREGATEROUTE);
from(AGGREGATEROUTE)
.log(LoggingLevel.INFO, LOG, "XXX - Starting aggregation.")
.aggregate(constant(true), new GroupedExchangeAggregationStrategy())
.completionFromBatchConsumer()
.completionTimeout(10000)
.log(LoggingLevel.INFO, LOG, "XXX - Aggregation completed, sending mail.");
In the logs i see:
16:02| ERROR | CamelLogger.java 156 | XXX - Error moving files
Then the logs for the Exception occurring during connection.
And then this:
16:02| ERROR | FatalFallbackErrorHandler.java 174 | Exception occurred while trying to handle previously thrown exception on exchangeId: ID-LP0641-1552662095664-0-2 using: [Pipeline[[Channel[Log(proefjes.camel_cursus.routebuilders.MoveWithPickupExceptions)[XXX - Error moving files]], Channel[sendTo(direct://aggregate)]]]].
16:02| ERROR | FatalFallbackErrorHandler.java 172 | \--> New exception on exchangeId: ID-LP0641-1552662095664-0-2
org.apache.camel.component.file.GenericFileOperationFailedException: Cannot connect to sftp://user#mycompany.nl:22
at org.apache.camel.component.file.remote.SftpOperations.connect(SftpOperations.java:149)
I do not see "XXX - Starting aggregation." which i would expect to see in the log. Does some kind of error occur befor aggregation? The breakpoint on aggregate(*, *) is never reached.
First, I just want to clarify something. You write "In case the network location is not available, i want the route to notify the admin and not delete the files from sftp", but shouldn't that be obvious anyhow? I mean, if the network location is not available, wouldn't deleting the files from sftp be impossible?
It's a little confusing that your exception handler is also routing .to(AGGREGATEROUTE). Given that you want to email an admin, shouldn't that be in the exception handler, not in the happy path? Why would you and how would you "aggregate" a connection failure?
Finally, and here I think is a real problem with your implementation, you may have misunderstood what handled(false) does. Setting this to false means routing should stop and propagate the exception returned to the caller. I'm not sure what having to the .to(AGGREGATEROUTE) would do in this case, but I'm not surprised it's not being called.
I suggest trying a few things. I don't have your code so I'm not sure which will work best. These are all related and any might work:
Change handled(false) to handled(true).
Replace handled with continued(true).
Use a Dead Letter Channel.
Reference:
Handle and Continue Exceptions
Dead Letter Channel
Since errorhandling is different depending on which endpoint causes the error, i have solved this by having two different versions of onException:
//configure exception on sft end
onException(Throwable.class)
.maximumRedeliveries(2)
.retryAttemptedLogLevel(LoggingLevel.WARN)
.redeliveryDelay(1000)
.onWhen(new hasSFTPErrorPredicate())
// .continued(true) // tries to connect once, mails and continues to aggregation with empty exchange
//.handled(false) // tries to connect twice but does not reach mail
.handled(true) // tries to connect once, does reach mail
// handled not defined: tries to connect twice but does not reach mail
.log(LoggingLevel.INFO, LOG, "XXX - SFTP exception")
.to(MAIL_ROUTE)
.end();
// exception anywhere else
onException(Throwable.class)
.maximumRedeliveries(2)
.retryAttemptedLogLevel(LoggingLevel.WARN)
.redeliveryDelay(1000)
.log(LoggingLevel.ERROR, LOG, "XXX - Error moving file ${file:name}: ${exception}")
.to(AGGREGATEROUTE)
.handled(false)
.end();
Exceptions occuring at the sftp end are handled in the first onException, because there the hasSFTPErrorPredicate returns 'true'. All this predicate does is check if any exception or their cause has "Cannot connect to sftp:" in the message.
No rollback is required in this case because nothing has happened yet.
Any other exception is handled by the second onException.

camel with netty4-http - EncoderException

I'm using camel 2.14.0 with netty4-http
and I get the following exception.
the scenario is this:
I have a route that sends a request, waits for the response (inOut) and then sends another request.
the first request works, and then the second one fails.
also, if I do it quickly enough after the failure - the first request will also fail.
while debugging a bit (HttpObjectEncoder) - I saw that in the working flow the state of the request is: state = ST_INIT (0)
and in the request that failed it is: ST_CONTENT_NON_CHUNK (1)
which causes the illegal state when the type of message is HttpMessage
is this a bug or is there anything I can configure to fix it?
Caused by: io.netty.handler.codec.EncoderException: java.lang.IllegalStateException: unexpected message type: DefaultFullHttpRequest
at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:107)
at io.netty.channel.CombinedChannelDuplexHandler.write(CombinedChannelDuplexHandler.java:192)
at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:658)
at io.netty.channel.AbstractChannelHandlerContext.access$2000(AbstractChannelHandlerContext.java:32)
at io.netty.channel.AbstractChannelHandlerContext$AbstractWriteTask.write(AbstractChannelHandlerContext.java:939)
at io.netty.channel.AbstractChannelHandlerContext$WriteAndFlushTask.write(AbstractChannelHandlerContext.java:991)
at io.netty.channel.AbstractChannelHandlerContext$AbstractWriteTask.run(AbstractChannelHandlerContext.java:924)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:380)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:357)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: unexpected message type: DefaultFullHttpRequest
at io.netty.handler.codec.http.HttpObjectEncoder.encode(HttpObjectEncoder.java:63)
at io.netty.handler.codec.http.HttpClientCodec$Encoder.encode(HttpClientCodec.java:106)
at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:89)
... 10 more
I managed to identify the problem:
the first request I sent was a GET request with null body.
in the class org.apache.camel.component.netty4.http.NettyHttpProducer -
the method getRequestBody(Exchange exchange) is creating the actual request object from the exchange.
in it - the method "toNettyRequest" in class org.apache.camel.component.netty4.http.DefaultNettyHttpBinding
checks if the body is null, and if so - it is creating a DefaultHttpRequest, and not DefaultHttpFullRequest
when the request reaches the encoder as a result of a writeAndFlush call - the encoder does not clean its state because of this part of the code:
if (msg instanceof LastHttpContent) {
state = ST_INIT;
}
the DefaultHttpRequest is not instanceof LastHttpContent, so the state remains ST_CONTENT_NON_CHUNK and the next request will get an IllegalStateException because the state is not ST_INIT
this bug did not exist in netty-http, it only happened when I moved to use netty4-http
the workaround is simple - use an empty String ("") as body

Jenkins testlink plugin FATAL: Error verifying developer key: Failed to parse server's response: Content is not allowed in prolog

br.eti.kinoshita.testlinkjavaapi.util.TestLinkAPIException: Error
verifying developer key:
Failed to parse server's response: Content is not allowed in prolog.
at
br.eti.kinoshita.testlinkjavaapi.MiscService.checkDevKey(MiscService.java:66)
at
br.eti.kinoshita.testlinkjavaapi.TestLinkAPI.(TestLinkAPI.java:162)
at
hudson.plugins.testlink.TestLinkBuilder.getTestLinkSite(TestLinkBuilder.java:241)
at
hudson.plugins.testlink.TestLinkBuilder.perform(TestLinkBuilder.java:134)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:19)
at
hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:717)
at hudson.model.Build$BuildExecution.build(Build.java:199) at
hudson.model.Build$BuildExecution.doRun(Build.java:160) at
hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:499)
at hudson.model.Run.execute(Run.java:1488) at
hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46) at
hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:236) Caused by:
org.apache.xmlrpc.client.XmlRpcClientException: Failed to parse
server's response: Content is not allowed in prolog. at
org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse(XmlRpcStreamTransport.java:188)
at
org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:156)
at
org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:143)
at
org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:69)
at
org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:56)
at
org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:167)
at
org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:158)
at
org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:147)
at
br.eti.kinoshita.testlinkjavaapi.BaseService.executeXmlRpcCall(BaseService.java:90)
at
br.eti.kinoshita.testlinkjavaapi.MiscService.checkDevKey(MiscService.java:62)
... 12 more Caused by: org.xml.sax.SAXParseException; lineNumber: 1;
columnNumber: 1; Content is not allowed in prolog.

Resources