I have used WSClient on my Grails application by adding groovyws-standalone-0.3.1.jar in lib folder of my project.
Added the following code in my controller:
import groovyx.net.ws.WSClient
....
....
def wsdlUrl = "url_Of_webservice?wsdl"
def payLoad = "list_Of_Parameters"
def result = ''
def proxy = new WSClient(wsdlUrl , this.class.classLoader)
try{
proxy.initialize()
result = proxy.getallvendorsbyurl(payLoad)
}
catch (java.lang.NullPointerException e){
println "proxy not initialize"
}
It is working fine in localhost but when i deploy it on tomcat6 server, it starts throwing exception :
On server logs:
ERROR errors.GrailsExceptionResolver - groovy.lang.GroovyObjectSupport
java.lang.ClassNotFoundException: groovy.lang.GroovyObjectSupport
On GSP page:
Error 500: Executing action [groupDetails] of controller [com.ongraph.yhd.GroupController] caused exception: java.lang.NoClassDefFoundError: groovy/lang/GroovyObjectSupport
Servlet: grails
URI: /grails/group/groupDetails.dispatch
Exception Message: groovy.lang.GroovyObjectSupport
Caused by:groovy.lang.GroovyObjectSupport
Class:GroupController
At Line: [758] (groupController->line-758->def wsdlUrl = "url_Of_webservice?wsdl")
I have also gone through the below mentioned link but no luck :(
link to a similar issue
I have used grails ws-client plugin and it worked like a charm.
Related
When I wrote some tests for webflux applications. And I tried to add credentials via mutateWith(mockUser().password("password")) in WebTestClient, but it caused NPE thrown.
I used bindToServer to connect test client to the running remote APIs, and tried to use mutateWith(mockUser().password("password")) add basic authentication to the request. It throws a NPE when the tests.
Updated Source codes: https://github.com/hantsy/spring-reactive-sample/blob/master/security-method/src/test/java/com/example/demo/IntegrationTests.java#L118-L127
After I explored the source codes of mockUser, it requires a MockServer environment to run the tests, but it was run as end 2 end in my sample.
Changed mutateWith(mockUser().password("password")) to .mutate().filter(basicAuthentication("user", "password")).build(), the NPE was disappeared.
Hope this helpful for you.
#Test
public void deletingPostsWhenUserCredentialsThenForbidden_mutateWith()
throws Exception {
this.rest
.mutate().filter(basicAuthentication("user", "password")).build()
.delete()
.uri("/posts/1")
.exchange()
.expectStatus().is4xxClientError()
.expectBody().isEmpty();
}
Updated Source codes: https://github.com/hantsy/spring-reactive-sample/blob/master/security-method/src/test/java/com/example/demo/IntegrationTests.java#L118-L127
As per the grails 3.1.13 guide I am trying to add service dependency to my controller, but somehow it is not working for me. It is throwing NullPointerException for Cannot get property 'serviceMethod' on null object. Below I am mentioning the steps to reproduce.
Execute following commands
grails create-app DepInjectionTest
grails create-controller com.abc.project.KpiReport
grails create-service com.abc.project.KpiReport
Above creates below directory structure
KpiReportService
#Transactional
class KpiReportService {
def serviceMethod() {
return "Hello from KpiReportService"
}
}
KpiReportController
class KpiReportController {
def index() {
def kpiReportService
render kpiReportService.serviceMethod
//render "Hello from KpiReportController"
}
}
Exception
Grails application running at http://localhost:8080 in environment: development
ERROR org.grails.web.errors.GrailsExceptionResolver - NullPointerException occurred when processing request: [POST] /KpiReport/index
Cannot get property 'serviceMethod' on null object. Stacktrace follows:
java.lang.reflect.InvocationTargetException: null
at org.grails.core.DefaultGrailsControllerClass$ReflectionInvoker.invoke(DefaultGrailsControllerClass.java:210)
at org.grails.core.DefaultGrailsControllerClass.invoke(DefaultGrailsControllerClass.java:187)
at org.grails.web.mapping.mvc.UrlMappingsInfoHandlerAdapter.handle(UrlMappingsInfoHandlerAdapter.groovy:90)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:961)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:895)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:869)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843)
at org.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:77)
at org.grails.web.filters.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:67)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException: Cannot get property 'serviceMethod' on null object
at com.abc.project.KpiReportController.index(KpiReportController.groovy:7)
... 13 common frames omitted
Using postman for request
I am new to grails, please help me figure out what is going wrong, may be I am missing something.
The error message indicates you are referring to a property that does not exist. Instead of render kpiReportService.serviceMethod you want render kpiReportService.serviceMethod().
Services are injected as class variables
class KpiReportController {
def kpiReportService
def index() {
render kpiReportService.serviceMethod()
//render "Hello from KpiReportController"
}
}
I am using groovy http-builder and using RestClient for accessing web service from JIRA.
In development mode it's working fine but when I deploy war on Tomcat server it throws exception as
"org.apache.commons.collections.map.ListOrderedMap: method ()V
not found. Stacktrace follows:
org.codehaus.groovy.grails.web.servlet.mvc.exceptions.ControllerExecutionException:
Executing action [list] of controller [com.tristar.JiraController]
caused exception: Runtime error executing action
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662) Caused by: org.codehaus.groovy.grails.web.servlet.mvc.exceptions.ControllerExecutionException:
Runtime error executing action
... 3 more Caused by: java.lang.reflect.InvocationTargetException
... 3 more Caused by: java.lang.NoSuchMethodError: org.apache.commons.collections.map.ListOrderedMap: method ()V
not found
at net.sf.json.JSONObject.(JSONObject.java:1603)
at groovyx.net.http.EncoderRegistry.encodeJSON(EncoderRegistry.java:301)
at groovyx.net.http.HTTPBuilder$RequestConfigDelegate.setBody(HTTPBuilder.java:1200)
at groovyx.net.http.HTTPBuilder$RequestConfigDelegate.setPropertiesFromMap(HTTPBuilder.java:1111)
at groovyx.net.http.HTTPBuilder$RequestConfigDelegate.(HTTPBuilder.java:946)
at groovyx.net.http.RESTClient.post(RESTClient.java:140)
at com.tristar.JiraController.list(JiraController.groovy:221) "
def jiraApiUrl = 'http://ipAddress:8080/rest/api/2/'
def jiraClient = new RESTClient(jiraApiUrl)
def searchResults = jiraClient.post(requestContentType: JSON,
path: 'search',
body: [jql: "project=XYZ AND (status=Open OR status='In Progress') AND issuetype!=Epic AND issuetype!='Technical task'", startAt: offset, maxResults: params.max, fields: ['summary', 'description','issuetype']])
How can I fix this issue?
I am added these dependencies in Build Config
compile 'com.atlassian.jira:jira-rest-java-client-api:2.0.0-m25'
compile 'com.atlassian.jira:jira-rest-java-client-core:2.0.0-m25'
and using
AsynchronousJiraRestClientFactory factory = new AsynchronousJiraRestClientFactory()
def jiraServerUri = URI.create("ipaddress")
JiraRestClient restClient = factory.createWithBasicHttpAuthentication(jiraServerUri, "username", "password")
for authentication and getting RestClient object
Using JIRA REST Client for JAVA in Grails application is not necessary, though it might have resolved your issue. I faced the same issue and was able to create a JIRA REST client with Groovy HTTP Builder.
The only dependency that I added in BuildConfig.groovy was:
dependencies {
compile("org.codehaus.groovy.modules.http-builder:http-builder:0.5.0-RC1") {
excludes 'groovy', 'xml-apis' } }
Then build your JSON query and post your request:
jiraClient.post(requestContentType: JSON, body: query)
If you're looking for more info this blog post might help:
http://ashahrami.blogspot.ca/2014/12/jira-rest-client-implementation-in.html
I am trying to read message bundle in a job (Grails 2.0, Quartz-0.4.2):
class Job1Job {
def timeout = 5000l // execute job once in 5 seconds
def grailsApplication
def execute() {
def ctx = grailsApplication.mainContext
def bean = ctx.getBean('org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib')
println bean.message(code:'default.home.label')
}
}
And get error:
Error 2011-12-28 14:30:14,021 [quartzScheduler_Worker-5] ERROR listeners.ExceptionPrinterJobListener - Exception occured in job: GRAILS_JOBS.testappcontext.Job1Job
Message: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
The code works perfectly in controller and service. What I am doing wrong ?
I suspect this code run perfectly in grails 1.3.7
You're going the long way around - just use what the taglib uses, the messageSource bean:
class Job1Job {
long timeout = 5000 // execute job once in 5 seconds
def messageSource
void execute() {
println messageSource.getMessage('default.home.label', null, Locale.default)
}
}
I've deployed my grails application on weblogic server. The front end is grails and backend is using spring and hibernate (not using gorm).
I am seeing the following error when I try to access a static dummy page:
<Dec 11, 2011 5:15:02 AM EST> <Error> <HTTP> <BEA-101362> <[ServletContext#450252357[app: spec-version:2.5]] could not deserialize the request scoped attribute with name: "userService"
java.io.NotSerializableException: org.codehaus.groovy.grails.commons.spring.ReloadAwareAutowireCapableBeanFactory
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1156)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1474)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
at org.springframework.transaction.interceptor.TransactionInterceptor.writeObject(TransactionInterceptor.java:186)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Truncated. see log file for complete stacktrace
><[ServletContext#450252357[app: spec-version:2.5]] could not deserialize the request scoped attribute with name: "referenceDataService"
java.io.NotSerializableException: org.codehaus.groovy.grails.commons.spring.ReloadAwareAutowireCapableBeanFactory
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1156)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1474)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
at org.springframework.transaction.interceptor.TransactionInterceptor.writeObject(TransactionInterceptor.java:186)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Truncated. see log file for complete stacktrace
>
Here are the action & controller classes:
class UserAdminController {
def messageSource
def userService
def referenceDataService
def manageUsers = {
render(view: "manageUsers")
}
def showCreateUserAdmin = {
//code goes here
}
}
The reason for writing a dummy action is that the user shouldn't call the gsp page using manageUsers.gsp.
How can I fix this issue?