Sunday, April 14, 2024

eclipse: java: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder" or Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder

 

>PROBLEM

Using Eclipse, you try to run a simple logging test using "org.slf4j.Logger" like the sample below:


package Test;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Test {

    private static final Logger LOGGER = LoggerFactory.getLogger(Test.class);

    public static void main(String[] args) {

        LOGGER.info("done");

    }

}


Unfortunately, it fails to return the following message:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

or:

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder



>SOLUTION


1. Check your slf4j jars.

First, make sure that you have the correct dependency jars.

For instance:

  slf4j-api-2.0.13.jar
  slf4j-simple-2.0.13.jar


More information:

https://www.slf4j.org/codes.html#StaticLoggerBinder

https://www.slf4j.org/faq.html#changesInVersion200


2. Check the Eclipse's ".classpath" file.

Edit it to find if there is some inconsistency with your lib, like references that differ in content.
It is rare but it may happen.

Make a copy of it (backup).
Edit it, and try to find old references to other conflicting jars.
Example of old entry not automatically removed by Eclipse:

    <classpathentry kind="lib" path="lib/log4j-1.2.15.jar"/>

You also may get the ".classpath" from another and similar project that works well, remove the unnecessary entries and insert the missing ones.

On Eclipse, close the project that you are fixing, replace it with the new ".classpath" file, and reopen the project.

Test it again.


3. Check the project libs searching for one that already provides the slf4j.

If a lib already contains the slf4j, its version may conflict with the slf4j's jars.

A simple way to check if the project has a lib that already contains slf4j is to remove the explicit slf4j jars from the project.

If the "import" to slf4j still works, not alarming that it misses the slf4j lib, then one of your jars is offering it.


For instance, the "apacheds-all" lib (apacheds-all-1.5.5.jar, apacheds-all-2.0.0.AM27.jar).

By the way...

"ApacheDS is an embeddable directory server entirely written in Java, which has been certified LDAPv3 compatible by the Open Group. Besides LDAP it supports Kerberos 5 and the Change Password Protocol. It has been designed to introduce triggers, stored procedures, queues and views to the world of LDAP which has lacked these rich constructs."

To discover which lib already contains the slf4j lib, you may create another project without lib (empty). The project will have just one class that uses slf4j like the example above (Test class).

Delete the jar files, all of them.
Update the project and check if the import is not working.
OK, if not, the test is successful.

Now add some jars and update the project.
Check again if the import is not resolving.
If it is, good! It means that there isn't a lib offering the slf4j.
Repeat this cycle adding other libs until the import is resolved.
There you go! Isolate the jar file that resolves the slf4j import and you have discovered the conflict.


>ENV

java
eclipse


Monday, April 1, 2024

java: spring boot/spring/mongodb: org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class



>PROBLEM


Attempt to save an instance on MongoDB database fails returning:

  org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class ...

  

  or for this example:

  org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class com.drillback.ws5.model.mongodb.MongoTest.


- other possible error messages:

custom Codec or PojoCodec may need to be explicitly configured and registered to handle this type.] with root cause 
org.bson.BsonInvalidOperationException: readString can only be called when CurrentBSONType is STRING, not when CurrentBSONType is DOCUMENT.


or yet:

Failed to decode 'MongoInfo'. Decoding 'references' errored with: readString can only be called when CurrentBSONType is STRING, not when CurrentBSONType is DOCUMENT.
A custom Codec or PojoCodec may need to be explicitly configured and registered to handle this type.] with root cause
org.bson.BsonInvalidOperationException: readString can only be called when CurrentBSONType is STRING, not when CurrentBSONType is DOCUMENT.


>SOLUTION


Follow the example below, check:

1. The java class has the @Document annotaion.

2. Just one constructor must have @BsonCreator annotation, with all fields.


>Java class example

@Document

//@Document(collection = "test")

public class MongoTest {


// @Id, or @BsonId

@BsonId

@BsonProperty("_id") public BsonObjectId id = null;

@BsonProperty("title") public String title = "";

@BsonProperty("regdate") public Date regdate = new Date();


@BsonCreator

public MongoTest(

@BsonProperty("_id") BsonObjectId id,

@BsonProperty("title") String title,

@BsonProperty("regdate") Date regdate

) {

this.id = id;

this.title = title;

this.regdate = regdate;

}



>ENV

Spring Boot (spring)

MongoDB

Java 17




Tuesday, January 16, 2024

virtualbox6: debian: netbeans install issues: "dpkg: warning: 'ldconfig' not found in PATH or not executable" and "pkg-deb: error: archive 'apache-netbeans_....deb' uses unknown compression for member 'control.tar.zst', giving up"

 

>PROBLEMS/SOLUTIONS


You desire to install Netbeans on a Debian O.S. using the VirtualBox v.6 because the VirtualBox v.7 fails on your current Windows 10 installation.

The first task is to download the Netbeans, and we usually do this using the last version, trying the following commands to install:

sudo apt install openjdk-17-jdk curl wget unzip
cd /home/USERNAME/Downloads
chmod 777 apache-netbeans_20-1_all.deb
dpkg -i apache-netbeans_20-1_all.deb

>PROBLEM #1

Then, the "dpkg" command throws the following error message:

dpkg: warning: 'ldconfig' not found in PATH or not executable
dpkg: warning: 'start-stop-daemon' not found in PATH or not executable
dpkg: error: 2 expected programs not found in PATH or not executable


>SOLUTION #1

scite /etc/profile &
export PATH=$PATH:/sbin

or

scite ~/.profile
export PATH=$PATH:/sbin

- Reboot and run dpkg command again, and you may get the problem #2.

>PROBLEM #2

Running the install command again:

dpkg -i apache-netbeans_20-1_all.deb


Returns:

pkg-deb: error: archive 'apache-netbeans_20-1_all.deb' uses unknown compression for member 'control.tar.zst', giving up
dpkg: error processing archive apache-netbeans_20-1_all.deb (--install):
 dpkg-deb --control subprocess returned error exit status 2



>SOLUTION #2

Remembering that VirtualBox v.6 is no longer maintained, we need to consider a possible downgrade.
If the last Netbeans version fails with the following procedure, download a previous version, until you get compatibility. In this procedure the attempt with the v.19 was enough.

Download the Netbeans , first apply alien command to make it compatible, then run dpkg as follow:

alien apache-netbeans_19-1_all.deb
dpkg -i apache-netbeans_19-1_all.deb

And... voilĂ !

Now, read to run Netbeans, and  on prompt do:

netbeans &

Note: if everything goes well, the installation set the netbeans command at:

/usr/bin/netbeans &


>ENV

Windows 10
VirtualBox 6
debian 10..12
netbeans 19..20

Tuesday, January 2, 2024

oracle: SQL Error: ORA-01861: literal does not match format string , 01861. 00000 - "literal does not match format string"


 >PROBLEM


The attempt to insert data from a migrated code from PostgreSQL to on a Oracle database using automatic generator resulted a generic message error.


- The insert command:

INSERT INTO loc_users( loc_users_id, nome, login, email, senha, nascimento, celular, idioma, ativo ) VALUES ( 1, 'Yuzefo', 'Abibeh', 'william@copel.com.br', 'Apukoyal', '1951-08-31', '05292770147', 'english', 1);



- Oracle returns a generic message not providing a tip to a specific field:


SQL Error: ORA-01861: literal does not match format string

01861. 00000 -  "literal does not match format string"

*Cause:    Literals in the input must be the same length as literals in

           the format string (with the exception of leading whitespace).  If the

           "FX" modifier has been toggled on, the literal must match exactly,

           with no extra whitespace.

*Action:   Correct the format string to match the literal.


>SOLUTION


Check your DDL comparing with the insert statement.

Usually operations involving date, time and timestamp cause issues during migration.

In this example, the field "nascimento" (born date in portuguese) has an incompatible format for date as concerns Oracle's usage.


Set TO_DATE() function:

TO_DATE('1951-08-31', 'YYYY-MM-DD')


INSERT INTO loc_users( loc_users_id, nome, login, email, senha, nascimento, celular, idioma, ativo ) VALUES ( 1, 'Yuzefo', 'Abibeh', 'william@copel.com.br', 'Apukoyal', TO_DATE('1951-08-31', 'YYYY-MM-DD'), '05292770147', 'english', 1);



>ENV

oracle 11g


Monday, January 1, 2024

oracle: timestamp ORA-01882: timezone region not found

 

>PROBLEM


Attempt to insert data using sqlplus (command console) into a table having TIMESTAMP type fails, returning error message.

SQL>INSERT INTO card( id, title, content, cardsz, colors, created_at, updated_at ) VALUES ( 1, 'test1 modified', 'hello world!\n', '', 'yellow', TIMESTAMP '2021-11-27 02:41:25 PM', TIMESTAMP '2022-06-01 09:56:56 PM');

- Output:
ERROR at line 1:
ORA-01882: timezone region not found


The target table configuration:

desc card;

ID NUMBER(10,0) No 1
TITLE VARCHAR2(255 BYTE) Yes 2
CONTENT CLOB Yes 3
CARDSZ VARCHAR2(16 BYTE) Yes 4
COLORS VARCHAR2(32 BYTE) Yes 5
CREATED_AT TIMESTAMP(6) No CURRENT_TIMESTAMP 6
UPDATED_AT TIMESTAMP(6) Yes "CURRENT_TIMESTAMP " 7


>SOLUTION


The issue was caused due a notation difference between the timestamp format migrated from a PostgreSQL dump, that uses the "AM|PM" and no reference to timezone (i.e. -03:00) values.

In the example given, the issue was solved just replacing the "PM" with the timezone value (-03:00) string from the timestamp, as follows:

INSERT INTO card( id, title, content, cardsz, colors, created_at, updated_at ) VALUES ( 1, 'test1 modified', 'hello world!\n', '', 'yellow', TIMESTAMP '2021-11-27 02:41:25 -03:00', TIMESTAMP '2022-06-01 09:56:56 -03:00');


>ENV


oracle 11g
sqlplus


Sunday, December 31, 2023

oracle: how to drop if exists a table

 

>PROBLEM

Oracle doesn't have "if exists" but it may be replaced by a procedure.


>SOLUTION

1. Run the following procedure on the target database.

create or replace procedure drop_table
(tablename in varchar2)

IS
dropcmd varchar(300);
table_exists NUMBER;
drop_ignored varchar(100);
dropped_msg varchar(100);
tabledropped varchar(100);

BEGIN
dropcmd := 'DROP TABLE ' || tablename;
drop_ignored := 'table ' || tablename || ' not found - dropping skipped';
dropped_msg := 'dropped table ' || tablename;
select COUNT(*) into table_exists from user_tables where table_name = upper(tablename);

IF table_exists > 0 THEN
-- DBMS_OUTPUT.PUT_LINE('dropping ' || tablename);
EXECUTE IMMEDIATE dropcmd;
commit;
select table_name into tabledropped from user_tables where table_name = upper(tablename);
ELSE
DBMS_OUTPUT.PUT_LINE(drop_ignored);
END IF;

exception
when no_data_found then
DBMS_OUTPUT.PUT_LINE(dropped_msg);
when others then
DBMS_OUTPUT.PUT_LINE(dropped_msg);


END;
/

show errors;



2. To test the procedure, create a table:


CREATE TABLE TESTONE.BIN017_BIDS ( 
BID_ID               NUMBER(19)   NOT NULL,
BID_DATE             TIMESTAMP(6)   ,
BID_PRICE            NUMBER(19,4)   ,
BIDDER_ID            VARCHAR2(255)   ,
ITEM_ID              NUMBER(19)   ,
CONSTRAINT SYS_C0023242 PRIMARY KEY ( BID_ID ) 
 );


3. Run the procedure to test it:

exec drop_table('BIN017_BIDS')


>ENV

Oracle 12g
pssql
sqlplus

Sunday, November 5, 2023

spring: APPLICATION FAILED TO START, , Description:, , Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured., , Reason: Failed to determine a suitable driver class,


 >PROBLEM

Starting the application, it fails returning the following message:


***************************

APPLICATION FAILED TO START

***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class


Action:

Consider the following:

If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.

If you have database settings to be loaded from a particular profile you may need to activate it (the profiles dev are currently active).




>SOLUTION


Cause:

Error on the scanBasePackages configuration that points to a wrong package.


wrong:
@SpringBootApplication(scanBasePackages={"com.drillback"})


package com.mongolib.ws;
import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication;


@SpringBootApplication(scanBasePackages={"com.drillback"})
public class Application {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}



Fix:

@SpringBootApplication(scanBasePackages={"com.mongolib"})


package com.mongolib.ws;

import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication(scanBasePackages={"com.mongosvc"})
public class Application {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}



>ENV

Spring 2.x

Wednesday, August 16, 2023

502 Bad Gateway


>PROBLEM

Attempt to access the site returns:

502 Bad Gateway


>SOLUTION

Scenario: there is a server interfacing with external requests like Nginx or Apache.

In such cases, the application behind the Nginx, Apache, etc. may have stopped working, returning no answer.

Go to the application's log and check its state.

Make sure that it is responsive.


>ENV

- x -


Tuesday, August 15, 2023

spring: spring boot: ERR_TOO_MANY_REDIRECTS


>PROBLEM


You try to access the site redirects to the default URL and the browser returns:

ERR_TOO_MANY_REDIRECTS




>SOLUTION

Edit your security class configuration that usually extends extends WebSecurityConfigurerAdapter.
Add the URL that fails.

@Configuration

@EnableWebSecurity

public class SpringSecConfig extends WebSecurityConfigurerAdapter {



@Override

protected void configure(HttpSecurity httpSecurity) throws Exception {

httpSecurity.cors().disable();

httpSecurity.headers().frameOptions().disable();

httpSecurity.csrf().disable()

.authorizeRequests()

.antMatchers("/", "THE MISSING URL HERE").permitAll()


//...

}


>ENV

Java
Spring/Spring Boot

java: spring boot: How to search project issues in the stack trace

 

>PROBLEM

The application throws a lot of exceptions and you get confused to understand the cause because there are so many compiler complaints.


>SOLUTION

Follow by the example below.
If you go to the first compiler's complaint, you'll be mislead.

To find the real cause, the one that triggered the others, begin from the bottom to the top of the stack trace (the yellow in the example). 
The issue was caused for a field notation error. On the database the field is denoted by "pass" and not "password". Check the images at the bottom.


2023-08-15 09:37:23 # [restartedMain] # ERROR # o.s.boot.SpringApplication # method: reportFailure # Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'appController': Unsatisfied dependency expressed through field 'wsSvc'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'wsSvcImpl': Unsatisfied dependency expressed through field 'encryptionSvc'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'encryptionSvc': Unsatisfied dependency expressed through field 'securitySvc'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securitySvc': Unsatisfied dependency expressed through field 'accControlSvc'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'accControlSvc': Unsatisfied dependency expressed through field 'accControlRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accControlRepository' defined in com.drillback.setget5.model.repository.security.AccControlRepository defined in @EnableJpaRepositories declared on JpaConfiguration: Invocation of init method failed; nested exception is org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract com.drillback.setget5.model.repository.security.AccControl com.drillback.setget5.model.repository.security.AccControlRepository.findByEmailAndMsg(java.lang.String,java.lang.String)! Reason: Validation failed for query for method public abstract com.drillback.setget5.model.repository.security.AccControl com.drillback.setget5.model.repository.security.AccControlRepository.findByEmailAndMsg(java.lang.String,java.lang.String)!; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract com.drillback.setget5.model.repository.security.AccControl com.drillback.setget5.model.repository.security.AccControlRepository.findByEmailAndMsg(java.lang.String,java.lang.String)!

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'wsSvcImpl': Unsatisfied dependency expressed through field 'encryptionSvc'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'encryptionSvc': Unsatisfied dependency expressed through field 'securitySvc'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securitySvc': Unsatisfied dependency expressed through field 'accControlSvc'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'accControlSvc': Unsatisfied dependency expressed through field 'accControlRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accControlRepository' defined in com.drillback.setget5.model.repository.security.AccControlRepository defined in @EnableJpaRepositories declared on JpaConfiguration: Invocation of init method failed; nested exception is org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract com.drillback.setget5.model.repository.security.AccControl com.drillback.setget5.model.repository.security.AccControlRepository.findByEmailAndMsg(java.lang.String,java.lang.String)! Reason: Validation failed for query for method public abstract com.drillback.setget5.model.repository.security.AccControl com.drillback.setget5.model.repository.security.AccControlRepository.findByEmailAndMsg(java.lang.String,java.lang.String)!; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract com.drillback.setget5.model.repository.security.AccControl com.drillback.setget5.model.repository.security.AccControlRepository.findByEmailAndMsg(java.lang.String,java.lang.String)!

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'encryptionSvc': Unsatisfied dependency expressed through field 'securitySvc'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securitySvc': Unsatisfied dependency expressed through field 'accControlSvc'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'accControlSvc': Unsatisfied dependency expressed through field 'accControlRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accControlRepository' defined in com.drillback.setget5.model.repository.security.AccControlRepository defined in @EnableJpaRepositories declared on JpaConfiguration: Invocation of init method failed; nested exception is org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract com.drillback.setget5.model.repository.security.AccControl com.drillback.setget5.model.repository.security.AccControlRepository.findByEmailAndMsg(java.lang.String,java.lang.String)! Reason: Validation failed for query for method public abstract com.drillback.setget5.model.repository.security.AccControl com.drillback.setget5.model.repository.security.AccControlRepository.findByEmailAndMsg(java.lang.String,java.lang.String)!; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract com.drillback.setget5.model.repository.security.AccControl com.drillback.setget5.model.repository.security.AccControlRepository.findByEmailAndMsg(java.lang.String,java.lang.String)!

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securitySvc': Unsatisfied dependency expressed through field 'accControlSvc'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'accControlSvc': Unsatisfied dependency expressed through field 'accControlRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accControlRepository' defined in com.drillback.setget5.model.repository.security.AccControlRepository defined in @EnableJpaRepositories declared on JpaConfiguration: Invocation of init method failed; nested exception is org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract com.drillback.setget5.model.repository.security.AccControl com.drillback.setget5.model.repository.security.AccControlRepository.findByEmailAndMsg(java.lang.String,java.lang.String)! Reason: Validation failed for query for method public abstract com.drillback.setget5.model.repository.security.AccControl com.drillback.setget5.model.repository.security.AccControlRepository.findByEmailAndMsg(java.lang.String,java.lang.String)!; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract com.drillback.setget5.model.repository.security.AccControl com.drillback.setget5.model.repository.security.AccControlRepository.findByEmailAndMsg(java.lang.String,java.lang.String)!

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'accControlSvc': Unsatisfied dependency expressed through field 'accControlRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accControlRepository' defined in com.drillback.setget5.model.repository.security.AccControlRepository defined in @EnableJpaRepositories declared on JpaConfiguration: Invocation of init method failed; nested exception is org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract com.drillback.setget5.model.repository.security.AccControl com.drillback.setget5.model.repository.security.AccControlRepository.findByEmailAndMsg(java.lang.String,java.lang.String)! Reason: Validation failed for query for method public abstract com.drillback.setget5.model.repository.security.AccControl com.drillback.setget5.model.repository.security.AccControlRepository.findByEmailAndMsg(java.lang.String,java.lang.String)!; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract com.drillback.setget5.model.repository.security.AccControl com.drillback.setget5.model.repository.security.AccControlRepository.findByEmailAndMsg(java.lang.String,java.lang.String)!

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accControlRepository' defined in com.drillback.setget5.model.repository.security.AccControlRepository defined in @EnableJpaRepositories declared on JpaConfiguration: Invocation of init method failed; nested exception is org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract com.drillback.setget5.model.repository.security.AccControl com.drillback.setget5.model.repository.security.AccControlRepository.findByEmailAndMsg(java.lang.String,java.lang.String)! Reason: Validation failed for query for method public abstract com.drillback.setget5.model.repository.security.AccControl com.drillback.setget5.model.repository.security.AccControlRepository.findByEmailAndMsg(java.lang.String,java.lang.String)!; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract com.drillback.setget5.model.repository.security.AccControl com.drillback.setget5.model.repository.security.AccControlRepository.findByEmailAndMsg(java.lang.String,java.lang.String)!

Caused by: org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract com.drillback.setget5.model.repository.security.AccControl com.drillback.setget5.model.repository.security.AccControlRepository.findByEmailAndMsg(java.lang.String,java.lang.String)! Reason: Validation failed for query for method public abstract com.drillback.setget5.model.repository.security.AccControl com.drillback.setget5.model.repository.security.AccControlRepository.findByEmailAndMsg(java.lang.String,java.lang.String)!; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract com.drillback.setget5.model.repository.security.AccControl com.drillback.setget5.model.repository.security.AccControlRepository.findByEmailAndMsg(java.lang.String,java.lang.String)!

Caused by: java.lang.IllegalArgumentException: Validation failed for query for method public abstract com.drillback.setget5.model.repository.security.AccControl com.drillback.setget5.model.repository.security.AccControlRepository.findByEmailAndMsg(java.lang.String,java.lang.String)!

Caused by: java.lang.IllegalArgumentException: org.hibernate.QueryException: could not resolve property: password of: com.drillback.setget5.model.repository.security.AccControl [from com.drillback.setget5.model.repository.security.AccControl ac where ac.email=:email and ac.password=:password]

Caused by: org.hibernate.QueryException: could not resolve property: password of: com.drillback.setget5.model.repository.security.AccControl [from com.drillback.setget5.model.repository.security.AccControl ac where ac.email=:email and ac.password=:password]

Caused by: org.hibernate.QueryException: could not resolve property: password of: com.drillback.setget5.model.repository.security.AccControl








>ENV

Java


Wednesday, July 12, 2023

RabbitMQ: Application terminated: factory failed to instantiate due to: Unsupported or unrecognized SSL message.

 

>PROBLEM


Attempt to access the RabbitMQ service, throws the follwing:


Application terminated: factory failed to instantiate due to: Unsupported or unrecognized SSL message.

javax.net.ssl.SSLException: java.net.SocketException: Connection reset

at sun.security.ssl.Alert.createSSLException(Alert.java:127)

at sun.security.ssl.TransportContext.fatal(TransportContext.java:370)

at sun.security.ssl.TransportContext.fatal(TransportContext.java:313)

at sun.security.ssl.TransportContext.fatal(TransportContext.java:308)

at sun.security.ssl.SSLTransport.decode(SSLTransport.java:141)

at sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1290)

...

Suppressed: java.net.SocketException: Connection reset by peer: socket write error

at java.net.SocketOutputStream.socketWrite0(Native Method)

at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:111)

...

Caused by: java.net.SocketException: Connection reset

at java.net.SocketInputStream.read(SocketInputStream.java:210)

at java.net.SocketInputStream.read(SocketInputStream.java:141)

at sun.security.ssl.SSLSocketInputRecord.read(SSLSocketInputRecord.java:475)

...

javax.net.ssl.SSLException: java.net.SocketException: Connection reset

at sun.security.ssl.Alert.createSSLException(Alert.java:127)

at sun.security.ssl.TransportContext.fatal(TransportContext.java:370)

at sun.security.ssl.TransportContext.fatal(TransportContext.java:313)

...

Caused by: java.net.SocketException: Connection reset

at java.net.SocketInputStream.read(SocketInputStream.java:210)

at java.net.SocketInputStream.read(SocketInputStream.java:141)

at sun.security.ssl.SSLSocketInputRecord.read(SSLSocketInputRecord.java:475)


>SOLUTION


Enable or disable the SSL protocol.

An example of the properties file (application.yml):


  rabbit-host: mydomain.com 

  rabbit-port: 5672

  rabbit-ssl: false

  rabbit-user: john doe

  rabbit-pass: secret



Java code snippet to check the "rabbit-ssl" property:


if (PropertiesYml.BROKER_SSL) {

try {

factory.useSslProtocol();

this.connection = factory.newConnection();

} catch (KeyManagementException | NoSuchAlgorithmException | IOException | TimeoutException e) {

logger.error(String.format("Application terminated: factory failed to instantiate due to: %s.", e.getMessage()));

}

} else {

try {

this.connection = factory.newConnection();

} catch (IOException | TimeoutException e) {

logger.error(String.format("Application terminated: factory failed to instantiate due to: %s.", e.getMessage()));

}

}


>ENV

RabbitMQ v3.7.8
Erlang v21.2.6
Java 17

RabbitMQ: Caused by: com.rabbitmq.client.ShutdownSignalException: connection error, java.io.IOException, Caused by: java.io.EOFException


>PROBLEM


Attempt to connect to RabbitMQ returns the following:


java.io.IOException

at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:129)

at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:125)

at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:396)

...

Caused by: com.rabbitmq.client.ShutdownSignalException: connection error

...

Caused by: java.io.EOFException

at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:290)

...

Caused by: com.rabbitmq.client.ShutdownSignalException: connection error

...

Caused by: java.io.EOFException

at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:290)

...

java.io.IOException

at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:129)

at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:125)

at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:396)

...

Caused by: com.rabbitmq.client.ShutdownSignalException: connection error

Caused by: java.io.EOFException

at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:290)

...



>SOLUTION


Check the following:

1.Usually, the console management uses 15672 port.

2. Usually, the HTTP request via app (web service/microserve) uses 5672

3. Make sure to enable these ports when working with container (docker).

4. Avoid using /api  on a RESTful web service because "/api" is already used by the native rabbitmq's ws,



An example of the properties file (application.yml):

  rabbit-host: mydomain.com 

  rabbit-port: 5672

  rabbit-ssl: false

  rabbit-user: john doe

  rabbit-pass: secret


>ENV

RabbitMQ v3.7.8
Erlang v21.2.6
Java 17

Thursday, June 1, 2023

software engineering: reducing risks and issues when deploying on production

 

>PROBLEM

While developing an application, you have worked using local env(environment), using your local database or cloud resources of your own.
Then, it comes the time when you need to deploy to production or another job's env.
It is the moment that may happen the usual setbacks, issues showing differences among the job's env versus your local env.

The question is:
How may you reduce the issues when deploying on another env?


>SOLUTION

The full evaluation of all possibilities is impossible, so I'll offer you an example, and  by analogy you may apply to yours.

One very trivial item from our checklist is the resources closing, like files and database connections.
This example uses PostgreSQL database and the connections issues.

In our checklist we may have these two basic items:
1- How does the job's database env differ from my local database?
2- How to test my application to make sure that all resources are really closed when it is terminated?


Solving item 2 - Is your app functioning well?

First, make sure that your application is closing all resources.
For instance, if using PostgreSQL, do:

a - Before starting the app, run:

SELECT sum(numbackends) FROM pg_stat_database;
The cmd returns the number of busy connections, for example: 8

b - Start your app and run some features.

c - Repeat step "a".
Take note.

d - Close the app and repeat step 'a'.

e - Compare de results.

NOTE: try to do this during periods the database hasn't an intense usage because the usage fluctuation may interfere and you have to do some guessing, but you may be lucky if you perform the test when no other new outside connection occurs among the procedures. Choose a proper time when your team is out, or not working with the resource.


Solving item 1 - How does the job's configuration differ from yours?

Considering that you have no access to the configurations of your job's database, as usual, do this:

Choose a moment when your job's database resource has little activity.
Start your app, then close it abruptly, forcing it to terminate without closing your database resources.
Repeat it many times until you the connection to the database is denied, but counting.
The denial is easy to check using DBeaver, DBSchema, PgAdmin, etc.

If your database denies access, you have two possibilities:
Or your job's configuration is restrictive or poor.
A restrictive configuration limits on purpose the number of available connections.
The poor configuration just happens to go as it is without further knowledge of the guy who did it.

After the test, it is recommended that you create another local database having the same restriction of your job's configuration. That way, you'll have one problem less when deploying to the job's env.

>ENV

PostgreSQL (any database)
Any application.


Tuesday, January 10, 2023

angular fails rendering elements (dropdowns, edtitor, etc.)


>PROBLEM

Suddenly, the angular project fails rendering some elements, like dropdowns, editors, and they disappear or stops working.


>SOLUTION

*** SEE ADDITIONAL NOTES BELOW, BEFORE PROCEEDING.


1. Stop the app.

2. Clean the cache:

Linux:

$ANGULAR_PROJECT/modules/setget-ax/ramnode1/.angular/cache/$VERSION/angular-webpack/*

$ANGULAR_PROJECT/drillback/modules/setget-ax/ramnode1/.angular/cache/$VERSION/babel-webpack/*


Example:

rm -Rf $ANGULAR_PROJECT/drillback/modules/setget-ax/ramnode1/.angular/cache/13.3.10/babel-webpack/*


Windows using CygWin

rm -Rf $ANGULAR_PROJECT\modules\setget-ax\ramnode1\.angular\cache\$VERSION\angular-webpack\*

rm -Rf $ANGULAR_PROJECT\drillback\modules\setget-ax\ramnode1\.angular\cache\$VERSION\babel-webpack

3. Restart the app


*** ADDITIONAL NOTES:

1. Instead of deleting the cache, you may move to a temporary folder just in case of rollback.


2. Sometimes, if a widget freezes, it may be a browser issue.

Before cleaning the cash, try to close the browser and make sure that there are no remaining threads.

Use tasklist (Windows) or ps aux (Linux).

Reopen the browser and test again.


3. Sometimes, Windows may get unstable, mostly after a system update.
Restart Windows.
Yeh! It may be strange, but it happened to me sometimes that just rebooting Windows solved the issue. 



>ENV

Angular CLI: 14.2.9
Node: 16.13.1
Package Manager: npm 8.5.4
OS: win32 x64


[MYREF]:
y;faq-angular fails rendering elements (dropdowns, edtitor, etc.)<memo<angular;.

Monday, December 12, 2022

postgreSQL: how to copy (duplicate) a row with binary data

 

>PROBLEM

You need to duplicate a table's row copying from a previous one that contains decode binary data that we shal avoid using copy/paste.


>SOLUTION

Notice that in this example, prtkey and pubkey are binary fields using bytea type.

The uptime is a timestamptz not null field.

 

INSERT INTO keysvc (id,title,pvtkey,pubkey,status,uptime) VALUES( 2, 'ramnode4',null ,null ,1, CURRENT_TIMESTAMP);  

with keys as (SELECT pvtkey, pubkey, uptime FROM keysvc where id = 1)
update keysvc set pvtkey=(select pvtkey from keys), pubkey=(select pubkey from keys), uptime=(select uptime from keys) where id =40;

NOTE: this solution was also published by myself at this date on 
There you'll find another alternative.

>ENV

PostgreSQL


Thursday, December 8, 2022

angular: [webpack-dev-server] Disconnected! polyfills.js:1 [webpack-dev-server] Trying to reconnect...

  

>PROBLEM


When you access the Angular app, the browser's console returns the following message, that keeps repeating:

[webpack-dev-server] Disconnected!
polyfills.js:1 [webpack-dev-server] Trying to reconnect...


>SOLUTION


When starting the Angular app using the "--host" flag, it may also require the "--disable-host-check" flag.

It usually happens when using docker, and it is required the "--host" flag to enable access to the app.


Notice that, when you start the service using just the "host" flag, you get this advice:


  Warning: This is a simple server for use in testing or debugging Angular applications

  locally. It hasn't been reviewed for security issues.

  Binding this server to an open connection can result in compromising your application or

  computer. Using a different host than the one passed to the "--host" flag might result in

  websocket connection issues. You might need to use "--disable-host-check" if that's the

  case.

  


>ENV

Angular CLI: 14.2.9

Node: 16.13.1

Package Manager: npm 8.5.4

OS: win32 x64

debian/docker




[MYREF]:
y;faq-angular [webpack-dev-server] Disconnected! polyfills.js:1 [webpack-dev-server] Trying to reconnect...<memo<angularx;.

Monday, November 28, 2022

Refused to apply style from 'http://localhost:80/api/index' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

 


>PROBLEM

Attempt to access the server returns:

Refused to apply style from 'http://localhost:80/api/index' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.


>SOLUTION 


This kind of issue usually happens because it was not possible to reference the sources.

In this examples, the code was developed using "/" as root URL by the respective spring annotation:

  @RequestMapping("/")   

In this specific case this annotation may be omitted, because the framework assumes it as default, but shown here to clarify.


And the access was:

  http://localhost:8047/


After, the root URL was mapped to "/sg5", using:

  @RequestMapping("/sg5")


And the access was switched:

  http://localhost:8047/sg5


Considering the changes also made in the security layer (in this case the spring security class), it is also required to refactor the static references adding "../" before them.


NOTES: 

1. JavaScript scripts generates CORS messages instead of MIME message. 

To solve, check the example below:

- BEFORE:

<script src="bootstrap/js/bootstrap.min.js"></script>



- SOLUTION: relative path was fixed:

<script src="../bootstrap/js/bootstrap.min.js"></script>


2. Possibly, It may be necessary to update the application's CORS configuration depending of its architecture.


>ENV

springboot

java17



[MYREF]:
y;faq-Refused to apply style from 'http://localhost:8047/sg5/index' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.<memo<springboot;.

Saturday, November 26, 2022

linux: docker: docker: Error response from daemon: driver failed programming external connectivity on endpoint


>PROBLEM


Attempt to start a docker container, returns:

  Error response from daemon: driver failed programming external connectivity on endpoint YOUR_CONTAINER_NAME

  (a8dc1e2b183712da69829c9efd642bf2bdcb504556a8dbd3324902adcb79fc3b): (

  iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport SOME_PORT_HERE -j DNAT --to-destination 172.17.0.2:8048 ! -i docker0

  : iptables: No chain/target/match by that name. 

   (exit status 1))

  Error: failed to start containers: YOUR_CONTAINER_NAME


>SOLUTION

This kind of issue has more than one cause.
It will be described two of them, very common causes.


1. iptables config

Set the following iptables rule before the others, at the beginning:

  iptables -t nat -A POSTROUTING -o docker0 -j MASQUERADE


2. Restart docker

If you already has set procedure below and if it happens again, try to do:

  systemctl restart docker



>ENV

docker/debian based distributions



[MYREF]:

y;faq-docker: Error response from daemon: driver failed programming external connectivity on endpoint<memo<docker;.


Thursday, November 24, 2022

linux: OpenVz: docker: iptables nat issue: iptables v1.8.7 (legacy): can't initialize iptables table `nat': Table does not exist (do you need to insmod?)


 >PROBLEM

Common scenarios:

1. Docker installation fails on Linux distributions,

 or  

2. Attempt to run "iptables -t nat -L -n" command fails.


Both scenarios return the same message:

iptables v1.8.7 (legacy): can't initialize iptables table `nat': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.


Reason:

Docker uses iptables during installations where the S.O. has this firewall command by default.


>SOLUTION


Make sure that is the case by running the following command:

iptables -t nat -L -n


If it fails, there are two main possibilities.
Choose first the easier one.

- If using a cloud hosting, check with the support service to "enable NatFilter".

or

- Maybe a system upgrade is required, sometimes even the kernel.


A successful test, when the NatFilter is enabled shall return something like this:

$ iptables -t nat -L -n

Chain PREROUTING (policy ACCEPT)

target     prot opt source               destination

Chain INPUT (policy ACCEPT)

target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)

target     prot opt source               destination

Chain POSTROUTING (policy ACCEPT)

target     prot opt source               destination


>ENV

cloud hosting

OpenVz/debian 9-11/Ubunto18-22



MYREF: 
y;faq-iptables v1.8.7 (legacy): can't initialize iptables table `nat': Table does not exist (do you need to insmod?)<memo<linux;.

Saturday, November 19, 2022

windows: npm: angular: 'ng' is not recognized as an internal command

 

>PROBLEM

Running the command "ng v", returns:

  'ng' is not recognized as an internal command

  'ng' nĂŁo Ă© reconhecido como um comando interno  (Portuguese)


>SOLUTION


This procedure is about Windows O.S.

After attempting to solve the problem through other experiences, I got no solution.

My Path seemed to be corrupted and there were no files under the user's folder, for instance at:

  C:\Users\<USER>\AppData\Roaming\npm\node_modules


So, to solve the issue, I decided to restart the environment installation from scratch.

This same procedure were executed several times, including restarting the sytem, until the success came. :-)

  1. Uninstall node.js using the windows "Add remove application...".

  2. Remove leftovers. Sometimes there are "skeleton" folder left behind. In my case, it was: C:\Users\<USER>\AppData\Roaming\npm\node_modules

  3. Run the node.js as Administrator. Make sure of that, because it is important.

  4. After the installation is fineshed, check it:
    node --version
    npm --version

  5. Install @angular/cli that it is the lib that provides the "ng" command, as global installation (important: not locally).

  6. The previous command will install the latest version. If you're working with a specific version, go to the angular project's root folder and check the package.json file to verify which version the project is working with: 
    "dependencies": {
     ...
     "@angular/cli": "^13.2.2",  
    ...

  7. Under the project's root folder, install cli using the same version:
    npm install @angular/cli@13.2.2

  8. Eventually, check it the project's env:
    ng v

  9. It shall return the same version used for the project.








>ENV

Angular
Node.js 16


Monday, November 7, 2022

angular: ERROR: TypeError: Cannot read properties of undefined (reading 'valid')

 

>PROBLEM


When the page loads, the browser's console shows the following error:

  ERROR: TypeError: Cannot read properties of undefined (reading 'valid')






>SOLUTION

1. Check if the HTML template uses form validation. For instance: f.form.valid.

Example:

  <button type="submit" class="btn btn-primary" [disabled]="!f.form.valid">Create info</button>


2. Check the form binding.

It shall be something like this:
#f="ngForm"


>BEFORE

        <form name="modalForm" id="modal_create_info_form" #f novalidate
          (ngSubmit)="f.form.valid && createInfo(modalSelector.value)">

>AFTER

        <form name="modalForm" id="modal_create_info_form" #f="ngForm" novalidate
          (ngSubmit)="f.form.valid && createInfo(modalSelector.value)">



3. Make sure that it declared the respective libs:
 

import { FormControl } from '@angular/forms';

or

// import { FormControl, AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms';



>ENV

Angular CLI: 13.2.2

Node: 16.13.1

Package Manager: npm 8.5.4

OS: win32 x64

Wednesday, November 2, 2022

angular: template/component renderization failure

 

>PROBLEM


The template/component fails to renderize (it doesn't appear where it should).


>SOLUTION


Considering an example component in the component.html file: 

<my-component></my-component>


Supposing multi-level modules, declare the component in the first level module.


>firts-level.module.ts

import { MyComponentComponent } from './first level path/MyComponentComponent.component';


@NgModule({

  declarations: [

    // ...

    MyComponentComponent,

  ],


NOTE: if the component has parent-child binding, check also its configuration.



>ENV

Angular CLI: 13.2.2

Node: 16.13.1

Package Manager: npm 8.5.4

OS: win32 x64


angular: Error: Inlining of fonts failed. An error has occurred while retrieving

 


>PROBLEM


Angular compilation fails returning the following message:


  Error: Inlining of fonts failed. An error has occurred while retrieving https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap over the internet.

  getaddrinfo ENOTFOUND fonts.googleapis.com





>SOLUTION


Check your Internet connection.



>ENV

Angular CLI: 13.2.2

Node: 16.13.1

Package Manager: npm 8.5.4

OS: win32 x64


Friday, October 28, 2022

angular: Error: NG0301

 

>PROBLEM


The angular app throws the following error during attempt to open a child modal:

   Error: NG0301

This error may have many types of causes.
It usually means some issue between the component and the template configuration or some subjacent library version incompatibility.

Below there are the four different solutions from different real cases that worked for me.

NOTE: the 3rd solution is the one that I most use. If you are sure that nothing changed in your code, try it. Run the "npm audit fix --force" once or more, but make sure that a node_modules backup is made before. If this folder gets corrupted, fixing it is time-consuming.


>SOLUTION #1


>before

<button id="btn_update_activity_" type="button" class="btn btn-primary icon-config icon-update_20g"
  style="margin-top: 5px; margin-left: 5px;" (click)="openModal(template)">Open modal</button>

<ng-template #template>

>after

Found duplicated ng-template reference.
The second one was switched to solve the conflict.

<button id="btn_update_todo_" type="button" class="btn btn-primary icon-config icon-update_20g"
  style="margin-top: 5px; margin-left: 5px;" (click)="openModal(templateUpTodo)">Open modal</button>

<ng-template #templateUpTodo>



>SOLUTION #2


>before

- todos.component.ts (parent-child biding):

  <!-- xxmodal TODO UPDATE -->

  <app-uptodo [theTodo]="todoi" [email]="email" [stoken]="stoken" [activity]="activity" [activities]="activities"

  (click)="setTodoi(todo)" (updateEvent)="updateTodo($event)"></app-uptodo>

  <!-- xxupdate -->



- uptodo.component.ts (child):

export class UptodoComponent implements OnInit {

  modalRef: BsModalRef;

  @Input()

  email: string;

  @Input()

  stoken: string;

  @Input()

  activities = [];

  @Input()

  theTodo: any;

  activity: string;

  @Output()

  updateEvent = new EventEmitter<string>();


>after

- uptodo.component.ts (child):

export class UptodoComponent implements OnInit {

// ...

  @Input()

  activity: string;

  @Output()

  updateEvent = new EventEmitter<string>();



>SOLUTION #3

Make a backup of the node_modules folder in another place.
Stop the app.

1. Run the command:
npm install

2. Apply the fix command:
npm audit fix

3. Usually there are issues. Run again with --force flag, one or many times:
npm audit fix --force

4. Restart the app.


>SOLUTION #4

If the issue happens too frequently, maybe an update may solve it.
Do:
npm update

Please!!! Create a backup first to not cry later!  :-)

NOTE:
After the update, it may appear some VSCode error messages.
Restart VSCode.


>ENV

Angular CLI: 13.2.2

Node: 16.13.1

Package Manager: npm 8.5.4

OS: win32 x64






MyRef;
y;faq-Error: NG0301<memo<angularx;.

eclipse: java: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder" or Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder

  >PROBLEM Using Eclipse, you try to run a simple logging test using "org.slf4j.Logger" like the sample below: package Test; im...