Skip to main content

Posts

Making Spray based ReST API publicly / remotely accessible

Recently I developed a demo Spray based ReST API and ran it on Windows. While I was able to access it locally using http://localhost:port/service link, but remotely I was not. I made following two changes to fix the issue: 1. In your application's application.conf file make hostname as 0.0.0.0 - 127.0.0.1 or localhost is foe listening only on the loopback interface. - 0.0.0.0 for listening on all available network interfaces. This works in Java 7 and 8 fine. In Java 6, only IPv4 address works. My application.conf looks like: akka { loglevel = DEBUG event-handlers = ["akka.event.slf4j.Slf4jEventHandler"] } spray.can.server { request-timeout = 10s } service { host = 0.0.0.0 port = 8090 } 2. Open 8090 (or whatever you want to use) port in Windows Firewall: http://windows.microsoft.com/en-gb/windows/open-port-windows-firewall#1TC=windows-7

SecurityException with Bouncy Castle

I am using BouncyCastle library to encrypt the data transfer with Kakfa. While my program run fine from IntelliJ, but when I package a fat JAR and run, it throws following exception: java.lang.SecurityException: JCE cannot authenticate the provider BC at javax.crypto.Cipher.getInstance(Cipher.java:657) at javax.crypto.Cipher.getInstance(Cipher.java:596) at com.xyz.abc.fusioncell.utils.CryptoService$class.decrypt(CryptoService.scala:63) at com.xyz.abc.fusioncell.Boot$.decrypt(Boot.scala:13) at com.xyz.abc.fusioncell.conf.Config$$anonfun$userId$1.apply(Config.scala:28) at com.xyz.abc.fusioncell.conf.Config$$anonfun$userId$1.apply(Config.scala:28) at scala.util.Try$.apply(Try.scala:192) at com.xyz.abc.fusioncell.conf.Config$class.userId(Config.scala:28) at com.xyz.abc.fusioncell.Boot$.userId$lzycompute(Boot.scala:13) at com.xyz.abc.fusioncell.Boot$.userId(Boot.scala:13) at com.xyz.abc.fusioncell.Boot$.main(Boot.scala:24) at com.xyz.abc.fu...

Akka: Printing list of actors

To print the list of actors that are running in the actor system, you can add following scheduler that will print actor path every 10 seconds: import akka.actor.{Actor, ActorIdentity, ActorLogging, ActorRef, Cancellable, Props} class TestActor extends Actor with ActorLogging { private var scheduler: Cancellable = _ @scala.throws[Exception](classOf[Exception]) override def preStart(): Unit = { import scala.concurrent.duration._ scheduler = context.system.scheduler.schedule( initialDelay = 0 seconds, interval = 10 seconds, receiver = self, message = ActorIdentity("", Some(self)) ) } @scala.throws[IOException](classOf[IOException]) override def postStop() = { scheduler.cancel } override def receive = { case ActorIdentity(_, Some(ref)) => log.info(ref.path.toString) } }

Terminating a run or test in Scala Build Tool (SBT)

When running a program or test in SBT, if you want to exit from it (and not from SBT) try adding following lines in your build.sbt file: fork := true To directly add forking in an SBT session, type set fork := true This will not detach and open a new consule from the original sbt console. But, users can kill this separately. The way to do this in Max OS or Windows is to search a Java process with command line having sbt-launch in Activity Monitor / Windows Task Manager, and end it. In Unix, try grepping a process with sbt-launch in a new terminal, and kill it. Command to do that is: kill -9 `ps -h | grep java | grep -v sbt-launch | grep -v grep | awk '{print $1}'` By default, the run or test tasks run in the JVM as sbt. Forking can be used to run these tasks in a child process. By default, a forked process uses the same Java and Scala versions being used for the build and the working directory and JVM options of the current process. SBT documentation page discusse...

Eclipse crashing and not starting

Problem: After restarting Eclipse, it crashes immediately and asks me to check C:\Users\username\Adobe Flash Builder 4.6\.metadata\.log In log it shows following error: !ENTRY org.eclipse.osgi 4 0 2013-02-13 11:53:46.760 !MESSAGE Application error !STACK 1 org.eclipse.swt.SWTError: Cannot initialize Drop     at org.eclipse.swt.dnd.DND.error(DND.java:266)     at org.eclipse.swt.dnd.DND.error(DND.java:227)     at org.eclipse.swt.dnd.DropTarget. (DropTarget.java:142)     at org.eclipse.ui.internal.EditorSashContainer.addDropSupport(EditorSashContainer.java:542)     at org.eclipse.ui.internal.EditorSashContainer.createControl(EditorSashContainer.java:534)     at org.eclipse.ui.internal.EditorAreaHelper. (EditorAreaHelper.java:41)     at org.eclipse.ui.internal.WorkbenchPage.init(WorkbenchPage.java:2507)     at org.eclipse.ui.internal.WorkbenchPage. (Workbench...

Preserving open nodes in AdvancedDataGrid with HierarchicalCollectionView

My dataProvider is an ArrayCollection, which is populated using XML. var initXML:XML = <items>    <item id="News" label="News" value_1="unchecked" value_2="unchecked" value_3="checked"/>    <item id="BBC" label="The Web" value_1="unchecked" value_2="unchecked" value_3="checked">        <item id="BBC1" label="BBC Homepage" value_1="unchecked" value_2="unchecked" value_3="checked">       <item id="YouTube" label="YouTube" value_1="unchecked" value_2="unchecked" value_3="checked"/>       <item id="GoogleMaps" label="Google Maps" value_1="unchecked" value_2="unchecked" value_3="checked"/>       <item id="MSN" label="MSN" value_1="unchecked" value_2="unchecked" valu...