How to expose a web-service with cxf:proxy-service - java

I am trying to expose a simple greeting web-service using "cxf:proxy-service" in mule. Given below is my flow.
<flow name="WS_In">
<http:inbound-endpoint address="http://localhost:8080/HelloService" exchange-pattern="request-response">
<cxf:proxy-service wsdlLocation="classpath:HelloService.wsdl" namespace="http://example.org/HelloService"/>
</http:inbound-endpoint>
<component>
<prototype-object class="com.example.ServiceProxy">
</prototype-object>
</component>
<echo-component></echo-component>
<logger level="INFO" />
</flow>
But it giving me error as below:
2013-01-03 16:13:35,569 ERROR [main] construct.AbstractFlowConstruct (AbstractFlowConstruct.java:180) - Failed to stop service: WS_In
org.mule.api.lifecycle.LifecycleException: Lifecycle Manager 'WS_In.stage1' phase 'start' does not support phase 'dispose'
My ServiceProxy calss is as below
public class ServiceProxy implements Callable, Initialisable
Please help me understand where I am missing the path.

Instead of attribute 'name' in <cxf:proxy-service> element, use attribute 'service' to specify service name.

Try this out ...
Get the service name from your WSDL and use it in cxf:proxy-service
User the class direclty in component.
....
<flow name="WS_In">
<http:inbound-endpoint address="http://localhost:8080/HelloService" exchange-pattern="request-response">
<cxf:proxy-service wsdlLocation="classpath:HelloService.wsdl" namespace="http://example.org/HelloService" service="HelloService"/>
</http:inbound-endpoint>
<component class="com.example.ServiceProxy" />
<echo-component></echo-component>
<logger level="INFO" />
</flow>

Related

Maintaining Mule Message

Similar to this discussion Maintain Payload State during mule flow execution
I would like to know how to maintain an entire Mule Message throughout my flow.
I am trying to call a jersey resource component after I have received information that the user is authorized to call it. In this authorization request the payload and original http request gets altered.
My predicament is that I don't want to call the resource first as that would be inefficient and insecure however I cannot see any other plausible way to do this.
<flow name="test">
<http:inbound-endpoint exchange-pattern="request-response" host="0.0.0.0" port="1234" path="test" doc:name="HTTP"/>
<!-- sub-flow here which changes the MuleMessage and loses all original inbound properties -->
<jersey:resources doc:name="REST">
<component class="com.Test" />
</jersey:resources>
</flow>
Thanks for any help in advance
Mule 3 includes two scopes that will allow you to preserve the original message, while executing other message processors:
If you must wait for the sub-flow to complete because you need to use information produced by the sub-flow, use a message enricher like so. This example assigns the variable "authorized" to whatever the payload is once the sub-flow finishes processing the message.
<enricher target="#[variable:authorized]">
<flow-ref name="checkAuthorization" />
</enricher>
If you do not need to wait for the sub-flow to complete before allowing your Jersey Resource to run, use the async scope like so:
<async>
<flow-ref name="goForthAndDoSomething" />
</async>
There are multiple ways to save a mule message and it's properties so that it could be retrieve when required .. In your case you could save the entire Mule message in a variable and retrieve it when required for example :
<flow name="test">
<http:inbound-endpoint exchange-pattern="request-response" host="0.0.0.0" port="1234" path="test" doc:name="HTTP"/>
<!-- You save your entire message in a session variable named entireMessage before calling a subflow-->
<set-session-variable variableName="entireMessage" value="#[message.payload]" />
<!-- You can now call your Sub flow -->
<jersey:resources doc:name="REST">
<component class="com.Test" />
</jersey:resources>
</flow>
Here in the above flow you store your Mule message in a session variable named entireMessage .. You can easily retrieve the value of this session variable whenever you need in any flow anywhere like the following :-
<logger level="INFO" message="#[sessionVars['entireMessage']]"/>
This will print you Mule message
There is also an alternative way to store the http headers before it get altered ..
you can also use the following :-
<flow name="test">
<http:inbound-endpoint exchange-pattern="request-response" host="0.0.0.0" port="1234" path="test" doc:name="HTTP"/>
<!-- You copy all the HTTP headers before calling a subflow-->
<copy-properties propertyName="http.*" doc:name="Copy All HTTP Headers"/>
<!-- You can now call your Sub flow -->
<jersey:resources doc:name="REST">
<component class="com.Test" />
</jersey:resources>
</flow>
The above flow will copy all the HTTP headers before calling any other flow
UPDATED FLOW :-
If you need the original unaltered payload for your Jersy component , please overwrite the current payload with the original payload stored in session variable using set payload component
<flow name="test">
<http:inbound-endpoint exchange-pattern="request-response" host="0.0.0.0" port="1234" path="test" doc:name="HTTP"/>
<!-- You save your entire message in a session variable named entireMessage before calling a subflow-->
<set-session-variable variableName="entireMessage" value="#[message.payload]" />
<!-- You can now call your Sub flow -->
<!-- overwrite current payload with original unaltered payload -->
<set-payload value="#[sessionVars['entireMessage']]" doc:name="Set Payload"/>
<jersey:resources doc:name="REST">
<component class="com.Test" />
</jersey:resources>
</flow>
Try somthing like this to store the original message in session:
<message-properties-transformer scope="session" doc:name="Save original message">
<add-message-property key="originalMessage" value="#[message:payload]"></add-message-property>
</message-properties-transformer>
Then try something like this to get it from session:
<expression-transformer evaluator="..." expression="SESSION:originalMessage" doc:name="Restore original message"></expression-transformer>
Thanks for all your help. The final solution answer was:
<flow name="test">
<http:inbound-endpoint exchange-pattern="request-response" host="0.0.0.0" port="1234" path="test" doc:name="HTTP"/>
<enricher target="#[variable:unwantedPayload]" source="#[payload]">
<flow-ref name="anotherFlowCalled" />
</enricher>
<jersey:resources doc:name="REST">
<component class="com.Test" />
</jersey:resources>
</flow>
best way to store the mule message into session , whether you flow contains subflows are private flow session vars carry till end of the execeution.

Obtaining Mule Variable Values in Java

In Mule 3.4, how do I obtain the value of the Mule variable set from the "set-variable" tag in Java? Also how do I obtain values of Mule variables in different flows such as counter in flow1 and prevCounter in flow2? I can't find this on Mule's website.
Below is the Mule XML:
<mule xmlns:smtp="http://www.mulesoft.org/schema/mule/smtp" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:mongo="http://www.mulesoft.org/schema/mule/mongo" xmlns:quartz="http://www.mulesoft.org/schema/mule/quartz" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core" version="EE-3.4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd
http://www.mulesoft.org/schema/mule/mongo http://www.mulesoft.org/schema/mule/mongo/2.0/mule-mongo.xsd
http://www.mulesoft.org/schema/mule/quartz http://www.mulesoft.org/schema/mule/quartz/current/mule-quartz.xsd
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://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/smtp http://www.mulesoft.org/schema/mule/smtp/current/mule-smtp.xsd">
<quartz:connector name="Quartz3" validateConnections="true" doc:name="Quartz"/>
<flow name="flow1" doc:name="flow1">
<set-variable variableName="#['counter']" value="#[0]" doc:name="Variable"/>
<flow-ref name="flow2" doc:name="Flow Reference"/>
</flow>
<flow name="flow2" doc:name="flow2">
<logger level="INFO" doc:name="Logger"/>
<set-variable variableName="prevCounter" value="#[flowVars['counter']]" doc:name="Variable"/>
<set-variable variableName="counter" value="#[flowVars['counter']+1]" doc:name="Variable"/>
<choice doc:name="Choice">
<when expression="#[flowVars['counter']==5]">
<logger level="INFO" doc:name="Logger"/>
</when>
<otherwise>
<flow-ref name="flow2" doc:name="Flow Reference"/>
</otherwise>
</choice>
</flow>
</mule>
You can get them from the Mule message with message.getInvocationProperty('counter').
Flow variables exist only during the flow of a message, so you can only access what was declared before in the same flow (or the flow that calls the current flow like you are doing right there in flow2). If you need them somewhere outside of the flow, you have to send them there from the flow.
Values stored with set-variable can be retrieved with MEL as flowVars['varName'].
Take a look at this:
http://blogs.mulesoft.org/wp-content/uploads/2012/12/refcard-mel.pdf
Please try to create session variable or Flow variable in java and to retrive them in java MEL wont support you should use syntax some thing like message.getInvocationProperty('name') if those are flow variables.

Mule - Set properties on spring object call in Mule flow

I'm using Mule 3.3.CE
I have a Class called SpringObject which implements Callable interface
package com.threads.test;
import org.mule.api.MuleEventContext;
import org.mule.api.lifecycle.Callable;
public class SpringObject implements Callable {
private String someData;
public String getSomeData() {
return someData;
}
public void setSomeData(String someData) {
this.someData = someData;
}
#Override
public Object onCall(MuleEventContext eventContext) throws Exception {
System.out.println("CALL SPRING --->>"+someData);
return eventContext.getMessage();
}
}
And my flow is
<http:connector name="httpConnectorEntryPoint" doc:name="HTTP\HTTPS"/>
<spring:beans xmlns="http://www.springframework.org/schema/beans">
<spring:bean id="component" name="component" class="com.threads.test.SpringObject" lazy-init="false">
</spring:bean>
</spring:beans>
<flow name="TestThreadsFlow1" doc:name="TestThreadsFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8099" path="m" connector-ref="httpConnectorEntryPoint" doc:name="HTTP"/>
<set-payload value="#["ExitA"]" doc:name="Set Payload"/>
<component doc:name="Java">
<spring-object bean="component">
<property key="someData" value="Information"/>
</spring-object>
</component>
</flow>
The problem is that when I run my flow and use the http connector, the console shows
CALL SPRING --->>null
instead of
CALL SPRING --->>Information
What could be?
you can try to configure your spring bean outside the flow as follow:
<spring:bean id="component" name="component"
class="com.threads.test.SpringObject" lazy-init="false">
<spring:property name="someData" value="Information" />
</spring:bean>
and inside the flow do:
<component>
<spring-object bean="component" />
</component>
From the property element description in the XSD:
Sets a Mule property. This is a name/value pair that can be set on
components, services, etc., and which provide a generic way of
configuring the system. Typically, you shouldn't need to use a generic
property like this, since almost all functionality is exposed via
dedicated elements. However, it can be useful in configuring obscure
or overlooked options and in configuring transports from the generic
endpoint elements.
This means it's not intended for what you are trying to use it. The appropriate way to set a property in your bean is as follows:
<spring:bean id="component" name="component" class="com.threads.test.SpringObject" lazy-init="false">
<spring:property name="someData" value="Information"/>
</spring:bean>

Mule session-variable missing from the message, when reading from JMS Queue inside a Component

I have requirement where in I need to read message from a JMS Queue from inside a Component.
But during this process the session variables associated with the message are missing.
But the session variables are available when the same message is read from JMS:inbound-endpoint instead of from inside a component.
Here are my sample flows.
Main flow sets a session-variable into MuleMessage and posts it onto a JMS:outbound-endpoint
<flow name="main-flow" >
<some inbound>
...
< Some processing >
<set-session-variable .... />
...
<jms:outbound-endpoint queue="myQueue1">
</flow>
When the message is read from a JMS:inbound-endpoint the session variable can be seen in the message.
<flow name="second-flow" >
<jms:inbound-endpoint queue="myQueue1" />
<logger level="INFO" />
...
< some processing />
</flow>
But when the message is read from the Component polling the JMS:queue the session variable is missing.
<flow name="third-flow" >
<quartz:inbound-endpoint repeat-interval="5 mins" />
....
<component>
<spring-object bean="MyComponent"/>
</component>
....
</flow>
MyComponent class's onCall method has the following code to read from the JMS queue.
String reqURL = "jms://" + queueName ;
muleMessage = eventContext.requestEvent(reqURL, 1000);
But the session variable is not present in the Mule Message.

Why am I not getting the changed payload after consuming JMS queue in Mule?

i've made a flow with JMS using ActiveMQ, i send a message to the queue, but for any reason when im trying to consume from the queue, get the message and change it by setting the new payload, it doesn't change. What am i doing wrong?
Basically i want to send back the changed payload through HTTP response
Here's my code:
<jms:activemq-connector name="Active_MQ"
specification="1.1"
brokerURL="tcp://localhost:61616"
validateConnections="true"
doc:name="Active MQ"
persistentDelivery="true"
/>
<flow name="jmsFlow1" doc:name="jmsFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="jms" doc:name="HTTP"/>
<set-payload value="#['This is a message test']" doc:name="Set Payload"/>
<choice doc:name="Choice">
<when expression="#[true]">
<processor-chain>
<logger message="Im here!!" level="INFO" doc:name="Logger"/>
<jms:outbound-endpoint queue="StudioIN" connector-ref="Active_MQ" doc:name="JMS Queue Studio IN" exchange-pattern="request-response"/>
</processor-chain>
</when>
</choice>
<logger message="#[payload]" level="INFO" category="//// RETURNED FROM QUEUE PAYLOAD" doc:name="Logger"/>
</flow>
<flow name="fmsAdapterConsumerFlow1" doc:name="fmsAdapterConsumerFlow1">
<jms:outbound-endpoint queue="StudioIN" connector-ref="Active_MQ" doc:name="JMS StudioIN Consumer" exchange-pattern="request-response"/>
<set-payload value="#[payload + ' returned from queue']" doc:name="Set Payload"/>
</flow>
You don't specify the exchange-pattern on the jms:outbound-endpoint and jms:inbound-endpoint. Therefore Mule uses the default, which is one-way. So it's impossible that the payload change made in fmsAdapterConsumerFlow1 get replied to jmsFlow1.
Set exchange-pattern="request-response" on both JMS endpoints and also set disableTemporaryReplyToDestinations="false" on the connector otherwise you'll never receive any response.
The second flow mentioned above is to be changed.
This flow starts with a inbound-endpoint if it has to read a message and process it.
<flow name="fmsAdapterConsumerFlow1" doc:name="fmsAdapterConsumerFlow1">
<jms:inbound-endpoint queue="StudioIN" connector-ref="Active_MQ" doc:name="JMS StudioIN Consumer" exchange-pattern="request-response"/>
<set-payload value="#[payload + ' returned from queue']" doc:name="Set Payload"/>
</flow>
Hope this helps.

Categories

Resources