Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to call a SOAP Web Service from Jira 7.2.x plugin

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:

Screenshot 2019-02-17 at 22.25.11.png

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!

6 comments

Hi! 

Thanks for your article. 

Any plans to show how to transfer from axis to axis2, jax etc? 

Cheers.

Gonchik Tsymzhitov

Axis is not in Jira anymore. We could use AXIS before because it was in Jira and it was easy to use. 

I showed an example with jax-ws. I do not think something else is needed to call a web service.

Great example. Thank you. Have you tried this plugin with any recent versions of Jira? It seems to work for me in Jira 7 with Oracle JDK 8, but on Jira 8 with AdoptOpenJDK 8 it gives the exception "java.lang.ClassCastException: com.sun.xml.bind.api.TypeReference cannot be cast to com.sun.xml.bind.api.TypeReference". Maybe some sort of mismatched classloader issue for JAXB?

I have not tried it in Jira 8. I developed an app for a client for Jira 7 and I did not need it yet for Jira 8. When i need it, i will update the tutorial. If you find a way to work it in Jira 8 , please make also a tutorial. This feature is often needed by community.

Hi has anyone managed to run this on Jira 8 so far?

Comment

Log in or Sign up to comment
TAGS
Community showcase
Published in Agile

On-demand: Fireside chat with Atlassian on scaling agile organizations

Scaling an agile organization and setting it up for success over the long term is a hard thing to do. We hear a common set of questions from customers all the time, questions like: Can agile scal...

3,947 views 2 17
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you