SOAP WebServices with JBoss AS7

If you want to create Soap WebServices you first have to extend your standalone.xml file. Add the module and it’s configuration:

...
<extensions>
	...
	<extension module="org.jboss.as.webservices"/>
	...
</extensions>
...
<profile>
	...
	<subsystem xmlns="urn:jboss:domain:webservices:1.0" xmlns:javaee="http://java.sun.com/xml/ns/javaee" xmlns:jaxwsconfig="urn:jboss:jbossws-jaxws-config:4.0">
            <wsdl-host>
                localhost
            </wsdl-host>
            <modify-wsdl-address>
                true
            </modify-wsdl-address>
            <endpoint-config>
                <jaxwsconfig:config-name>
                    Standard-Endpoint-Config
                </jaxwsconfig:config-name>
            </endpoint-config>
            <endpoint-config>
                <jaxwsconfig:config-name>
                    Recording-Endpoint-Config
                </jaxwsconfig:config-name>
                <jaxwsconfig:pre-handler-chains>
                    <javaee:handler-chain>
                        <javaee:protocol-bindings>
                            ##SOAP11_HTTP ##SOAP11_HTTP_MTOM ##SOAP12_HTTP                                                                                                                                                                                                                         							##SOAP12_HTTP_MTOM
                        </javaee:protocol-bindings>
                        <javaee:handler>
                            <javaee:handler-name>
                                RecordingHandler
                            </javaee:handler-name>
                            <javaee:handler-class>
                             org.jboss.ws.common.invocation.RecordingServerHandler
                            </javaee:handler-class>
                        </javaee:handler>
                    </javaee:handler-chain>
                </jaxwsconfig:pre-handler-chains>
            </endpoint-config>
        </subsystem>
        ...
</profile>

You find a template in standalone-ha.xml.

And here an example WebService with Interface.

import java.util.logging.Logger;

import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.jws.WebService;
import javax.xml.ws.soap.Addressing;
import javax.xml.ws.soap.MTOM;

/**
 *
 * @author manuel
 *
 */
@Stateless
@WebService(endpointInterface = "at.coffeebeans.shop.soap.SoapServiceIface", serviceName = "SoapService", portName = "SoapServicePort")
@MTOM(enabled = true)
@Addressing(enabled = true, required = true)
public class SoapService implements SoapServiceIface {

	@Inject
	private Logger log;

	@Override
	public String ping(final String payload) throws SoapServiceError {
		if (null == payload) {
			log.warning("ping with no payload");
			throw new SoapServiceError("payload must not be null");
		}
		log.info("ping from " + payload);
		return "pong from " + payload;
	}

}
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

/**
 *
 * @author manuel
 *
 */
@WebService(targetNamespace = "http://coffeebeans.at/shop/soap")
public interface SoapServiceIface {

	@WebMethod(operationName = "ping")
	public String ping(@WebParam(name = "payload") final String payload) throws SoapServiceError;

}
import javax.xml.ws.WebFault;

/**
 * @author manuel
 *
 */
@WebFault
public class SoapServiceError extends Exception {

	/** UID. */
	private static final long """"serialVersionUID"""" = 5063725310269125585L;

	public SoapServiceError() {
		super();
	}

	public SoapServiceError(final Exception exc) {
		super(exc);
	}

	public SoapServiceError(final String msg) {
		super(msg);
	}

}

In my example, the project is accessible over http://localhost:8080/shop and the WebService WSDL is under http://localhost:8080/shop/SoapService/SoapService?wsdl

If you use maven, the following dependencies should add full WebService support that is included in JBoss AS7:

<dependencies>
	<dependency>
		<groupId>org.jboss.ws</groupId>
		<artifactId>jbossws-api</artifactId>
		<version>1.0.0.Beta2</version>
		<scope>provided</scope>
	</dependency>
	<dependency>
		<groupId>org.apache.ws.security</groupId>
		<artifactId>wss4j</artifactId>
		<version>1.6.1</version>
		<scope>provided</scope>
	</dependency>
</dependencies>

Leave a Comment