Grails profile plugin issue - grails

I am working to add the Grails profile plugin the documentation says I should add...
log4j {
...
logger {
...
com.linkedin.grails = "info"
}
...
}
This seems to suggest it should be something more like...
com.linkedin.grails "info"
But when I run that I get...
Error | log4j:ERROR Property missing when configuring log4j: com Error
| log4j:ERROR WARNING: Exception occured configuring log4j logging: No
signature of method: groovy.util.ConfigObject.grails() is applicable
for argument types: (java.lang.String) values: [info]
Can someone help with what I am missing

You have the order backwards. First comes loglevel, then comes the package.
info "com.linkedin.grails"

Related

Grails log4j SMTPAppender NoClassDefFoundError

How do I configure SMTPAppender in a new Grails 2.4.5 project? I receive a NoClassDefFoundError when running in the development environment:
| Error log4j:ERROR Error initializing log4j: javax/mail/Message
| Error java.lang.NoClassDefFoundError: javax/mail/Message
Gist: Detailed stacktrace
I have configured a dependency for javax.mail and configured log4j as follows:
dependencies {
provided 'javax.mail:mail:1.4.7'
}
log4j = {
appenders {
appender new org.apache.log4j.net.SMTPAppender(
name: 'smtp',
layout: pattern(conversionPattern: '%d{MM-dd-yyyy HH:mm:ss.SSS} [%t] %c %M %x%n%p: %m%n')
to: 'example#example.com',
from: 'example#example.com',
subject: 'Grails Message',
SMTPHost: '127.0.0.1')
)
}
}
GitHub: Example Project
I know this post is old, but I struggled with the same till I found a solution that is at least working for me (not with SMTPAppender but with Sentry - same purpose).
The explanation I found with the errors you where receiving
Error log4j:ERROR Error initializing log4j: javax/mail/Message
Error java.lang.NoClassDefFoundError: javax/mail/Message
Come from this piece of code:
dependencies {
provided 'javax.mail:mail:1.4.7'
}
The thing is that when you compile things work, when you try to do grails run-app you receive this error.
The explanation I found is that the log4j initializes before the maven dependency is resolved.
I wrote a comment of how I've used Sentry as an appender.
https://github.com/getsentry/raven-java/issues/184#issuecomment-259432057
Basically, instead of adding the maven dependency I've downloaded the java file, and added it to the grails project in src/java
So for Sentry por example I added the SentryAppender.java to my.package.sentry so then in log4j I added:
appenders {
environments {
// This block is set up to use the stock raven SentryAppender in
// production. Sentry Appender runs into all kinds of
// class loading weirdness when used in a forked grails environment
production {
appender new my.package.sentry.SentryAppender(
name: 'sentry',
dsn: 'REDACTED',
threshold: org.apache.log4j.Level.WARN
)
}
// Uncomment this block if you need to test sentry
// in a dev environment
development {
appender new my.package.sentry.SentryAppender(
name: 'sentry',
dsn: 'REDACTED',
threshold: org.apache.log4j.Level.WARN
)
}
}
}
root {
warn 'stdout', 'sentry'
error 'stdout', 'sentry'
additivity = false
}
in that way, it does not depend on an external dependency.
I guess that you could do something similar to the mail dependency and add the java files to the src folder.
I hope it helps!
That looks weird - are you combining the dependencies block and the log4j block here unintenionally, or are they in the same file in your app? The dependency should be in BuildConfig.groovy and the log4j block should be in Config.groovy. Also, it shouldn't be log4j { but rather log4j = {.
This is likely a timing issue. If Config.groovy is parsed before the Javamail dependency is resolved, it will fail. Try commenting out the parts that reference the Javamail classes and run grails clean and grails compile. That will resolve dependencies and add that jar to the classpath. Then you can uncomment that code and run grails compile again.

Grails won't read external config file?

I'm on Windows 7. Inside my Grails (2.3.6) app's Config.groovy file I have:
grails.config.locations = [
"file:/etc/myapp/env.groovy"
]
// fizz.buzz is defined inside env.groovy
println "fizz.buzz=${fizz.buzz}"
At the root of my D:\ drive:
etc/
myapp/
env.groovy
When I run grails -Dgrails.env=local run-app I get the following output:
fizz.buzz=[:]
What's going on here? Why can't Grails find my env.groovy file and/or read its properties?
My permissions:
Running File('/etc/myapp/env.groovy').absolutePath in the Groovy Console, I get:
Exception thrown
groovy.lang.MissingMethodException: No signature of method: ConsoleScript2.File() is
applicable for argument types: (java.lang.String) values: [/etc/myapp/env.groovy]
Possible solutions: find(), find(groovy.lang.Closure), use([Ljava.lang.Object;),
with(groovy.lang.Closure), is(java.lang.Object), wait()
I also tried running my app and passing in the value for fizz.buzz on the command line via a switch like so:
grails -Dgrails.env=local -Dfizz.buzz="true" run-app
The result was the same. Is it possible that the configs ARE being read in, but are just not available (caching, etc.) at the time that the println is running inside Config.groovy?

No such property: GormEncryptedStringType when installing jasypt in grails

I'm trying to use Jasypt plugin on my grails project. I followed the setup described on the wiki but I got the following exception:
ERROR context.GrailsContextLoader - Error executing bootstraps: Error evaluating ORM mappings block for domain [domain.Branch]: No such property: GormEncryptedStringType for class: org.codehaus.groovy.grails.orm.hibernate.cfg.HibernateMappingBuilder
Message: Error evaluating ORM mappings block for domain [domain.Branch]: No such property: GormEncryptedStringType for class: org.codehaus.groovy.grails.orm.hibernate.cfg.HibernateMappingBuilder
Does any body have any idea how to solve this?
Thanks,
It might be as simple as a missing import line:
import com.bloomhealthco.jasypt.GormEncryptedStringType

grails wsclient "file not found" consuming a .net web service

first of all, I want to apologize if my question is stupid, but I'm really new in consuming .net web service in grails.
There's a SOAP WS (wich I can't manipulate in any way) that I consume whis way:
def wsdlURL = "_HttpUrl_'/AspNetOracleProviderService.asmx?WSDL"
def proxy = webService.getClient(wsdlURL) <= This is the line where my project fails
Now, I've tested this service in a asp.Net Project with no troubles, but in Grails it generates me this error:
Error 500: Executing action [create] of controller [pruebaplugins.PruebaWsClientController] caused exception: Unable to create JAXBContext for generated packages: "com.something.anothersomething" doesnt contain ObjectFactory.class or jaxb.index
I have defined the JAVA_HOME and javac Is there, I can acces to it in any location in a command prompt.
At the end of this post I'll put de detailed info.
I've only tested this service and the well-known Celsius-Farenheit example, wich works with no problems, I think it's because it only returns a String, unlike mine or any other services.
I don't know if its a lack of something, surely could be something I ignore.
Like I said, I'm very new in this kind of stuff and I'd appreciate any kind of help.
Thanks anyway.
Detailed info:
When I put
debug 'org.apache.cxf'
in log4j in Config.groovy
the output throw me this:
2012-01-25 16:08:13,514 [http-8080-2] INFO spring.BusApplicationContext - Refreshing org.apache.cxf.bus.spring.BusApplicationContext#5c3e99: startup date [Wed Jan 25 16:08:13 CLST 2012]; root of context hierarchy
2012-01-25 16:08:13,639 [http-8080-2] INFO spring.BusApplicationContext
- No cxf.xml configuration file detected, relying on defaults.
2012-01-25 16:08:13,820 [http-8080-2] DEBUG spring.ControlledValidationXmlBeanDefinitionReader
- Loaded 0 bean definitions from location pattern [classpath:META-INF/cxf/cxf-extension-http.xml]
2012-01-25 16:08:13,848 [http-8080-2] DEBUG spring.BusApplicationContext
- Bean factory for org.apache.cxf.bus.spring.BusApplicationContext#5c3e99: org.springframework.beans.factory.support.DefaultListableBeanFactory#e3e8f3: defining beans [cxf,org.apache.cxf.bus.spring.BusApplicationListener,org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor,org.apache.cxf.bus.spring.Jsr250BeanPostProcessor,org.apache.cxf.bus.spring.BusExtensionPostProcessor,org.apache.cxf.resource.ResourceManager,org.apache.cxf.configuration.Configurer,org.apache.cxf.binding.BindingFactoryManager,org.apache.cxf.transport.DestinationFactoryManager,org.apache.cxf.transport.ConduitInitiatorManager,org.apache.cxf.wsdl.WSDLManager,org.apache.cxf.phase.PhaseManager,org.apache.cxf.workqueue.WorkQueueManager,org.apache.cxf.buslifecycle.BusLifeCycleManager,org.apache.cxf.endpoint.ServerRegistry,org.apache.cxf.endpoint.ServerLifeCycleManager,org.apache.cxf.endpoint.ClientLifeCycleManager,org.apache.cxf.transports.http.QueryHandlerRegistry,org.apache.cxf.endpoint.EndpointResolverRegistry,org.apache.cxf.headers.HeaderManager,org.apache.cxf.catalog.OASISCatalogManager,org.apache.cxf.endpoint.ServiceContractResolverRegistry,org.apache.cxf.binding.corba.CorbaBindingFactory,org.apache.cxf.binding.corba.wsdl.WSDLExtensionRegister#0,org.apache.cxf.jaxws.context.WebServiceContextResourceResolver,org.apache.cxf.jaxws.context.WebServiceContextImpl,org.apache.cxf.binding.soap.SoapBindingFactory,org.apache.cxf.binding.soap.SoapTransportFactory,org.apache.cxf.binding.soap.customEditorConfigurer,org.apache.cxf.binding.xml.XMLBindingFactory,org.apache.cxf.ws.addressing.policy.AddressingAssertionBuilder,org.apache.cxf.ws.addressing.policy.AddressingPolicyInterceptorProvider,org.apache.cxf.ws.addressing.policy.UsingAddressingAssertionBuilder,org.apache.cxf.javascript.JavascriptQueryHandlerRegistry,org.apache.cxf.transport.local.LocalTransportFactory,org.apache.cxf.transport.http.policy.HTTPClientAssertionBuilder,org.apache.cxf.transport.http.policy.HTTPServerAssertionBuilder,org.apache.cxf.transport.http.policy.NoOpPolicyInterceptorProvider,org.apache.cxf.transport.http.ClientOnlyHTTPTransportFactory,org.apache.cxf.management.InstrumentationManager,org.apache.cxf.transport.http_jetty.JettyHTTPTransportFactory,org.apache.cxf.transport.jms.JMSTransportFactory,org.apache.cxf.binding.object.ObjectBindingFactory,org.apache.cxf.binding.http.HttpBindingFactory,org.apache.cxf.jaxrs.JAXRSBindingFactory,org.apache.cxf.ws.security.policy.WSSecurityPolicyLoader,org.apache.cxf.ws.policy.AssertionBuilderRegistry,org.apache.cxf.ws.policy.PolicyInterceptorProviderRegistry,org.apache.cxf.ws.policy.attachment.external.DomainExpressionBuilderRegistry,org.apache.cxf.ws.policy.attachment.external.EndpointReferenceDomainExpressionBuilder,org.apache.cxf.ws.policy.PolicyBuilder,org.apache.cxf.ws.policy.PolicyEngine,org.apache.cxf.ws.policy.attachment.wsdl11.Wsdl11AttachmentPolicyProvider,org.apache.cxf.ws.policy.attachment.ServiceModelPolicyProvider,org.apache.cxf.ws.policy.mtom.MTOMAssertionBuilder,org.apache.cxf.ws.policy.mtom.MTOMPolicyInterceptorProvider,org.apache.cxf.ws.rm.RMManager,org.apache.cxf.ws.rm.policy.RMPolicyInterceptorProvider,org.apache.cxf.ws.rm.RMAssertionBuilder]; root of factory hierarchy
2012-01-25 16:08:14,009 [http-8080-2] DEBUG spring.BusApplicationContext
- Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource#cb229]
2012-01-25 16:08:14,009 [http-8080-2] DEBUG spring.BusApplicationContext
- Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster#184b649]
2012-01-25 16:08:16,095 [http-8080-2] DEBUG spring.BusApplicationContext
- Unable to locate LifecycleProcessor with name 'lifecycleProcessor': using default [org.springframework.context.support.DefaultLifecycleProcessor#1e10f02]
2012-01-25 16:08:18,925 [http-8080-2] INFO dynamic.DynamicClientFactory
- Created classes: com.something.anothersmth.Aplicacion, com.something.anothersmth.ArrayOfControl, com.something.anothersmth.ArrayOfModulo, com.something.anothersmth.ArrayOfPagina, com.something.anothersmth.ArrayOfRol, etc (...all the classes)
javac: file not found: C:\Users\DYT01\AppData\Local\Temp\org.apache.cxf.endpoint.dynamic.DynamicClientFactory#8a3c71-1327518498999-src\com\something\anothersmth\CambiarContraseña.java
Usage: javac
use -help for a list of possible options
2012-01-25 16:08:20,637 [http-8080-2] ERROR dynamic.DynamicClientFactory - Could not compile java files for ...HttpUrl/AspNetOracleProviderService.asmx?WSDL.

Setting grails proxy username with special \ character causes error

Our firm uses a corporate proxy with a username in the following form domainName\username . When I try to add the proxy from command line using add-proxy command.
The exception I get is:
Error WARNING: Error configuring proxy settings: startup failed:
C:\Documents and Settings\username\.grails\ProxySettings.groovy: 1: unexpected cha
r: '\' # line 1, column 94.
8080", "http.proxyUser":"company\username"
What is the workaround for this? I tried manually editing the ProxySettings.groovy file, but same error is thrown on startup.
[UPDATE] I tried with Grails 2.0.0 RC3 but still unable to connect.
It looks like you have ran into a grails bug, when domain is used in the proxy configuration: http://jira.grails.org/browse/GRAILS-7387. The work-around is to configure the proxy within the BuildConfig.groovy (kind of manually). Add the following to the existing company\username:
grails.project.dependency.resolution = {
System.setProperty("http.proxyHost", "host");
System.setProperty("http.proxyPort", "port");
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("company\\username","password".toCharArray());
}
});
[rest of code]
}
This way there shouldn't be problems with the backslash.

Resources