My Spring integration configuration file having
<int-http:outbound-gateway request-channel="loadToFtpChannel"
url="http://localhost:8107/ftpService/processFTP"
http-method="POST" message-converters="ftpMessgaeConverter"
expected-response-type="java.lang.String">
</int-http:outbound-gateway>
<bean id="ftpMessgaeConverter" class="com.ftp.FTPMessgaeConverter" ></bean>
and FTPMessageConverter
class
public class FTPMessgaeConverter implements HttpMessageConverter<JSONObject> {
private static final List<MediaType> MEDIA_TYPES = new ArrayList<MediaType>();
static {
MEDIA_TYPES.add(MediaType.parseMediaType("application/json"));
}
@Override
public boolean canRead(Class<?> clazz, MediaType mediaType) {
// TODO Auto-generated method stub
return String.class.equals(clazz);
}
@Override
public boolean canWrite(Class<?> clazz, MediaType mediaType) {
// TODO Auto-generated method stub
return false;
}
@Override
public List<MediaType> getSupportedMediaTypes() {
// TODO Auto-generated method stub
return MEDIA_TYPES;
}
@Override
public JSONObject read(Class<? extends JSONObject> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {
JSONObject body = null;
try {
body = new JSONObject(inputMessage.getBody().toString());
} catch (JSONException e) {
e.printStackTrace();
}
return body;
}
@Override
public void write(JSONObject t, MediaType contentType, HttpOutputMessage outputMessage)
throws IOException, HttpMessageNotWritableException {
System.out.println("outputMessage " + outputMessage.getBody());
System.out.println("JSONObject " + t);
System.out.println("contentType " + contentType);
}
its throwing the error
org.springframework.web.client.RestClientException: Could not write request: no suitable HttpMessageConverter found for request type [org.json.JSONObject] and content type [application/json]
In request-channel="loadToFtpChannel"
I am getting the message in Json format, with this message I have to prepare the source and destination for<int-http:inbound-gateway>
and once inbound-gateway process the request, it will send the response back to outbound-gateway where I have to read the message through message-converters="ftpMessgaeConverter"
.
Can any one help on this. Thanks