Connection timed out when call Rest API from Eclipse - java

Help me! I have a restful API link, I used Postman tool call success, but when I code on eclipse a Restful client, it's fail. I tried on off proxy, but not success.
public class JersyGetClient {
public static void main(String[] args) {
String url = "https://abc.custhelp.com/services/rest/connect/v1.4/accounts";
String name = "thai.hoangan";
String password = "123456a#";
String authString = name + ":" + password;
String authStringEnc = new BASE64Encoder().encode(authString.getBytes());
System.out.println("Base64 encoded auth string: " + authStringEnc);
Client restClient = Client.create();
WebResource webResource = restClient.resource(url);
ClientResponse resp = webResource.accept("application/json")
.header("Authorization", "Basic " + authStringEnc)
.header("OSvC-CREST-Application-Context", "asd")
.get(ClientResponse.class);
if (resp.getStatus() != 200) {
System.err.println("Unable to connect to the server");
}
String output = resp.getEntity(String.class);
System.out.println("response: " + output);
}
}
Output:
Exception in thread "main" com.sun.jersey.api.client.ClientHandlerException:
java.net.ConnectException: Connection timed out: connect
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:155)
at com.sun.jersey.api.client.Client.handle(Client.java:652)
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682)
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
at com.sun.jersey.api.client.WebResource$Builder.get(WebResource.java:509)
at JersyGetClient.main(JersyGetClient.java:22)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)
at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:173)
at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
at sun.net.www.protocol.https.HttpsClient.(HttpsClient.java:264)
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1105)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:999)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1513)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:338)
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(URLConnectionClientHandler.java:253)
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:153)
... 5 more

Oh, I resolved, Just add:
System.setProperty("https.proxyHost", "proxytest.vcb");
System.setProperty("https.proxyPort", "8080");

Related

Unable to generate AAD Token using java

I have to embed power BI report using service principle in my java application. so i am trying to generate AAD access token. But I fail to generate access token. Below is the code and output. I have tried to generate aad access token using Javascript also but could not do so. Please help.
Find my code here
import java.net.MalformedURLException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import com.microsoft.aad.adal4j.AuthenticationCallback;
import com.microsoft.aad.adal4j.AuthenticationContext;
import com.microsoft.aad.adal4j.AuthenticationResult;
import com.microsoft.aad.adal4j.ClientCredential;
public class GenerateToken {
public static void main(String[] args) throws InterruptedException, ExecutionException {
System.out.println("Connecting to Azure......");
System.out.println("AAD Token" + ServicePrinciple.getAADAccessTokenFromAzure().get().getAccessToken());
}
}
final class ServicePrinciple {
static String authority = "https://login.microsoftonline.com/tenant_id/oauth2/token";
static String clientId = "";
static String clientSecret = "";
static String resource = "https://analysis.windows.net/powerbi/api";
private static Future<AuthenticationResult> getAADAccessToken(String authority, String resource, String clientId, String clientSecret) {
AuthenticationCallback callback = null;
ClientCredential clientCredential = null;
ExecutorService executorService = Executors.newFixedThreadPool(1);
clientCredential = new ClientCredential(clientId, clientSecret);
AuthenticationContext context = null;
try {
context = new AuthenticationContext(authority, false, executorService);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Future<AuthenticationResult> authenticationResult = context.acquireToken(resource, clientCredential, callback);
return authenticationResult;
}
static Future<AuthenticationResult> getAADAccessTokenFromAzure() {
return getAADAccessToken(authority, resource, clientId, clientSecret);
}
}
Output of my code
Connecting to Azure......
[pool-1-thread-1] INFO com.microsoft.aad.adal4j.AuthenticationAuthority - [Correlation ID: 9f8f9bde-fc94-4cb9-bf91-1a3ef2e79d10] Instance discovery was successful
[pool-1-thread-1] ERROR com.microsoft.aad.adal4j.AuthenticationContext - [Correlation ID: 9f8f9bde-fc94-4cb9-bf91-1a3ef2e79d10] Request to acquire token failed.
java.net.UnknownHostException: login.microsoftonline.com
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:673)
at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:173)
at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:558)
at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:264)
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1156)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1050)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1334)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1309)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:259)
at com.microsoft.aad.adal4j.AdalOAuthRequest.configureHeaderAndExecuteOAuthCall(AdalOAuthRequest.java:117)
at com.microsoft.aad.adal4j.AdalOAuthRequest.send(AdalOAuthRequest.java:72)
at com.microsoft.aad.adal4j.AdalTokenRequest.executeOAuthRequestAndProcessResponse(AdalTokenRequest.java:72)
at com.microsoft.aad.adal4j.AuthenticationContext.acquireTokenCommon(AuthenticationContext.java:726)
at com.microsoft.aad.adal4j.AuthenticationContext.access$100(AuthenticationContext.java:61)
at com.microsoft.aad.adal4j.AuthenticationContext$1.call(AuthenticationContext.java:128)
at com.microsoft.aad.adal4j.AuthenticationContext$1.call(AuthenticationContext.java:117)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Exception in thread "main" java.util.concurrent.ExecutionException: java.net.UnknownHostException: login.microsoftonline.com
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at com.inetpsa.spd.raloyalty.action.GenerateToken.main(GenerateToken.java:25)
Caused by: java.net.UnknownHostException: login.microsoftonline.com
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:673)
at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:173)
at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:558)
at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:264)
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1156)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1050)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1334)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1309)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:259)
at com.microsoft.aad.adal4j.AdalOAuthRequest.configureHeaderAndExecuteOAuthCall(AdalOAuthRequest.java:117)
at com.microsoft.aad.adal4j.AdalOAuthRequest.send(AdalOAuthRequest.java:72)
at com.microsoft.aad.adal4j.AdalTokenRequest.executeOAuthRequestAndProcessResponse(AdalTokenRequest.java:72)
at com.microsoft.aad.adal4j.AuthenticationContext.acquireTokenCommon(AuthenticationContext.java:726)
at com.microsoft.aad.adal4j.AuthenticationContext.access$100(AuthenticationContext.java:61)
at com.microsoft.aad.adal4j.AuthenticationContext$1.call(AuthenticationContext.java:128)
at com.microsoft.aad.adal4j.AuthenticationContext$1.call(AuthenticationContext.java:117)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
I have almost the same code working (for the last day or so)
However my code snippet look like the folowing
String authority = "https://login.microsoftonline.com/{your tenant id}";
ExecutorService service = Executors.newFixedThreadPool(1);
AuthenticationContext context = new AuthenticationContext(authority, true, service);
Are you behind a firewall that isn't allowing you reach login.microsoftonline.com?
You can use the following API page to login and generate a report token
https://learn.microsoft.com/en-gb/rest/api/power-bi/embedtoken/reports_generatetokeningroup
is your login.microsoftonline.com behind a proxy? if so, set your proxy with the either set of jvm arguments depending if it is http or https:
HTTPS
-Dhttps.proxyHost=proxy-name-without-https.com -Dhttps.proxyPort=proxy-port
ex. -Dhttps.proxyHost=myproxy.com -Dhttps.proxyPort=2021
or
HTTP
-Dhttp.proxyHost=proxy-name-without-http.com -Dhttp.proxyPort=proxy-port
ex. -Dhttp.proxyHost=myproxy.com -Dhttp.proxyPort=2021

javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;

This is my code
public class Email {
static Properties props;
public static void main(String[] args){
String from = "some email";
String to= "some other email";
String host = "localhost";
props = System.getProperties();
props.setProperty("mail.host", host);
props.put("mail.transport.protocol", "smtp");
Session session = Session.getDefaultInstance(props,null);
try{
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("This is the Subject Line!");
message.setText("This is actual message");
Transport.send(message);
System.out.println("Sent message successfully....");
}catch (MessagingException mex) {
mex.printStackTrace();
}
}
}
I am getting following exception:
javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;
nested exception is:
java.net.ConnectException: Connection refused
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1961)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:654)
at javax.mail.Service.connect(Service.java:295)
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)
at com.cisco.ci.support.email.Email.main(Email.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:321)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:237)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1927)
... 12 more
It seems that I do not have smtp server on my mac? any solutions?
You either need to install a smtp Server on your mac, which is not that simple, or use an existing smtp server. Obviously you will need an account for that server, as there are not many smtp Servers without authentication in the wild.
E.g. Create a googlemail Account, then check: http://www.mkyong.com/java/javamail-api-sending-email-via-gmail-smtp-example/ for example of how to use it!

MySQL communication link failure

Here is the error.
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1117)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:355)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2461)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2498)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2283)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:822)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:404)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:317)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at eventmanagementsystem.infinity.dbHandler.buildConnection(dbHandler.java:43)
at eventmanagementsystem.infinity.dbHandler.getParticipantResultSet(dbHandler.java:395)
at eventmanagementsystem.infinity.ParticipantList.populateList(ParticipantList.java:96)
at eventmanagementsystem.infinity.EMS.<init>(EMS.java:31)
at eventmanagementsystem.infinity.EventManagementSystemInfinity.main(EventManagementSystemInfinity.java:25)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at java.net.Socket.<init>(Socket.java:434)
at java.net.Socket.<init>(Socket.java:244)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:259)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:305)
... 19 more
May 24, 2015 3:48:58 PM eventmanagementsystem.infinity.EMS <init>
SEVERE: null
java.lang.NullPointerException
at eventmanagementsystem.infinity.dbHandler.getParticipantResultSet(dbHandler.java:396)
at eventmanagementsystem.infinity.ParticipantList.populateList(ParticipantList.java:96)
at eventmanagementsystem.infinity.EMS.<init>(EMS.java:31)
at eventmanagementsystem.infinity.EventManagementSystemInfinity.main(EventManagementSystemInfinity.java:25)
BUILD SUCCESSFUL (total time: 21 seconds)
Here is the code.
public static Connection buildConnection()
{
try{
//Class.forName("org.apache.derby.jdbc.ClientDriver");
//Class.forName("oracle.jdbc.driver.OracleDriver");
Class.forName("com.mysql.jdbc.Driver");
//String connString = "jdbc:derby://localhost:4040/EventManagementSystem";
//String username = "Event";
//String password = "event";
//String username = "system";
//String password = "a1234";
String JDBC_DRIVER = "com.mysql.jdbc.Driver";
String DB_URL = "jdbc:mysql://localhost:3306/user";
String USER = "root";
String PASS = "a1234";
//Connection conn = DriverManager.getConnection(connString,username,password);
//Connection conn = DriverManager.getConnection("jdbc:oracle:thin:#oracle-prod:1521:OPROD",username,password);
Connection conn = DriverManager.getConnection(DB_URL,USER,PASS);
return conn;
}
catch(Exception e)
{
e.printStackTrace();
}
return null;
}
I think the problem is with the DB_URL but I am not very sure. I have added mysql-connector jar as well. It cannot access the database that I have created. The error list also shows that connection is refused but I am not sure why is that so.

JavaMail API keeps saying it cannot connect. CAS Array & Exchange

Here is what I have so far. I am trying to send an email in Outlook and embed that functionality into my application.
String to = "me#mine.com";
String from = "you#yours";
String host = "casarray.ex2.specificallygeneral.net";
final String username = "user#doamin.com";
final String password = "password";
Properties props = new Properties();
props.put("mail.smtp.host", host);
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.user", "user#domain.com");
props.put("mail.smtp.password", "password");
props.put("mail.smtp.port", "25");
props.put("mail.smtp.auth", "true");
Authenticator authenticator = new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
};
Session session = Session.getDefaultInstance(props, authenticator);
try {
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject("Test");
msg.setSentDate(new Date());
msg.setText("This API works");
Transport transport = session.getTransport();
transport.connect(username, password);
transport.sendMessage(msg, msg.getRecipients(Message.RecipientType.TO));
Transport.send(msg);
transport.sendMessage(msg, address);
if (transport == null) {
JOptionPane.showMessageDialog(rootPane, "Mail carrier was shot. Sorry.");
}
}
catch (MessagingException ex) {
Logger.getLogger(AAIApplication.class.getName()).log(Level.SEVERE, null, ex);
}
And here is what I get each time:
com.sun.mail.util.MailConnectException: Couldn't connect to host, port: casarray.ex2.secureserver.net, 25; timeout -1;
nested exception is:
java.net.ConnectException: Connection timed out: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1961)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:654)
at javax.mail.Service.connect(Service.java:345)
at javax.mail.Service.connect(Service.java:226)
at javax.mail.Service.connect(Service.java:246)
at AAIworkordertracker.AAIApplication.addToTrackerbtnActionPerformed(AAIApplication.java:412)
at AAIworkordertracker.AAIApplication.access$1200(AAIApplication.java:27)
at AAIworkordertracker.AAIApplication$13.actionPerformed(AAIApplication.java:171)
at java.awt.Button.processActionEvent(Button.java:409)
at java.awt.Button.processEvent(Button.java:377)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:297)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:229)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1927)
... 29 more
If someone could give me a hand on this and let me know what I am doing wrong. It looks perfectly to me, so, I am assuming that the issues lies with the Exchange server. What do you think?
Thank you!
"Couldn't connect to host, port" could be caused by wrong host name, wrong port, a blocking firewall (on the server, on gateways, even on your own machine), network failure, server downtime, etc. You might want to find out if you can connect/"talk" to the mail server using telnet from the command line. See also http://www.oracle.com/technetwork/java/javamail/faq/index.html#condebug
Note: On Windows 7, you might need to install telnet first. See http://support.microsoft.com/kb/978779

How to RMI in netbeans

I am working on a RMI client, but when I try to connect to it from any machine but localhost it gets a refused connection stack trace. I verified that my firewall is off. What else do I need to do?
Here is my code
public class FrontManagerClient {
boolean state;
String command;
String value;
public FrontManagerClient(String cmd,String value) {
this.command=cmd;
this.value=value;
}
public boolean getCommand() throws RemoteException, NotBoundException, MalformedURLException{
FrontPanelManagerIntrface f=(FrontPanelManagerIntrface)Naming.lookup("lookup=//localhost//frontPanelRequestControllerService");
state=f.Communicate(command, value);
return state;
}
public static void main(String[] args) throws RemoteException, NotBoundException, MalformedURLException {
FrontManagerClient f = new FrontManagerClient("Password_Enter", "admin");
System.out.println(""+f.getCommand());
}
}
when i run the server and run the client ,it displays this error message
Exception in thread "main" java.rmi.ConnectException: Connection refused to host: 10.96.28.6; nested exception is:
java.net.ConnectException: Connection refused: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:340)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Naming.java:101)
at doormanager.FrontManagerClient.getCommand(FrontManagerClient.java:30)
at doormanager.FrontManagerClient.main(FrontManagerClient.java:37)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at java.net.Socket.<init>(Socket.java:425)
at java.net.Socket.<init>(Socket.java:208)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:146)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
... 7 more
Java Result: 1
There is no RMI Registry running at the host 10.96.28.6, or you haven't fixed your firewall.

Categories