Communication between two REST Services - java

I have two REST Services (developed using Spring Boot), one for Authentication and one that returns Data. The Data service validates a token against the Authentication service when data i requested. The validation is done by the Data service sending a request to the Authentication service containing an ID like this https://name.com/auth/key?id=[ID]. I have tested the validation by having the Authentication service deployed as a WAR-file on a Tomcat server https://name.com/auth/ and having the Data service running local on my computer. This setup worked fine. Now I have deployed the Data service as WAR-file to the same Tomcat server https://name.com/data/. The issue now is that the Data service is not able to connect to the Authentication service giving the following error message
HTTP Status 500 - I/O error on GET request for "https://name.com/auth/key": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)
Why is the connection refused when both WAR-files are running on the same Tomcat server?

The issue was by using the internal IP addresses rather then the external.

Related

Why I got authentication failed exception when sending emails using spring boot app deployed on AWS EC2?

when deploying my jar file on a remote server like AWS EC2 and using it to send emails over smtp connection i got :
Authentication failed; nested exception is javax.mail.AuthenticationFailedException: 535 5.7.3 Authentication unsuccessful [MN2PR01CA0051.prod.exchangelabs.com]
But it is working proberly when running this app on my local machine,
Is remote servers or there is a configurations must be added ?

Connection Timeout Problem in Inter service communication in microservices when deployed on kubernetes

I am working on a demo project , which has 5 microservices - discovery server , api-gateway , user-order-detail , order and user service.
I will expose the order and user service internally on GKE
I will expose the user-order-detail service externally which will call the other two services using a rest endpoint
Services that are up on google kubernetes engine:
user-order-detail LoadBalancer
kubernetes ClusterIP
order-management LoadBalancer
user-management LoadBalancer
user-order-detail hits an endpoint to retrieve all users. I am getting this error :No matches for the virtual host name :user-management
Code :
String url = "user-management/user";
InstanceInfo instance = eurekaClient.getNextServerFromEureka("user-management", false);
Object response = restTemplate.getForObject(instance.getHomePageUrl() + url +"/" + userId, Object.class);
I am having problem in inter-service communication.please help
UPDATE:
I was able to redirect my service,but I am getting connection timeout error.How should I solve this?
I/O error on GET request for "http://user-management/user-management/user/1": Operation timed out (Connection timed out); nested exception is java.net.ConnectException: Operation timed out (Connection timed out)
check the port for your service and target port
port can be 80
targetport

Spring RestTemplate on Jelastic - Connection Refused when requesting external rest service

I have application that need to call Rest service, to do authentication process. The service and my application are in a same server. I used Spring RestTemplate to call it. When it tested in localhost, it works perfectly. But when I deploy it to the cloud server (in this case, Jelastic) I get this error:
I/O error on GET request for "[my_rest_service_address]":Connection refused; nested exception is java.net.ConnectException: Connection refused
All the code is follow this doc : http://docs.spring.io/spring/docs/3.0.x/javadoc-api/org/springframework/web/client/RestTemplate.html. Only the url that changed to my rest url.
Is it happened because jelastic server blocked outbound request? But, both the service and my application are in the same server, why it still blocked?
Please explain to me, what is the problem? Thanks
The http 401 code means that the user that made the request is not authenticated. It can be the user of your webapp or the user used for the rest call.
It can for example that different credentials are used in prod and test, different security schemes in each environment, etc.

Remote host closed connection during handshake exception while sending out mail using Java Mail

I am using Java Mail API Ver. 1.4.2 for sending out email in JSF 1.2-Spring based Web Application. I am using non secured SMTP connection for sending out a mail. This email configuration is working fine standalone. Also verified this utility using JUnit 4 test and I am able to send mail using non secure connection.
When I integrate this email module with main web application I am getting following exception at runtime while sending out a mail.
javax.mail.MessagingException: Exception reading response; nested exception is: javax.net.ssl.SSLHandshakeException: Remote host closed
connection during handshake at
com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1764)
at
com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1523)
at
com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:453)
at javax.mail.Service.connect(Service.java:317) at
javax.mail.Service.connect(Service.java:176) at
javax.mail.Service.connect(Service.java:125) at
javax.mail.Transport.send0(Transport.java:194) at
javax.mail.Transport.send(Transport.java:124)
Verified this email module using secure SMTP connection and it's working fine.
Anyone having idea on this issue? Why non-secured SMTP connection not working in integration with Web Application?
I am using email module for both secured and non secured connections.
In that following property was causing the issue : props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
Removed this property for non secured connections and now my non-secured SMTP connection is working in integration with Web Application.

GWT send mail in development mode mail server problem

I am trying to send a mail with gwt and java on the server with the buitin jetty on eclipse but I am getting the following error:
Cannot open and load mail server properties file.
Cannot send email. javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;
nested exception is:
java.net.ConnectException: Connection refused: connect
does someone know what to configure to make it work??
This is not GWT related problem. Test you email sending code in isolation (without GWT and Jetty).
Start with sample code and configure it's parameters to your need. You will also need to use a SMTP server to send emails this way.

Categories