Hello,
Recently I had to develop a program to call a SOAP web service from Jira.
All I could find is an example of Joe Clark for Jira 5. You can find this answer here:
https://community.atlassian.com/t5/Answers-Developer-Questions/Implement-JAX-WS-in-jira-5-plugin/qaq-p/564908
But this code does not work for Jira 7, that is why I had to write my own code. In this article I will walk you through the code, which I wrote.
You can find my code here:
https://bitbucket.org/alex1mmm/jira-jaxws-tutorial/src
First of all in Jira 7 the ability to call SOAP services was removed. Before you could use AXIS to call web services, and as far as I understand it was easy, but right now you have to find your own solution.
In this plugin I decided not to write my own SOAP endpoint (maybe in the next article I will create my own one), that is why I took the first SOAP endpoint, I could find in the internet.
I found this one:
http://gcomputer.net/webservices/dilbert.asmx
Create Jira plugin
You have to create the skeleton for our Jira plugin with the atlas-create-jira-plugin.
Generate classes for the web service
We could manually generate classes for this web service, but let's do it automatically with the wsimport command. You need to go to src/main/java folder in your plugin and type:
wsimport -keep http://gcomputer.net/webservices/dilbert.asmx?WSDL
All necessary files will be generated
Modify your pom.xml file
You should add libraries to call the web service:
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.2.12</version>
<exclusions>
<exclusion>
<groupId>javax.jws</groupId>
<artifactId>jsr181</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.2.10</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.11</version>
</dependency>
<dependency>
<groupId>activesoap</groupId>
<artifactId>xercesImpl</artifactId>
<version>1.5</version>
</dependency>
Add to the Import-Package tag the following dependency:
*;resolution:="optional"
Create a rest endpoint to call the web service
You should execute the atlas-create-jira-plugin-module and choose number 14 in the list
Create a handler for you web service
You can call your web service without a handler. But this handler will help you to debug your requests and responses from the service. It will print the raw soap message in the debug level.
The code for the handler is here:
public class MyServiceLogHandler implements SOAPHandler<SOAPMessageContext> {
private static final Logger log = LoggerFactory.getLogger(MyServiceLogHandler.class);
@Override
public Set<QName> getHeaders() {
// TODO Auto-generated method stub
return null;
}
@Override
public void close(MessageContext arg0) {
// TODO Auto-generated method stub
}
@Override
public boolean handleFault(SOAPMessageContext arg0) {
SOAPMessage message= arg0.getMessage();
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
message.writeTo(out);
String strMsg = new String(out.toByteArray());
log.debug(String.format("handleFault message: ", strMsg));
} catch (SOAPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
@Override
public boolean handleMessage(SOAPMessageContext arg0) {
SOAPMessage message= arg0.getMessage();
boolean isOutboundMessage= (Boolean)arg0.get (MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if(isOutboundMessage){
log.debug("OUTBOUND MESSAGE\n");
}else{
log.debug("INBOUND MESSAGE\n");
}
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
message.writeTo(out);
String strMsg = new String(out.toByteArray());
log.debug(String.format("handleFault message: %s", strMsg));
} catch (SOAPException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return true;
}
}Modify your Rest Endpoint
Add this code to your method, which is called from the endpoint, created by you rest :
Dilbert dilbert = new Dilbert();
DilbertSoap ss = dilbert.getDilbertSoap();
BindingProvider bindProv = (BindingProvider) ss;
java.util.List<Handler> handlers = bindProv.getBinding().getHandlerChain();
handlers.add(new MyServiceLogHandler());
bindProv.getBinding().setHandlerChain(handlers);
String res = ss.todaysDilbert();
return Response.ok(new JaxWsEndpointModel(res)).build();
Run Jira and try to call the web service
type atlas-run in the terminal and after Jira started, open a web browser with the http://localhost:2990/jira url. Login to Jira with admin:admin credentials and enter in the url:
http://localhost:2990/jira/rest/jaxws/1.0/service
You will get the following result:

Do not pay attention that the message looks like an error. This web service returns a response like this:)
Ok. I hope this article helped you!