SMTP transport extension for JAX-WS RI
JAX-WS
Finally, we (vivek,
kohsuke
and I) put together a SMTP transport for JAX-WS !! JAX-WS works with
various transports and it also provides plugin
extensions to write any custom transport. SMTP transport takes
advantage of these extensions. SMTP transport is implemented as a custom
transport using
href="http://fisheye5.cenqua.com/browse/jax-ws-sources/jaxws-ri/rt/src/com/sun/xml/ws/api/server/Adapter.java?r=1.2">Adapter
extension on the server side and
href="http://fisheye5.cenqua.com/browse/jax-ws-sources/jaxws-ri/rt/src/com/sun/xml/ws/api/pipe/TransportTubeFactory.java?r=1.2">TransportTubeFactory.java
on the client side.
Basics
For the communication to happen between "Me" and "You", there needs to
be two inboxes: "My Inbox" and "Your Inbox". "Me" sends
request messages to "You" and expect responses in "My Inbox".
Similarly, "You" sends response messages to "My Inbox" in
order to reach "Me".
SMTP advantages
- It is reachable. No server setup is necessary.
- Great asynchrony. Server need not be there when
client sends a request message.
Client-side Programming
You need jaxws-smtp.jar and JavaMail in
your classpath for this to work. Typical client code would like this:
public void testSmtp() {<br> SMTPTransportTube.dump = true; // Enable logging<br><br> SMTPFeature feature = new SMTPFeature("smtp.host", "me@sun.com");<br> feature.setPOP3("pop.host", "uid", "password");<br> GreetingService proxy =<br> new GreetingServiceService().getGreetingServicePort(feature);<br><br> WSBindingProvider bp = (WSBindingProvider)bp;<br> bp.setAddress("smtp://you@sun.com");<br> ... = proxy.sayHelloTo("...");<br> bp.close();<br>}<br>
This
configures SMTPFeature with SMTP(sending) and POP3(receiving)
configuration. This feature is used to create proxy. Once the endpoint
address is set, then proxy can be used to invoke web service.
Server-side Configuration
JAX-WS SMTP extension can be used with
href="https://jax-ws-commons.dev.java.net/spring/">JAX-WS
Spring extension for more flexible configuration --- in
particular to expose the same endpoint as both HTTP and SMTP. See
href="https://jax-ws-commons.dev.java.net/source/browse/jax-ws-commons/trunk/transport/smtp/test-app/">the
sample application for the complete example of how to put
this all together by using Maven.
<beans<br> xmlns:ws ="http://jax-ws.dev.java.net/spring/core"<br> xmlns:wsm="http://jax-ws.dev.java.net/spring/smtp"<br> xsi:schemaLocation=<br> "http://jax-ws.dev.java.net/spring/smtp http://jax-ws.dev.java.net/spring/smtp.xsd<br> http://jax-ws.dev.java.net/spring/core http://jax-ws.dev.java.net/spring/core.xsd"><br><br> <wsm:smtp service="#myservice" incoming="#in" outgoing="#out" /><br> <wsm:pop3 id="in" host="pop3.Host" uid="uid" password="password" /><br> <wsm:sender id="out" host="smtp.host" from="server.from@com"/><br><br> <ws:service id="myservice"><br> <ws:bean><br> <bean class="greeter.GreetingService" /><br> </ws:bean><br> </ws:service><br><br></beans><br>
Alternatively, you can also configure the srever side
programatically without Spring like
href="https://jax-ws-commons.dev.java.net/source/browse/jax-ws-commons/trunk/transport/smtp/jaxws-smtp/src/test/java/pop3/SmtpTest.java?view=markup">this.
Testing
We'll be showing a SMTP demo (along with JSON demo!)
in our JavaOne session
href="http://www28.cplan.com/cc158/sessions_catalog.jsp?ilc=158-1&ilg=english&isort=&isort_type=&is=yes&icriteria1=+&icriteria2=+&icriteria7=+&icriteria9=TS-4948&icriteria8=&icriteria3=">TS-4948
"Unleashing the Power of JAX-WS RI: Spring, Stateful Web Services,
SMTP, and More", so mark your calendars accordingly ...
- Login or register to post comments
- Printer-friendly version
- jitu's blog
- 1297 reads





