I'm trying to use Event Push plugin and I have not managed to make it work. I read several subjects without success.
When I call newActivities, I get an error in the Chrome console:
SSE failed. Downgrading to fallback transport and resending
I don't know if it's an set up or version plugin/dependencies issue
BuildConfig
dependencies {
compile 'org.atmosphere:atmosphere-runtime:2.1.4'
}
plugins {
compile(":events-push:1.0.M7") {
excludes 'resources'
excludes 'atmosphere-runtime'
}
}
MyEvents.groovy in conf directory
events = {
'UserNotification' namespace: 'browser', browser:true
}
TestController
def newEvent() {
event([namespace: 'browser', topic: 'UserNotification'])
render "OK"
}
myView.gsp
<r:require module="grailsEvents"/>
<r:script>
var grailsEvents = new grails.Events("../TestController/newEvent",{transport:'sse'});
grailsEvents.on("UserNotification",function(){ alert("OK");});
</r:script>
Related
I'm trying to launch my Ktor backend app in Docker. But I have an exception on app start:
java.lang.IllegalStateException: No Koin Context configured. Please use startKoin or koinApplication DSL.
at org.koin.core.context.KoinContextHandler.getContext(KoinContextHandler.kt:29)
at org.koin.core.context.KoinContextHandler.get(KoinContextHandler.kt:35)
at org.koin.ktor.ext.KtorApplicationExtKt.getKoin(KtorApplicationExt.kt:34)
at com.widgets.ApplicationKt$module$$inlined$inject$1.invoke(KtorApplicationExt.kt:77)
at kotlin.UnsafeLazyImpl.getValue(Lazy.kt:81)
at com.widgets.ApplicationKt$module$4.invoke(Application.kt:117)
at com.widgets.ApplicationKt$module$4.invoke(Application.kt)
at io.ktor.auth.Authentication.configure(Authentication.kt:77)
at io.ktor.auth.Authentication$Feature.install(Authentication.kt:165)
at io.ktor.auth.Authentication$Feature.install(Authentication.kt:148)
at io.ktor.application.ApplicationFeatureKt.install(ApplicationFeature.kt:68)
at com.widgets.ApplicationKt.module(Application.kt:116)
at com.widgets.ApplicationKt.module$default(Application.kt:91)
This is my Application code:
fun main(args: Array<String>) {
embeddedServer(Netty) {
module {
install(Koin) {
modules(
module {
single<Logger> { BackendLogger() }
},
ApiInjection.koinBeans
// ...
)
}
apiModule()
}
}.start(wait = true)
}
#kotlin.jvm.JvmOverloads
fun Application.apiModule() {
val userApi by inject<UserApi>() // when this dependency used - I have a crash
// ...
}
When I launch my app locally (Intellij Idea) all works fine. So why Koin installing doesn't work correctly?
After long researching finally I've found solution.
I added this line to build.gradle file:
application {
mainClassName = "com.mypackage.ApplicationKt"
}
And also I edited resources/application.conf file:
application {
modules = [ com.mypackage ]
// modules = [ com.mypackage.ApplicationKt.module ] // previous version
}
So it helps me! And I hope it can help you!
My ruby on rails app's CSP was working perfectly until I added webpacker. Now I get this:
Content Security Policy: The page’s settings observed the loading of a resource at inline (“style-src”). A CSP report is being sent. injectStylesIntoStyleTag.js:117
Content Security Policy: The page’s settings observed the loading of a resource at inline (“style-src”). A CSP report is being sent. injectStylesIntoStyleTag.js:190
The code in question looks like this:
function insertStyleElement(options) {
var style = document.createElement('style');
...
if (typeof options.insert === 'function') {
options.insert(style);
} else {
var target = getTarget(options.insert || 'head');
if (!target) {
throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");
}
target.appendChild(style); //LINE 117//
}
return style;
}
And:
function applyToTag(style, options, obj) {
var css = obj.css;
...
if (style.styleSheet) {
style.styleSheet.cssText = css;
} else {
while (style.firstChild) {
style.removeChild(style.firstChild);
}
style.appendChild(document.createTextNode(css)); //LINE 190//
}
}
How do I add a nonce? This says to add __webpack_nonce__ = 'random'; to my entry file ( in this case app/javascript/packs/application.js), yet adding that nonce to my csp file has no effect on the style-src violation. Which in this case, looks like this: config.style_src :self, 'https://fonts.googleapis.com', 'nonce-random'
I somehow wasn't able to find the injected styles in source, but the answer was to open the page in Chrome (I was using Firefox) and copy the sha-256 hash from the console log into the app's CSP.
I'm trying to change the location of the AndroidManifest.xml file when using the experimental gradle plugin version 0.7.x. The reason for doing this is that I generate the file (as there is no manifest merger/property replacer in the experimental plugin) so I don't want an output file together with the sources.
My app build.gradle:
apply plugin: "com.android.model.application"
def buildDir = project.buildDir
model {
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.myapp.android"
minSdkVersion.apiLevel 9
targetSdkVersion.apiLevel 23
versionCode 1
versionName "1.0"
}
sources {
main {
manifest {
source {
srcDirs = ["$buildDir"]
}
}
}
}
}
}
task createManifest {
doLast {
buildDir.mkdirs()
new FileOutputStream(new File(buildDir, "AndroidManifest.xml"))
}
}
tasks.all { task ->
if (task.name.startsWith('check') && task.name.endsWith('Manifest')) {
task.dependsOn createManifest
}
}
The above configures fine but when I try to build I get:
A problem was found with the configuration of task ':app:checkDebugManifest'.
> File '/home/the_jk/source/test/app/src/main/AndroidManifest.xml' specified for property 'manifest' does not exist.`
I cannot seem to change the default manifest "property" at all, anyone had any luck?
Try
manifest { source { srcDirs = $buildDir } }
This seems to do ok with just 1 manifest, but the experimental plugin barfs if you give it 2 directories that you want to merge.
(I'm also guessing you have some other task to generate the manifest in the $buildDir since that gets blown away by clean tasks....)
Update:
Secondary issue, the check[Deubg|Release]Manifest task wants the file to exist when it runs. The above works ok for me for a static file. For something generated from a task in the build directory I had to add a dependency that looks like
task createManifest {
// code to create $buildDir if it did not exist
// code to generate AndrdroidManfest.xml in $buildDir
}
tasks.all {
task ->
if (task.name.startsWith('check') && task.name.endsWith('Manifest')) {
task.dependsOn createManifest
}
}
The tasks.all loop lets me only add it if checkDebugManifest and/or checkReleaseManifest tasks are going to happen (I had trouble with ./gradlew clean not finding the checkDebugManifest task without it.)
I had a similar issue with com.android.tools.build:gradle-experimental:0.7.0-alpha4. The way I solve it was with the following code:
sources {
main {
manifest {
source {
srcDirs = [ "$buildDir" ]
}
}
}
}
Using Jms plugin for grails and add dependencies for ActiveMQ worked perfect. No problems.
Now I want to go beyond and perform some customization and fine tuning to make ActiveMQ behaves as I need, so I need to configure the broker instance.
e.g. I want to use JDBC storage.
How is possible to do that with grails and the vm embedded broker?
I've actually followed the reference documentation for the JMS grails plugin ... I add jms plugin and activemq dependencies and place this on resources:
jmsConnectionFactory(SingleConnectionFactory) {
targetConnectionFactory = { ActiveMQConnectionFactory cf ->
//brokerURL = 'vm://localhost'
brokerURL = 'tcp://localhost:61616?jms.useAsyncSend=true'
}
}
As I've said this is fine ... but I need more tuning here, so I've tried to go adding this in the resources, so I can access the broker to fine tuning:
/* Establish the broker */
amq.broker(useJmx: false, persistent: true) {
amq.transportConnectors() {
amq.transportConnector(uri: "tcp://localhost:61616")
}
}
amqConnectionFactory(ActiveMQConnectionFactory) {
brokerURL = "vm://localhost"
}
jmsConnectionFactory(SingleConnectionFactory) {
targetConnectionFactory = ref(amqConnectionFactory)
}
But I start to have dependency problems like:
2015-03-18 13:44:14 - spring.RuntimeSpringConfigUtilities [RuntimeConfiguration] Unable to load beans from resources.groovy
org.springframework.beans.FatalBeanException: NamespaceHandler class [org.apache.xbean.spring.context.v2.XBeanNamespaceHandler] for namespace [http://activemq.apache.org/schema/core] not found; nested exception is java.lang.ClassNotFoundException: org.apache.xbean.spring.context.v2.XBeanNamespaceHandler
So I start adding dependencies:
compile 'org.apache.activemq:activemq-spring:5.7.0'
compile 'org.springframework:spring-beans:4.1.1.RELEASE'
compile 'org.apache.xbean:xbean-spring:4.1'
But still have problems:
java.lang.NoClassDefFoundError: org/springframework/core/OrderComparator$OrderSourceProvider
At this point I get the feeling that I am doing something wrong since I see too much complexity.
Is there a best way to do this?
In order to be able to configure ActiveMQ you'll need:
Dependencies:
compile 'org.apache.activemq:activemq-core:5.7.0'
compile 'org.apache.activemq:activemq-spring:5.7.0'
compile 'org.springframework:spring-beans:4.0.6.RELEASE'
compile 'org.apache.xbean:xbean-spring:4.1'
Resources.groovy:
xmlns amq:"http://activemq.apache.org/schema/core"
...
/* Establish the broker */
amq.broker(useJmx: false, persistent: true) {
amq.transportConnectors() {
amq.transportConnector(uri: "tcp://localhost:61616")
}
//HERE YOU CAN CONFIGURE BROKER
}
amqConnectionFactory(ActiveMQConnectionFactory) {
brokerURL = "vm://localhost"
}
jmsConnectionFactory(SingleConnectionFactory) {
targetConnectionFactory = ref(amqConnectionFactory)
}
The above answer of Rafael is very useful just a small change you need to do if you are working with Grails 3.2.+ it took me few hrs to figure it out.
Depedencies (add them in build.gradle)
compile 'org.grails.plugins:jms:2.0.0.RC2'
compile 'org.apache.activemq:activemq-core:5.7.0'
compile 'org.apache.activemq:activemq-spring:5.14.5'
compile 'org.apache.xbean:xbean-spring:4.1'
Resources.groovy (should look something like)
import org.apache.activemq.ActiveMQConnectionFactory
import org.springframework.jms.connection.SingleConnectionFactory
beans = {
....
xmlns amq:"http://activemq.apache.org/schema/core"
amq.broker(useJmx: false, persistent: true) {
amq.transportConnectors() {
amq.'transportConnector'(uri: "tcp://localhost:61616")
// optional if you want to do something with mqtt
amq.'transportConnector'(uri:'mqtt://0.0.0.0:61612')
}
}
jmsConnectionFactory(SingleConnectionFactory) {
targetConnectionFactory = { ActiveMQConnectionFactory cf ->
brokerURL = 'vm://localhost'
}
}
...
}
Has anyone managed to get the Geb and Spock plugins working with Grails 2.2?
If so, what exact versions of Geb, Selenium and Spock are you using?
There's a pull request in the Grails Geb example that updates to 2.2
The version can be found in the "files changed" tab:
def gebVersion = '0.9.0-RC-1'
def seleniumVersion = '2.27.0'
def spockVersion = '0.7'
My config that works on 2.2.3
in grails-app/Config/BuildConfig.groovy
def gebVersion = '0.9.0'
def seleniumVersion = '2.21.0'
def spockVersion = '0.7
dependencies {
test("org.seleniumhq.selenium:selenium-htmlunit-driver:$seleniumVersion") {
exclude "xml-apis"
}
test("org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion")
test("org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion")
test "org.spockframework:spock-grails-support:0.7-groovy-2.0"
test "org.gebish:geb-spock:$gebVersion"
}
plugins {
test ":spock:$spockVersion"
test ":geb:$gebVersion"
}
In test/functional/GebConfig.groovy
/*
This is the Geb configuration file.
See: http://www.gebish.org/manual/current/configuration.html
*/
import org.openqa.selenium.htmlunit.HtmlUnitDriver
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.chrome.ChromeDriver
// Use htmlunit as the default
// See: http://code.google.com/p/selenium/wiki/HtmlUnitDriver
driver = {
def driver = new HtmlUnitDriver()
driver.javascriptEnabled = true
driver
}
environments {
// run as “grails -Dgeb.env=chrome test-app”
// See: http://code.google.com/p/selenium/wiki/ChromeDriver
chrome {
driver = { new ChromeDriver() }
}
// run as “grails -Dgeb.env=firefox test-app”
// See: http://code.google.com/p/selenium/wiki/FirefoxDriver
firefox {
driver = { new FirefoxDriver() }
}
}