WS Client API

API to easily create WebService Client (CXF)

License

License

Categories

Categories

CLI User Interface
GroupId

GroupId

fr.foop.ws
ArtifactId

ArtifactId

werbservice-client-api
Last Version

Last Version

0.5.0
Release Date

Release Date

Type

Type

jar
Description

Description

WS Client API
API to easily create WebService Client (CXF)
Project URL

Project URL

http://github.com/cedricbou/webservice-client-api
Source Code Management

Source Code Management

http://github.com/cedricbou/webservice-client-api

Download werbservice-client-api

How to add to project

<!-- https://jarcasting.com/artifacts/fr.foop.ws/werbservice-client-api/ -->
<dependency>
    <groupId>fr.foop.ws</groupId>
    <artifactId>werbservice-client-api</artifactId>
    <version>0.5.0</version>
</dependency>
// https://jarcasting.com/artifacts/fr.foop.ws/werbservice-client-api/
implementation 'fr.foop.ws:werbservice-client-api:0.5.0'
// https://jarcasting.com/artifacts/fr.foop.ws/werbservice-client-api/
implementation ("fr.foop.ws:werbservice-client-api:0.5.0")
'fr.foop.ws:werbservice-client-api:jar:0.5.0'
<dependency org="fr.foop.ws" name="werbservice-client-api" rev="0.5.0">
  <artifact name="werbservice-client-api" type="jar" />
</dependency>
@Grapes(
@Grab(group='fr.foop.ws', module='werbservice-client-api', version='0.5.0')
)
libraryDependencies += "fr.foop.ws" % "werbservice-client-api" % "0.5.0"
[fr.foop.ws/werbservice-client-api "0.5.0"]

Dependencies

compile (6)

Group / Artifact Type Version
org.apache.cxf : cxf-rt-frontend-jaxws jar 2.7.11
org.apache.cxf : cxf-rt-transports-http jar 2.7.11
org.apache.cxf : cxf-rt-ws-security jar 2.7.11
fr.foop.parsers : simple-xml jar 0.2.2
com.github.tomakehurst : wiremock jar 1.46
com.google.guava : guava jar 16.0.1

test (2)

Group / Artifact Type Version
junit : junit jar 4.11
ch.qos.logback : logback-classic jar 1.1.2

Project Modules

There are no modules declared in this project.

WebService Client API

An API to easily built webservice client, based on CXF.

Quick start Guide

The easiest way is to clone the existing example project. Although you can start from scratch by creating a maven simple jar project.

  • Clone the example project :

git clone https://github.com/cedricbou/webservice-client-example.git <<your project name here>>

  • (Optional) Remove the .git folder to "ungit" the project :

cd <<your project name here>> rm -rf .git

  • Open the pom.xml file :

    1. Modify the groupId, artifactId, version with yours.
    2. Change description and name to something describing the client you are creating.
    3. Update the <wsdl> tag in the cxf plugin with the URL to your WSDL.
  • Clean and generate source

mvn clean generate-sources

  • The project will contain compilation error, we need to adapt the Client class :
    1. Open the CRMClient class, rename it to whatever you need, and change the package as well to something you like.
    2. Adapt the CxfClient extended class with generic types corresponding to the Port generated by CXF, and the service manager class generated by CXF : public class CRMClient extends CxfClient<_WebServicePort_, _WebServiceManager_>
    3. In the newPort method, calls the manager method to instanciate your port interface, the manager is passed in parameter.
    4. In the checkIfPortUp method, implements a health check. If an exception is thrown the service is considered unhealthy.

Configuration DSL

Basic features

builder()
	.withWsseCredentials(username, password) // Configure username and password using the WSSE standard, as PasswordText.
	.withConnectionTimeout(1000) // Set the timeout in millis on socket connection
	.withReceiveTimeout(3000) // Set the timeout in millis to wait for data.
	.withEndpoint("http://....") // Define the endpoint to use.
	.withInLogger(logger) // The SLF4J logger to use for payload sent to the server, the level is INFO.
	.withOutLogger(logger) // The SLF4J logger to use for payload received from the server, the level is INFO.
	.withLogger(logger) // Shortcut for withInLogger(logger).withOutLogger(logger)

Endpoint and servers

During service instanciation, the API endpoint failover. For an endpoint, you can defined several target servers address.

When instanciating the service, for each server, it will attempt to configure a client. It uses the checkIfPortUp method to check if the server is available. If everything is fine, it will use this port, otherwise, it would try the next server. If nothing works, it returns null.

For this to work, you need to write your endpoint with the special {{server}} tag :

builder()
    .withEndpoint("http://{{server}}/mywebservice")

Then you'll configure the server list to use :

builder()
    .withEndpoint("http://{{server}}/mywebservice")
    .withServers("localhost:8080", "10.10.10.10:6541");

Loading from properties

Properties props = new Properties();
props.load(...);

builder()
    .withProperties("com.myprops", props)
    .withServers("localhost:8080", "10.10.10.10:6541");

The Client class

To build the client, use the build method :

final CRMClient client = CRMClient.builder()
	.withReceiveTimeout(2000)
	.withLogger("com.myservice.Trames")
	.build(CRMClient.class); // The port is instanciated at this stage.

final CRMServicePT port = client.service(); // Return the port instanciated above.

// Now you can call the web services.
port.getAll();
port.create(new CustomerType(...));

You need to pass the Client class. This is used to automatically cast to the right type in the return.

Versions

Version
0.5.0