spring httpinvoker client can not find the service

2019-09-15 14:12发布

I have following configuration for the web application.

web.xml

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        classpath:mail-application-context.xml
....
    </context-param>
....
<servlet> 
<servlet-name>mailbox</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>mailbox</servlet-name>
        <url-pattern>*.htm</url-pattern>
</servlet-mapping>

mailbox-servlet.xml

    <bean name="remoteProvisioningServiceImpl" class="pw.domain.service.RemoteProvisioningServiceImpl"/>

<bean name="/remote/domain/provision.htm" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
    <property name="service" ref="remoteProvisioningServiceImpl" />
    <property name="serviceInterface" value="pw.domain.service.RemoteProvisioningService" />
</bean>

I have the clients configured properly, like following, in mail-application-context.xml

    <bean id="remoteProvisioningService1" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
    <property name="serviceUrl" value="http://${mailapp.dc.host.1.url}/remote/domain/provision.htm" />
    <property name="serviceInterface" value="pw.domain.service.RemoteProvisioningService" />
</bean> 

<bean id="remoteProvisioningService2" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
    <property name="serviceUrl" value="http://${mailapp.dc.host.2.url}/remote/domain/provision.htm" />
    <property name="serviceInterface" value="pw.domain.service.RemoteProvisioningService" />
</bean> 

And now... the problem. On an appropriate event, the clients rightly call service through httpinvoker facility but the response is http-404. In nginx logs, i trace that spring makes a POST call to http://{host}/remote/domain/provision.htm.

Questions :

  1. Do i need to create a separate app-context for httpInvoker bit? i mean, i already have one web context to deal with normal web operations. Do i need to declare {another-context} in web.xml for httpInvoker facility and having the service config. defined in {another-context}-servlet.xml?

  2. If not 1, what is wrong in my configuration?

1条回答
迷人小祖宗
2楼-- · 2019-09-15 14:36

Got it.. Question 1 above has the answer attached to it. I need to create a separate web context for http-invoking facility to work.

This is because, in my normal webapp context (mailbox), i already have defined SimpleUrlHandlerMapping which maps appropriate urls to controllers. There it doesnt find place for http-invoker-serivce i want to define. When i separated web contexts, it worked like a charm! :D

Happy coding! :)

查看更多
登录 后发表回答