Why is mstor throwing a NotSerializableException on inbox.close() - spring-boot

I'm using the basic mstor logic with version 1.0.0 of of the maven mstor library, but it's throwing an Exception on the inbox.close() method. Note: I am not doing any writing to the disk so this Exception is odd. I made, as an attempt, my class which calls this code to "implement Serializable", but that did not help.
This code is running from a SpringBoot REST Service.
If I don't do an inbox.close(), then on Windows the mbox file is still open (not released by this library) after the method below completes.
Here's the basic code:
Properties properties = new Properties();
properties.setProperty("mail.store.protocol", "mstor");
properties.setProperty("mstor.mbox.metadataStrategy", "none");
properties.setProperty("mstor.mbox.cacheBuffers", "disabled");
properties.setProperty("mstor.mbox.bufferStrategy", "mapped");
properties.setProperty("mstor.metadata", "disabled");
properties.setProperty("mstor.mozillaCompatibility", "enabled");
Session session = Session.getInstance(properties);
try {
store = session.getStore(new URLName("mstor:" + pathToMboxFile));
store.connect();
inbox = (MStorFolder) store.getDefaultFolder();
inbox.open(Folder.READ_ONLY);
Message[] messages = inbox.getMessages();
int bodyPartCount = 0;
// ***********************
// process all mbox data.
// *************************
for (int pos = 0; pos < messages.length; pos++)
{
// processing.
}
catch (NoSuchProviderException e)
{
log.debug("MboxController NoSuchProviderException Exception: " + e.getMessage());
}
catch (javax.mail.MessagingException e)
{
errors.append(e);
log.debug("MboxController MessagingException Exception: " + e.getMessage());
}
finally
{
// close the mbox store
try
{
inbox.close(false);
store.close();
}
catch (MessagingException e)
{
log.debug("MboxController Closing Store Exception: " + e.getMessage());
}
}
Now, although the code does work and returns the mbox text and closes the file, when the inbox.close(false) runs, I get this error stack (or something close to it) each time in the Tomcat log:
2019-03-31 08:06:09 - Disk Write of 191 failed:
"java.io.NotSerializableException: net.fortuna.mstor.data.MessageInputStream
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:441)
at net.sf.ehcache.Element.writeObject(Element.java:791)
at sun.reflect.GeneratedMethodAccessor88.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1140)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
at net.sf.ehcache.util.MemoryEfficientByteArrayOutputStream.serialize(MemoryEfficientByteArrayOutputStream.java:97)
at net.sf.ehcache.store.disk.DiskStorageFactory.serializeElement(DiskStorageFactory.java:413)
at net.sf.ehcache.store.disk.DiskStorageFactory.write(DiskStorageFactory.java:392)
at net.sf.ehcache.store.disk.DiskStorageFactory$DiskWriteTask.call(DiskStorageFactory.java:493)
at net.sf.ehcache.store.disk.DiskStorageFactory$PersistentDiskWriteTask.call(DiskStorageFactory.java:1151)
at net.sf.ehcache.store.disk.DiskStorageFactory$PersistentDiskWriteTask.call(DiskStorageFactory.java:1135)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

Related

Connection closed while handshake in process with websockets

I have a problem when sending a message to a websocket server.
2020-06-15 17:06:51,830 INFO [snc.mob.gro.myt.con.ws.MutinyWebsocket] (vert.x-eventloop-thread-6) erreur {}: io.netty.handler.codec.http.websocketx.WebSocketHandshakeException: Connection closed while handsh
ake in process
at io.vertx.core.http.impl.WebSocketHandshakeInboundHandler.channelInactive(WebSocketHandshakeInboundHandler.java:57)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:260)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:246)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:239)
at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelInactive(CombinedChannelDuplexHandler.java:418)
at io.netty.handler.codec.ByteToMessageDecoder.channelInputClosed(ByteToMessageDecoder.java:386)
at io.netty.handler.codec.ByteToMessageDecoder.channelInactive(ByteToMessageDecoder.java:351)
at io.netty.handler.codec.http.HttpClientCodec$Decoder.channelInactive(HttpClientCodec.java:288)
at io.netty.channel.CombinedChannelDuplexHandler.channelInactive(CombinedChannelDuplexHandler.java:221)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:260)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:246)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:239)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelInactive(DefaultChannelPipeline.java:1405)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:260)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:246)
at io.netty.channel.DefaultChannelPipeline.fireChannelInactive(DefaultChannelPipeline.java:901)
at io.netty.channel.AbstractChannel$AbstractUnsafe$8.run(AbstractChannel.java:818)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:497)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
I tried with some chrome plugins and everything works fine.
Here is my code :
public void send(final String message){
WebSocketConnectOptions wsoptions = new WebSocketConnectOptions()
.setSsl(Boolean.FALSE).setURI( "/" ).setPort( 9304 ).setHost( "myserver.com" );
HttpClientOptions httpClientOptions = new HttpClientOptions( )
.setTrustAll( true ).setSsl( false );
Uni< WebSocket > webSocketUni = vertx.createHttpClient(httpClientOptions).webSocket( wsoptions );
webSocketUni
.subscribe()
.with( a -> {
a.handler( data -> {
log.info( "server message {}", data.toString() );
a.writeTextMessageAndForget( message );
} );
},
e -> log.info( "erreur {}", e ))
;
}
I don't know what's the handshake problem with my client.
Any help really appreciated.
Thank you!

CouchbaseException: INVALID_ARGUMENTS when using a counter

I have a springBoot 2.1.9.RELEASE application that uses Spring Data for Couchbase
But when I use the Atomic counters in Couchbase to Increment a counter with 1
bucket.counter(doc.getId(), 1);
I got an exception
com.couchbase.client.core.CouchbaseException: INVALID_ARGUMENTS
...Caused by: rx.exceptions.OnErrorThrowable$OnNextValue: OnError while emitting onNext value: com.couchbase.client.core.message.kv.CounterResponse.class
at rx.exceptions.OnErrorThrowable.addValueAsLastCause(OnErrorThrowable.java:118)
at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:73)
... 22 common frames omitted
I also have tried
try {
bucket.counter(docId, 1);
} catch (CouchbaseException e) {
if ("INVALID_ARGUMENTS".equalsIgnoreCase(e.getMessage())) {
LegacyDocument legacyDocument = rqmBucket.get(LegacyDocument.create(docId));
String s = legacyDocument.content().toString();
Long value = Long.parseLong(s) + 1;
bucket.upsert(JsonLongDocument.create(docId, value));
}
}
but I got at a java.lang.NumberFormatException because legacyDocument.content() gives me all the Json doc. :
"{"hostel":{"address":15..."

c3p0 error in spark streaming

i use c3po to connect jdbc(impala),but it failed.Could you give me help:)
ConnectPool.scala
class ConnectPool extends Serializable{
private val cpds: ComboPooledDataSource = new ComboPooledDataSource(true)
private val conf = Utils.getPropmap("env.properties")
try {
cpds.setJdbcUrl(conf("kudu.produce.url"))
cpds.setDriverClass(conf("jdbc.driver"))
cpds.setMaxPoolSize(400)
cpds.setMinPoolSize(20)
cpds.setAcquireIncrement(5)
cpds.setMaxStatements(380)
} catch {
case e: Exception => e.printStackTrace()
}
def getConnection: Connection = {
try {
return cpds.getConnection()
} catch {
case ex: Exception =>
ex.printStackTrace()
null
}
}
}
object ConnectManager {
var kuduManager: ConnectPool = _
def getConnectManager: ConnectPool = {
synchronized {
if (kuduManager == null) {
kuduManager = new ConnectPool
}
}
kuduManager
}
}
main.scala
messages.foreachRDD(rdd => {
val conn = ConnectManager.getConnectManager.getConnection
val stmt = conn.createStatement
if(!rdd.isEmpty() && rdd.count() >0){
//初始化spark
val spark = SparkSession.builder.config(rdd.sparkContext.getConf).getOrCreate()
try{
// use stmt
}catch {
case e: Exception => print("\ntest\n")
} finally {
stmt.close()
conn.close()}
}
})
out put
18/03/16 16:56:00 INFO c3p0.SQLWarnings:
[Simba]ImpalaJDBCDriver Error setting default connection
property values: {0} java.sql.SQLWarning:
[Simba]ImpalaJDBCDriver Error setting default connection
property values: {0}
at com.cloudera.jdbc.common.SWarningListener.createSQLWarning(Unknown
Source)
at com.cloudera.jdbc.common.SWarningListener.postWarning(Unknown Source)
at com.cloudera.jdbc.common.SConnection.(Unknown Source)
at com.cloudera.jdbc.common4.C4SConnection.(Unknown Source)
at com.cloudera.jdbc.jdbc41.S41Connection.(Unknown Source)
at com.cloudera.impala.jdbc41.ImpalaJDBC41Connection.(Unknown
Source)
at com.cloudera.impala.jdbc41.ImpalaJDBC41ObjectFactory.createConnection(Unknown
Source)
at com.cloudera.jdbc.common.BaseConnectionFactory.doConnect(Unknown
Source)
at com.cloudera.jdbc.common.AbstractDriver.connect(Unknown Source)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:119)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:143)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:132
The output you are seeing is a warning, not an error. c3p0 resets and prints any warnings that a Connection experiences prior to checking them back into the pool. This surprises developers sometimes, as very few developers bother to check for warnings, and so they often go unnoticed.
I don't know what this warning means, exactly. But JDBC Connection warnings often occur for nonserious conditions. Is your application working properly, besides the warning output?
If you decide you can live with the warnings, you can redirect them or shut them down by configuring the special logger com.mchange.v2.c3p0.SQLWarnings. Setting the log level of this logger to anything more severe than INFO will prevent the appearance of these messages.

Trying to get spark streaming to read data stream from website, what is the socket?

I am trying to get this data http://stream.meetup.com/2/rsvps into spark stream
They are JSON objects, I know the lines will be strings, I just want it to work before I try JSON.
I am not sure what to put as the port, I assume that is the problem.
SparkConf conf = new SparkConf().setMaster("local[2]").setAppName("Spark Streaming");
JavaStreamingContext jssc = new JavaStreamingContext(conf, Durations.seconds(1));
JavaReceiverInputDStream<String> lines = jssc.socketTextStream("http://stream.meetup.com/2/rsvps", 80);
lines.print();
jssc.start();
jssc.awaitTermination();
Here is my error
java.net.UnknownHostException: http://stream.meetup.com/2/rsvps
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at java.net.Socket.<init>(Socket.java:425)
at java.net.Socket.<init>(Socket.java:208)
The socketTextStream isn't designed to work as an http client. As you noticed, you will need to create a custom receiver, one potential place to start is based on the receiver created as part of the meetup streaming data source (see https://github.com/actions/meetup-stream/blob/master/src/main/scala/receiver/MeetupReceiver.scala ).
Here is a custom UrlReceiver which follows spark documentation on custom receivers:
class UrlReceiver(urlStr: String) extends Receiver[String](StorageLevel.MEMORY_AND_DISK_2) with Logging {
override def onStart() = {
new Thread("Url Receiver") {
override def run() = {
val urlConnection: URLConnection = new URL(urlStr).openConnection
val bufferedReader: BufferedReader = new BufferedReader(
new InputStreamReader(urlConnection.getInputStream)
)
var msg = bufferedReader.readLine
while (msg != null) {
if (!msg.isEmpty) {
store(msg)
}
msg = bufferedReader.readLine
}
bufferedReader.close()
}
}.start()
}
override def onStop() = {
// nothing to do
}
}
Then use it like this:
val lines = sc.receiverStream(new UrlReceiver("http://stream.meetup.com/2/rsvps"))

Plotting Image Histogram Using Androidplot

I m a beginner programmer, I am developing an android application which process an image and generate its histogram. I am using AndroidPlot to draw different color channels of an image in the histogram, but I'm having some errors and exceptions.
This is my code :
public class ImgHistogram extends Activity {
ImageView ImageView;
LinearLayout ll;
ImageView imgView;
private Bitmap source ;
private XYPlot xyPlot;
public XYSeries rSerie;
int[] intensities={
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,
101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,
201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255
} ;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.histo);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
imgView = (ImageView) findViewById(R.id.img);
Bundle bundle = this.getIntent().getExtras();
source=(Bitmap) bundle.getParcelable("img");
imgView.setImageBitmap(source);
// initialize our XYPlot reference:
xyPlot = (XYPlot) findViewById(R.id.xyplot);
Bitmap image = Bitmap.createBitmap(source.getWidth(),source.getHeight(), Bitmap.Config.ARGB_8888);
ArrayList<Integer> rVals = new ArrayList<Integer>();
for (int x = 0; x < image.getWidth(); x++) {
for (int y = 0; y < image.getHeight(); y++) {
int color = image.getPixel(x, y);
rVals.add((color >> 16) & 0xff); //red channel
}}
rSerie = new SimpleXYSeries(
rVals, SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "red channel");
// Create a formatter to format Line and Point of income series
LineAndPointFormatter format = new LineAndPointFormatter(
Color.rgb(0, 0, 255), // line color
Color.rgb(200, 200, 200), // point color
Color.rgb(10, 20, 20), // fill color (none)
null );
// add series to the xyplot:
xyPlot.addSeries(rSerie, format);
// Formatting the Domain Values ( X-Axis )
xyPlot.setDomainValueFormat(new Format() {
private static final long serialVersionUID = 1L;
#Override
public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
return new StringBuffer( intensities[ ( (Number)obj).intValue() ] );
}
#Override
public Object parseObject(String source, ParsePosition pos) {
return null;
}
});
xyPlot.setDomainLabel("");
xyPlot.setRangeLabel("");
// Increment X-Axis by 1 value
xyPlot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 1);
xyPlot.getGraphWidget().setRangeLabelWidth(50);
// Reduce the number of range labels
xyPlot.setTicksPerRangeLabel(2);
// Reduce the number of domain labels
xyPlot.setTicksPerDomainLabel(2);
// Remove all the developer guides from the chart
// xyPlot.disableAllMarkup();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
and this is the stack trace:
05-23 23:52:21.731: E/AndroidRuntime(30404): FATAL EXCEPTION: main
05-23 23:52:21.731: E/AndroidRuntime(30404): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dreamaker.magipixel/com.dreamaker.magipixel.processing.ImgHistogram}: java.lang.NullPointerException
05-23 23:52:21.731: E/AndroidRuntime(30404): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
05-23 23:52:21.731: E/AndroidRuntime(30404): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
05-23 23:52:21.731: E/AndroidRuntime(30404): at android.app.ActivityThread.access$700(ActivityThread.java:159)
05-23 23:52:21.731: E/AndroidRuntime(30404): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
05-23 23:52:21.731: E/AndroidRuntime(30404): at android.os.Handler.dispatchMessage(Handler.java:99)
05-23 23:52:21.731: E/AndroidRuntime(30404): at android.os.Looper.loop(Looper.java:137)
05-23 23:52:21.731: E/AndroidRuntime(30404): at android.app.ActivityThread.main(ActivityThread.java:5419)
05-23 23:52:21.731: E/AndroidRuntime(30404): at java.lang.reflect.Method.invokeNative(Native Method)
05-23 23:52:21.731: E/AndroidRuntime(30404): at java.lang.reflect.Method.invoke(Method.java:525)
05-23 23:52:21.731: E/AndroidRuntime(30404): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
05-23 23:52:21.731: E/AndroidRuntime(30404): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
05-23 23:52:21.731: E/AndroidRuntime(30404): at dalvik.system.NativeStart.main(Native Method)
05-23 23:52:21.731: E/AndroidRuntime(30404): Caused by: java.lang.NullPointerException
05-23 23:52:21.731: E/AndroidRuntime(30404): at com.dreamaker.magipixel.processing.ImgHistogram.onCreate(ImgHistogram.java:110)
05-23 23:52:21.731: E/AndroidRuntime(30404): at android.app.Activity.performCreate(Activity.java:5372)
05-23 23:52:21.731: E/AndroidRuntime(30404): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
05-23 23:52:21.731: E/AndroidRuntime(30404): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
05-23 23:52:21.731: E/AndroidRuntime(30404): ... 11 more
I hope that someone could help me!
Given the fact that in the line in question (ImgHistogram.java:110) you have only 1 object which could possibly cause the exception - xyPlot:
xyPlot.addSeries(rSerie, format);
This suggests that findViewByID returns null =< xyPlot is null. There is a question about this: findViewByID returns null the accepted answer should solve your problem:
Wait until onFinishInflate()

Resources