curl: (52) Empty reply from server while calling ejabbered API Commands - docker

My ejabberd server is running in a docker container and I am trying to call ejabberd API commands. Somehow I am always getting "curl: (52) Empty reply from server". I don't know where I am wrong in configuring yml file for ejabbered.
I tried getting the list of vhosts and registered_users. But all I am getting is Empty reply.
Below is my YML file
hosts:
- localhost
loglevel: 4
log_rotate_size: 10485760
log_rotate_date: ""
log_rotate_count: 1
log_rate_limit: 100
certfiles:
- /home/ejabberd/conf/server.pem
ca_file: "/home/ejabberd/conf/cacert.pem"
## When using let's encrypt to generate certificates
##certfiles:
## - /etc/letsencrypt/live/localhost/fullchain.pem
## - /etc/letsencrypt/live/localhost/privkey.pem
##
##ca_file: "/etc/letsencrypt/live/localhost/fullchain.pem"
listen:
-
port: 5222
ip: "::"
module: ejabberd_c2s
max_stanza_size: 262144
shaper: c2s_shaper
access: c2s
starttls_required: true
-
port: 5269
ip: "::"
module: ejabberd_s2s_in
max_stanza_size: 524288
-
port: 5443
ip: 127.0.0.1
module: ejabberd_http
request_handlers:
/: ejabberd_web_admin
"/api": mod_http_api
"/bosh": mod_bosh
"/captcha": ejabberd_captcha
"/upload": mod_http_upload
"/ws": ejabberd_http_ws
"/oauth": ejabberd_oauth
-
port: 5180
ip: "::"
module: ejabberd_http
request_handlers:
/: ejabberd_web_admin
-
port: 1883
ip: "::"
module: mod_mqtt
backlog: 1000
##
## https://docs.ejabberd.im/admin/configuration/#stun-and-turn
## ejabberd_stun: Handles STUN Binding requests
##
##-
## port: 3478
## ip: "0.0.0.0"
## transport: udp
## module: ejabberd_stun
## use_turn: true
## turn_ip: "{{ IP }}"
## auth_type: user
## auth_realm: "example.com"
##-
## port: 3478
## ip: "0.0.0.0"
## module: ejabberd_stun
## use_turn: true
## turn_ip: "{{ IP }}"
## auth_type: user
## auth_realm: "example.com"
##-
## port: 5349
## ip: "0.0.0.0"
## module: ejabberd_stun
## certfile: "/home/ejabberd/conf/server.pem"
## tls: true
## use_turn: true
## turn_ip: "{{ IP }}"
## auth_type: user
## auth_realm: "example.com"
##
## https://docs.ejabberd.im/admin/configuration/#sip
## To handle SIP (VOIP) requests:
##
##-
## port: 5060
## ip: "0.0.0.0"
## transport: udp
## module: ejabberd_sip
##-
## port: 5060
## ip: "0.0.0.0"
## module: ejabberd_sip
##-
## port: 5061
## ip: "0.0.0.0"
## module: ejabberd_sip
## tls: true
s2s_use_starttls: optional
acl:
local:
user_regexp: ""
loopback:
ip:
- 127.0.0.0/8
- ::1/128
- ::FFFF:127.0.0.1/128
admin:
user:
- "admin#localhost"
access_rules:
local:
allow: local
c2s:
deny: blocked
allow: all
announce:
allow: admin
configure:
allow: admin
muc_create:
allow: local
pubsub_createnode:
allow: local
trusted_network:
allow: loopback
api_permissions:
"console commands":
from:
- ejabberd_ctl
- mod_http_api
who: all
what: "*"
"admin access":
who:
access:
allow:
##acl: loopback
acl: admin
oauth:
scope: "ejabberd:admin"
scope: "registered_users"
access:
allow:
##acl: loopback
acl: admin
what:
- "*"
- "!stop"
- "!start"
"public commands":
from:
- mod_http_api
who:
ip: 127.0.0.1/8
what:
- "*"
- "!stop"
- "!start"
shaper:
normal: 1000
fast: 50000
shaper_rules:
max_user_sessions: 10
max_user_offline_messages:
5000: admin
100: all
c2s_shaper:
none: admin
normal: all
s2s_shaper: fast
max_fsm_queue: 10000
acme:
contact: "mailto:example-admin#example.com"
ca_url: "https://acme-staging-v02.api.letsencrypt.org/directory"
modules:
mod_adhoc: {}
mod_admin_extra: {}
mod_announce:
access: announce
mod_avatar: {}
mod_blocking: {}
mod_bosh: {}
mod_caps: {}
mod_carboncopy: {}
mod_client_state: {}
mod_configure: {}
mod_disco: {}
mod_fail2ban: {}
mod_http_api: {}
mod_http_upload:
put_url: https://#HOST#:5443/upload
mod_last: {}
mod_mam:
## Mnesia is limited to 2GB, better to use an SQL backend
## For small servers SQLite is a good fit and is very easy
## to configure. Uncomment this when you have SQL configured:
## db_type: sql
assume_mam_usage: true
default: never
mod_mqtt: {}
mod_muc:
access:
- allow
access_admin:
- allow: admin
access_create: muc_create
access_persistent: muc_create
access_mam:
- allow
default_room_options:
allow_subscription: true # enable MucSub
mam: false
mod_muc_admin: {}
mod_offline:
access_max_user_messages: max_user_offline_messages
mod_ping: {}
mod_privacy: {}
mod_private: {}
mod_proxy65:
access: local
max_connections: 5
mod_pubsub:
access_createnode: pubsub_createnode
plugins:
- flat
- pep
force_node_config:
## Avoid buggy clients to make their bookmarks public
storage:bookmarks:
access_model: whitelist
mod_push: {}
mod_push_keepalive: {}
mod_register:
## Only accept registration requests from the "trusted"
## network (see access_rules section above).
## Think twice before enabling registration from any
## address. See the Jabber SPAM Manifesto for details:
## https://github.com/ge0rg/jabber-spam-fighting-manifesto
ip_access: trusted_network
mod_roster:
versioning: true
mod_sip: {}
mod_s2s_dialback: {}
mod_shared_roster: {}
mod_stream_mgmt:
resend_on_timeout: if_offline
mod_vcard: {}
mod_vcard_xupdate: {}
mod_version:
show_os: false
### Local Variables:
### mode: yaml
### End:
### vim: set filetype=yaml tabstop=8

Assuming a configuration that includes at least those parts:
hosts:
- localhost
listen:
port: 5443
ip: "::"
module: ejabberd_http
tls: true
request_handlers:
"/api": mod_http_api
-
port: 5280
ip: "::"
module: ejabberd_http
request_handlers:
"/api": mod_http_api
api_permissions:
"admin access":
who:
access:
allow: all
what:
- "registered_users"
modules:
...
mod_http_api: {}
All those queries work correctly:
curl -X GET \
http://localhost:5280/api/registered_users?host=localhost
curl -X POST \
http://localhost:5280/api/registered_users \
-d '{"host": "localhost"}'
curl -X GET \
--insecure \
https://localhost:5443/api/registered_users?host=localhost
curl -X POST \
--insecure \
https://localhost:5443/api/registered_users \
-d '{"host": "localhost"}'
All them report the same result:
["admin"]
In the ejabberd log file you should view something like:
2022-02-14 20:13:41.686208+00:00 [info] (<0.758.0>)
Accepted connection [::ffff:172.18.0.1]:50040 -> [::ffff:172.18.0.2]:5443
2022-02-14 20:13:41.696906+00:00 [info]
API call registered_users [{<<"host">>,<<"localhost">>}] from ::ffff:172.18.0.1:50040

Related

configtxgen command doesn't work. How can I resolve?

I'm having a problem running the "configtxgen" command to generate the genesis block.
I'm following this specific guide and in the part where you have to run this command, the following errors come out:
$ configtxgen -profile IstumNetworkProfile -channelID system-channel -configPath ${PWD}/config -outputBlock ./system-genesis-block/genesis.block
2023-01-31 11:38:54.354 CET [common/tools/configtxgen] main -> INFO 001 Loading configuration
2023-01-31 11:38:54.378 CET [common/tools/configtxgen/localconfig] Load -> CRIT 002 Error unmarshaling config into struct: 4 error(s) decoding:
* 'Orderer' has invalid keys: EtcdRaft
* 'Organizations[0]' has invalid keys: OrdererEndpoints
* 'Profiles[IstumNetworkProfile].Orderer' has invalid keys: EtcdRaft
* 'Profiles[IstumNetworkProfile].Orderer.Organizations[0]' has invalid keys: OrdererEndpoints
2023-01-31 11:38:54.379 CET [common/tools/configtxgen] func1 -> CRIT 003 Error unmarshaling config into struct: 4 error(s) decoding:
* 'Orderer' has invalid keys: EtcdRaft
* 'Organizations[0]' has invalid keys: OrdererEndpoints
* 'Profiles[IstumNetworkProfile].Orderer' has invalid keys: EtcdRaft
* 'Profiles[IstumNetworkProfile].Orderer.Organizations[0]' has invalid keys: OrdererEndpoints
panic: Error unmarshaling config into struct: 4 error(s) decoding:
* 'Orderer' has invalid keys: EtcdRaft
* 'Organizations[0]' has invalid keys: OrdererEndpoints
* 'Profiles[IstumNetworkProfile].Orderer' has invalid keys: EtcdRaft
* 'Profiles[IstumNetworkProfile].Orderer.Organizations[0]' has invalid keys: OrdererEndpoints [recovered]
panic: Error unmarshaling config into struct: 4 error(s) decoding:
* 'Orderer' has invalid keys: EtcdRaft
* 'Organizations[0]' has invalid keys: OrdererEndpoints
* 'Profiles[IstumNetworkProfile].Orderer' has invalid keys: EtcdRaft
* 'Profiles[IstumNetworkProfile].Orderer.Organizations[0]' has invalid keys: OrdererEndpoints
My cryptogen version is :
$ cryptogen version
cryptogen:
Version: 1.2.0
Commit SHA: cae2ad4
Go version: go1.10
OS/Arch: linux/amd64
And this is my configtx.yaml file. Can you check if it is correct?
Organizations:
- &OrdererOrg
Name: OrdererOrg
ID: OrdererMSP # Consente agli altri partecipanti alla rete l'identificazione di questa entità.
MSPDir: ../crypto-material/ordererOrganizations/istum.com/msp
Policies: # Configurazione del tipo di ruoli a cui si è autorizzati a fare
Readers:
Type: Signature
Rule: "OR('OrdererMSP.member')"
Writers:
Type: Signature
Rule: "OR('OrdererMSP.member')"
Admins:
Type: Signature
Rule: "OR('OrdererMSP.admin')"
OrdererEndpoints:
- orderer0.istum.com:7050
- &Org1
Name: Org1
ID: Org1MSP # Consente agli altri partecipanti alla rete l'identificazione di questa entità.
MSPDir: ../crypto-material/peerOrganizations/org1.istum.com/msp
Policies: # Configurazione del tipo di ruoli a cui si è autorizzati a fare
Readers:
Type: Signature
Rule: "OR('Org1MSP.member')"
Writers:
Type: Signature
Rule: "OR('Org1MSP.member')"
Admins:
Type: Signature
Rule: "OR('Org1MSP.admin')"
Endorsement:
Type: Signature
Rule: "OR('Org1MSP.member')"
AnchorPeers: # Gateway peer da un'organizzazione all'Anchor Peer di un'altra organizzazione
- Host: peer0.org1.istum.com
Port: 7051
- &Org2
Name: Org2
ID: Org2MSP # Consente agli altri partecipanti alla rete l'identificazione di questa entità.
MSPDir: ../crypto-material/peerOrganizations/org2.istum.com/msp
Policies: # Configurazione del tipo di ruoli a cui si è autorizzati a fare
Readers:
Type: Signature
Rule: "OR('Org2MSP.member')"
Writers:
Type: Signature
Rule: "OR('Org2MSP.member')"
Admins:
Type: Signature
Rule: "OR('Org2MSP.admin')"
Endorsement:
Type: Signature
Rule: "OR('Org2MSP.member')"
AnchorPeers: # Gateway peer da un'organizzazione all'Anchor Peer di un'altra organizzazione
- Host: peer0.org2.istum.com
Port: 8051
- &Org3
Name: Org3
ID: Org3MSP # Consente agli altri partecipanti alla rete l'identificazione di questa entità.
MSPDir: ../crypto-material/peerOrganizations/org3.istum.com/msp
Policies: # Configurazione del tipo di ruoli a cui si è autorizzati a fare
Readers:
Type: Signature
Rule: "OR('Org3MSP.member')"
Writers:
Type: Signature
Rule: "OR('Org3MSP.member')"
Admins:
Type: Signature
Rule: "OR('Org3MSP.admin')"
Endorsement:
Type: Signature
Rule: "OR('Org3MSP.member')"
AnchorPeers: # Gateway peer da un'organizzazione all'Anchor Peer di un'altra organizzazione
- Host: peer0.org2.istum.com
Port: 8052
# Nelle Capabilities *Channel* definisce il set di funzionalità di Hyperledger che viene utilizzato solo dai peer,
# mentre *Orderer* definisce il set di funzionalità che è rilevante (lo indovini) solo per gli ordini.
# L'*applicazione* , d'altra parte, definisce il set di funzionalità, che è rilevante per tutti i peer E tutti gli ordinatori e quindi definisce il minimo comune denominatore per l'intera rete.
Capabilities:
Channel: &ChannelCapabilities
V2_0: true
Orderer: &OrdererCapabilities
V2_0: true
Application: &ApplicationCapabilities
V2_0: true
Application: &ApplicationDefaults
Organizations:
Policies:
Readers:
Type: ImplicitMeta
Rule: "ANY Readers"
Writers:
Type: ImplicitMeta
Rule: "ANY Writers"
Admins:
Type: ImplicitMeta
Rule: "MAJORITY Admins"
LifecycleEndorsement:
Type: ImplicitMeta
Rule: "MAJORITY Endorsement"
Endorsement:
Type: ImplicitMeta
Rule: "MAJORITY Endorsement"
Capabilities:
<<: *ApplicationCapabilities
Orderer: &OrdererDefaults
OrdererType: etcdraft
EtcdRaft:
Options:
TickInterval: 500ms
ElectionTick: 10
HeartbeatTick: 1
MaxInflightBlocks: 5
SnapshotIntervalSize: 20971520
Consenters:
- Host: orderer0.istum.com
Port: 7050
ClientTLSCert: ../crypto-material/ordererOrganizations/istum.com/orderers/orderer0.istum.com/tls/server.crt
ServerTLSCert: ../crypto-material/ordererOrganizations/istum.com/orderers/orderer0.istum.com/tls/server.crt
BatchTimeout: 2s # Definiscono alcune specifiche riguardanti il ​​tempo dopo il quale un blocco dovrebbe essere
BatchSize: # costruito e quante transazioni dovrebbe contenere al massimo
MaxMessageCount: 10
AbsoluteMaxBytes: 99 MB
PreferredMaxBytes: 512 KB
Organizations:
Policies: # Configurazione del tipo di ruoli a cui si è autorizzati a fare (in questo caso per l'intera rete)
Readers:
Type: ImplicitMeta
Rule: "ANY Readers"
Writers:
Type: ImplicitMeta
Rule: "ANY Writers"
Admins:
Type: ImplicitMeta
Rule: "MAJORITY Admins"
BlockValidation:
Type: ImplicitMeta
Rule: "ANY Writers"
Channel: &ChannelDefaults #Si definisce qui quali criteri di canale predefiniti sono impostati per il canale
Policies:
Readers:
Type: ImplicitMeta
Rule: "ANY Readers"
Writers:
Type: ImplicitMeta
Rule: "ANY Writers"
Admins:
Type: ImplicitMeta
Rule: "MAJORITY Admins"
Capabilities:
<<: *ChannelCapabilities
Profiles:
IstumNetworkProfile:
<<: *ChannelDefaults
Orderer:
<<: *OrdererDefaults #definiscono chi sarà in grado di modificare ( Admins ) la nostra rete o semplicemente leggere / scrivere ( Readers / Writers ) sulla nostra rete.
Organizations: # Qui definiamo da quali organizzazioni provengono i nostri ordinatori
- *OrdererOrg
Capabilities:
<<: *OrdererCapabilities
Consortiums:
IstumConsortium:
Organizations: # Quali organizzazioni sono autorizzate a unirsi alla rete e creare canali ecc..?
- *Org1
- *Org2
- *Org3
IstumChannelProfile:
Consortium: IstumConsortium
<<: *ChannelDefaults
Application:
<<: *ApplicationDefaults
Organizations:
- *Org1
- *Org2
- *Org3
Capabilities:
<<: *ApplicationCapabilities
Thanks a lot to whoever will help me!!
EDIT
I resolved by downgrade my Hyperledger Binaries to 1.4.7 version!!

Selenium::WebDriver::Error::UnknownError: unknown error: net::ERR_CONNECTION_REFUSED Docker Capybara ROR 6

I am trying to run capybara test for minitest through docker-compose and I can no longer connect to my selenium chrome browser. It complains that the connection is failing. The service itself, begins to spin up when the tests are run. How can I properly connect my rails application to the chrome service setup? Mind you, we do use subdomains -- so there will always be a test running with it set.
Error:
HelloWorldCapybaraTest#test_testing_navigation:
Selenium::WebDriver::Error::UnknownError: unknown error: net::ERR_CONNECTION_REFUSED
(Session info: chrome=108.0.5359.98)
test/features/hello_world_capybara_test.rb:12:in `block in <class:HelloWorldCapybaraTest>'
docker-compose.yml
web:
init: true
build: ~/projects/web/
container_name: testme
restart: unless-stopped
ports:
- "3000:3000"
- "5000:5000"
volumes:
- ~/projects/web:/web
- /web/node_modules
depends_on:
- mongo
links:
- elasticsearch
- selenium_chrome
command: sh -c "./docker_scripts/run-rails.sh"
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- PGHOST=postgres
- MONGODB_USER=admin
- MONGODB_PASSWORD=root
- MONGODB_URL=mongo:27017
- RAILS_ENV=development
tty: true
stdin_open: true
selenium_chrome:
image: selenium/standalone-chrome
privileged: true
ports:
- "5900:5900"
- "4444:4444"
- "7900:7900"
test_helper.rb
WebMock.allow_net_connect!
require 'capybara/rails'
require 'capybara/minitest'
require 'capybara/dsl'
require 'webdrivers'
class ActionDispatch::IntegrationTest
include Capybara::DSL
include Capybara::Minitest::Assertions
config.include Rails.application.routes.url_helpers
Capybara.default_max_wait_time = 10
Capybara.run_server = false
Capybara.default_driver = :selenium_chrome_in_container
Capybara.always_include_port = true
Capybara.server_host = "0.0.0.0"
Capybara.server_port = 5000
Capybara.javascript_driver = :selenium
Capybara.register_driver :headless_selenium_chrome_in_container do |app|
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: { args: %w(headless disable-gpu disable-dev-shm-usage window-size=1440x768) }
)
Capybara::Selenium::Driver.new(app,
:browser => :remote,
url: "http://selenium_chrome:4444/wd/hub",
capabilities: capabilities
)
end
Capybara.register_driver :selenium_chrome_in_container do |app|
Capybara::Selenium::Driver.new(app,
:browser => :remote,
url: "http://selenium_chrome:4444/wd/hub",
capabilities: :chrome
)
end
# Reset sessions and driver between tests
teardown do
Capybara.reset_sessions!
end
end
hello_world_capybara_test.rb
require 'test_helper'
class HelloWorldCapybaraTest < ActionDispatch::IntegrationTest
setup do
#company = create(:company)
#mailing = create(:user)
Capybara.server_host = '0.0.0.0'
Capybara.server_port = 5000
Capybara.app_host = "http://#{#company.subdomain}.lvh.me:5000"
end
test 'testing navigation' do
visit new_user_session_url
end
end
Logs
web-selenium_chrome-1 | 19:43:35.809 INFO [LocalDistributor.newSession] - Session request received by the Distributor:
web-selenium_chrome-1 | [Capabilities {browserName: chrome}]
web-selenium_chrome-1 | Starting ChromeDriver 108.0.5359.71 (1e0e3868ee06e91ad636a874420e3ca3ae3756ac-refs/branch-heads/5359#{#1016}) on port 24771
web-selenium_chrome-1 | Only local connections are allowed.
web-selenium_chrome-1 | Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
web-selenium_chrome-1 | ChromeDriver was started successfully.
web-selenium_chrome-1 | [1671392615.878][SEVERE]: bind() failed: Cannot assign requested address (99)
web-selenium_chrome-1 | 19:43:37.496 INFO [LocalNode.newSession] - Session created by the Node. Id: 5fb54cb47e07699de29b43b00ecef29a, Caps: Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 108.0.5359.98, chrome: {chromedriverVersion: 108.0.5359.71 (1e0e3868ee06..., userDataDir: /tmp/.com.google.Chrome.PEanHy}, goog:chromeOptions: {debuggerAddress: localhost:39557}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: LINUX, proxy: Proxy(), se:cdp: http://localhost:39557, se:cdpVersion: 108.0.5359.98, se:vncEnabled: true, se:vncLocalAddress: ws://172.18.0.6:7900, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
web-selenium_chrome-1 | 19:43:37.507 INFO [LocalDistributor.newSession] - Session created by the Distributor. Id: 5fb54cb47e07699de29b43b00ecef29a
web-selenium_chrome-1 | Caps: Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 108.0.5359.98, chrome: {chromedriverVersion: 108.0.5359.71 (1e0e3868ee06..., userDataDir: /tmp/.com.google.Chrome.PEanHy}, goog:chromeOptions: {debuggerAddress: localhost:39557}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: LINUX, proxy: Proxy(), se:bidiEnabled: false, se:cdp: ws://172.18.0.6:4444/sessio..., se:cdpVersion: 108.0.5359.98, se:vnc: ws://172.18.0.6:4444/sessio..., se:vncEnabled: true, se:vncLocalAddress: ws://172.18.0.6:7900, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
web-selenium_chrome-1 | 19:43:38.397 WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "1d19d9608398dc55bfe4ff408f323fa2","eventTime": 1671392618396368100,"eventName": "HTTP request execution complete","attributes": {"http.flavor": 1,"http.handler_class": "org.openqa.selenium.remote.http.Route$PredicatedRoute","http.host": "selenium_chrome:4444","http.method": "POST","http.request_content_length": "45","http.scheme": "HTTP","http.status_code": 500,"http.target": "\u002fsession\u002f5fb54cb47e07699de29b43b00ecef29a\u002furl","http.user_agent": "selenium\u002f4.1.0 (ruby linux)"}}
web-selenium_chrome-1 |
web-selenium_chrome-1 | 19:43:38.926 INFO [LocalSessionMap.lambda$new$0] - Deleted session from local Session Map, Id: 5fb54cb47e07699de29b43b00ecef29a
web-selenium_chrome-1 | 19:43:38.929 INFO [GridModel.release] - Releasing slot for session id 5fb54cb47e07699de29b43b00ecef29a
web-selenium_chrome-1 | 19:43:38.931 INFO [SessionSlot.stop] - Stopping session 5fb54cb47e07699de29b43b00ecef29a
mongo | {"t":{"$date":"2022-12-18T19:43:47.530+00:00"},"s":"I", "c":"NETWORK", "id":22944, "ctx":"conn31","msg":"Connection ended","attr":{"remote":"172.18.0.8:60484","connectionId":31,"connectionCount":27}}
mongo | {"t":{"$date":"2022-12-18T19:43:47.547+00:00"},"s":"I", "c":"NETWORK", "id":22944, "c

Grails 3.2.6 with spring security. In memory h2 database is not created when saving users

I didn't find a solution from other postings although this seems a problems that others have encountered.
This is my application.yml
---
grails:
profile: web-plugin
codegen:
defaultPackage: bioprofile
spring:
transactionManagement:
proxies: false
info:
app:
name: '#info.app.name#'
version: '#info.app.version#'
grailsVersion: '#info.app.grailsVersion#'
spring:
main:
banner-mode: "off"
groovy:
template:
check-template-location: false
# Spring Actuator Endpoints are Disabled by Default
endpoints:
enabled: false
jmx:
enabled: true
---
grails:
mime:
disable:
accept:
header:
userAgents:
- Gecko
- WebKit
- Presto
- Trident
types:
all: '*/*'
atom: application/atom+xml
css: text/css
csv: text/csv
form: application/x-www-form-urlencoded
html:
- text/html
- application/xhtml+xml
js: text/javascript
json:
- application/json
- text/json
multipartForm: multipart/form-data
pdf: application/pdf
rss: application/rss+xml
text: text/plain
hal:
- application/hal+json
- application/hal+xml
xml:
- text/xml
- application/xml
urlmapping:
cache:
maxsize: 1000
controllers:
defaultScope: singleton
converters:
encoding: UTF-8
views:
default:
codec: html
gsp:
encoding: UTF-8
htmlcodec: xml
codecs:
expression: html
scriptlets: html
taglib: none
staticparts: none
endpoints:
jmx:
unique-names: true
---
hibernate:
cache:
queries: false
use_second_level_cache: true
use_query_cache: false
region.factory_class: org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
dataSources:
dataSource:
pooled: true
jmxExport: true
driverClassName: org.h2.Driver
username: sa
password:
dbCreate: create-drop
dialect : com.hp.opr.hibernate.dialect.H2Dialect
url: jdbc:h2:mem:blogDB;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
master:
pooled: true
jmxExport: true
driverClassName: org.h2.Driver
username: sa
password:
dbCreate: create-drop
url: jdbc:h2:mem:masterDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
but when the application starts and in the bootstrap I try to add some users:
User admin = new User(username: 'admin', password: 'password')
admin.save(flush: true)
User user = new User(username: 'user', password: 'user')
user.save(flsuh:true)
Role adminRole = new Role(authority: Role.ROLE_ADMIN)
adminRole.save(flush:true)
Role userRole = new Role(authority: Role.ROLE_USER)
userRole.save(flush:true)
UserRole.create(admin, adminRole)
UserRole.create(admin, userRole)
UserRole.create(user, userRole)
no database is created.
However if I open the console from the url: http://localhost:8080/dbconsole than a database is created.
Any idea why ?
You are using the in-memory configuration of H2 in your grails config, so no database file is created. But when you open the dbconsole, there problably is a connection string with a file instead of in-memory configuration, so a db file is created. Change the config in the dbconsole configuration.

grails incompatible with neo4j

I am trying to develop a sample application using grails and neo4j. I am using grails 3.0.8. I have installed the neo4j plugin and have followed the instructions as mentioned in the documentation. I have updated application.yml to include neo4j credentials. My application.yml looks something like this.
---
grails:
profile: web
codegen:
defaultPackage: sftwitter
info:
app:
name: '#info.app.name#'
version: '#info.app.version#'
grailsVersion: '#info.app.grailsVersion#'
spring:
groovy:
template:
check-template-location: false
---
grails:
mime:
disable:
accept:
header:
userAgents:
- Gecko
- WebKit
- Presto
- Trident
types:
all: '*/*'
atom: application/atom+xml
css: text/css
csv: text/csv
form: application/x-www-form-urlencoded
html:
- text/html
- application/xhtml+xml
js: text/javascript
json:
- application/json
- text/json
multipartForm: multipart/form-data
pdf: application/pdf
rss: application/rss+xml
text: text/plain
hal:
- application/hal+json
- application/hal+xml
xml:
- text/xml
- application/xml
urlmapping:
cache:
maxsize: 1000
controllers:
defaultScope: singleton
converters:
encoding: UTF-8
views:
default:
codec: html
gsp:
encoding: UTF-8
htmlcodec: xml
codecs:
expression: html
scriptlets: html
taglib: none
staticparts: none
---
grails:
neo4j:
type: rest
location: http://localhost:7474/db/data/
username: neo4j
password: welcome123
hibernate:
cache:
queries: false
use_second_level_cache: true
use_query_cache: false
region.factory_class: 'org.hibernate.cache.ehcache.EhCacheRegionFactory'
endpoints:
jmx:
unique-names: true
dataSource:
pooled: true
jmxExport: true
driverClassName: org.h2.Driver
username: sa
password:
environments:
development:
dataSource:
username: neo4j
password: welcome123
dbCreate: create-drop
url: jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
test:
dataSource:
dbCreate: update
url: jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
production:
dataSource:
dbCreate: update
url: jdbc:h2:./prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
properties:
jmxEnabled: true
initialSize: 5
maxActive: 50
minIdle: 5
maxIdle: 25
maxWait: 10000
maxAge: 600000
timeBetweenEvictionRunsMillis: 5000
minEvictableIdleTimeMillis: 60000
validationQuery: SELECT 1
validationQueryTimeout: 3
validationInterval: 15000
testOnBorrow: true
testWhileIdle: true
testOnReturn: false
jdbcInterceptors: ConnectionState
defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED
The code executes fine, but when I try to create the instance of a domain I get an error like this.
ERROR org.grails.web.errors.GrailsExceptionResolver - IllegalStateException occurred when processing request: [GET] /person/index
Method on class [neo4j.Person] was used outside of a Grails application. If running in the context of a test using the mocking API or bootstrap Grails correctly.. Stacktrace follows:
java.lang.reflect.InvocationTargetException: null
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_60]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_60]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_60]
Caused by: java.lang.IllegalStateException: Method on class [neo4j.Person] was used outside of a Grails application. If running in the context of a test using the mocking API or bootstrap Grails correctly.
at neo4j.PersonController.index(PersonController.groovy:13) ~[main/:na]
at grails.transaction.GrailsTransactionTemplate$2.doInTransaction(GrailsTransactionTemplate.groovy:93) ~[grails-core-3.0.8.jar:3.0.8]
at grails.transaction.GrailsTransactionTemplate.execute(GrailsTransactionTemplate.groovy:90) ~[grails-core-3.0.8.jar:3.0.8]
... 3 common frames omitted
I have done this configuration completely as per the documentation, then why am I getting this error. Is it that the newer versions of grails are having compatibility issues with neo4j or is it that I have made some mistake in the configuration.

Symfony strange factories.yml

I needed to send an email through symfony but in my factories.yml it has something like this
all:
routing:
class: sfPatternRouting
param:
generate_shortest_url: true
extra_parameters_as_query_string: true
view_cache_manager:
class: sfViewCacheManager
param:
cache_key_use_vary_headers: true
cache_key_use_host_name: true
And I modify them to something like:
all:
mailer:
param:
transport:
class: Swift_SmtpTransport
param:
host: smtp.gmail.com
port: 465
encryption: ssl
username: myemail#gmail.com
password: password
will it effect anything ? or what's the original on top does?
Why remove the previous values? Just merge the two files, like this:
all:
routing:
class: sfPatternRouting
param:
generate_shortest_url: true
extra_parameters_as_query_string: true
view_cache_manager:
class: sfViewCacheManager
param:
cache_key_use_vary_headers: true
cache_key_use_host_name: true
mailer:
param:
transport:
class: Swift_SmtpTransport
param:
host: smtp.gmail.com
port: 465
encryption: ssl
username: myemail#gmail.com
password: password
otherwise the settings for the routing and the view_cache_manager will be the one you can find on that other factories.yml somewhere in lib/vendor/symfony

Resources