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;.

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...