I am using svnkit (standalone 1.8.12) to checkout an svn repository with java.
I tried several possibilities to do so (1, 2). Unfortunately, as soon as SVNkit starts to connect to the SVN server it crashes with the following stack trace (checkout, test connection, get revision number and so on). Checkout via terminal works just fine (using Ubuntu 14 with subversion installed), also open the used repo-url with a browser works just fine.
Exception in thread "main" java.lang.IndexOutOfBoundsException: Bounds exceeds available space : size=7, offset=8
at com.sun.jna.Memory.boundsCheck(Memory.java:185)
at com.sun.jna.Memory.getPointer(Memory.java:509)
at org.tmatesoft.svn.core.internal.util.jna.SVNGnomeKeyring.setPassword(SVNGnomeKeyring.java:334)
at org.tmatesoft.svn.core.internal.util.jna.SVNGnomeKeyring.setPassword(SVNGnomeKeyring.java:308)
at org.tmatesoft.svn.core.internal.util.jna.SVNJNAUtil.addPasswordToGnomeKeyring(SVNJNAUtil.java:170)
at org.tmatesoft.svn.core.internal.wc.DefaultSVNPersistentAuthenticationProvider$GnomeKeyringPasswordStorage.savePassword(DefaultSVNPersistentAuthenticationProvider.java:696)
at org.tmatesoft.svn.core.internal.wc.DefaultSVNPersistentAuthenticationProvider.savePasswordCredential(DefaultSVNPersistentAuthenticationProvider.java:416)
at org.tmatesoft.svn.core.internal.wc.DefaultSVNPersistentAuthenticationProvider.saveAuthentication(DefaultSVNPersistentAuthenticationProvider.java:323)
at org.tmatesoft.svn.core.internal.wc.DefaultSVNAuthenticationManager.acknowledgeAuthentication(DefaultSVNAuthenticationManager.java:274)
at org.tmatesoft.svn.core.auth.BasicAuthenticationManager.acknowledgeAuthentication(BasicAuthenticationManager.java:105)
at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection.request(HTTPConnection.java:771)
at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection.request(HTTPConnection.java:398)
at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection.request(HTTPConnection.java:386)
at org.tmatesoft.svn.core.internal.io.dav.DAVConnection.performHttpRequest(DAVConnection.java:863)
at org.tmatesoft.svn.core.internal.io.dav.DAVConnection.exchangeCapabilities(DAVConnection.java:699)
at org.tmatesoft.svn.core.internal.io.dav.DAVConnection.open(DAVConnection.java:118)
at org.tmatesoft.svn.core.internal.io.dav.DAVRepository.openConnection(DAVRepository.java:1049)
at org.tmatesoft.svn.core.internal.io.dav.DAVRepository.testConnection(DAVRepository.java:100)
at Main.svnCheckout(Main.java:131)
at Main.svnCheckoutPrep(Main.java:106)
at Main.main(Main.java:76)
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:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
The code that produces this error is the following
static void svnCheckout(String url, String dest) throws SVNException {
/* Setup SVNKIT library */
setupSVNKit();
SVNRepository repository = null;
try {
repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url));
} catch (SVNException svne) {
System.err.println("error while creating an SVNRepository for the location '"
+ url + "': " + svne.getMessage());
System.exit(1);
}
ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager("someName", "somePWD");
repository.setAuthenticationManager(authManager);
repository.testConnection();
}
...
static void setupSVNKit(){
/* For using http:// and https:// */
DAVRepositoryFactory.setup();
}
Does anyone have an idea what I do wrong?
I would be so happy, if only the testConnection() function would work.
Since it is https, do I need to setup SVNkit to accept the fingerprint or similar?
Any help is highly appreciated!
markus
Alright, after many trials and errors I figured it out. Actually, I run into a different error using another repository. I did two things (not sure which one was the actual reason, maybe both of them).
Added the untrusted certificate (yes it was not validated) to the JVM
Added the following line to the VM options: -Dsvnkit.library.gnome-keyring.enabled=false
Further Reading:
Point 1: https://issues.tmatesoft.com/issueMobile/SVNOLD-290
Point 2: https://issues.tmatesoft.com/issue/SVNKIT-231
Related
I'm developing a RESTful web-service using Jersey. I am using maven to manage my dependencies and eclipse export method to create the jar.
When running the jar on my Ubuntu pc, everything is working fine, but when I'm executing the same jar on a remote Openshift server I'm experiencing this weird thing:
The server start and running, executing a GET request returns the expected answer.
Executing a POST method return a 500 server error, when on my local machine it returns the expected result.
Diving into this problem I have realised the following facts:
The last line the program is printing is validate.fullmessage: ... and the correct String message representation of the JSONObject. The "1" line is not printed to the log. No exception is thrown or written to the log as well!
public static boolean validate(String fullMessage) {
...
try {
System.out.println("validate.fullmessage: " + fullMessage);
JSONObject jsonMessage = new JSONObject(fullMessage);
System.out.println("1");
...
} catch (Exception e) {
System.out.println("validation exception");
e.printStackTrace();
}
...
}
Moreover, whenever I return 200 ok or server error I'm writing it to the log, but no error is written to the log. It seems like the server return 500 server error with no reason and not from my code...
RESTHandler:
#POST
#Consumes(MediaType.APPLICATION_JSON)
#Path("/createPlayer")
public Response createUser(String strPlayer) {
System.out.println("createPlayer. strPlayer: " + strPlayer);
Response r;
System.out.println("validating");
if (!ValidateHandler.validate(strPlayer)) {
System.out.println("validation failed!");
r = Response.serverError().build();
}
...
System.out.println("finished");
return r;
}
The "finished" is also not written to the log.
Can anyone help me figure out this weird behaviour?
Ok. So after temporarily changing the Exception handling to catch all Throwables (this way catching RuntimeErrors also, not only Exceptions), the problem turned out to be java versioning issue.
On the remote machine you are using a different version of java, probably older than the one which was used to compile one of your libraries.
The easy solution (if this is available) is upgrading your remote server java version to the one that is used on your computer locally.
If that is not an option, then you need to analyze the error and find and downgrade the library which is incompatible with your outdated server java version.
I'm working on an old project and, due to the short time to deploy new release, I cannot migrate the upload of content using CMIS so, I need to use old WebServiceFactory code to create binary into Alfresco.
But, with the new release of Alfresco (5.0.a) I'm not able to obtain the authorization using:
WebServiceFactory.setEndpointAddress("http://localhost:8080/alfresco/api");
AuthenticationUtils.startSession(userName, password);
This is the error I'm getting:
Caused by: (404)Not Found
at org.apache.axis.transport.http.HTTPSender.readFromSocket(HTTPSender.java:744)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:144)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
Any clue? Do you know if there a really (really really) fast way to create folder and update binary from Java classes?
thanks,
Andrea
Go grab the File Loader example from this code, edit the pom.xml to the latest version of everything, point it at your server, run, enjoy.
The problem is related only to the start of the first session, in our case, because the WebServiceFactory try to load the file "alfresco/webserviceclient.properties" by default.
We've resolved the issue with this workaround:
public static void startSession(String endpoint, String username, String password)
throws Exception {
try {
if (_log.isDebugEnabled()) {
_log.debug("Connecting to: " + endpoint);
}
/** fix for http 404 error during start first session
* needs to init {#link WebServiceFactory#loadedProperties} field to true and nothing else
*/
WebServiceFactory.getEndpointAddress();
/** fix for http 404 error during start first session*/
WebServiceFactory.setEndpointAddress(endpoint);
AuthenticationUtils.startSession(username, password);
if (_log.isDebugEnabled()) {
_log.debug("Start session with ticket: " + AuthenticationUtils.getTicket());
}
}
catch (Exception e) {
_log.error("Can not initiate session with Alfresco server.");
throw e;
}
}
I've inherited a Java based project that includes a cron job to upload a file via SFTP to a third-party server. Here's the relevant code.
String filePath = IUtil.getInstance().getProperties("cheetah_sftp_filepath");
try{
SshClient ssh = new SshClient();
ssh.connect(host, port);
//Authenticate
PasswordAuthenticationClient passwordAuthenticationClient = new PasswordAuthenticationClient();
passwordAuthenticationClient.setUsername(userName);
passwordAuthenticationClient.setPassword(password);
int result = ssh.authenticate(passwordAuthenticationClient);
if(result != AuthenticationProtocolState.COMPLETE){
throw new Exception("Login to " + host + ":" + port + " " + userName + "/" + password + " failed");
}
//Open the SFTP channel
SftpClient client = ssh.openSftpClient();
client.cd("autoproc");
client.put(filePath);
//disconnect
client.quit();
ssh.disconnect();
} catch(Exception e) {
String message = "Failed during sftp: " + e.getMessage();
addJobMessage(message, JobMessageType.JOB_MESSAGE_TYPE_ERROR);
e.printStackTrace();
return false;
}
Pretty straightforward, but it's not working. When client.put() executes, it fails with "java.io.IOException: No such file". Here's the stack trace.
java.io.IOException: No such file
at com.sshtools.j2ssh.sftp.SftpSubsystemClient.getOKRequestStatus(Unknown Source)
at com.sshtools.j2ssh.sftp.SftpSubsystemClient.setAttributes(Unknown Source)
at com.sshtools.j2ssh.sftp.SftpSubsystemClient.changePermissions(Unknown Source)
at com.sshtools.j2ssh.SftpClient.chmod(Unknown Source)
at com.sshtools.j2ssh.SftpClient.put(Unknown Source)
at com.sshtools.j2ssh.SftpClient.put(Unknown Source)
at com.sshtools.j2ssh.SftpClient.put(Unknown Source)
at com.sshtools.j2ssh.SftpClient.put(Unknown Source)
at com.dez.store.scripts.SendEmailShellCommand.sftpToCheetah(SendEmailToCheetahShellCommand.java:99)
at com.dez.store.scripts.SendEmailShellCommand.execute(SendEmailToCheetahShellCommand.java:34)
at com.fry.ocp.common.ShellCommandExecutor.main(ShellCommandExecutor.java:90)
filePath is an absolute path to the file. Yes, I've checked the obvious: the path is correct and the file exists. File permissions are 664 so a read shouldn't be failing in any case, but the process is running as root to boot.
I've tried everything I can think of.
I've checked read permissions all the way up the directory tree (which is kind of deep).
I've tried lcd() to the directory and once I get there lpwd(). That seems fine, but put still fails so a long path name doesn't seem to be the issue.
I double checked to make sure the file streams that originally wrote the file were all being closed correctly. I don't see anything that makes me think that could be the issue.
I tried creating and instance of j2ssh.sftp.SftpFile with the full path to see if it could access the file and make sure the "No such file" error wasn't related to the remote host. When I execute SftpFile.canRead() I get a null pointer exception, so I'm thinking it's a local problem.
I haven't touched Java in years. To say that I am rusty would be a gross understatement. However, our last "Java guy" just quit and I'm the only person left in my shop who has touched Java ever, so I'm the new "Java guy".
Am I missing something simple? Any other ideas?
-Sean
From the callstack and your description, I would expect the error refers to the remote file.
The chmod has to be done only after the transfer completes, so I assume the SftpClient believes the transfer is done and it tries to update the remote file permissions. And it seems like it fails, because the file is actually not there. Once you get the error, use SftpClient.ls(), to check, if the file is there. Chances are that you have some remote-side process that takes the file away the moment the upload finishes.
As a workaround, you can also try to prevent the SftpClient trying to modify the permissions after the upload finishes. I do not know J2SSH. Having a quick look, I have not found any API for this though. Maybe the SftpClient.umask().
You can try to switch to JSch. It does not seem to do implicit chmod after upload.
Also it's worth checking the remote server log.
I am implementing a class that needs to connect to a MYSQL database....on a windows system, i had some connection issue which were resolved with changing the "bind-address" paramater in the MYSQL configuration file to localhost and setting the MYSQL connector in the classpath.
I tried the same steps on Red Hat Linux,..but no connection is made. Is it something with the security configuration?. Below is the code i am using to test for a MYSQL connection.
import java.sql.*;
public class test {
static Connection con = null;
public static void main(String[]args) throws SQLException,ClassNotFoundException {
//Load Driver
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql://localhost/IMS","root","root1");
System.out.println("Database Connected");
} catch(Exception e) {
System.err.println("error connecting database: little challenge" + e);
System.exit(2);
}
}
}
The error being returned is
error connecting database:
little challenge java.sql.SQLException:
Unexpected exception encountered during query.
I believe this means the connection is not being made. How can i resolve this?
Looks like a problem related to use of GCJ. It relates to the connection attempt raising an exception when it reaches an unknown character or one it cannot convert.
Recommendation: use Hotspot (a.k.a. Sun) JVM.
Update: To do so, install the JDK rpm and use alternatives command to set the default JVM version as shown on superuser.
Define port of server
jdbc:mysql://localhost:3306/IMS
You have to add mysql jar file in project.After its work also on linux.
I am trying to download a xml text file from a web server using this method:
static void download (String url , String fileName) throws IOException{
FileWriter xmlWriter;
xmlWriter = new FileWriter(fileName);
System.out.println("URL to download is : " + url);
// here Exception is thrown/////////////////////////////////
BufferedReader inputTxtReader = new BufferedReader
(new BufferedReader(new InputStreamReader(addURL.openStream())));
////////////////////////////////////////////////////////
String str ;
String fileInStr = "";
str = inputTxtReader.readLine();
while (!(str == null) ){///&& !(str.equals("</tv>"))
fileInStr += (str + "\r\n");
str = inputTxtReader.readLine();
}
xmlWriter.write(fileInStr);
xmlWriter.flush();
xmlWriter.close();
System.out.println("File Downloaded");
}
Sometimes this exception is thrown (where I specified is code):
java.net.SocketException: Network is unreachable: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.Socket.connect(Socket.java:518)
at java.net.Socket.connect(Socket.java:468)
at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:389)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:516)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:233)
at sun.net.www.http.HttpClient.New(HttpClient.java:306)
at sun.net.www.http.HttpClient.New(HttpClient.java:318)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:788)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:729)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:654)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:977)
at java.net.URL.openStream(URL.java:1009)
at MessagePanel.download(MessagePanel.java:640)
at WelcomThread.run(MainBody2.java:891)
Please guide me
Thank you all.
You are facing a connection breakdown. Does this happen in 3G, WiFi or "plain" connection on a computer?
Anyway, you must assume that the connection may be lost from time to time, when writing your app. For example, with mobiles, this happens frequently in the tube, in basements, etc. With PC apps, this is less frequent but occurs sometimes.
A retry can be a good solution. And a clean error message that explains the network is not available at this moment too.
I faced situation of getting java.net.SocketException not sometimes but every time. I've added -Djava.net.preferIPv4Stack=true to java command line and my program started to work properly.
"Network is unreachable" means just that. You're not connected to a network. It's something outside of your program. Could be a bad OS setting, NIC, router, etc.
I haven't tested with your code so it would be totally different case though, still I'd like to share my experience. (Also this must be too late answer though, I hope this answer still would help somebody in the future)
I recently faced similar experience like you such as some times Network is unreachable, but sometimes not. In short words, what was cause is too small time out. It seems Java throws IOException with stating "Network is unreachable" when the connection fails because of it. It was so misleading (I would expect something like saying "time out") and I spent almost a month to detect it.
Here I found another post about how to set time out.
Alternative to java.net.URL for custom timeout setting
Again, this might not the same case as you got experienced, but somebody for the future.
this just happened to me. None of the answers helped, as the issue was I have recently changed the target host configuration and put incorrect host value there. So it could just be wrong connection details as well.
I faced this error after updating my network adapter configuration (migration to a NIC coupled network by PowerShell commandlet New-NetSwitchTeam). My guess is, that something in the java configuration must be adapted to reflect this change to the java system. But it is unclear where the changes should take place. I am investigating further.