/
Java client implementation guide

Java client implementation guide

We will use Maven and Spring WS to create simple Web Service client.

  • Configure Maven dependencies:

    pom.xml

    <project...> <dependencies> <!-- JAXB dependencies --> <dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> <version>2.2.2</version> </dependency> <dependency> <groupId>com.sun.xml.bind</groupId> <artifactId>jaxb-impl</artifactId> <version>2.2.2</version> </dependency> <!-- Spring WS dependencies --> <dependency> <groupId>org.springframework.ws</groupId> <artifactId>spring-ws-core</artifactId> <version>2.0.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.ws</groupId> <artifactId>spring-ws-security</artifactId> <version>2.0.1.RELEASE</version> </dependency> <dependency> <groupId>org.apache.ws.commons.schema</groupId> <artifactId>XmlSchema</artifactId> <version>1.4.7</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-oxm</artifactId> <version>${spring.version}</version> </dependency> </dependencies> </project>



  • Download WS XSD schemas to project directory src/main/resources/schema

  • Configure JAXB to generate classes:

    pom.xml

    <project...> <build> <plugins> <plugin> <groupId>org.jvnet.jaxb2.maven2</groupId> <artifactId>maven-jaxb2-plugin</artifactId> <version>0.7.5</version> <executions> <execution> <id>jaxb-ws-pvplanner</id> <goals> <goal>generate</goal> </goals> </execution> </executions> <configuration> <schemaDirectory>src/main/resources/schema</schemaDirectory> </configuration> </plugin> </plugins> </build> <project>



  • Define Spring WebServiceTemplate context:

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:oxm="http://www.springframework.org/schema/oxm" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <!-- contextPath - package where to find request and response classes to marshall / unmarshal if request and response are in different packages, declare marshaller and unmarshaller separately --> <oxm:jaxb2-marshaller id="jaxb2marshaller" contextPath="eu.geomodel.schema.ws.pvplanner"/> <bean id="pvPlannerTemplate" class="org.springframework.ws.client.core.WebServiceTemplate" p:marshaller-ref="jaxb2marshaller" p:unmarshaller-ref="jaxb2marshaller" p:defaultUri="https://solargis.info/ws/soap/pvPlanner"> <!-- web service endpoint uri --> <property name="interceptors"> <list> <bean class="org.springframework.ws.soap.security.wss4j.Wss4jSecurityInterceptor" p:securementActions="Timestamp UsernameToken" p:securementUsername="demo" p:securementPassword="demo"/> </list> </property> </bean> </beans>



  • Define client Spring bean:



Related content

Data Delivery WS request / response examples
Data Delivery WS request / response examples
More like this
WS API technical documentation
WS API technical documentation
More like this
PDF Signing and Verification
PDF Signing and Verification
Read with this
Simple PHP web service client
Simple PHP web service client
More like this
Postman API tool requests example
Postman API tool requests example
Read with this
Web Services
Web Services
More like this