compile-time error: illegal Character: \8279 - java

When I try to compile my servlet I get folowing exception:
illegal character: \8279
And it's pointing to &
msg.setContent("<a href=\"" + server +
":8080/myApp/ResetPasswordPage.jsp?randNum=" + randNum + ‌​
"&practiceName=" + practiceName+"\" Click Here </a>",
"text/html" );
I can't find a whole lot on the net about it...

I tried to copy this String to a java file in Eclipse. When I tried to save it I got :
There are 2 problematic invisible characters just after randNum +.
Remove them.

This is a dump of a copy-and-paste of your code:
00000010 3c 61 20 68 72 65 66 3d 5c 22 22 20 2b 20 73 65 |<a href=\"" + se|
00000020 72 76 65 72 20 2b 20 0a 20 20 20 20 20 20 20 20 |rver + . |
00000030 20 20 20 20 20 20 20 22 3a 38 30 38 30 2f 6d 79 | ":8080/my|
00000040 41 70 70 2f 52 65 73 65 74 50 61 73 73 77 6f 72 |App/ResetPasswor|
00000050 64 50 61 67 65 2e 6a 73 70 3f 72 61 6e 64 4e 75 |dPage.jsp?randNu|
00000060 6d 3d 22 20 2b 20 72 61 6e 64 4e 75 6d 20 2b 20 |m=" + randNum + |
00000070 e2 80 8c e2 80 8b 0a 20 20 20 20 20 20 20 20 20 |....... |
00000080 20 20 20 20 20 20 22 26 70 72 61 63 74 69 63 65 | "&practice|
00000090 4e 61 6d 65 3d 22 20 2b 20 70 72 61 63 74 69 63 |Name=" + practic|
000000a0 65 4e 61 6d 65 2b 22 5c 22 20 43 6c 69 63 6b 20 |eName+"\" Click |
Note the e2 80 8c and e2 80 8b between randNum + and the next line. You need to remove those.

Related

How to encode properly the plus sign (+) when making a request with webflux webclient?

I am trying to send an international formatted phone number using spring Webflux Webclient and to read this phone number via another application also using webflux.
My code looks like this :
webClient = WebClient.builder()
.baseUrl(baseUrl)
.build();
return webClient
.get()
.uri(uriBuilder -> uriBuilder
.path("/endpoint")
.queryParam("phone-number", "+33612345678")
.build()
)
.retrieve()
.bodyToMono(String.class);
Unfortunately, somewhere between this call and the receiver, the plus sign is replaced by a space.
The endpoint receives : " 33612345678" as a String.
The netty debug log of the request shows this :
+--------+-------------------------------------------------+----------------+
|00000000| 47 45 54 20 2f 63 75 73 74 6f 6d 65 72 73 3f 70 |GET /endpoint?p|
|00000010| 68 6f 6e 65 2d 6e 75 6d 62 65 72 3d 2b 33 33 36 |hone-number=+336|
|00000020| 31 32 33 34 35 36 37 38 26 6f 6e 6c 79 2d 72 65 |12345678
I tried to encode the phone-number by myself like this :
.queryParam("phone-number", UriUtils.encode("+34612345678", StandardCharsets.UTF_8))
And netty's log shows :
+--------+-------------------------------------------------+----------------+
|00000000| 47 45 54 20 2f 63 75 73 74 6f 6d 65 72 73 3f 70 |GET /endpoint?p|
|00000010| 68 6f 6e 65 2d 6e 75 6d 62 65 72 3d 25 32 35 32 |hone-number=%252|
|00000020| 42 33 34 36 31 32 33 34 35 36 37 38 20 48 54 54 |B34612345678 HTT|
It seems that the phone number has been encoded twice.
+ -> %2B -> %252B
the plus sign has been encoded by UriUtils.encode then uriBuilder has encoded the %.
The only way I found to make it work is by disabling the encoding of the UriBuilder :
DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory(baseUrl);
factory.setEncodingMode(DefaultUriBuilderFactory.EncodingMode.NONE);
this.webClient = WebClient.builder()
.baseUrl(baseUrl)
.uriBuilderFactory(factory)
.build();
and having my custom encoding UriUtils.encode("+34612345678", StandardCharsets.UTF_8)
in which case the netty's logs looks like expected :
+--------+-------------------------------------------------+----------------+
|00000000| 47 45 54 20 2f 63 75 73 74 6f 6d 65 72 73 3f 70 |GET /endpoint?p|
|00000010| 68 6f 6e 65 2d 6e 75 6d 62 65 72 3d 25 32 42 33 |hone-number=%2B3|
|00000020| 34 36 31 32 33 34 35 36 37 38 20 48 54 54 50 2f |4612345678 HTTP/|
And of course, the endpoint receiving the phone number get : "+33612345678"
To sum it up, it looks like the UriBuilder is encoding certain sign like "%" but does not encode the "+" sign.
Spring reference : https://docs.spring.io/spring-framework/docs/current/reference/html/web.html#web-uri-encoding
I struggled with same issue but found a workaround from the Spring reference you linked.
This should work for you:
return webClient
.get()
.uri(uriBuilder -> UriComponentsBuilder.fromUri(uriBuilder.build())
.path("/endpoint")
.queryParam("phone-number", "{phone-number}")
.encode()
.buildAndExpand("+33612345678")
.toUri()
)
.retrieve()
.bodyToMono(String.class);
I had the same issue and was able to resolve it in my Kotlin application using:
webClient.get()
.uri { uriBuilder ->
val queryParams = mapOf(
"phone-number" to "+33612345678",
"mobile-number" to "+61432111222"
)
uriBuilder.path("/endpoint")
.apply {
queryParams.keys.forEach { key ->
queryParam(key, "{$key}")
}
}
.build(queryParams)
}
.retrieve()
.bodyToMono<String>()
A solution provided here, you can try this way
DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory();
factory.setEncodingMode(DefaultUriBuilderFactory.EncodingMode.VALUES_ONLY);
URI uri = factory.uriString("https://spring.io/")
.queryParam("query", "{query}")
.build("spring+framework");
// http://spring.io/?query=spring%2Bframework

Blowfish decrypting hex encoded string

I'm trying to decrypt Hex encoded string via Blowfish. But the result is different from the correct one.
String s="a1d0534e4baf9e670bde8670caee8b87"
String decKey = "R=U!LH$O2B#";
Cipher m_decrypt = Cipher.getInstance("Blowfish/ECB/PKCS5Padding");
m_decrypt.init(Cipher.DECRYPT_MODE, new SecretKeySpec(decKey.getBytes(),"Blowfish"));
byte[] decrypted = m_decrypt.doFinal(Hex.decodeHex(s.toCharArray()));
Correct result from site: c6 b7 8d 52 31 35 30 34 31 38 38 36 39 37 02 02
My result: -58 -73 -115 82 49 53 48 52 49 56 56 54 57 55
I check the correct byte array with mine on this site http://blowfish.online-domain-tools.com/
The correect result: c6 b7 8d 52 31 35 30 34 31 38 38 36 39 37 02 02
is in hex encoding and contains two bytes of padding.
My result: -58 -73 -115 82 49 53 48 52 49 56 56 54 57 55
in in signed decimal encoding without the padding bytes.
They are the same value just in different encodings where "My result" has had the padding removed as is usual.

Extract .gz files in java

I'm trying to unzip some .gz files in java. After some researches i wrote this method:
public static void gunzipIt(String name){
byte[] buffer = new byte[1024];
try{
GZIPInputStream gzis = new GZIPInputStream(new FileInputStream("/var/www/html/grepobot/API/"+ name + ".txt.gz"));
FileOutputStream out = new FileOutputStream("/var/www/html/grepobot/API/"+ name + ".txt");
int len;
while ((len = gzis.read(buffer)) > 0) {
out.write(buffer, 0, len);
}
gzis.close();
out.close();
System.out.println("Extracted " + name);
} catch(IOException ex){
ex.printStackTrace();
}
}
when i try to execute it i get this error:
java.util.zip.ZipException: Not in GZIP format
how can i solve it? Thanks in advance for your help
Test a sample, correct, gzipped file to see whether the problem lies in your code or not.
There are many possible ways to build a (g)zip file. Your file may have been built differently from what Java's built-in support expects, and the fact that one uncompressor understands a compression variant is no guarantee that Java will also recognize that variant. Please verify exact file type with file and/or other uncompression utilities that can tell you which options were used when compressing it. You may also have a look at the file itself with a tool such as hexdump. This is the output of the following command:
$ hexdump -C lgpl-2.1.txt.gz | head
00000000 1f 8b 08 08 ed 4f a9 4b 00 03 6c 67 70 6c 2d 32 |.....O.K..lgpl-2|
00000010 2e 31 2e 74 78 74 00 a5 5d 6d 73 1b 37 92 fe 8e |.1.txt..]ms.7...|
00000020 ba 1f 81 d3 97 48 55 34 13 7b 77 73 97 78 2b 55 |.....HU4.{ws.x+U|
00000030 b4 44 d9 bc 95 25 2d 29 c5 eb ba ba aa 1b 92 20 |.D...%-)....... |
00000040 39 f1 70 86 99 17 29 bc 5f 7f fd 74 37 30 98 21 |9.p...)._..t70.!|
00000050 29 7b ef 52 9b da 58 c2 00 8d 46 bf 3c fd 02 d8 |){.R..X...F.<...|
00000060 da fe 3f ef 6f 1f ed cd 78 36 1b 4f ed fb f1 ed |..?.o...x6.O....|
00000070 78 3a ba b1 f7 8f ef 6e 26 97 96 fe 1d df ce c6 |x:.....n&.......|
00000080 e6 e0 13 f9 e7 57 57 56 69 91 db 37 c3 d7 03 7b |.....WWVi..7...{|
00000090 ed e6 65 93 94 7b fb fa a7 9f 7e 32 c6 5e 16 bb |..e..{....~2.^..|
In this case, I used standard gzip on this license text. The 1st few bytes are unique to GZipped files (although they do not specify variants) - if your file does not start with 1f 8b, Java will complain, regardless of remaining contents.
If the problem is due to the file, it is possible that other uncompression libraries available in Java may deal with the format correctly - for example, see Commons Compress
import com.horsefly.utils.GZIP;
import org.apache.commons.io.FileUtils;
....
String content = new String(new GZIP().decompresGzipToBytes(FileUtils.readFileToByteArray(fileName)), "UTF-8");
in case someone needs it.

Invalid session/connection in Openfire

We are running an openfire server with hazelcast plugin for clustering. Sometimes the client IP shows as null or Invalid session/connection in the XMPP Console, as shown in the image and when this is shown the clients get disconnected, and are never able to reconnect
The warn.log file shows:
2016.10.05 23:45:36 org.jivesoftware.openfire.nio.ConnectionHandler - Closing connection due to exception in session: (0x0002298E: nio
socket, server, null => 0.0.0.0/0.0.0.0:5222)
org.apache.mina.filter.codec.ProtocolDecoderException:
org.jivesoftware.openfire.nio.XMLNotWellFormedException: Character is
invalid in: ^V (Hexdump: 16 03 03 00 96 10 00 00 92 91 04 01 AC EF A4
1F 6D 28 E6 B0 99 33 B2 D6 87 2C 1B B1 DF 77 1E 1D D7 FB E5 47 7D 04
8A 5E B8 77 59 FA 31 80 68 BA C0 8C C8 A9 7E A0 7D 74 2D 68 EF E0 B1
35 32 05 1D EA 97 2B 27 CB A9 D8 38 6F C0 59 0C B4 AB AC 33 90 09 05
38 18 97 EC 6F 97 1E 7B 09 56 FD A8 CC B3 2B 15 CA 22 9B 8E 02 84 25
9F E7 90 72 2A 7D 84 12 10 4C 58 21 10 E6 C3 77 03 79 F0 4D 7C 7C 15
4C BD AD 24 72 7D B7 CD AD 53 4B 2F BF 3F AD E7 F0 D5 A4 2C 55 36 84
D0 74 14 03 03 00 01 01 16 03 03 00 40 95 06 24 78 2F 4A 9C 0D 92 22
EB 32 2A 03 13 35 4A 5A E6 44 2B 31 D7 48 99 4A BC AF 32 BE F5 D3 22
09 92 E2 1C 9E 14 EA 3D 76 93 31 D8 45 A1 D8 FB 46 E2 BD C6 42 59 E4
5B C2 24 73 77 01 DA 95)
at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:242)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:417)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(DefaultIoFilterChain.java:47)
at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:765)
at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:74)
at org.apache.mina.core.session.IoEvent.run(IoEvent.java:63)
at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:769)
at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:761)
at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:703)
at java.lang.Thread.run(Thread.java:745) Caused by: org.jivesoftware.openfire.nio.XMLNotWellFormedException: Character is
invalid in: ^V
at org.jivesoftware.openfire.nio.XMLLightweightParser.read(XMLLightweightParser.java:223)
at org.jivesoftware.openfire.nio.XMPPDecoder.doDecode(XMPPDecoder.java:41)
at org.apache.mina.filter.codec.CumulativeProtocolDecoder.decode(CumulativeProtocolDecoder.java:176)
at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:232)
... 9 more
2016.10.05 23:46:51 com.hazelcast.nio.tcp.ReadHandler - [172.31.29.146]:5701 [openfire] [3.5.1] hz.openfire.IO.thread-in-0
Closing socket to endpoint Address[172.31.20.168]:5701,
Cause:java.io.EOFException: Remote socket closed!
2016.10.05 23:46:52 com.hazelcast.nio.tcp.TcpIpConnectionMonitor - [172.31.29.146]:5701 [openfire] [3.5.1] Removing connection to
endpoint Address[172.31.20.168]:5701 Cause => java.net.SocketException
{Connection refused to address /172.31.20.168:5701}, Error-Count: 5
2016.10.05 23:46:57 com.hazelcast.nio.tcp.ReadHandler - [172.31.29.146]:5701 [openfire] [3.5.1] hz.openfire.IO.thread-in-1
Closing socket to endpoint Address[172.31.29.47]:5701,
Cause:java.io.EOFException: Remote socket closed!
2016.10.05 23:46:58 com.hazelcast.nio.tcp.TcpIpConnectionMonitor - [172.31.29.146]:5701 [openfire] [3.5.1] Removing connection to
endpoint Address[172.31.29.47]:5701 Cause => java.net.SocketException
{Connection refused to address /172.31.29.47:5701}, Error-Count: 5
2016.10.05 23:46:59 com.hazelcast.map.impl.BasicMapContextQuerySupport - [172.31.29.146]:5701 [openfire] [3.5.1] Could not get results java.util.concurrent.ExecutionException:
com.hazelcast.spi.exception.TargetNotMemberException: Not Member!
target:Address[172.31.29.47]:5701, partitionId: -1, operation:
com.hazelcast.map.impl.operation.QueryOperation, service:
hz:impl:mapService
at com.hazelcast.spi.impl.operationservice.impl.InvocationFuture.resolveApplicationResponseOrThrowException(InvocationFuture.java:357)
at com.hazelcast.spi.impl.operationservice.impl.InvocationFuture.get(InvocationFuture.java:225)
at com.hazelcast.spi.impl.operationservice.impl.InvocationFuture.get(InvocationFuture.java:204)
at com.hazelcast.map.impl.BasicMapContextQuerySupport.addResultsOfPredicate(BasicMapContextQuerySupport.java:350)
at com.hazelcast.map.impl.BasicMapContextQuerySupport.query(BasicMapContextQuerySupport.java:249)
at com.hazelcast.map.impl.proxy.MapProxySupport.query(MapProxySupport.java:1136)
at com.hazelcast.map.impl.proxy.MapProxyImpl.entrySet(MapProxyImpl.java:575)
at com.hazelcast.map.impl.proxy.MapProxyImpl.entrySet(MapProxyImpl.java:560)
at org.jivesoftware.openfire.plugin.util.cache.ClusteredCache.entrySet(ClusteredCache.java:117)
at org.jivesoftware.util.cache.CacheWrapper.entrySet(CacheWrapper.java:130)
at org.jivesoftware.openfire.spi.RoutingTableImpl.leftCluster(RoutingTableImpl.java:1065)
at org.jivesoftware.openfire.cluster.ClusterManager$2.run(ClusterManager.java:118)
Caused by: com.hazelcast.spi.exception.TargetNotMemberException: Not
Member! target:Address[172.31.29.47]:5701, partitionId: -1, operation:
com.hazelcast.map.impl.operation.QueryOperation, service:
hz:impl:mapService
at com.hazelcast.spi.impl.operationservice.impl.Invocation.initInvocationTarget(Invocation.java:298)
at com.hazelcast.spi.impl.operationservice.impl.Invocation.doInvoke(Invocation.java:222)
at com.hazelcast.spi.impl.operationservice.impl.Invocation.run(Invocation.java:262)
at com.hazelcast.spi.impl.operationservice.impl.TargetInvocation.run(TargetInvocation.java:29)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
at com.hazelcast.util.executor.HazelcastManagedThread.executeRun(HazelcastManagedThread.java:76)
at com.hazelcast.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:92)
at ------ End remote and begin local stack-trace ------.(Unknown Source)
at com.hazelcast.spi.impl.operationservice.impl.InvocationFuture.resolveApplicationResponse(InvocationFuture.java:384)
at com.hazelcast.spi.impl.operationservice.impl.InvocationFuture.resolveApplicationResponseOrThrowException(InvocationFuture.java:334)
... 11 more
2016.10.05 23:47:01 com.hazelcast.spi.EventService - [172.31.29.146]:5701 [openfire] [3.5.1] Error while logging processing
event java.lang.NullPointerException
at org.jivesoftware.util.StringUtils.getBytes(StringUtils.java:1098)
at org.jivesoftware.openfire.plugin.util.cache.CacheListener.handleEntryEvent(CacheListener.java:68)
at org.jivesoftware.openfire.plugin.util.cache.CacheListener.entryRemoved(CacheListener.java:60)
at com.hazelcast.map.impl.MapListenerAdaptors$2$1.onEvent(MapListenerAdaptors.java:83)
at com.hazelcast.map.impl.InternalMapListenerAdapter.onEvent(InternalMapListenerAdapter.java:51)
at com.hazelcast.map.impl.MapEventPublishingService.callListener(MapEventPublishingService.java:90)
at com.hazelcast.map.impl.MapEventPublishingService.dispatchEntryEventData(MapEventPublishingService.java:102)
at com.hazelcast.map.impl.MapEventPublishingService.dispatchEvent(MapEventPublishingService.java:46)
at com.hazelcast.map.impl.MapEventPublishingService.dispatchEvent(MapEventPublishingService.java:33)
at com.hazelcast.map.impl.MapService.dispatchEvent(MapService.java:91)
at com.hazelcast.map.impl.MapService.dispatchEvent(MapService.java:61)
at com.hazelcast.spi.impl.eventservice.impl.EventPacketProcessor.process(EventPacketProcessor.java:53)
at com.hazelcast.spi.impl.eventservice.impl.RemoteEventPacketProcessor.run(RemoteEventPacketProcessor.java:38)
at com.hazelcast.util.executor.StripedExecutor$Worker.process(StripedExecutor.java:190)
at com.hazelcast.util.executor.StripedExecutor$Worker.run(StripedExecutor.java:174)
The error.log shows
2016.10.05 23:47:13 org.jivesoftware.openfire.SessionManager - Could not close socket
com.hazelcast.core.HazelcastInstanceNotActiveException: Hazelcast
instance is not active!
at com.hazelcast.spi.AbstractDistributedObject.getService(AbstractDistributedObject.java:93)
at com.hazelcast.map.impl.proxy.MapProxySupport.toData(MapProxySupport.java:1122)
at com.hazelcast.map.impl.proxy.MapProxyImpl.remove(MapProxyImpl.java:178)
at org.jivesoftware.openfire.plugin.util.cache.ClusteredCache.remove(ClusteredCache.java:96)
at org.jivesoftware.util.cache.CacheWrapper.remove(CacheWrapper.java:145)
at org.jivesoftware.openfire.spi.RoutingTableImpl.removeClientRoute(RoutingTableImpl.java:903)
at org.jivesoftware.openfire.SessionManager.removeSession(SessionManager.java:1234)
at org.jivesoftware.openfire.SessionManager.removeSession(SessionManager.java:1206)
at org.jivesoftware.openfire.SessionManager$ClientSessionListener.onConnectionClose(SessionManager.java:1409)
at org.jivesoftware.openfire.nio.NIOConnection.notifyCloseListeners(NIOConnection.java:260)
at org.jivesoftware.openfire.nio.NIOConnection.close(NIOConnection.java:242)
at org.jivesoftware.openfire.nio.ConnectionHandler.exceptionCaught(ConnectionHandler.java:161)
at org.apache.mina.core.filterchain.DefaultIoFilterChain$TailFilter.exceptionCaught(DefaultIoFilterChain.java:672)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextExceptionCaught(DefaultIoFilterChain.java:461)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1100(DefaultIoFilterChain.java:47)
at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.exceptionCaught(DefaultIoFilterChain.java:760)
at org.apache.mina.core.filterchain.IoFilterAdapter.exceptionCaught(IoFilterAdapter.java:102)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextExceptionCaught(DefaultIoFilterChain.java:461)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1100(DefaultIoFilterChain.java:47)
at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.exceptionCaught(DefaultIoFilterChain.java:760)
at org.apache.mina.core.filterchain.IoFilterAdapter.exceptionCaught(IoFilterAdapter.java:102)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextExceptionCaught(DefaultIoFilterChain.java:461)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1100(DefaultIoFilterChain.java:47)
at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.exceptionCaught(DefaultIoFilterChain.java:760)
at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:93)
at org.apache.mina.core.session.IoEvent.run(IoEvent.java:63)
at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:769)
at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:761)
at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:703)
at java.lang.Thread.run(Thread.java:745)
2016.10.05 23:47:13 org.jivesoftware.openfire.nio.ConnectionHandler - Closing connection due to error while processing message: dXNlcm5hbWU9Ijk2NjUwNDgxMTkxOCIscmVhbG09InhtcHAuc2F5ZmVhcHAuY29tIixjbm9uY2U9ImY2MmM2OWMxOGU4ZWEzM2Y5NmRhY2I0ODU4YzhiNTQwNWU0ZDRiMzVmM2U4NWNmNjk0OGJmNWE5M2Q0MDAzNmIiLG5jPTAwMDAwMDAxLHFvcD1hdXRoLGRpZ2VzdC11cmk9InhtcHAveG1wcC5zYXlmZWFwcC5jb20iLHJlc3BvbnNlPTY3ODQ0MDM0ZjA5ZDc4YzQyODFmN2E1YzhmMGMyNDFhLGNoYXJzZXQ9dXRmLTgsbm9uY2U9IlpCME1CUVBwNFZsT2RxTWhIZTQwcWIxTHh4b1NoNkZwRDhRaXZKUm4i
com.hazelcast.core.HazelcastInstanceNotActiveException: Hazelcast
instance is not active!
at com.hazelcast.spi.AbstractDistributedObject.getService(AbstractDistributedObject.java:93)
at com.hazelcast.map.impl.proxy.MapProxySupport.toData(MapProxySupport.java:1122)
at com.hazelcast.map.impl.proxy.MapProxyImpl.get(MapProxyImpl.java:81)
at org.jivesoftware.openfire.plugin.util.cache.ClusteredCache.get(ClusteredCache.java:92)
at org.jivesoftware.util.cache.CacheWrapper.get(CacheWrapper.java:140)
at org.jivesoftware.openfire.lockout.LockOutManager.getUserLockOut(LockOutManager.java:244)
at org.jivesoftware.openfire.lockout.LockOutManager.getDisabledStatus(LockOutManager.java:152)
at org.jivesoftware.openfire.lockout.LockOutManager.isAccountDisabled(LockOutManager.java:163)
at org.jivesoftware.openfire.net.SASLAuthentication.authenticationSuccessful(SASLAuthentication.java:682)
at org.jivesoftware.openfire.net.SASLAuthentication.handle(SASLAuthentication.java:357)
at org.jivesoftware.openfire.net.StanzaHandler.process(StanzaHandler.java:191)
at org.jivesoftware.openfire.nio.ConnectionHandler.messageReceived(ConnectionHandler.java:180)
at org.apache.mina.core.filterchain.DefaultIoFilterChain$TailFilter.messageReceived(DefaultIoFilterChain.java:690)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:417)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(DefaultIoFilterChain.java:47)
at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:765)
at org.apache.mina.core.filterchain.IoFilterAdapter.messageReceived(IoFilterAdapter.java:109)
Kindly help me with this. Thanks!
Regards,
Iqbal

Java serialization with empty and substrings

Had a look at the implementation and haven't been able to think of an explanation to this but maybe someone here will know.
public static void main(String[] args) throws Exception {
List<String> emptyStrings = new ArrayList<String>();
List<String> emptySubStrings = new ArrayList<String>();
for (int i = 0; i < 20000; i++) {
String actuallyEmpty = "";
String subStringedEmpty = " ";
subStringedEmpty = subStringedEmpty.substring(0, 0);
emptyStrings.add(actuallyEmpty);
emptySubStrings.add(subStringedEmpty);
}
System.out.println("Substring test");
// Write to files
long time = System.currentTimeMillis();
writeObjectToFile(emptyStrings, "empty.list");
System.out.println("Time taken to write empty list " + (System.currentTimeMillis() - time));
time = System.currentTimeMillis();
writeObjectToFile(emptySubStrings, "substring.list");
System.out.println("Time taken to write substring list " + (System.currentTimeMillis() - time));
//Read from files
time = System.currentTimeMillis();
List<String> readEmptyString = readObjectFromFile("empty.list");
System.out.println("Time taken to read empty list " + (System.currentTimeMillis() - time));
time = System.currentTimeMillis();
List<String> readEmptySubStrings = readObjectFromFile("substring.list");
System.out.println("Time taken to read substring list " + (System.currentTimeMillis() - time));
}
private static void writeObjectToFile(Object o, String file) throws Exception {
FileOutputStream out = new FileOutputStream(file);
ObjectOutputStream oout = new ObjectOutputStream(out);
oout.writeObject(o);
oout.flush();
oout.close();
}
private static <T> T readObjectFromFile(String file) throws Exception {
ObjectInputStream ois = null;
try {
ois = new ObjectInputStream(new FileInputStream(file));
return (T) ois.readObject();
} finally {
ois.close();
}
}
Ultimately these 2 lists contain 20,000 empty strings (one list contains "" empty strings and the other contains empty strings generated by substring(0,0)). But if you check the sizes of the serialized files generated (empty.list and substring.list) you will notice that the empty.list contains substantially more data.
I have noticed that the callers of remote EJB's which un-serialize these substring objects seem to have severe performance issues also.
The sizes of the lists are different because java uses a mechanism to store multiples references to the same object, like described:
References to other objects (except in transient or static fields)
cause those objects to be written also. Multiple references to a
single object are encoded using a reference sharing mechanism so that
graphs of objects can be restored to the same shape as when the
original was written.
see ObjectOutputStream
If you look the generated serialized file, you will see:
With 1 String empty inside:
empty.list:
ac ed 00 05 73 72 00 13 6a 61 76 61 2e 75 74 69
6c 2e 41 72 72 61 79 4c 69 73 74 78 81 d2 1d 99
c7 61 9d 03 00 01 49 00 04 73 69 7a 65 78 70 00
00 00 01 77 04 00 00 00 01 74 00 00 78
The string "" corresponds to the last three bytes (00 00 78)
substring.list
ac ed 00 05 73 72 00 13 6a 61 76 61 2e 75 74 69
6c 2e 41 72 72 61 79 4c 69 73 74 78 81 d2 1d 99
c7 61 9d 03 00 01 49 00 04 73 69 7a 65 78 70 00
00 00 01 77 04 00 00 00 01 74 00 00 78
Note that with one element the resulted file is the same.
But if we want to add more times the same object, we will be faced with other behavior.
Look the respective files with 2 times that string.
empty.list:
ac ed 00 05 73 72 00 13 6a 61 76 61 2e 75 74 69
6c 2e 41 72 72 61 79 4c 69 73 74 78 81 d2 1d 99
c7 61 9d 03 00 01 49 00 04 73 69 7a 65 78 70 00
00 00 02 77 04 00 00 00 02 74 00 00 71 00 7e 00
02 78
substring.list
ac ed 00 05 73 72 00 13 6a 61 76 61 2e 75 74 69
6c 2e 41 72 72 61 79 4c 69 73 74 78 81 d2 1d 99
c7 61 9d 03 00 01 49 00 04 73 69 7a 65 78 70 00
00 00 02 77 04 00 00 00 02 74 00 00 74 00 00 78
Note that substring continues "normal", two non related strings with different references. But empty has some extra bytes to handle the issue of same reference.
Six bytes from substring (00 00 74 00 00 78) versus eight bytes from emptylist (00 00 71 00 7e 00 02 78)
This goes wrong because every repeated string that you add, more extra bytes are added. So when you full your arrayList there will be a lot of extra bytes to make it possible to reconstruct as it's original way.
If you want to know why there is that sharing mechanism, I suggest you to take a look at this question:
What is the meaning of reference sharing in Serialization? How Enums are Serialized?
empty.list contains one String object and lots of references to it.
substring.list contains 2000 string objects, all of them are equal in content.
You could "fix" this by intern()ing the strings.
private void verify(String name, Supplier<String> stringSupplier) throws IOException, ClassNotFoundException {
List<String> inputStrings = new ArrayList<String>();
inputStrings.add(stringSupplier.get());
inputStrings.add(stringSupplier.get());
ByteArrayOutputStream boas = new ByteArrayOutputStream();
ObjectOutputStream emptyOut = new ObjectOutputStream(boas);
emptyOut.writeObject(inputStrings);
emptyOut.flush();
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(boas.toByteArray()));
List<String> returnedStrings = (List<String>)ois.readObject();
if(returnedStrings.get(0) == returnedStrings.get(1)) {
System.out.println(name + " contains the same object");
} else {
System.out.println(name + " contains DIFFERENT objects");
}
}
#Test
public void test() throws IOException, ClassNotFoundException {
verify("empty string", new Supplier<String>() {
#Override
public String get() {
return "";
}
});
verify("sub string", new Supplier<String>() {
#Override
public String get() {
String data = " ";
return data.substring(0, 0);
}
});
verify("intern()ed substring", new Supplier<String>() {
#Override
public String get() {
String data = " ";
return data.substring(0, 0).intern();
}
});
}

Categories