What is this?

JAX-WS works with various transports and it also provides plugin extensions to write any custom transport. This extension takes advantage of the extensions and allows JAX-WS services to be used with SMTP transport.

SMTP transport is implemented as a custom transport using Adapter extension on the server side and TransportTubeFactory.java on the client side.

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() throws Exception {
    SMTPTransportTube.dump = true;          // Enable logging

    SMTPFeature feature = new SMTPFeature("smtp.host", "me@sun.com");
    feature.setPOP3("pop.host", "uid", "password");

    GreetingService proxy =
        new GreetingServiceService().getGreetingServicePort(feature);
    WSBindingProvider bp = (WSBindingProvider)bp;

    ... = proxy.sayHelloTo("...");


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 JAX-WS Spring extension for more flexible configuration --- in particular to expose the same endpoint as both HTTP and SMTP. See the sample application for the complete example of how to put this all together by using Maven.

 xmlns:ws ="http://jax-ws.java.net/spring/core"

  <wsm:smtp service="#myservice" incoming="#in" outgoing="#out" />
  <wsm:pop3 id="in" host="pop3.Host" uid="uid" password="password" />
  <wsm:sender id="out" host="smtp.host" from="server.from@com"/>

  <ws:service id="myservice">
      <bean class="greeter.GreetingService" />

Alternatively, you can also configure the srever side programatically without Spring like this.

Terms of Use; Privacy Policy; Copyright ©2013-2017 (revision 20160708.bf2ac18)
Please Confirm