Hello, everyone!
I hope these samples of a SOAP web service client usage in a Jira custom plugin help you in your implementations .
You can find complete code here:
https://github.com/AntonFermat/jira-soap-plugin
There are two part of the project:
jira-ws-plugin – the custom Jira plugin (8.13.6) with Axis2 SOAP web service client and its scheduled background job runner.
producing-ws-server – the Spring-boot sample web service server for the jira-ws-plugin demo. To start it just execute mvn spring-boot:run in comman line. You can check it with url http://localhost:8888/ws/currency.wsdl
Install the Atlassian SDK and configure your environment.
Create a new Jira plugin project.
It takes as input a WSDL and generates client stubs for calling a web service matching the WSDL.
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
<version>1.7.9</version>
<executions>
<execution>
<id>ws</id>
<goals>
<goal>wsdl2code</goal>
</goals>
<configuration>
<packageName>ru.testgu.jira_ws_plugin.ws</packageName>
<wsdlFile>src/main/resources/currency.wsdl.xml</wsdlFile>
<options>
<encoding>UTF-8</encoding>
</options>
<databindingName>adb</databindingName>
</configuration>
</execution>
</executions>
</plugin>
<!-- Web Service -->
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-kernel</artifactId>
<version>${axis2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-jaxws</artifactId>
<version>${axis2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-adb</artifactId>
<version>${axis2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-local</artifactId>
<version>${axis2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-http</artifactId>
<version>${axis2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.14</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.4</version>
<scope>provided</scope>
</dependency>
Some of it (with scope provided) to exclude the enforcer plugin "banned" dependencies
Also add to the Import-Package tag the following dependency:
org.w3c.dom,
*;resolution:="optional"
We can run this service from the other part of the plugin
@Named("exchangeRate")
public class ExchangeRateServiceImpl implements ExchangeRateService {
private static final Logger log = LoggerFactory.getLogger(ExchangeRateServiceImpl.class);
@Override
public double exchangeRateUSD() {
double currencyValue = -1;
try {
CurrencyPortServiceStub stub = new CurrencyPortServiceStub();
// Authentication
// setAuth(stub, username, password);
CurrencyPortServiceStub.GetExchangeRateRequest request = new CurrencyPortServiceStub.GetExchangeRateRequest();
request.setCurrency(CurrencyPortServiceStub.Currency.USD);
CurrencyPortServiceStub.GetExchangeRateResponse exchangeRateResponse = stub.getExchangeRate(request);
currencyValue = exchangeRateResponse.getExchangeRate().getCurrencyValue();
} catch (RemoteException rex) {
}
log.info("=============================");
log.info("USD exchange rate: {}", currencyValue);
log.info("=============================");
return currencyValue;
}
}
Manually with the REST resource (ExchangeRateService.java) - http://<JIRA_BASE_URL>rest/exchangerate/1.0/message
with the http GET response:
<message>
<value>USD exchange rate: 3.0</value>
</message>
or it can be scheduled as the background job runner (ScheduledWebService.java).
Anton Pichugin
0 comments