Mule School: Invoking Java Component over HTTP


Since Mule is built on and Spring, it has native integration capabilities to invoke Java and Spring components. In this tutorial, we shall learn how to pass request received from endpoint on to Java component and receive response.

Please complete Hello World lesson from last week before proceeding further.

First step, create a new project as described in the Hello World tutorial. Name the flow “java”.

Drag and drop the “HTTP” endpoint and “Echo” component as described in Hello World lesson. Double click on HTTP (Inbound Endpoint) and specify “java” for path field


Create a new Java class by clicking on File -> New -> Class.

Could not embed GitHub Gist 2031052: Bad credentials. The API can't be accessed using username/password authentication. Please create a personal access token to access this endpoint:

Drag and drop a “Java” component between HTTP (Inbound Endpoint) and Echo component. Double click on “Java” component to bring up properties dialog. Click the + symbol next to “Object” field and select “core:singleton-object” and for object type and class respectively. Click OK to save and close.

Open “Configuration XML” tab to see generated XML content.

Could not embed GitHub Gist 2031059: Bad credentials. The API can't be accessed using username/password authentication. Please create a personal access token to access this endpoint:

Hit Save All and run “java.mflow” as Mule Application (right click on the file). Access http://localhost:8081/java from browser to see “Hello /java” output. If you carefully observe, we didn’t explicitly specify which method to invoke from JavaMule class. Through reflection, Mule automatically tries to identify relevant Java method. Sometimes, we may need to explicitly map request to specific methods. We are going to explore how to do this in subsequent lessons.

[nggallery id=1]

We'd love to hear your opinion on this post

7 Responses to “Mule School: Invoking Java Component over HTTP”

  1. Cannot get this tutorial to work. Got the following error:
    ERROR 2012-03-22 10:26:56,270 [[learning_mule].connector.http.mule.default.receiver.02] org.mule.exception.DefaultMessagingExceptionStrategy:
    Message : Failed to find entry point for component, the following resolvers tried but failed: [
    CallableEntryPointResolver: Object “” does not implement required interface “interface org.mule.api.lifecycle.Callable”
    ReflectionEntryPointResolver: Could not find entry point on: “” with arguments: “{class java.lang.String}”
    MethodHeaderPropertyEntryPointResolver: The required property “method” is not set on the event
    AnnotatedEntryPointResolver: Component: doesn’t have any annotated methods, skipping.

    • Hi Daniel, this error suggests that Mule couldn’t find a method in “JavaMule” class with “String” parameter. Looks like this blog post was missing the definition for JavaMule class. I’ve corrected it now. Please update JavaMule class as described in the blog and run the flow again.

  2. Updated JavaMule as in the blog but still get the same error:
    Component that caused exception is: DefaultJavaComponent{javaFlow1.commponent.23999306}. Message payload is of type: String

  3. Forget my previous comment. It works now after I restart Mute Studio.


  4. […] the previous lesson Invoking Java Component Over HTTP, we learned how to invoke a simple method of a Java component in Mule Flow. Let’s now go a […]

  5. When I made this tutorial, I just added a second flow into the learningmule project from tut 1. Running the app with more than 1 flow doesnt seem to work. No listeners get registered, and I see an error/warning “This JVM wasnt styarted by wrapper” Is there a 1:1 mapping of flow to app?

    • Stuart, each Mule project can have multiple flows. Only flow names need to be unique. Doest the embeded Mule Server start when you try to run Mule Application? If yes, can you post error message you see on console.