Error connecting to a share folder from java - java

I am working at an application in java which gets files from a share folder. For 2 days, i got same error trying to connect to the share folder. Until now, i didn't get this error. I dont know what is happened. Please help me.
My code:
package ScanPatch;
import java.util.TimerTask;
import Controllers.InterfataController;
import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbFile;
public class MyTask extends TimerTask{
public MyTask(){
}
#Override
public void run() {
//System.out.println("Hi see you after 10 seconds");
for(int i=0;i<InterfataController.getListaCheckbox().size();i++)
{
String path="smb://bcr-hqb-w0935/Oracle/Patchuri/" + InterfataController.getListaCheckbox().get(i).getText() +"/";
NtlmPasswordAuthentication userCred = new NtlmPasswordAuthentication("BCRWAN",
"Sebastian.burchidrag", "Parola952491");
SmbFile smbFile;
jcifs.Config.setProperty("jcifs.smb.client.disablePlainTextPasswords","false");
try {
smbFile = new SmbFile(path, userCred);
String [] patchuri=smbFile.list();
if(patchuri.length>1)
{
InterfataController.getListaCheckbox().get(i).setStyle("-fx-text-fill: red;");
}
else
{
InterfataController.getListaCheckbox().get(i).setStyle("-fx-text-fill: black;");
}
}catch(Exception e)
{
e.printStackTrace();
}
}
}
}
The error is : jcifs.smb.SmbException: 0xC000009A on String [] patchuri=smbFile.list(); this line.
The idea is that if a restart my computer, the application will work for the first connection, but only first time, then a i will get this error.

Related

Spigot Minecraft plugin coding NoClassDefFound error mysql

When i start the server this error comes :
I am using IntelliJ Idea and MySQL jar is added to the src and in the project modules.
Error pastebin
Here is my code
package com.okaam.jaajhome;
import org.bukkit.plugin.java.JavaPlugin;
import pro.husk.mysql.MySQL;
import java.sql.Connection;
import java.sql.SQLException;
public class JaaJHome extends JavaPlugin {
static JaaJHome instance = null;
MySQL MySQL = new MySQL("address", "port", "schema", "user", "password", "");
static Connection c = null;
#Override
public void onEnable() {
System.out.println("Plugin JaaJHome active");
getCommand("sethome").setExecutor(new SetHomeExecutor());
getCommand("home").setExecutor(new HomeExecutor());
try {
c = MySQL.getConnection();
} catch (SQLException e) {
e.printStackTrace();
}
instance = this;
}
public static JaaJHome getInstance() {
return instance;
}
}
It seems like you're missing on some dependencies, make sure you have them either in the plugins folder as a non plugin or in the classpath to make sure they're loaded.

NotBoundException when I'm trying to connect with RMI server

I try to launch this app using RMI client-server.
Firstly, I ran it and had the error "Connection refused to host: localhost".
After that I went go system32/drivers/etc/hosts and fix it, added line:
127.0.0.1 localhost
It wasn't led me to problem solution.
Then I looked up same questions in stackoverflow about how to fix this problem, then solved it with (ran in cmd):
start rmiregistry
So, rmiregistry ran and i had got a new error - NotBoundException (but I could fix "Connection refusal" problem).
servicebrowser.java:
package servicebrowser;
import java.awt.*;
import javax.swing.*;
import java.rmi.*;
import java.awt.event.*;
public class ServiceBrowser {
JPanel mainPanel;
JComboBox serviceList;
ServiceServer server;
public void buildGUI() {
Object[] services = getServicesList();
}
Object[] getServicesList() {
Object obj = null;
Object[] services = null;
try {
obj = Naming.lookup("rmi://127.0.0.1/ServiceServer");
}
catch (Exception ex) { ex.printStackTrace(); }
server = (ServiceServer) obj;
try {
services = server.getServiceList();
}
catch (Exception ex) { ex.printStackTrace(); }
return services;
}
class MyListListener implements ActionListener {
public void actionPerformed(ActionEvent ev) {
Object selection = serviceList.getSelectedItem();
loadService(selection);
}
}
public static void main(String[] args) {
new ServiceBrowser().buildGUI();
}
}
class ServiceServerImpl:
import java.rmi.*;
import java.util.*;
import java.rmi.server.*;
public class ServiceServerImpl extends UnicastRemoteObject
implements ServiceServer {
HashMap serviceList;
public ServiceServerImpl() throws RemoteException {
setUpServices();
}
private void setUpServices() {
serviceList = new HashMap();
}
public Object[] getServiceList() {
System.out.println("in remote");
return serviceList.keySet().toArray();
}
public Service getService(Object serviceKey) throws RemoteException {
Service theService = (Service) serviceList.get(serviceKey);
return theService;
}
public static void main (String[] args) {
try {
Naming.rebind("ServiceServer", new ServiceServerImpl());
}
catch (Exception ex) {
ex.printStackTrace();
}
System.out.println("Remote service is running");
}
}
What is wrong with it? I turned off firewall too, certaintly.
Thanks a lot!
I solved my problem right this way.
Firstly, I edited classes servicebrowser, ServiceServerImpl.
class servicebrowser:
Before:
try {
obj = Naming.lookup("rmi://127.0.0.1/ServiceServer");
}
Now (plus I added import java.rmi.registry.LocateRegistry, import java.rmi.registry.Registry in top part of code):
try {
Registry registry = LocateRegistry.getRegistry("127.0.0.1", 10001);
obj = registry.lookup("ServiceServer");
}
class ServiceServerImpl:
Before:
try {
Naming.rebind("ServiceServer", new ServiceServerImpl());
}
Now (like a previous class I added import classes in top part of code):
try {
Registry registry = LocateRegistry.createRegistry(10001);
registry.bind("ServiceServer", new ServiceServerImpl());
}
Secondly, I try to ran project (F6) in Netbeans, where servicebrowser marked as main class. It was refusal connection again. After that I only ran class ServiceServerImpl (Shift + F6) then ran entire projecе. So, it works.
P.S. I didn't use cmd and try to
"start rmiregistry"
because the app works without it.

try/catch not working in Java?

I am making an app for android in Qt. So in order to use the Google API I need to implement Java. So I have looked through the QtNotifier example and I am trying to implement the same as a starter.
This Java example comes from the QtNotifier example aswell so it should work the same but it doesn't. I have tried to debug it using the Qt debugger but the breakpoints do not seem to trigger So I added println statements to see at which line it goes wrong. But this is not enough so I am trying to print a stacktrace using a catch/try clause.
I have implemented it like this:
package org.qtproject.qt5.example;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import java.lang.Object;
import java.io.Writer;
import java.io.StringWriter;
import java.io.PrintWriter;
public class NotificationClient extends org.qtproject.qt5.android.bindings.QtActivity
{
private static NotificationManager m_notificationManager;
private static Notification.Builder m_builder;
private static NotificationClient m_instance;
public NotificationClient()
{
System.out.println("it works2222");
m_instance = this;
}
public static void notify(String s)
{
System.out.println(s);
try {
if (m_notificationManager == null) {
System.out.println("1111");
m_notificationManager = (NotificationManager)m_instance.getSystemService(Context.NOTIFICATION_SERVICE);
System.out.println("2222");
m_builder = new Notification.Builder(m_instance);
System.out.println("3333");
m_builder.setContentTitle("A message from Qt!");
System.out.println("4444");
}
System.out.println("5555");
m_builder.setContentText(s);
System.out.println("6666");
m_notificationManager.notify(1, m_builder.build());
System.out.println("7777");
} catch(Exception e) {
StringWriter writer = new StringWriter();
PrintWriter pw = new PrintWriter(writer);
e.printStackTrace(pw);
String errorDetail = writer.toString();
}
}
}
The output is:
I/System.out( 4768): test string
I/System.out( 4768): 1111
It would seem that m_instance is still null because "System.out.println("it works2222");" does not get called. But the error does not get caught.
Is it because this is an error that is not an exception?
I have also tried running the QtNotifier app but the printstatement inside.
public NotificationClient()
{
System.out.println("it works2222");
m_instance = this;
}
But that is also not called in the QtNotifier app.
My question is: How can I trace this error?
In Java, there are both Errors and Exceptions. Normally, an Error is significant enough that your program should just crash and exit. However, for debugging purposes, if you want to catch both you should
catch (Throwable t)
{
t.printStackTrace();
}
to get information on both.

using git with apache sshd

I'm trying to use msysgit over an SSH server I wrote in Java using sshd and I have made great progress in that i got past some git errors, I am able to connect using putty and get a shell, I have git in my windows path, but I still can't actually use git to connect to my repository over my ssh daemon. I get the following error from msysgit:
fatal: ''/C/gitrepo'' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I used the following to add the remote to the repo I'm trying to connect from:
git remote set-url origin "ssh://test#localhost:22/C/gitrepo".
I tried a lot of other variations as well of the path with no luck. I have two git repos set up on localhost, the one i'm running git push from and the one at c:\gitrepo.
What am I missing?
Also I had to add the path to mysysgit/bin to my windows 7 environment variable, but would also like a way to get this to work without adding it to my windows environment variables but specifying it programmatically in my ssh server, but more importantly I would like to be able to run git over this ssh server.
The code for my server is below.
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import org.apache.sshd.SshServer;
import org.apache.sshd.server.UserAuth;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.util.OsUtils;
import org.apache.sshd.server.Command;
import org.apache.sshd.server.CommandFactory;
import org.apache.sshd.server.ForwardingFilter;
import org.apache.sshd.server.PasswordAuthenticator;
import org.apache.sshd.server.auth.UserAuthPassword;
import org.apache.sshd.server.command.ScpCommandFactory;
import org.apache.sshd.server.filesystem.NativeFileSystemFactory;
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
import org.apache.sshd.server.session.ServerSession;
import org.apache.sshd.server.shell.ProcessShellFactory;
public class SSHD {
public SSHD() {
init();
}
public void start() throws IOException {
sshServer.start();
}
private void init() {
sshServer = SshServer.setUpDefaultServer();
sshServer.setPort(22);
sshServer.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("hostkey.ser"));
setupAuthentication();
setupCommandHandling();
}
private void setupAuthentication() {
sshServer.setPasswordAuthenticator(new SSHD.MyPasswordAuthenticator());
List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>();
userAuthFactories.add(new UserAuthPassword.Factory());
sshServer.setUserAuthFactories(userAuthFactories);
}
private void setupCommandHandling() {
CommandFactory myCommandFactory = new CommandFactory() {
#Override
public Command createCommand(String command) {
System.out.println("command = \"" + command + "\"");
return new ProcessShellFactory(command.split(" ")).create();
}
};
sshServer.setCommandFactory(new ScpCommandFactory(myCommandFactory));
sshServer.setFileSystemFactory(new NativeFileSystemFactory());
sshServer.setForwardingFilter(new ForwardingFilter() {
public boolean canForwardAgent(ServerSession session) {
return true;
}
public boolean canForwardX11(ServerSession session) {
return true;
}
public boolean canListen(InetSocketAddress address, ServerSession session) {
return true;
}
public boolean canConnect(InetSocketAddress address, ServerSession session) {
return true;
}
});
ProcessShellFactory shellFactory = null;
if (OsUtils.isUNIX()) {
shellFactory = new ProcessShellFactory(new String[]{"/bin/sh", "-i", "-l"},
EnumSet.of(ProcessShellFactory.TtyOptions.ONlCr));
} else {
shellFactory = new ProcessShellFactory(new String[]{"cmd.exe "},
EnumSet.of(ProcessShellFactory.TtyOptions.Echo, ProcessShellFactory.TtyOptions.ICrNl, ProcessShellFactory.TtyOptions.ONlCr));
}
sshServer.setShellFactory(shellFactory);
}
private static class MyPasswordAuthenticator implements PasswordAuthenticator {
#Override
public boolean authenticate(String username, String password, ServerSession session) {
return true;
}
}
public static void main(String[] args) {
SSHD sshd = new SSHD();
try {
sshd.start();
} catch (IOException ex) {
System.out.println("EXCEPTION: " + ex);
ex.printStackTrace();
}
}
private SshServer sshServer;
}
Does anybody know how to fix this manual parsing on the server side. Is there a different command processor I can use or something like that?

Java Applet to Download files files

I have an applet that is executed in an HTML file that the user downloads and opens locally (i.e. file:// on the URL bar). This applet has a method that downloads a file from the web and stores it in a directory inside the directory where the applet is running. On my HTML file I call the function to download a file and it works but when I call it the second time, to download another file, I get a Error calling method on NPObject. I don't get any error on the Java side (I have the console open and it stays clean).
What can be the issue here? Thank you a lot for your help. Below, the code of the applet.
import java.security.*;
import java.io.*;
import java.nio.channels.*;
import java.net.*;
public class EPPenDrive extends java.applet.Applet {
public final static String baseURL = "http://localhost/data/documents/";
public String downloadFile(final String filename) {
return (String)AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
try {
URL finalURL = new URL(baseURL + filename);
ReadableByteChannel rbc = Channels.newChannel(finalURL.openStream());
URL appletDir = getCodeBase();
FileOutputStream fos = new FileOutputStream(appletDir.getPath() + "documents/"+ filename);
fos.getChannel().transferFrom(rbc, 0, 1 << 24);
return 1;
} catch (Exception x) {
x.printStackTrace();
return null;
}
}
});
}
public void init() { }
public void stop() { }
}
I found the problem: the run() method would block if returning 1. I changed it to return null and now everything works. :)

Categories

Resources