Wednesday 19 August 2015

Textual Representation of logo

Error In Starting of Mule App

Some times Mule app failed to start , throwing weird exception like this :
org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'mule'.
        at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
        at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
        at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
        at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
        at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
        at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
        at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source)
        at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
        at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
        at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
        at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
        at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
        at org.mule.config.spring.MuleApplicationContext.loadBeanDefinitions(MuleApplicationContext.java:113)
        at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
        at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
        at org.mule.config.spring.SpringRegistry.doInitialise(SpringRegistry.java:89)
        at org.mule.registry.AbstractRegistry.initialise(AbstractRegistry.java:109)
        at org.mule.config.spring.SpringXmlConfigurationBuilder.createSpringRegistry(SpringXmlConfigurationBuilder.java:119)
        at org.mule.config.spring.SpringXmlConfigurationBuilder.doConfigure(SpringXmlConfigurationBuilder.java:73)
        at org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:46)
        at org.mule.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:78)
        at org.mule.config.builders.AutoConfigurationBuilder.autoConfigure(AutoConfigurationBuilder.java:101)
        at org.mule.config.builders.AutoConfigurationBuilder.doConfigure(AutoConfigurationBuilder.java:57)
        at org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:46)
        at org.mule.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:78)
        at org.mule.context.DefaultMuleContextFactory.createMuleContext(DefaultMuleContextFactory.java:84)
        at org.mule.module.launcher.application.DefaultMuleApplication.init(DefaultMuleApplication.java:207)
        at org.mule.module.launcher.application.ApplicationWrapper.init(ApplicationWrapper.java:64)
        at org.mule.module.launcher.DefaultMuleDeployer.deploy(DefaultMuleDeployer.java:47)
        at org.mule.module.launcher.MuleDeploymentService.guardedDeploy(MuleDeploymentService.java:420)
        at org.mule.module.launcher.MuleDeploymentService.start(MuleDeploymentService.java:186)
        at org.mule.module.launcher.MuleContainer.start(MuleContainer.java:160)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.mule.module.reboot.MuleContainerWrapper.start(MuleContainerWrapper.java:56)
        at org.tanukisoftware.wrapper.WrapperManager$12.run(WrapperManager.java:2788)
[28/01/2015 18:17:07 INFO  DefaultMuleApplication:197] App 'plum-slice-rest-api-3.3.4-SNAPSHOT' never started, nothing to dispose of
ERROR 2015-01-28 18:17:07,426 [WrapperListener_start_runner] org.mule.module.launcher.MuleDeploymentService:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Failed to deploy app                                     +
+ 'test', see below          +
The solution which you can try in this case pretty simple .
Just delete .mule folder
Post Comments and Suggestions !!

Thursday 6 August 2015

Textual description of firstImageUrl

Double Colon Operator in Java

Java 8 has introduced double colon (::) apart from lambda expressions. Let's see how does it work .

public class DoubleColonTest {
  
  interface MyInterface{
      public void interfaceMethod(String input);
  }
  
  public static void staticmethod(String input)
  {
    System.out.println(" static mymethod  " + input);
  }
  
  public void method1(String input)
  {
    System.out.println(" mymethod  " + input);
  }
  
  public static void main(String[] args) {
    DoubleColonTest obj = new DoubleColonTest();
    MyInterface dd = obj::method1;
    dd.interfaceMethod(" test string ");
    MyInterface second = DoubleColonTest::staticmethod;
    second.interfaceMethod(" test static string ");
      
    
  }

}
In this example , we have a functional interface with method name interfaceMethod , and we have a DoubleColonTest class which has two method which takes same parameters as interfaceMethod .Now this line :
MyInterface dd = obj::method1;
This line tells the compiler to create an implementation of MyInterface by applying the body of method1 defined in the DoubleColonTest class . Since this method is instance method , we need to use instance of class. This is called instance method reference .We can take static method reference also like this :
MyInterface second = DoubleColonTest::staticmethod;
So , now we can reference methods and reuse them again and again . We can also reference Constructor also , but we need to have a constructor which matches the interface method signature like this :
public DoubleColonTest(String in)
  {
    System.out.println(" constructor  " + in);
  }
Now to create an implementation of MyInterface , just need to write :
 MyInterface third = DoubleColonTest::new;
 third.interfaceMethod(" test string ");   
please post comments and suggestions !!!

Tuesday 4 August 2015

Textual Representation of logo

How Does Lambdas Work In Java

In this post , i will show how lambdas in java work , with a simple example .Consider the following code snipped using java lambda .
package java8Test;

import java.io.File;
import java.io.FileReader;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class LambdaTest2 {
  
  
  public static void main(String[] args) {
    
      ExecutorService service = Executors.newSingleThreadExecutor();
      service.submit(()-> {
        File f = new File("abcd.txt");
        FileReader reader = new FileReader(f);
        //use reader to read stuff
        return null ;
      });
  }
}
The above code compiles fine , now if you remove return statement(which seems redundant here) from above code , it fails to compile with following error :
Unhandled exception type FileNotFoundException
Reason for this behavior is , ExecutorService's submit method has two overloaded versions . One takes Callable , and the other one takes Runnable , Both methods have no arguments .

So , which one the java compiler chooses ?

It looks for return type as well . When you write return statement , it creates Callable and when you return nothing , it creates Runnable . Since Runnable does not throw Checked Exceptions , that is why you get compile time errors in the code .

You can explicitly cast it to Callable by using cast operator like this :
service.submit((Callable)()-> {
You can add marker interfaces also in the cast like this :
Callable calls = (Callable & Serializable) () -> { return null; };
Lambda Removes a lot of boilerplate code , but it might behave differently if you don't know how it works .
You can go to original link here