How to interact with teamcity rest-api from Java

Hi,

I'm new to wadl, I was expecting to fire up some open source tool to generate a whole load of client code from the wadl. I had a look at both CXF wadl2java
http://cxf.apache.org/docs/maven-cxf-codegen-plugin-wsdl-to-java.html
and java.net wadl2java
https://wadl.java.net/wadl2java.html

Both fail with the same error from the wadl  Error compiling schema from WADL : Two declarations cause a collision in the ObjectFactory class.

I traced the error back to two declarations of "projects" within xsd1.xsd
<xs:element name="Projects" type="ns1:projects"/>
<xs:element name="projects" type="projects"/>

I hacked about with the wadl and managed to generate some code, however it appears that what is generated is not actually client code, but stub code for the server side implementation.

Question - what is the recommended way to programatically interact with the rest-api?  I assume that manually constructing & parsing chunks of xml is not the way to go.

Are there any examples?

thanks in advance, Nathan

5 comments
Comment actions Permalink

Nathan,

I have filed inability to generate the client from the as-is application.wadl as http://youtrack.jetbrains.com/issue/TW-34205
However, it seems like the error is caused by under-featured generators, not an error in the application.wadl.

As to getting a client based on the generated file: I've never gone through the excerside myself, but it seems you will need to use Jersey with the generated files to get the client code.
Something along the lines described in a post on the topic.

0
Comment actions Permalink

Thanks Yegor,

Is there any open source generator that you can recommend that will work with teamcity.wadl?  Both cxf and java-net are fairly industry instandard and both fail with the exact same error.  Interestingly the java-net generator uses jersey classes under the hood.

Having hacked the teamcity.wadl I have been able to generate classes using cxf.   I have been using apache HttpClient to communicate with the server and javax.xml.bind.Marshaller & Unmarshaller to convert between xml and java.

I am quite disappointed with the generators, I would have expected generated code to hide all of the boilerplate work for connecting over http and object conversion.

What do other people do who use the rest-api?

0
Comment actions Permalink

Nathan,

As I've mentioned, the reason why the tools fail on the current wadl is to be investigated/fixed in the scope of TW-34205 issue.
A this time I do not know other tools which can be used. However, patching the files and using cxf seems to be good enough workaround.

> What do other people do who use the rest-api?

Sorry, I do not have knowledge on what TeamCity REST API users use nor do I have experience in generating REST clients. May be others readers of the forum have.

0
Comment actions Permalink

nathancoast wrote:

Having hacked the teamcity.wadl I have been able to generate classes using cxf.   I have been using apache HttpClient to communicate with the server and javax.xml.bind.Marshaller & Unmarshaller to convert between xml and java.

I am quite disappointed with the generators, I would have expected generated code to hide all of the boilerplate work for connecting over http and object conversion.

What do other people do who use the rest-api?


Hello Nathan,

I am facing the exact same issues right now. Could you share the hacks you mention, and/or provide more details about your final solution to this?

0
Comment actions Permalink

This is caused by the following two declarations:
<xs:element name="Projects" type="ns1:projects"/>
<xs:element name="projects" type="projects"/>

You can make it working for example, like this:
<xs:element name="CCProjects" type="ns1:projects"/>

0

Please sign in to leave a comment.