layout | key | title |
---|---|---|
docs |
tutorial-build-simple-webservice-client |
How to build a simple web service client |
Go to the epages-soapclient repository and integrate it with your build automation tool or manually.
Include bintray to your maven repository resolution. For gradle this might look like this:
{% highlight bash %} repositories { maven { url 'http://jcenter.bintray.com' } } {% endhighlight %}
Add the dependencies for the epages-soapclient for provider and shop services. With the next call of your build task the dependencies will be automatically downloaded from bintray and integrated into your project.
{% highlight bash %} dependencies { compile 'de.epages:soapclient-shop:${soapShopVersion}' compile ‘de.epages:soapclient-provider:${soapProviderVersion}’ {% endhighlight %}
Run your specified task to get the dependencies into your favourite IDE (e.g.: eclipse).
{% highlight bash %} ./gradlew eclipse {% endhighlight %}
You can also download the jars from the bintray repository and add it manually. Open your IDE (here: eclipse) and right-click on your project >> properties >> Java Build Path >> Libraries. Add the dependencies with Add External JARs to your java build path.
Import the packages and use the services for your project.
{% highlight java %} import de.epages.ws.pagecache.PageCacheServiceClientImpl; import de.epages.ws.product{version}.ProductServiceClient; {% endhighlight %}
Create an implementation of the interface WebServiceConfiguration with methods for your web service URL, your username and password. Give this object to the web service client implementation you want to use or create your own one with the provided interfaces.
{% highlight java %} PageCacheServiceClientImpl pageCacheService = new PageCacheServiceClientImpl (soapShopConfig); {% endhighlight %}
Use the PageCacheService to delete all cached pages of the shop.
{% highlight java %} pageCacheServiceClient.clear(); {% endhighlight %}
Check if one or more products exists. Create an array with strings of aliases you want to check.
{% highlight java %} String[] productAliases = new String[1]; productAliases[0] = “fancyAlias”; {% endhighlight %}
It’s always possible to check more than one value with one SOAP call. Create the instance of the service and perform the actual call:
{% highlight java %} ProductServiceClientImpl productService = new ProductServiceClientImpl(soapShopConfig); TExists_Return[] existsReturn productService.exists(productAliases); {% endhighlight %}
This kind of service will return an array with information, e.g. call was successful or failed, product exists or not, etc.
Get the data of one or more product(s) with the same array as before.
{% highlight java %} ProductServiceClientImpl productService = new ProductServiceClientImpl(soapShopConfig); TGetInfo_Return[] getInfoReturn = productService.getInfo(productAliases); TExists_Return[] existsReturn productService.exists(productAliases); {% endhighlight %}
It will return an array of objects form the type TGetInfo_Return
.
You could reach the data of the product with the setter and getter methods of this object.
{% highlight java %} getInfoReturn[0].getManufacturer(); {% endhighlight %}
Create one or more products.
First create an object of the type TCreate_Input
with your new data.
The values for TaxClass and alias are required and the TaxClass should exist already.
{% highlight java %} TCreate_Input createInput = new TCreate_Input(); craeteInput.setAlias("fancyAlias"); createInput.setTaxClass("/TaxMatrixGermany/normal"); {% endhighlight %}
Create the array for the actual call.
{% highlight java %} Tcreate_Input[] createInputs = new TCreate_input[1]; createInput[0] = createInput; {% endhighlight %}
After that you could call the service to create the product.
{% highlight java %} TCreate_Return[] createReturn = productService.create(createInputs); {% endhighlight %}
{% callout info Pro tip: %} See also the unit/integration tests of the project for more practical examples. {% endcallout %}