0
votes

In my Spring Boot application with Spring Integration http outbound gateway, I got http error code 415. So I added a headerMapper bean to the configuration, but this throws NotWritablePropertyException. Message is property 'Content-Type' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

Configuration:

<int:gateway id="requestGateway"
    service-interface="org.myorg.springintegration.gateway.http.RequestGateway"
    default-request-channel="post_send_channel" />

<int:channel id="post_send_channel" />

<int:header-enricher input-channel="post_send_channel">
    <int:header name="Content-Type" value="application/json; charset=utf8"/>
</int:header-enricher>

<int-http:outbound-gateway
    request-channel="post_send_channel"
    url="http://localhost:8080/incomes" http-method="POST"
    expected-response-type="java.lang.String" />

Request Gateway

public interface RequestGateway {
    String echo(Map<String, String> request);
}

Main class

@SpringBootApplication
public class HttpApplication {

    public static void main(String[] args) {
        SpringApplication.run(HttpApplication.class, args);

        ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("http-outbound-gateway.xml");

        Map<String, String> postMap = new HashMap<String, String>();
        postMap.put("amount", "2000");
        postMap.put("description", "Second Income");

        RequestGateway rg = context.getBean("requestGateway", RequestGateway.class);
        System.out.println(rg.echo(postMap));

        context.close();
    }
}

UPDATE on 17-May-2018 After configuring a header-enricher as suggested by Artem Bilan, I now get the following error:

2018-05-17 12:30:48.354  INFO 4452 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : started _org.springframework.integration.errorLogger
[WARNING]
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run (AbstractRunMojo.java:496)
    at java.lang.Thread.run (Thread.java:748)
Caused by: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.util.HashMap<?, ?>] to type [java.lang.String]
    at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound (GenericConversionService.java:321)
    at org.springframework.core.convert.support.GenericConversionService.convert (GenericConversionService.java:194)
    at org.springframework.core.convert.support.GenericConversionService.convert (GenericConversionService.java:174)
    at org.springframework.integration.gateway.GatewayProxyFactoryBean.convert (GatewayProxyFactoryBean.java:755)
    at org.springframework.integration.gateway.GatewayProxyFactoryBean.invokeGatewayMethod (GatewayProxyFactoryBean.java:527)
    at org.springframework.integration.gateway.GatewayProxyFactoryBean.doInvoke (GatewayProxyFactoryBean.java:469)
    at org.springframework.integration.gateway.GatewayProxyFactoryBean.invoke (GatewayProxyFactoryBean.java:460)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (ReflectiveMethodInvocation.java:185)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke (JdkDynamicAopProxy.java:212)
    at com.sun.proxy.$Proxy79.echo (Unknown Source)
    at org.javacodegeeks.springintegration.gateway.http.HttpApplication.main (HttpApplication.java:24)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run (AbstractRunMojo.java:496)
    at java.lang.Thread.run (Thread.java:748)
1

1 Answers

1
votes

I guess you mean header-enricher before http:Outbound-Gateway. You need to populate such a header, meanwhile a mapper is about to add an existing header to the request or not.

See Reference Manual for more info: https://docs.spring.io/spring-integration/docs/5.0.4.RELEASE/reference/html/messaging-transformation-chapter.html#content-enricher