>PROBLEM
>SOLUTION
2. To test the procedure, create a table:
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).
Attempt to access the site returns:
502 Bad Gateway
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.
- x -
You try to access the site redirects to the default URL and the browser returns:
ERR_TOO_MANY_REDIRECTS
@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()
//...
}
Java
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)
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()));
}
}
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)
...
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
Suddenly, the angular project fails rendering some elements, like dropdowns, editors, and they disappear or stops working.
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
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.
[MYREF]:
y;faq-angular fails rendering elements (dropdowns, edtitor, etc.)<memo<angular;.
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.
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;
PostgreSQL
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...
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.
Angular CLI: 14.2.9
Node: 16.13.1
Package Manager: npm 8.5.4
OS: win32 x64
debian/docker
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.
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.
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.
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;.
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
This kind of issue has more than one cause.
It will be described two of them, very common causes.
Set the following iptables rule before the others, at the beginning:
iptables -t nat -A POSTROUTING -o docker0 -j MASQUERADE
If you already has set procedure below and if it happens again, try to do:
systemctl restart docker
docker/debian based distributions
[MYREF]:
y;faq-docker: Error response from daemon: driver failed programming external connectivity on endpoint<memo<docker;.
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.
- 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
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;.
Running the command "ng v", returns:
'ng' is not recognized as an internal command
'ng' não é reconhecido como um comando interno (Portuguese)
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. :-)
Angular
Node.js 16
When the page loads, the browser's console shows the following error:
ERROR: TypeError: Cannot read properties of undefined (reading 'valid')
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"
3. Make sure that it declared the respective libs:
import { FormControl } from '@angular/forms';
or
// import { FormControl, AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms';
Angular CLI: 13.2.2
Node: 16.13.1
Package Manager: npm 8.5.4
OS: win32 x64
The template/component fails to renderize (it doesn't appear where it should).
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.
Angular CLI: 13.2.2
Node: 16.13.1
Package Manager: npm 8.5.4
OS: win32 x64
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
Check your Internet connection.
Angular CLI: 13.2.2
Node: 16.13.1
Package Manager: npm 8.5.4
OS: win32 x64
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.
- 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>();
- uptodo.component.ts (child):
export class UptodoComponent implements OnInit {
// ...
@Input()
activity: string;
@Output()
updateEvent = new EventEmitter<string>();
Angular CLI: 13.2.2
Node: 16.13.1
Package Manager: npm 8.5.4
OS: win32 x64
Attempt to close the modal fails.
ERROR TypeError: Cannot read properties of undefined (reading 'hide') at main.js:1:434209 at UT (main.js:1:69900) at s (main.js:1:70062) at HTMLButtonElement.<anonymous>
The new modal component code:
import { Component, OnInit, TemplateRef } from '@angular/core'; import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal'; @Component({ selector: 'app-deltodo', templateUrl: './deltodo.component.html', styleUrls: ['./deltodo.component.scss'], }) export class DeltodoComponent implements OnInit { modalRef: BsModalRef; title: string; constructor() {} ngOnInit(): void {} }
The modal component code:
import { Component, OnInit, TemplateRef } from '@angular/core'; import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal'; @Component({ selector: 'app-deltodo', templateUrl: './deltodo.component.html', styleUrls: ['./deltodo.component.scss'], }) export class DeltodoComponent implements OnInit { title: string; // list: any[] = []; constructor(public modalRef: BsModalRef) {} ngOnInit(): void {} }
angularx_ngx_bootstrap_modal_
Angular CLI: 13.2.2
Node: 16.13.1
Package Manager: npm 8.5.4
OS: win32 x64
Create a revision summary.
A request generates the following error:
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
It happens when some exception occurs before returning the request, for instance a "res.sent" statement.
Debug the application step-by-step.
To simplify, you may comment on the code from the start.
Tip: check database exceptions not treated.
Having more than one exception becomes tricky if you can't reproduce the same request.
Be sure to fix all possible exceptions.
Node: 16.13.1
Package Manager: npm 8.5.4
OS: win32 x64
Supposing using date-and-time lib:
npm install date-and-time --save
const date = require('date-and-time')
and the date returning the standard format, something like this (locale: Brazil):
obj.createdAt = 'Fri Aug 26 2022 21:14:34 GMT-0300 (Horário Padrão de Brasília)';
the compiler throws the following error:
date-and-time offset = dateObj.getTimezoneOffset()
TypeError: Cannot read properties of undefined (reading 'getTimezoneOffset')
created_at: date.format(obj.createdAt, 'YYYY/MM/DD HH:mm:ss'),
created_at: date.format(new Date(obj.createdAt), 'YYYY/MM/DD HH:mm:ss'),
Node: 16.13.1
Package Manager: npm 8.5.4
OS: win32 x64
TypeError: Cannot read properties of undefined
This error may have many causes.
Here, it's shown a tricky one — cyclic reference, when one file references the other.
Check the example below:
const UserSvc = require('../../models/business/UserSvc');
static verifySToken(req) {
if (req === 'undefined' || req == null) return false;
let userStoken = UserSvc.stokenSvc[req.body.email];
//...
}
const SecTools = require('../security/SecTools');
myOtherfunction() {
user.token = SecTools.signWithJwt(user.email);
}
The SecTools has reference to UserSvc, and vice-e-versa.
Remove the cyclic reference to fix the issue.
Node: 16.13.1
Package Manager: npm 8.5.4
OS: win32 x64
>PROBLEM Using Eclipse, you try to run a simple logging test using "org.slf4j.Logger" like the sample below: package Test; im...