Help

Built with Seam

You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.

Here is a simple way to access web service clients from Seam.

Objectives

  • Access web services clients as if they are seam components
  • Allow web service clients to be mocked out for testing
  • Provide dynamic substitution of endpoint address
  • Simple configuration

Example

Here is what the configuration looks like:

	<jaxws:client-factory name="sampleServiceClient" 
		serviceQName="{http://service.jaxws.taylor.net/}SampleService" 
		serviceEndpointInterface="net.taylor.sample.service.SampleService"
		endpointAddress="@sample.service.endpoint@"/>

Here is the injection of the client:

	@In
	private SampleService sampleServiceClient;

Here is the factory code. Note the use of @Unwrap.

@Scope(ScopeType.APPLICATION)
@Install(value = false, precedence = Install.FRAMEWORK)
@AutoCreate
@BypassInterceptors
public class ClientFactory {

	private Object client;

	private String serviceQName;

	private String wsdlLocation;

	private Class<?> serviceEndpointInterface;

	private String endpointAddress;

	// setters/getters
	
	@Create
	public void create() throws Exception {
		Service service = Service.create(new URL(getWsdlLocation()), QName
				.valueOf(getServiceQName()));
		client = service.getPort(getServiceEndpointInterface());

		Map<String, Object> requestContext = ((BindingProvider) client)
				.getRequestContext();
		requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
				getEndpointAddress());
	}

	@Unwrap
	public Object getClient() {
		return client;
	}
}

Here is the full code: ClientFactory.java

5 comments:
 
18. May 2009, 14:53 America/New_York | Link
Bertrand

Hello,

Can you describe where the configuration should be go?

Thank you,

Bertrand.

 
18. May 2009, 15:51 America/New_York | Link
Jean
Bertrand wrote on May 18, 2009 14:53:
Hello, Can you describe where the configuration should be go? Thank you, Bertrand.

Hi,

could you please address me to the correct namespace (and xsd) involved in the example above?

Bertrand, I am presuming (and I might be completely wrong! :)) that the configuration has to be set in your components.xml file where all your Seam components are declared. Unfortunately I am stuck too... I am googling for some schema that contains a client-factory element, no success so far.

Regards Jean

 
18. May 2009, 18:56 America/New_York | Link

Yes, the configuration would go in your components.xml file.

The ClientFactory class is an example. You would create the class in your own jar/package and add a package info file to define the namespace. Optionally, you can define a schema as well.

 
26. Aug 2009, 15:49 America/New_York | Link
Markus

Hi John,

I'd like to use your code, but I don't understand the configuration. What do you mean by add a package info file to define the namespace?

Thx Markus

 
26. Aug 2009, 15:51 America/New_York | Link
Markus

Forgot to ask how do you dynamically substitude or set the endpoint address?

Thx Markus