I am looking for an Spring integration XML config that creates the payload object in a chain using one of the headers.
Java DSL has org.springframework.messaging.support.MessageBuilder.withPayload support that can create a message with payload, Can someone please share an XML configuration equivalent to this, which can set payload with a given header of the Message.
-Praveen
Clearly that is a Transformer responsibility and in pure xml you can do this:
<transformer expression ="headers.my_header_for_payload"/>
And the result of that SpEL becomes as a payload of output message from the transformer.
Related
I have a general question. We are upgrading some old code to v4.1.3 of spring-integration. Let's say we have a service activator that receives a domain object of type Foo, and returns the same object on the output channel (after changing some properties of that object).
Our existing code has signatures like below. Is it the right convention? If I don't need the headers, can I return my payload directly and will the framework wrap it into a Message?:
public Message<Foo> computeValue(Foo payload, #Headers Map<String, Object> headerMap) {
//...
return MessageBuilder.withPayload(payload).copyHeaders(headerMap).build();
}
Yes, you don't need do that. More over that is pointless because in case of Service Activator the Framework populates request headers to the reply message independently of your effort.
So, consider do not care about headers at all if you don't need to do some specific logic on the matter.
I would like to implement the following simple use case with Spring Integration v4.2+:
A REST endpoint is provided to clients, for example (/api/person).
The clients can POST data to this endpoint. The data can be submitted in JSON, XML or Google Protocol Buffers format.
The application accepts the data and saves it to a database table.
I have the following Spring Integration configuration that allows the endpoint to accept JSON data:
<int:channel id="receiveChannel"/>
<http:inbound-channel-adapter id="restInputAdapter"
channel="receiveChannel"
path="/api/person"
request-payload-type="java.util.Map"
supported-methods="POST"/>
<jdbc:outbound-channel-adapter id="jdbcOutputAdapter"
channel="receiveChannel"
data-source="dataSource"
query='INSERT INTO "person" ("first_name", "last_name", "email_address") VALUES (:payload[firstName], :payload[lastName], :payload[email])'/>
This is in a Maven project with Jackson2 on the classpath, which is why no special configuration is required for reading JSON from the request.
However, attempting to post XML data results in the following exception:
org.springframework.messaging.MessagingException: Could not convert request: no suitable HttpMessageConverter found for expected type [java.util.Map] and content type [application/xml]]
I have tried using the message-converters attribute with http:inbound-channel-adapter, specifying Jackson, JAXB and Protocol Buffers converters explicitly but that does not help either.
I know how to do this in a bespoke Spring MVC application with #RestControllers so I am not looking for solutions outside of Spring Integration.
How can the Spring Integration configuration above be tweaked so that the REST endpoint can be made to accept JSON, XML and Google Protocol Buffers at the same time?
It seems that although JSON converts to java.util.Map, XML does not. This is why the seen error.
I created a class:
#XmlRootElement class Person { ... }
and then modified the configuration as follows (only changes shown):
<http:inbound-channel-adapter ...
request-payload-type="Person"
.../>
<jdbc:outbound-channel-adapter ...
query='INSERT INTO "person" ("first_name", "last_name", "email_address") VALUES (:payload.firstName, :payload.lastName, :payload.email)'
.../>
I can now post both XML and JSON data to the endpoint.
Google Protocol Buffers support can now be added using the Protostuff library.
In Mule ESB I want to validate incoming SOAP/XML, using a standard Mule "schema-validation filter".
Something like:
<mulexml:schema-validation-filter schemaLocations="xxx.xsd" name="xxxValidationFilter"/>
However this kind of definition seem to assume that the schema is located in a separate xsd-file, whereas in a lot of cases the schema definition is embedded in the "wsdl:types" element of a wsdl-file.
Is there any way to use the Mule schema-validation-filter to validate against schema's which are embedded in the wsdl (except for copying the schema element definitions out of the
wsdl and into a separate xsd-file).
Mule service element tags which expose the service haave an attribute that can enable validation on the incoming request.
validationEnabled="true"
<cxf:simple-service validationEnabled="true"/>
<cxf:jaxws-service validationEnabled="true"/>
<cxf:proxy-service validationEnabled="true"/>
For more information refer to the following Mule documentation link.
http://www.mulesoft.org/documentation/display/current/Building+Web+Services+with+CXF
Hope this helps.
I need to create a new content type in orchard cms that will only have a field indicating a json url to be consumed.
My question is how to consume json in content-type and return the data consumed.
Thanks
You need to issue a web request using eg. RestSharp (or built-in WebClient class) and return deserialized data. RestSharp already has a JSON deserializer built-in, but if you need more robust solution you can use JSON.NET.
The request would be best done in one of the content part handler events (eg. OnLoaded) - just set a value of some property on your custom part to the returned data from there.
I want to implement a webservice client using Spring WS JAXB and CXF.
I use CXF to generate my Stubs from a WSDL file.
This WSDL contains the following schema :
For this schema the only thing that cxf generates is an ObjectFactory and no stub.
I want to use Spring Ws marshalSendAndReceive method to send a request to my service but I don't know how to construct my request object from what was generated with CXF.
Someone can help ?
thx
You don't really need CXF to generate the JAXB types from the WSDL file, JDK comes with a tool called xjc which can do this for you - http://docs.oracle.com/javase/6/docs/technotes/tools/share/xjc.html
Can you try using this and see if the artifacts created with this tool suffice.