I'm trying to make a connection to xmpp server and this returning me this error.
W/AbstractXMPPConnection: Connection closed with error
org.jivesoftware.smack.XMPPException$StreamErrorException: host-unknown You can read more about the meaning of this stream error
at http://xmpp.org/rfcs/rfc6120.html#streams-error-conditions
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1003)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPConnection.java:944)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:959)
at java.lang.Thread.run(Thread.java:818)
I tried to use this example in github and put this data.
private static final String DOMAIN = "10.20.0.125";
private static final String HOST = "10.20.0.125";
private static final int PORT = 5222;
private String userName ="admin2#localhost";
private String passWord = "asdfasdf";
The server is ok, we conducted another test pc to make a communication on android but this error persists.
I see mainly 2 errors:
in the demo configuration you have this lines of code:
XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();
configBuilder.setUsernameAndPassword(userName, passWord);
configBuilder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
configBuilder.setResource("Android");
configBuilder.setServiceName(DOMAIN);
configBuilder.setHost(HOST);
configBuilder.setPort(PORT);
First problem (main one):
DOMAIN variable SHOULD (but MUST) BE the server name you can read in server configuration, not just the IP; some functionality will broke outside the localhost.
Second problem:
while I suggest to split login from configuration (so just configure the connection and THEN login) what I don't get it's the username: localhost will be not resolved outside the server machine, so again has to be replaced with DOMAIN name (even if, in theory, the connection will give the user his domain, doesn't need to be so explicit).
so:
connection.connect();
login();
will be replaced with
connection.connect();
login(userName ,passWord,"Android" );
and you'll need to remove this 2 lines:
configBuilder.setResource("Android");
configBuilder.setUsernameAndPassword(userName, passWord);
about DOMAIN name: you'll find it in Server configuration, in Openfire it's the "Server Name" you can read in web interface in Server Information page.
I managed to find the solution.
I was using .jar files instead of the compile gradle dependencies:
compile 'org.igniterealtime.smack:smack-android:4.1.4'
compile 'org.igniterealtime.smack:smack-tcp:4.1.4'
compile 'org.igniterealtime.smack:smack-im:4.1.4'
compile 'org.igniterealtime.smack:smack-extensions:4.1.4'
Thus the error has been resolved. Thank you for your help.
Related
In a java service, I'm trying to upload a file in an azure storage directory; therefore I've written a code like this :
import com.azure.core.util.*;
import com.azure.storage.file.share.*;
import com.azure.storage.file.share.models.*;
//Create connexion string
String connectStr ="DefaultEndpointsProtocol=https;AccountName=" + accountName + ";AccountKey=" + accountKey + ";EndpointSuffix=" + endpoint;
//ShareDirectoryClient
ShareDirectoryClient dirClient = new ShareFileClientBuilder().connectionString(connectStr).shareName(shareName).resourcePath(directoryName).configuration(proxyOptions).buildDirectoryClient();
// Create empty file
dirClient.createFile(fileName, body.length());
The HTTPS request must goes through a proxy server, so, I get this error :
"Could not run 'sendFileInDirectoryProxyTest'
reactor.core.Exceptions$ReactiveException: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection timed out: no further information: "
I can't set/use a global setting.
To set a proxy in the Java code, I've tried several things, like using the Configuration Class :
Configuration configuration = new Configuration();
configuration.put("java.net.useSystemProxies", "true");
configuration.put("https.proxyHost", "xxxxxxxxx");
configuration.put("https.proxyPort", "xxxx");
ShareDirectoryClient dirClient = new ShareFileClientBuilder().connectionString(connectStr).shareName(shareName).resourcePath(directoryName).configuration(configuration).buildDirectoryClient();
But it did not solve the issue.
I'm sure it is pretty simple, any help would be appreciated.
Thanks. Charles de Saint Andre.
You need to configure ProxyOptions and set them on the httpClientBuilder. All our Storage client builders have a .httpClient() method that accepts a client, and you can build a client with all defaults + the proxy options using a NettyAsyncClientBuilder(), which has a .proxyOptions() method. Please give that a try and let me know if you have any more issues.
Sample : azure-sdk-for-java/sdk/storage/azure-storage-blob at main ยท Azure/azure-sdk-for-java (github.com)
I have problem using HikariCP and Google App Engine for JEE.
When trying to access site, i have the logged error :
com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: Cannot connect to MySQL server on localhost:3,306.
As you can see, it add a ',' in the port address.
I try to send full URL to it but nothing append.
Here is my Servlet INIT class :
public class InitialServlet extends HttpServlet {
public static final String SEANCE_MANAGER = "SEANCE_MANAGER";
public static final String CLOUD_SQL_CONNECTION_NAME="";
public static final String DB_USER="test_db";
public static final String DB_PASS="password";
public static final String DB_NAME="dbname";
#Override
public void init(ServletConfig config) throws ServletException {
HikariConfig configs = new HikariConfig();
configs.setJdbcUrl("jdbc:mysql://localhost:3306/dbname");
configs.setUsername(DB_USER);
configs.setPassword(DB_PASS);
configs.addDataSourceProperty("socketFactory", "com.google.cloud.sql.mysql.SocketFactory");
configs.addDataSourceProperty("cloudSqlInstance", CLOUD_SQL_CONNECTION_NAME);
configs.addDataSourceProperty("useSSL", "false");
DataSource pool = new HikariDataSource(configs);
DataAccess dataAccess = new DataAccess(pool);
SeancesManager seancesManager = new SeancesManager(dataAccess);
config.getServletContext().setAttribute(SEANCE_MANAGER, seancesManager);
}
}
How i can do to fix this bug ?
Thanks
The only difference from the official connection specified in the documentation that you can follow in order to connect App Engine with Cloud SQL through Java that I see is the format of the setJdbcurl.
I know this might be far fetched but can you attempt to format the setJdbcUrl like this?
config.setJdbcUrl(String.format("jdbc:mysql:///%s", DB_NAME));
Also please double check the connection variables in case something went through.
Let me know and if it doesn't work we will look more into it.
EDIT:
Are you using SQL Proxy?
If you are using SQL Proxy run the command again and make sure you specify the port correctly.
That is the first thing that I can think off where you can specify the port and maybe had a "," in the command you specified.
Another thing I wonder, are you overwriting or have you modified the port number in any place? I would recommend you checking that because the error "3,306" is because the port specified is "3,306". The normal failure error directly fails with 3306.
I am trying to create a basic connection and login to an Openfire server that I have installed. I have the following user in my users database which I created through the Openfire web admin interface:
User: user
Password: 12345678
I can connect fine to the server as the connection returns true in my sout. The problem is when it tries to log in I get the following error:
org.jivesoftware.smack.sasl.SASLErrorException: SASLError using DIGEST-MD5: not-authorized
I have the following code:
private XMPPConnection connection;
public void connect(String serverIP) {
try {
System.setProperty("smack.debugEnabled", "true");
ConnectionConfiguration config = new ConnectionConfiguration(serverIP, 5223);
config.setDebuggerEnabled(true);
config.setSocketFactory(new DummySSLSocketFactory());
config.setSecurityMode(ConnectionConfiguration.SecurityMode.enabled);
config.setCompressionEnabled(true);
connection = new XMPPTCPConnection(config);
connection.connect();
System.out.println("Connected: " + connection.isConnected());
connection.login("user", "12345678");
System.out.println("Logged in: " + connection.isAuthenticated());
} catch (SmackException | IOException | XMPPException ex) {
ex.printStackTrace();
}
}
public static void main(String[] args) {
connectionHandler test = new connectionHandler();
test.connect("localhost");
}
If anyone can correct what I am doing wrong I would be really grateful.
I have also tried the username as the email would be for example
user#localhost.com
or
user#localhost
I finally managed to find the answer to this. The problem (possibly not even a problem) was that the authentication methods weren't set in the server config and as default allowed all methods. The first one chosen in java seems to be DIGEST-MD5 which was what was causing the errors. To fix this I added:
<sasl>
<mechs> PLAIN </mechs>
</sasl>
before the last closing tag of the openfire.xml found in the config folder of the server. This can also be changed in the ofproperty database table for the column called sasl.mechs.
Hopefully this helps someone (possibly me) in the future.
P.S. this is unsecure if not using SSL (port 5223 by default)
SASLError using DIGEST-MD5: not-authorized
This is most likely caused because you did not configure the correct XMPP domain (/service name) in your ConnectionConfiguration. DIGEST-MD5 would not only fail if the username or password is wrong, but also if the wrong XMPP domain is used.
I have set up a local proxy server for request logging but my java code ignores it and connects directly (Windows XP, JDK 1.7). Web browsers work with it. So I wrote test code for discussion that seems to connect directly even if a (bogus) proxy is specified. With the bogus proxy, I would expect connection failure but the code succeeds, connecting directly:
System.setProperty("http.proxyHost", "localhost");
System.setProperty("http.proxyPort", "12345");
System.setProperty("http.nonProxyHosts", "noNonProxyHost.com");
URL url = new URL("http://docs.oracle.com/javase/7/docs/technotes/guides/net/proxies.html");
InputStream in = url.openStream();
System.out.println("Connection via bogus proxy succeeded");
The code is run as standalone Java, no Maven, no applet, no container. I have a direct internet connection.
In your case using java.net.URL(), if the proxy server cannot be reached at http.proxyHost and http.proxyPort then it simply falls back and tries to do a direct connect. If that succeeds, you'll see no exception thrown which is why your code works without error. You should see a pause while it tries to find the proxy though.
This sample code below happily fetches the URL and displays it, without error, even when run with bogus proxy settings. -Dhttp.proxyHost=bogus -Dhttp.proxyPort=2345 but will talk to my local proxy localhost port 8888 if set correctly
import java.io.*;
import java.net.URL;
import java.util.*;
public class URLClient {
private static String sUrl = "http://www.apache.org/";
public static void main(String[] args) {
try {
URL url = new URL(sUrl);
InputStream is = url.openStream();
java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
String output = s.hasNext() ? s.next() : "";
System.out.println(output);
} catch(Throwable e) {
System.err.println("exception");
}
}
}
The problem I was originally having with http.proxyHost and http.proxyPort being ignored (Google led me to your question) was that those settings are completely ignored by apache.commons.httpClient because it uses its own sockets, as described here.
http://cephas.net/blog/2007/11/14/java-commons-http-client-and-http-proxies/
I have faced a similar problem recently. First of all, one part of the above answer from Daemon42 explains pretty well, why the bogus proxy server didn't lead to a failure of the program:
if the proxy server cannot be reached at http.proxyHost and http.proxyPort then it simply falls back and tries to do a direct connect. If that succeeds, you'll see no exception thrown which is why your code works without error. You should see a pause while it tries to find the proxy though.
Still, your actual question was, why the proxy server configured via the operating system is not used by the Java application. As stated in the Oracle documentation (https://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html), the system proxy settings are not evaluated by Java by default. To do so, you have to set the value of the system property "java.net.useSystemProxies" to the value "true".
You can set that system property on the command line, or you can edit the JRE installation file jre/lib/net.properties, that way you have to change it only once on a given system.
When I enter my base URL it refuses to connect, which means I probably have the wrong URL. This is what I currently have:
public static final String BASE_URL = "http://127.0.0.1:5984/_utils/";
What would the base URL be? Any examples would be helpful.
The localhost refers to the device on which the code is running, in this case the emulator.
There is however a far better solution. You can access your host machine with the IP address "10.0.2.2".
This has been designed in this way by the Android team. So your webserver can perfectly run at localhost and from your Android app you can access it via http://10.0.2.2:5984/_utils/
please try with below code
public static final String BASE_URL = "http://10.0.2.2:5984/_utils/";