Does Grails provide built-in or via a plugin support to consume (not to generate) XML based REST or SOAP web services ( esp. REST) ?
http://www.grails.org/plugin/rest
For SOAP based webservices, use WSClient. The plugin is a wrapper around GroovyWS. Under the hood, Apache CXF is working there.
In the past, I created a script (grails create-script) that used wsimport to create POJOs in the java src directory. Each time the script ran, it would delete the generated directory if it existed first, then generate new files.
I did this because the API that was being consumed was being developed and I wanted an easy way to consume the latest and greatest when new functionality was added.
In grails 3.x you can use the plugin in build.gradle
compile 'com.github.groovy-wslite:groovy-wslite:1.1.2'
Then add the import to your controller like in http://guides.grails.org/grails-soap/guide/index.html
import wslite.soap.*
import wslite.soap.SOAPClient
import wslite.soap.SOAPResponse
and use as the example available in https://github.com/jwagenleitner/groovy-wslite
def client = new SOAPClient('http://www.holidaywebservice.com/Holidays/US/Dates/USHolidayDates.asmx')
def response = client.send(SOAPAction:'http://www.27seconds.com/Holidays/US/Dates/GetMothersDay') {
body {
GetMothersDay('xmlns':'http://www.27seconds.com/Holidays/US/Dates/') {
year(2011)
}
}
}
assert "2011-05-08T00:00:00" == response.GetMothersDayResponse.GetMothersDayResult.text()
assert 200 == response.httpResponse.statusCode
assert "ASP.NET" == response.httpResponse.headers['X-Powered-By']
render (response.GetMothersDayResponse.GetMothersDayResult.text())
Related
I am trying to call a web service written in C#. Below is client side in corona:
local client = require "soap.client"
local ns, meth, ent = client.call {
url = "http://172.16.1.162:7878/BaksetBilgi.svc",
soapaction = "doubler",
method = "http://titck.kara.com/bask",
entries = {
......}
When I run this code, it gives error :
module 'soap.client' not found:resource (soap.client.lu) does not exist in archive..
How can I solve it?
That module is not part of corona. Looks like it's only 3 files, you could copy them into your Corona project. Note that the language that SOAP service is written in is irrelevant to the client: SOAP is a protocall, if you know how to format your data in HTML then you can do SOAP. Look at any good SOAP tutorial. But I don't know why you wouldn't want to use that library, just copy the files into your project.
I'm using rhino and envjs embedded in my java application as described in the envjs guide
Java code:
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ContextFactory;
import org.mozilla.javascript.tools.shell.Global;
import org.mozilla.javascript.tools.shell.Main;
...
Context cx = ContextFactory.getGlobal().enterContext();
cx.setOptimizationLevel(-1);
cx.setLanguageVersion(Context.VERSION_1_5);
Global global = Main.getGlobal();
global.init(cx);
Main.processSource(cx, "path/to/your/JSfile");
This is working and my test javascript file correctly loads a remote site and does some manipulation with the HTML elements using jQuery.
What I can't figure out is how to send data from the JavaScript back to my Java application.
Here's my .js file:
load('env.rhino.js');
load('jquery.js');
Envjs.scriptTypes['text/javascript'] = true;
window.location = 'http://[mytestpage].html'
var body = $("body");
print("The body is: "+ $.trim(body));//this prints in the Java console!
//I'd like to call a function in my Java code from the Javascript and pass the bodyText as a parameter to it. How can i do this?
myJavaFunction(bodytext);
So this Rhino tutorial was very useful in learning how to connect your Java to JS.
https://developer.mozilla.org/en-US/docs/Scripting_Java
With a local client side application, with
import 'dart:io';
I see no way to load up the consumers current default browser and then load a web page. (Locally stored HTML or a website)
I've searched the API documentation at http://api.dartlang.org yet have found no easy way.
Is there any way of doing this yet?
Preferably similar to the Desktop class in java ?
I don't think there's a function for that. You can fill a new feature request.
If you need a workaround, you can deal with the Process and Platform classes.
on Windows you should be able to launch the default browser with start ${url}.
on linux, you can do that with xdg-open ${url} if xdg-open is present.
in other cases, there should be a solution...
Here is a sample :
import 'dart:io';
main() {
final url = "http://dartlang.org";
if (Platform.operatingSystem == 'windows') {
Process.run("start", [url]);
} else if (Platform.operatingSystem == 'linux') {
Process.run("xdg-open", [url]);
}
}
On Windows I find the runInShell flag needs to be set:
Process.run("start", [url], runInShell: true);
(at least on Windows 7).
I'm surprised that someone has not created a package to reliably invoke the default browser on all platforms.
I need to use some connectors which are actually servlets. How can I do this in Grails and what about the web.xml? How do I configure the url of the servlet?
I actually have a Spring application here and I am trying to convert it into a partial Grails app. I have a connector servlet in the spring-app, which I wish to use here but the mapping is a must to call the servlet in the gsp file. How can I do this? I basically need to know where the xml file is in case of Grails.
To get the web.xml file, you can run:
grails install-templates
Then, the file can be found in:
<yourapp>/src/templates/war/web.xml
Edit this as usual to add <servlet> and <servlet-mapping> sections, then put your servlet code in:
<yourapp>src/java/your/package/structure/WhateverServlet.java
and you should be good to go
If you are within a grails-plugin, then you have a defined place within your *GrailsPlugin.groovy, where to do such things. E.g. Look at the auto generated closure:
def doWithWebDescriptor = { xml ->
[]
}
In here you can add your custom servlet configurations:
def servlets = xml.'servlet'
servlets[servlets.size() - 1] + {
servlet {
'servlet-name'('yourName')
'servlet-class'('yourpackage.YourClass')
}
}
def mappings = xml.'servlet-mapping'
mappings[mappings.size() - 1] + {
'servlet-mapping' {
'servlet-name'('yourName')
'url-pattern'('/yourPattern/*')
}
}
good news and bad news, and I myself have asked this question here before. With spring application you can have multiple level of URI such as domain.com/abc/def/efg/abc vs grails has a lot of issue with anything beyond domain.com/controller/view. here is a link to my original question: Grails URL mapping cause error on GSP
The good news is, you don't need to deal with XML mapping, grails does it seemlessly by controllers and views. So you are almost limited to domain.com/YouController/YourView/SomeParamteres... but if thats all you'll need, all u have to do is create grails-app/Controller/SomethingController.groovy and you automatically have domain.com/Something
I have gradle project (backend) and I want to add Vaadin-based frontend. But I haven't find any gradle-plugins for Vaadin.
While, as was already mentioned above, Vaadin app is a simple web application and does not require any additional plugins but "java" and "war" (and maybe "jetty" to run the app), currently there seems to be the first vaadin-specific gradle plugin available:
https://github.com/johndevs/gradle-vaadin-plugin
It will help you with Vaadin-specific task like building widgetsets, creating components skeletons, etc.
I think there is no a Vaadin plugin for Gradle but I have used Gradle in one of my Vaadin add-on projects: SplitButton. It's a project with sub-projects, widgetset compilation and it writes necessary jar manifest entries neebed by Vaadin Directory.
EDIT
Actually there is Gradle Vaadin plugin now - it allows you to easily build Vaadin projects with Gradle. It helps with the most tedious tasks when building a Vaadin project like building the widgetset and running development mode. It also helps you to quickly get started by providing tasks for project, component and theme creation:
https://github.com/johndevs/gradle-vaadin-plugin
You don't need a Vaadin plugin. A Vaadin application is simply a web application.The war plugin will suffice. If you want support for automatically creating the folder layout that Vaadin wants however, you might look into using the vaadin eclipse plugin found here:
http://vaadin.com/eclipse
If you are looking for deployment support, you can simply use the jetty plugin that comes with gradle or the tomcat plugin found here
https://github.com/bmuschko/gradle-tomcat-plugin
If you need to create custom widgets and compile them into a widgetset that's a GWT compile
https://vaadin.com/book/vaadin6/-/page/gwt.development.html#gwt.development.compiler
Note: The Vaadin7 Book no longer has the section on developing Gwt widgets.
There is a gradle plugin for GWT that could help with that. However, I've not needed a custom widget yet, so I haven't actually tried it.
https://github.com/markuskobler/gwt-gradle-plugin
This post:
Using Gradle with Vaadin
looks very comprehensive as far as Gradle+Vaadin setup goes. I'm also including a link to another Vaadin-based 'build.gradle' file I found on my travels, using Google's very useful 'filetype' search (see also the associated gradle.properties file).
JFYI that Google file search is:
filetype:<extension> <your search phrases>
Gradle can also be used to configure Eclipse and IntelliJ's project files by using a fragment such as the following (Eclipse natures can be 'found' by using the above Google file search for "project" extension and "natures" search, etc.):
//Template plugin - Great for project-layout setup - See http://tellurianring.com/wiki/gradle/templates
apply from: 'http://launchpad.net/gradle-templates/trunk/latest/+download/apply.groovy'
apply plugin: 'eclipse'
apply plugin: 'idea'
// if you want to distribute the gradle with your code
task('wrapper', type: Wrapper).configure {
gradleVersion = '1.0-milestone-8a'
}
def versionCompatibility = 1.6
//configurations.providedDependencies.extendsFrom configurations.gwt
eclipse {
project {
comment = ""
buildCommand "org.eclipse.jdt.core.javabuilder"
buildCommand "org.eclipse.wst.jsdt.core.javascriptValidator"
buildCommand "org.eclipse.wst.common.project.facet.core.builder"
buildCommand "org.eclipse.wst.validation.validationbuilder"
buildCommand "com.vaadin.integration.eclipse.widgetsetBuilder"
//buildCommand "org.eclipse.m2e.core.maven2Builder"
//buildCommand "org.maven.ide.eclipse.maven2Builder"
//buildCommand "com.google.gdt.eclipse.core.webAppProjectValidator"
//buildCommand "com.google.gwt.eclipse.core.gwtProjectValidator"
//buildCommand "com.google.gdt.eclipse.designer.GWTBuilder"
//Don't forget commas - no trailing
natures "org.eclipse.jdt.core.javanature",
"com.vaadin.integration.eclipse.widgetsetNature",
"org.eclipse.wst.jsdt.core.jsNature",
"org.eclipse.wst.common.project.facet.core.nature",
"org.eclipse.wst.common.modulecore.ModuleCoreNature",
"org.eclipse.jem.workbench.JavaEMFNature"
//"org.eclipse.m2e.core.maven2Nature",
//"org.maven.ide.eclipse.maven2Nature",
//"com.google.gwt.eclipse.core.gwtNature"
//"com.google.gdt.eclipse.designer.GWTNature",
//"ch.epfl.lamp.sdt.core.scalanature",
//"com.springsource.sts.grails.core.nature",
//"org.eclipse.jdt.groovy.core.groovyNature"
}
classpath {
containers "com.google.gwt.eclipse.core.GWT_CONTAINER"
//"com.springsource.sts.gradle.classpathcontainer"
//minusConfigurations=[configurations.gwt]
}
}
idea {
project {
jdkName = versionCompatibility
ipr {
withXml { provider ->
def node = provider.asNode()
// Set Gradle home
def gradleSettings = node.appendNode('component', [name: 'GradleSettings'])
gradleSettings.appendNode('option', [name: 'SDK_HOME', value: gradle.gradleHomeDir])
}
}
}
}
Cheers
Rich