0
votes

I have a requirement of exposing a REST webservice in Mule .. I have the following Mule :-

<flow name="MainService" doc:name="MainService">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" doc:name="HTTP" contentType="application/json"/>
<logger  level="INFO" doc:name="RequestLogger" message="#[message.inboundProperties['http.context.path']]     #[message.inboundProperties['http.request']] "/>
<set-property propertyName="HTTP_REQUEST_PROPERTY" value=" #[message.inboundProperties['http.request']]" doc:name="Property"/>
<set-property propertyName="HTTP_CONTEXT_PATH_PROPERTY" value="#[message.inboundProperties['http.context.path']]" doc:name="Property"/>

<mulexml:object-to-xml-transformer acceptMuleMessage="true" doc:name="Object to XML"/>
<logger message="Pay :- #[message.payload]" level="INFO" doc:name="Logger"/>
<vm:outbound-endpoint exchange-pattern="request-response" path="Flow1-WT-Main" doc:name="VM"/>
<logger message="ResponseLog :- #[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
</flow>

<flow name="testFlow1" doc:name="testFlow1" initialState="started">
<vm:inbound-endpoint exchange-pattern="request-response" path="Flow1-WT-Main" doc:name="VM"/> 
<mulexml:xml-to-object-transformer doc:name="XML to Object"/>
<jersey:resources doc:name="REST">
<component class="com.test.services.schema.maindata.v1.Impl.MainDataImpl">
   <method-entry-point-resolver>
        <include-entry-point method="retrieveDataOperation"/>
        <include-entry-point method="insertDataOperation"/>
        <include-entry-point method="updateDataOperation"/>
        <include-entry-point method="deleteDataOperation"/>
   </method-entry-point-resolver>
</component>
</jersey:resources>
</flow>

Now .. whenever I am running the application and triggering the webservice I am getting following Exception :-

ERROR 2014-08-11 19:23:27,861 [[RESTWebServiceWithVM].connector.http.mule.default.receiver.02] org.mule.exception.DefaultMessagingExceptionStrategy: 
********************************************************************************
Message               : Failed to invoke JerseyResourcesComponent{testFlow1.component.1947219057}. Component that caused exception is: JerseyResourcesComponent{testFlow1.component.1947219057}. Message payload is of type: String
Code                  : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. null (java.lang.NullPointerException)
  org.mule.module.jersey.JerseyResourcesComponent:116 (null)
2. Failed to invoke JerseyResourcesComponent{testFlow1.component.1947219057}. Component that caused exception is: JerseyResourcesComponent{testFlow1.component.1947219057}. Message payload is of type: String (org.mule.component.ComponentException)
  org.mule.component.AbstractComponent:144 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/component/ComponentException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.lang.NullPointerException
    at org.mule.module.jersey.JerseyResourcesComponent.doInvoke(JerseyResourcesComponent.java:116)
    at org.mule.component.AbstractComponent.invokeInternal(AbstractComponent.java:122)
    at org.mule.component.AbstractComponent.access$000(AbstractComponent.java:57)
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************

INFO  2014-08-11 19:23:27,907 [[RESTWebServiceWithVM].connector.http.mule.default.receiver.02] org.mule.api.processor.LoggerMessageProcessor: ResponseLog :- {NullPayload}

After debugging the application .. it was found that it is getting a Null value for HTTP_REQUEST_PROPERTY and HTTP_CONTEXT_PATH_PROPERTY from the payload coming from VM inbound endpoint .. For that reason I tried to set HTTP_CONTEXT_PATH_PROPERTY and HTTP_REQUEST_PROPERTY explicitly in the first flow like the following :-

<set-property propertyName="HTTP_REQUEST_PROPERTY" value=" #[message.inboundProperties['http.request']]" doc:name="Property"/>
<set-property propertyName="HTTP_CONTEXT_PATH_PROPERTY" value="#[message.inboundProperties['http.context.path']]" doc:name="Property"/>

But still it's throwing the same exception .. If it is a Bug in Mule .. is there any work around ??? Is it possible to expose a REST webservice configuring with VM ?? Please help

1
Can you try adding acceptMuleMessage="true" to the mulexml:xml-to-object-transformer and removing the two set-property?David Dossot
Hi David ... <mulexml:xml-to-object-transformer doc:name="XML to Object" acceptMuleMessage="true"/> throws following exception :- cvc-complex-type.3.2.2: Attribute 'acceptMuleMessage' is not allowed to appear in element 'mulexml:xml-to-object-transformer'. ... Does it not have that property ?Anirban Sen Chowdhary

1 Answers

2
votes
  • Remove both XML transformers
  • Remove the two set-property
  • Add: <copy-properties propertyName="http.*" doc:name="Copy All HTTP Headers"/> between HTTP inbound and VM outbound.