a little while later, with a config here.. and a config there... A class exposed via http.
Ok so you need a web project with a web.xml that looks like:
remoting org.springframework.web.servlet.DispatcherServlet 1 remoting /httpremote/* 30 index.jsp
a remoting-servlet.xml Spring context file:
bob.blog.NormalPojo
And the Java interface and class you want to expose:
package bob.blog; public interface NormalPojo { void myExposedMethod(final String input); }
package bob.blog; public class NormalPojoImpl implements NormalPojo { public void myExposedMethod(String input) { System.out.println("Method Called with: " + input); } }
That is all for the "Service" part... Once the war is deployed you can call it via http from a client. The client is also pretty simple, the reason I included the org.apache.commons.httpclient.HttpClient config in the application context was to be able to configure the timeout of the http call and one very nasty little thing you wouldn't expect. The default implementation is not thread safe.... that lead to some lets say "interesting" bugs, thankfully there is a thread safe implementation (MultiThreadedHttpConnectionManager, the one I used in the config below).
Hint: make sure the bean name in you server "/pojo-httpinvoker", the context in you web.xml "/httpremote/*" and client config all tie up "http://localhost:80/httpremote/pojo-httpinvoker".
You'll need an applicationContext.xml:
60000 20 http://localhost:80/httpremote/pojo-httpinvoker" bob.blog.NormalPojo
And then just use it as per any other Spring bean:
ApplicationContext ctx = new ClassPathXmlApplicationContext("bob/blog/applicationContext.xml"); NormalPojo testhttp = (NormalPojo) ctx.getBean("pojoHttp"); testhttp.myExposedMethod("whoo hoo");
There is also...
ReplyDelete|bean id="httpServer" class="org.springframework.remoting.support.SimpleHttpServerFactoryBean"|
|property name="contexts"|
...
|/property|
|property name="hostname" value="127.0.0.1" /|
|property name="port" value="2345" /|
|/bean|
for simple stuff.
Thanks, I had not looked at that before actually, we had a fair amount of load and I had Weblogic servers available ... it is however a good way to go for stand alone apps. will definitely keep it in mind.
ReplyDeleteHi thanks for pposting this
ReplyDeleteMua vé tại Aivivu, tham khảo
ReplyDeleteVé máy bay đi Mỹ
vé máy bay từ seattle về việt nam
thông tin chuyến bay từ canada về việt nam
chuyến bay từ nhật về việt nam
đặt vé máy bay từ hàn quốc về việt nam
Vé máy bay từ Đài Loan về Việt Nam
Chi phí cho chuyên gia nước ngoài