How to generate code for groovy-wslite from a wsdl? - soap

Is there an easy way to generate code for groovy-wslite from a wsdl? Similar to wsimport from JaxWS we would like to generate the code for the send/envelopes for several dozen services. Any ideas, trick, libraries, or tools we can use?

Have you had a look at Groovy SOAP?
Groovy makes it easier than with JaxWE to handle SOAP webservices. Something like:
def myService = new SoapClient("myNiceWSDLURL")
def result = myService.method(param1, param2)

Related

How can I write a code generator in Ceylon

I want to write a code generator that generates a class based on the meta model of another ceylon class. I want the code generator to run at compile time. What is the best way for me to do this. I could probably accomplish this by writing a plugin for gradle or the ceylon build system but I'm hoping for a simpler solution. Unfortunately, I don't see any support for code generators in ceylon. Also, are there any plans for code generators in ceylon?
I want to write this code generator because I'm thinking about writing a simple web framework for ceylon that look at a class like the following using the meta-model:
controller
shared class Controller() {
shared void doSomething() => print("did it!");
}
I plan for it to be like Spring MVC. This framework would make a restful API from the Controller class that allows someone to write an AJAX call like this:
$http.get("/Controller/doSomething");
I want to make things more convenient, high level, and simple by doing something like GWT. I want to create a code generator that automatically generates a class like this:
shared class RemoteController() {
shared void doSomething() {
$http.get("/Controller/doSomething");
}
}
The RemoteController would be run in a user's browser as javaScript and allow client side ceylon code to do an Ajax call like this:
RemoteController().doSomething();
That would end up calling the Controller().doSomething() on the server so "did it!" would be printed.
AST Transformers have been proposed, but are still in the early design phase. For now, to do compile-time code generation, you’ll have to rig up something of your own.
To actually generate the code, I would recommend use of ceylon.ast and ceylon.formatter. The workflow would roughly be:
analyze source code –
either parse it with ceylon.ast (ceylon.ast.redhat::compileAnyCompilationUnit) and analyze it without typechecking,
or parse it using the compiler, run the typechecker, then convert it to ceylon.ast (ceylon.ast.redhat::anyCompilationUnitToCeylon), keeping the typechecker information using the new update hooks in the very soon upcoming 1.2.0 release
edit the source code AST to add your new code (using a custom ceylon.ast.core::Editor that injects new class definitions into the CompilationUnits), or perhaps create entirely new compilation units if the RemoteController lives in a different module
convert the ceylon.ast AST to a compiler AST and feed it into ceylon.formatter to turn the AST into code again (see here for an example of that)
Alternatively, if you integrate this into your build step, you could skip the ceylon.formatter part of step 3 and instead feed the converted compiler AST into the typechecker and rest of the compiler directly.

Using Cucumber to test a RESTful service, how can I capture a value to use in a future RESTful method?

I have a RESTful method that returns some JSON, say
{
"A":"B",
"C":"D"
}
And I need to use the value of "C" (here, "D") in the next RESTful call to validate it. But, without knowing what the value is ahead of time (ie, it is a UUID, so I can't guess it)
How can I do this with Cucumber syntax?
A good reference for more info like this would be appreciated.
I do a lot of cuke testing of rest services. You are welcome to look at some of my stuff inside my rest_baby gem
myuuid = JSON(response.body)["C"]

Understanding WSDL's, SOAP, REST, etc

I'm trying to learn how to use WSDL's to call web services from a Grails project. I've been provided with the WSDL and some XML results for reference.
I've been able to generate Java code from the WSDL, and everything seems to be working correctly.
Here's the WSDL: http://www.restfulwebservices.net/rest/USAZipCodeService.svc?wsdl
And here is the XML: http://api.geonames.org/postalCodeSearch?placename=MN&username=demo
I am receiving this exception in my project:
ERROR client.WebServiceClientFactoryImpl$WSClientInvocationHandler - No namespace on "geonames" element.
javax.xml.ws.soap.SOAPFaultException: No namespace on "geonames" element.
It seems like it is saying that the XML returned isn't valid for SOAP? Am I missing/misunderstanding some pieces the puzzle here? It is all pretty new to me.
Edit:
I am trying to use a Grails plugin called cxf client: https://github.com/ctoestreich/cxf-client
It is configured with the following in Config.groovy (something could be wrong/missing here?):
wsdl = "http://www.restfulwebservices.net/wcf/USAZipCodeService.svc?wsdl"
namespace = "cxf.client.postalcode"
clientInterface = "cxf.client.postalcode.IPostalCodeService"
serviceEndpointAddress = "http://api.geonames.org/postalCodeSearch"
I guess you just sent the XML returned from http://api.geonames.org/postalCodeSearch?placename=MN&username=demo as a parameter to the web service. Obviously, from the WSDL description returned you can see there is no such element named geonames, so the SOAPFaultException exception is quite a fair result.
To fix it, you have to refer to the WSDL description carefully, to make sure the invoke method has the right parameters work with whatever defined in the USAZipCodeService WSDL description tags like <wsdl:operation> and <wsdl:message>.
Another issue: 2 different WSDLs were metioned in your invoker and Config.groovy. The former is a RESTful service, and the later is a SOAP one. They work with different invoke methods and parameters, so make sure your code has consistent invoker and parameters, too.

Convert a WSDL to its respective HTTP Bindings

I'm simply trying to convert a WSDl into a number of different HTTP-requests from data supplied by the WSDL. I have read through a ton of similar questions, but none really provided an answer.
Some say to use SOAPUI - I am familiar with this application and do use it. But I need to create these HTTP-requests from the WSDL on my own.
Some say to try JAXWS - I looked at a number of tutorials on this as well as on Axis and these translate the WSDL into Java class bindings and you use those methods to test the web services. I really would like to just generate the HTTP-request myself so that at one point I can manipulate the request and send my own tests.
I started using wsdl4j to begin parsing the WSDL myself but would rather not go down this path until I'm absolutely sure I'm not reinventing the wheel. Seems to me there has been a need for this in past? But with WSDL4J and every other library I do not see a WSDL to Soap message translation.
Any suggestions would be very helpful. The goal is I want to be able to take a WSDL, examine it and create HTTP-SOAP requests for each method in the WSDL and be able to than test them for security issues. The first step is to create those requests!
When calling a SOAP web service you can use a static invocation or a dynamic invocation.
Static invocation means creating a stub from the WSDL and using that to perform the call. This creates all the "plumbing" code for you, but is tightly tied to just that web service and you can't use it for other web services with different contracts. For each WSDL you need to create another stub.
With dynamic invocation, you read the WSDL at runtime and figure out how to call the web service based on the info you get from the WSDL. Feed it multiple WSDLs and the client adapts.
The dynamic invocation is what SoapUI uses to generate the sample requests and responses.
It reads the WSDL you feed it, extracts the XML schema from the types section and generates XML instances. To do so, it uses Wsdl4j and XmlBeans under the hood.
Your decision to use Wsdl4j is good as it gives you control when parsing the WSDL. But also have a look at XmlBeans; it has some other tools you might find useful, like the schema to instance class for example.
If you need to see it in action (maybe debug it to see what's going on) you could create a quick dirty test with the SoapUI API:
import com.eviware.soapui.impl.wsdl.WsdlInterface;
import com.eviware.soapui.impl.wsdl.WsdlProject;
import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlImporter;
public class Test {
public static void main(String[] args) throws Exception {
WsdlProject project = new WsdlProject();
WsdlInterface[] wsdls = WsdlImporter.importWsdl(project, "http://www.html2xml.nl/Services/Calculator/Version1/Calculator.asmx?wsdl");
WsdlInterface wsdl = wsdls[0];
System.out.println(wsdl.getOperationByName("Add").createRequest(true));
System.exit(0); // just to clear up some threads created by the project
}
}
The message you should see printed (for the Add operation of the Calculator WS) would be something like this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:Add>
<tem:a>?</tem:a>
<tem:b>?</tem:b>
</tem:Add>
</soapenv:Body>
</soapenv:Envelope>
Hope this helps you move beyond the first step.

Using Clojure with an annotation-based REST Server

I am considering writing a REST Server using Clojure.
I have experience using RESTEasy with Java. It uses annotations to associate URLs, template parameters, and query parameters with Java classes, methods, and method parameters. I believe that the Jersey REST Server also uses annotations (since it, too, is based on JAX-RS).
Is it possible to use these frameworks with Clojure? Is there an official way to associate annotations with functions?
I found the answer in the forth-coming book "Clojure Programming", by Chas Emerick, Brian Carper, and Christophe Grand.
If you define a new type with deftype, you can add annotations the newly created class:
(ns my.resources
(:import (javax.ws.rs Path PathParam Produces GET)))
(definterface PersonService
(getPerson [^Integer id]))
(deftype ^{Path "/people/{id}"} PersonResource []
PersonService
(^{GET true
Produces ["text/plain"]}
getPerson
[this ^{PathParam "id"} id]
; blah blah blah
))
I'm not sure if this will work with gen-class. I'll need to experiment.