1

I am attempting a tutorial from the book 'MULE_ESB_COOKBOOK' by packt publishing and I have posted this question in another forum too. In the first chapter, there is a 'Deploying your first Hello World application on the Mule server' exercise which I am trying out. The expected output is Hello/(The value I enter as part of the url)

However when I run the application, I am getting the following error in the browser when I enter this: http://localhost:9081. The error message is as follow: "Component that caused exception is: DefaultJavaComponent{helloworldFlow.component.1468192631}. Message payload is of type: NullPayload"

The XML file is as follow:

 <?xml version="1.0" encoding="UTF-8"?>

 <mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
     xmlns:spring="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
 http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
 http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
     <http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="9081" doc:name="HTTP Listener Configuration"/>
     <flow name="helloworldFlow">
         <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
         <component class="com.org.Greeting" doc:name="Java"/>
     </flow>
 </mule>

The Greeting.java file is as follows:

package com.org;

public class Greeting {

     public String sayHi(String str)
     {
         return "Hello " +str;
     }

 }

I am not sure why I am getting this error. Hope someone can help, thanks.

utechtzs
  • 1,013
  • 5
  • 12
javaperson
  • 109
  • 1
  • 12
  • I'd ask for more of the tutorial, but it's dangerous posting published material on SO. This book is also from 2013, so I'm curious as to which AnypointStudio and Mule Runtime you're using. – utechtzs Nov 21 '18 at 19:07

2 Answers2

1

You Java class is wrong. To invoke a Java class in Mule 3.x it has to implement the Mule org.mule.api.lifecycle.Callable interface. See the example at https://docs.mulesoft.com/mule-runtime/3.9/java-component-reference#basic-hello-world-java-component-class

I'm guessing the complete error in the log points to the correct issue.

aled
  • 21,330
  • 3
  • 27
  • 34
  • That is not correct.. Why should he implement callable when mule 3.x can access the java method by setting the input payload? Yes there can be a issue in method resolver exception incase of multiple java method (can be resolved by method resolver in that case),but since it's only single method it will easily be picked and will display response. This is a valid java class. He can invoke this java class in different ways. The way he is doing now and adding input payload and also using spring beans with invoke component. He doesn't require callable interface. – Anirban Sen Chowdhary Nov 22 '18 at 11:48
0

This is expected because you are not passing any input to your Java class.
Try setting some input using set-payload component before java class component:

 <http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="9081" doc:name="HTTP Listener Configuration"/>
     <flow name="helloworldFlow">
         <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
         <set-payload value="Anirban" doc:name="Set Payload"/>
         <component class="com.org.Greeting" doc:name="Java"/>
     </flow>
Anirban Sen Chowdhary
  • 8,233
  • 6
  • 39
  • 81