I am trying to connected with my provider by the help of these lines of code:
import javax.telephony.*;
import javax.telephony.Phone.*;
import javax.comm.*;
import Phone.ProviderService;
public class terminals
{
private Address origaddr;
private Provider myprovider;
public void getTerm()
{
try
{
JtapiPeer peer = JtapiPeerFactory.getJtapiPeer(null);
myprovider = peer.getProvider(null);
System.out.println("Provider is " + myprovider);
} catch (Exception e)
{
System.out.println("Can't get Provider: " + e.toString());
System.exit(0);
}
}
}
On executing this code, system is not able to get Provider. When I am using gjtapi-1.8.jar in the library then it is showing "net.sourceforge.gjtapi.GenericProvider#53c015" as the provider. I have added log4j-1.2.12.jar, jtapi-1.3.1.jar, gjtapi-tapi3-1.9-rc1.jar, Gjtapi-1.8.jar, log4j.properties file in library to make it. Its running but i want to connect it with my mobile service provider. I am using MTNL (through Serial prot) mobile service provider in Delhi (India) and MTNL braodband connection (through LAN). Please suggest me how to proceed.
"javax.telephony.JtapiPeerUnavailableException: JtapiPeer: DefaultJtapiPeer could not be instantiated. at javax.telephony.JtapiPeerFactory.getJtapiPeer(JtapiPeerFactory.java:135) at Phone.Outcall.main(Outcall.java:24)" is the stack trace thrown when I am removing gjtapi-1.8.jar file from the library. And when i am adding this file in the library, it is showing provider as "net.sourceforge.gjtapi.GenericProvider#53c015", and the call is not connecting to any mobile no. There is some more classes on which I am working, taken from "jtapi-1_4-fr3-spec>javax>Telephony>package.html" file.
Those files are OutCall.java & MyOutCallObserver.java on which I am working.
In other implementations of JTAPI (Cisco for example), you have to pass a provider connection string into the getProvider method:
provider = peer.getProvider("host;login=username;passwd=password;appinfo=MyApp");
Related
A few classmates and I are creating a Java project which requires a database. I have created a connection in MySQL and connected it to my Java project successfully using the following Connect class:
package com.example.javaworkoutgame.Model;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Connect {
static Connection con;
public Connect() {
connect();
}
// attempt to connect to MySQL database
public static void connect() {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
System.out.println("Driver Loaded Successfully");
con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/lab3", "root",
"**********"); // not the actual password
System.out.println("Successful Connection");
} catch (ClassNotFoundException cnfe) {
System.err.println(cnfe);
} catch (SQLException sqle) {
System.err.println(sqle);
}
}
}
This code runs properly on my machine.
I committed and pushed the code to Bitbucket so my partners could access it. However, when they run the code on their computers, they get the following error message:
java.sql.SQLException: Access denied for user 'root'#'localhost' (using password: YES)
Is there something I need to change in MySQL workbench in order for other people to be able to access the database? I could not find any information on this.
The only thing I was able to try was found at this thread:
java.sql.SQLException: Access denied for user 'root'#'localhost' (using password: YES)
I opened a new .sql file and tried running the command:
GRANT ALL PRIVILEGES ON . TO 'root'#'localhost' IDENTIFIED BY '%password%' WITH GRANT OPTION;
(I replaced '%password%' with the actual password)
When I tried that I got the following error message:
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IDENTIFIED BY '*********' WITH GRANT OPTION'
No, and you need to stop this line of thought and do some research first.
Your current configuration says that the mysql server is on the very same physical machine that the code is running on. You installed mysql on your dev machine, your friends need to install it on theirs, and each has their own unique database (nothing is shared).
You could, instead, take your mysql server, open it up to the world (which, for virtually all ways internet is made available in residential connections, requires messing with your router to 'open a port').
But then you have an open mysql server, and the username and password are on a public bitbucket site.
It also requires either a permanent IP (which few residential internet providers offer) or a dyndns service. More generally, hosting open MySQL servers that see lots of traffic gets your internet shut down, for good reason. You'd end up hosting a whole bunch of hackers. All hardware in your network will be p0wned and turned into bot nets. Hence, very very bad idea.
Good ways to solve this problem:
Everybody installs their own MySQL server. This is sensible; you're writing code and bound to make mistakes, it'd be real bad if all code you write is first-run and tested on live data. You don't want one of your friends to wipe your database. If you need some initial data to test with, set it up properly, and read up on how to make an SQL dump. With such a dump file you can reset any mysql server to that exact state - and that'd be how you and your friends develop: Set up the DB to be in that known state, write some code, and if you ruin the db by doing so, no problem. Just reset it again.
Set up a VPN between your friends. NOW you can share the IP your system has within the VPN (it'll be 10., 172.16., 192.168.* - if it's 127.0.0.1, it's localhost, i.e. everybody needs to install mysql on their own and nothing is shared, and if it's anything else, you're opening it to the world, which you don't want to do). Do not put the VPN username/password info anywhere in that bitbucket. And you need to trust your friends.
You should have a properties type file so that each person who is going to interact with the code has their local data without the need to replicate yours, in the same way you can have different values in the properties for test or production environments.
example of a property file:
system.properties
#BD
db.driver=com.mysql.cj.jdbc.Driver
db.user=user
db.pass=password
db.server=server_IP
db.port= port_IP
db.db = DB
Then you should have a procedure to read from java the properties inside the file
Utils.java
package com.example.javaworkoutgame.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public final class Utils {
public static Properties getProperties() {
String path = String.format("PATH to your properties FILE/system.properties",
System.getProperty("user.dir"));
Properties properties = new Properties();
try (InputStream is = new FileInputStream(new File(path))) {
properties.load(is);
} catch (IOException e) {
throw new IllegalStateException(e);
}
return properties;
}
}
And finally you make a call to the function that gets the properties from your connection class
Connect.java
package com.example.javaworkoutgame.Model;
import com.example.javaworkoutgame.util.Utils;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Connect {
Properties properties = Utils.getProperties();
static Connection con;
public Connect() {
connect();
}
// attempt to connect to MySQL database
public static void connect() {
try {
String driver = properties.getProperty("db.driver");
String ip = properties.getProperty("db.ip");
String port = properties.getProperty("db.port");
String db = properties.getProperty("db.db");
String user = properties.getProperty("db.user");
String pass = properties.getProperty("db.pass"):
Class.forName(driver);
System.out.println("Driver Loaded Successfully");
con = DriverManager.getConnection("jdbc:mysql://"+ip+":"+port+"/"+db, user,
pass);
System.out.println("Successful Connection");
} catch (ClassNotFoundException cnfe) {
System.err.println(cnfe);
} catch (SQLException sqle) {
System.err.println(sqle);
}
}
}
About the MYSQL error, if your partners do not have a local mysql environment with the same values as you, they will experience the error you describe, since your configuration is a local configuration, if you need your partners to connect to your pc, you must open the ports of mysql and give them your public IP (not recommended)
I hope this answer helps you!
i am trying to implement java RMI client server connection, i made my server in NetBeans IDE and client class made in oracle database as java store procedure and use this via oracle function in my PLSQL block, everything is working fine but I stuck in little issue below:
I made this java store procedure in SYSTEM user and give dbms_java.grant_permission('SYSTEM','java.net.SocketPermission','192.168.43.25:*','connect,resolve') to SYSTEM user via SYSDBA, "*" is used for all available ports. I get perfect response from my server but till specific session expiry.
Whenever I logout from SYSTEM user and login back again, its again throws me an exception the Permission ("java.net.SocketPermission" "192.168.43.25:56792" "connect,resolve") has not been granted please guide me how can I get rid from this repeated task? because in development environment I'll manage it but how can deploy it on production with this issue. My Environment is Oracle DB 18c XE, Thank You!
Following is my java store procedure:
create or replace and compile java source named rmi as
package rmi;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.Naming;
import java.security.Policy;
public class RmiClient {
public RmiClient(){
}
public static String getRequestFromClient(){
Policy.setPolicy(new MyPolicy());
String result = "";
try {
IServer server = getServer();
result = server.getRequestFromClient();
} catch (Exception ex) {
result = ex.getMessage().toString();
}
return result;
}
private static IServer getServer() throws Exception {
Parameter configurationParameters = new Parameter();
IServer server = (IServer) Naming.lookup( configurationParameters.objectName);
return server;
}
}
Granting permissions with DBMS_JAVA is a little different than a typical Oracle grant. After granting a permission using DBMS_JAVA.GRANT_PERMISSION, you will need to COMMIT at some point after the grant as been executed for it to take affect permanently. Notice how there is a COMMIT after the DBMS_JAVA call in the Oracle documentation.
Description:
Trying to send requests to an application that tries to access a Netopeer2 server, but a problem happens and the key exchange fails. There are solutions out there how to configure it on the server side in /etc/ssh/sshd_config, but we want it to be on the client side that is in the application.
The application uses Apache MINA SSHD to establish the connection (GitHub). By default, certain algorithms are disabled. We want to enable them in that Main class below to be able to exchange rsa-sha2-512, rsa-sha2-256 with the server. Any idea on how to do that with Apache MINA SSHD?
The full error message says:
java.lang.IllegalStateException: Unable to negotiate key exchange for server host key algorithms
(client: ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519,ssh-rsa,ssh-dss /
server: rsa-sha2-512,rsa-sha2-256)
The code that throws the error:
import org.apache.sshd.client.SshClient;
import org.apache.sshd.client.session.ClientSession;
import java.io.IOException;
public class Main{
public static void main(String[] args) {
SshClient client = SshClient.setUpDefaultClient();
client.start();
try {
ClientSession session = client.connect("root", "172.17.0.2", 830).verify(10000).getSession();
session.addPasswordIdentity("root");
session.auth().verify(9999);
// error 'Unable to negotiate key exchange for server host key algorithms' is thrown
}
catch (IOException e){
e.printStackTrace();
}
}
}
I'm also not solving my own problem but I am in the same zone as you. But for me, looking at SSHD log I think I see the client offering rsa_sha2_512 and the (one) server rejecting that and dropping the connection request.
Here is a little Scala snippet that didn't change anything for me. I think this is what you get if you don't set it; every default factory (that I found).
import org.apache.sshd.common.kex.{BuiltinDHFactories, KeyExchangeFactory}
val kexList: util.List[KeyExchangeFactory] = {
val kex = List(
BuiltinDHFactories.dhg1,
BuiltinDHFactories.dhg14,
BuiltinDHFactories.dhgex,
BuiltinDHFactories.dhg14_256,
BuiltinDHFactories.dhg15_512,
BuiltinDHFactories.dhg16_512,
BuiltinDHFactories.dhg17_512,
BuiltinDHFactories.dhg18_512,
BuiltinDHFactories.dhgex256,
BuiltinDHFactories.ecdhp256,
BuiltinDHFactories.ecdhp384,
BuiltinDHFactories.ecdhp521)
val dh2kex = kex.map(k => ClientBuilder.DH2KEX(k))
dh2kex.asJava
}
session.setKeyExchangeFactories(kexList)
Or this in Java:
List<KeyExchangeFactory> kexList =
BuiltinDHFactories.VALUES.stream().map(ClientBuilder.DH2KEX).collect(Collectors.toList());
Below should solve the problem.
client.setKeyExchangeFactories(NamedFactory.setUpTransformedFactories(
false,
BuiltinDHFactories.VALUES,
ClientBuilder.DH2KEX
));
client.setSignatureFactories(new ArrayList<>(BuiltinSignatures.VALUES))
For putty support
https://github.com/apache/mina-sshd/blob/master/docs/files-parsing.md
Simply add the following
<dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-common</artifactId>
<version>...same version as the rest of the artifacts...</version>
</dependency>
<dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-putty</artifactId>
<version>...same version as the rest of the artifacts...</version>
</dependency>
I got a google cloud platform - compute engine instance, which I installed MySQL server on.
And now I can't get any signal of life our of the VM the sql installed on,
for exsample:
package com.company;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Main {
public static void connection(){
try {
Class.forName("com.mysql.jdbc.Driver");
System.out.println("in conncection");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public static void connectToMySQL(){
connection();
String host = "jdbc:mysql://hotsIP:3306/DBname";
String user = "user";
String pass = "password";
try {
Connection connection = DriverManager.getConnection(host,user,pass);
System.out.println("???");
} catch (SQLException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
connectToMySQL();
}
}
It's take a few second like he trying to connect and the EXEPTION
in conncection
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
What I done to make it work:
in the my.conf:bind address = 0.0.0.0, skip-external-locking comment out
restart the server
looked if the server is active
looked if the server listening to the port
looked if its TCP
I don't know what to do anymore.
You have to make the following change to your my.cnf file
my.cnf
bind-address = www.000webhost.com (OR)
bind-address = xx.xx.xx.xx (IP Address)
You need to restart your MySQL service, once this setting is changed.
Also worth noting is the point that MAMP/ MAMP Pro sets MAMP_skip-networking_MAMP by default. You've to disable this line in your my.cnf
And if you don't have any user login issues, you should be able to connect to the MySQL Database from your Java code.
In my case the root cause was: Firewall. I was trying to run the application at work.
What was interesting is that the App Engine Standard running locally actually generated a non-error log in Google Cloud Platform Logs, making me discard the firewall hypotheses.
Solution: I found out bringing my notebook from home and connecting to company's network, did not work. When I connected to the shared connection in my mobile, worked perfectly.
I'm trying to access online .Net Webservice through Java Webservice client.
But unfortunately, am getting an error "Connection timed out: connect"
Below is my code:
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
public class WebServiceMain {
public static void main(String[] args) {
try {
String endpoint = "http://wsf.cdyne.com/SpellChecker/check.asmx";
Service service = new Service();
Call call = (Call)service.createCall();
call.setProperty(Call.SOAPACTION_USE_PROPERTY, new Boolean(true));
call.setProperty(Call.SOAPACTION_URI_PROPERTY, "http://ws.cdyne.com/CheckTextBodyV2");
call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setPortName(new QName("http://ws.cdyne.com/", "check"));
call.setOperationName(new QName("http://ws.cdyne.com/", "CheckTextBodyV2"));
System.out.println(call.invoke(new Object[] {"helo is my name"}));
} catch (Exception e) {
System.err.println(e.toString());
}
}
}
Connection timeout comes because of network issues.try to acess URL in browser.also try to append ?wsdl at the end of URL,you should see the wsdl.if this doesn't work troubleshoot network settings.
Connection timed out: connect
This means that your client application cannot even talk to the Web Service. This is not a programmatic issue.
Check and see whether you can access the end-point through your web browser. If not, then that service is not available. So it doesn't work.
If your browser can access it, and if you are connecting to Internet through a proxy, then you need to specify the proxy details to Java Client. To do that, you can use -Dhttp.proxyHost=10.2.240.11 and -Dhttp.proxyPort=8080 (replace with your values) system properties when you start up your client application.
Download the soapui software and get installed it.
then load the wsdl file and create the project.
Then test your web service via soap ui.
you can edit the connection timeout value of the soap ui. chane it for big vlue and test.still your getiong time out ping to the ip addres of the service