RMI Server-side java.net.MalformedURLException: unknown protocol: c - java

I surfed the net for 2 days, and I didn't find a solution formyproblem, so I decided to ask here.
I'm doing a book exercise: "Write a program Client-Server with Java RMI, that return the sum of integer given by clients. It has to implement a method to add an integer, anda method to get the total".
I'm facing with the Server-side.
The error the program returns is:
java.rmi.UnmarshalException: Error unmarshaling return; nested exception is:
java.net.MalformedURLException: unknown protocol: c
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
at java.rmi.Naming.bind(Unknown Source)
at ContatoreServer.main(ContatoreServer.java:15)
Caused by: java.net.MalformedURLException: unknown protocol: c
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at sun.rmi.server.LoaderHandler.pathToURLs(Unknown Source)
at sun.rmi.server.LoaderHandler.getDefaultCodebaseURLs(Unknown Source)
at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
at java.rmi.server.RMIClassLoader$2.loadClass(Unknown Source)
at java.rmi.server.RMIClassLoader.loadClass(Unknown Source)
at sun.rmi.server.MarshalInputStream.resolveClass(Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
... 5 more
Here there are my classes:
LocalObject
public class ContatoreLocale {
private int num;
public ContatoreLocale(){
this.num=0;
}
public synchronized int get(){
return this.num;
}
public synchronized void add(int i){
this.num+=i;
}
}
Remote Interface
public interface IContatore extends Remote{
int get() throws RemoteException;
void add(int i) throws RemoteException;
}
Remote Object
public class ContatoreRemoto extends ContatoreLocale implements IContatore{
Logger log= Logger.getLogger("global");
//Costruttore
public ContatoreRemoto() throws RemoteException{
super();
UnicastRemoteObject.exportObject(this, 0);
try {
Naming.rebind("Contatore", this);
//errore
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
public int get(String nome) throws RemoteException{
return this.get();
}
public void add(String nome,int i) throws RemoteException{
this.add(i);
}
}
Server
public class ContatoreServer {
static Logger log= Logger.getLogger("global");
public static void main(String[] args) {
try {
ContatoreRemoto cr=new ContatoreRemoto();
log.info("Server Pronto");
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
Please, help me :S

In my experience, this has to do with the absolute path in the File System where the RMI Eclipse project is placed. I think you may have a blank, a space, in the path. So RMI is unable to parse the path and it is interrupted, ... then we get the 'malformed' exception. It might be near a 'c', and for this reason, you get the 'c' in the exception.
I recommend you go to the file system, navigate to the project folder, and check the absolute path to the project. I bet you have a blank.
Such as c:\Users\mylab c\MyProjects....
Did you notice the blank space?

Related

STEP Files Parsing

I am working to parse STEP files ISO-10303-21; using Part21Parser in java
Following is file structure
HEADER;
FILE_DESCRIPTION(('STEP AP214'),'1');
FILE_NAME('s25552_b159_a1_13.stp','2016-10-04T07:52:56',(' '),(' '),'Spatial InterOp 3D',' ',' ');
FILE_SCHEMA(('automotive_design'));
ENDSEC;
static Model read_file (String filename) throws STDevException, IOException {
Part21Parser parser = new Part21Parser();
return parser.parse(filename);
}
public static void main(String[] args) {
try {
Part21Parser parser = new Part21Parser();
try {
Model m1 = read_file("D:/Braunschweig_board.stp");
} catch (IOException e) {
e.printStackTrace();
}
} catch (STDevException e1) {
e1.printStackTrace();
}
But when I run, it gives exception that
Cannot find schema automotive_design
I am not sure what kind of schema is it expecting and what should be the valid schema as there is no help regarding this exception online. Any one who worked on STEP/EXPRESS files could please help
Following is stacktrace
com.steptools.stdev.SchemaNotFoundException: Cannot find schema automotive_design
at com.steptools.stdev.SchemaBase.forName(SchemaBase.java:61)
at com.steptools.stdev.p21.Part21Parser.getSchema(Part21Parser.java:693)
at com.steptools.stdev.p21.Part21Parser.getSchema(Part21Parser.java:673)
at com.steptools.stdev.p21.Part21Parser.getPopulation(Part21Parser.java:547)
at com.steptools.stdev.p21.Part21Parser.parse_DATA_SECTION(Part21Parser.java:561)
at com.steptools.stdev.p21.Part21Parser.parse_EXCHANGE_FILE(Part21Parser.java:302)
at com.steptools.stdev.p21.Part21Parser.parse(Part21Parser.java:230)
at com.steptools.stdev.p21.Part21Parser.parse(Part21Parser.java:112)
at com.steptools.stdev.p21.Part21Parser.parse(Part21Parser.java:92)
at com.steptools.stdev.p21.Part21Parser.parse(Part21Parser.java:80)
at CadParser.read_file(CadParser.java:26)
at CadParser.main(CadParser.java:35)
Caused by: java.lang.ClassNotFoundException: com.steptools.schemas.automotive_design.Schema
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)`enter code here`
at java.lang.Class.forName(Unknown Source)
at com.steptools.stdev.SchemaBase.forName(SchemaBase.java:59)
... 11 more

File in use error while calling java.nio.Files.copy(Path source, Path target, CopyOption... options)

I have a method to copy file:
public static void copyFiles(File source, File destination)
{
try
{
destination.setWritable(true);
Files.copy(source.toPath(), destination.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING,
java.nio.file.LinkOption.NOFOLLOW_LINKS);
}
catch (IOException e)
{
e.printStackTrace();
}
}
But I am getting an error while calling this method as:
java.nio.file.FileSystemException: C:\analyticslogs\fsLogs.log: The process cannot access the file because it is being used by another process.
at sun.nio.fs.WindowsException.translateToIOException(Unknown Source)
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at sun.nio.fs.WindowsFileCopy.copy(Unknown Source)
at sun.nio.fs.WindowsFileSystemProvider.copy(Unknown Source)
at java.nio.file.Files.copy(Unknown Source)
at com.platform.module.analytics.util.FileOps.copyFiles(FileOps.java:1417)
... 14 more
I searched around this and found that my file MAY be kept open by my own program. Am I keeping any resources open or it's a different issue?

Trying to connect to RMI Registry but getting java.net.ConnectException: Connection refused: connect

I have two computers. On one of them, is running an RMI Registry - which was created from this code alone:
package main;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Scanner;
public class TheRegistry{
public static void main(String[] args) {
try {
Registry reg = LocateRegistry.createRegistry(2020);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
System.out.println("Registry Created");
Scanner input = new Scanner(System.in);
input.nextInt();
System.exit(0);
}
}
}
The other computer has a server that is trying to register an Object on this registry, however, it gets an exception. Here is the code for the server:
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.*;
public class TextScramblerServer implements TextScramblerInterface
{
private static Remote obj;
// main method to export
#Override //Return input text as-is.
public String testInputText(String inputText) {
return "Your input text is: " + inputText;
}
#Override //Return the string reversed.
public String reverse(String inputText) {
String reversedInput = "";
for(int i=0; i<inputText.length();i++)
{
reversedInput=reversedInput+inputText.charAt((inputText.length()-1)-i);
}
return "Result: "+reversedInput;
}
#Override //Return the string scrambled.
public String scramble(String inputText) {
String scrambledInput="";
for(int i=0; i<inputText.length();i++)
{
if(i%2==0)
{
scrambledInput=scrambledInput+inputText.charAt(i);
}
else
{
scrambledInput=inputText.charAt(i)+scrambledInput;
}
}
return "Result: "+scrambledInput;
}
public void exportServer() throws Exception {
System.setSecurityManager(new RMISecurityManager());
obj = UnicastRemoteObject.exportObject(this, 2022);
Registry registry = LocateRegistry.getRegistry("132.205.94.50", 2020);
registry.bind("test", obj);
}
public static void main(String[] args) {
try {
(new TextScramblerServer()).exportServer();
System.out.println("Server is up and running");
}
catch(Exception e){
e.printStackTrace();
try {
UnicastRemoteObject.unexportObject(obj, true); //close port
} catch (NoSuchObjectException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
}
I keep getting the error:
java.rmi.ConnectException: Connection refused to host: 132.205.94.50; nested exception is:
java.net.ConnectException: Connection refused: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
at sun.rmi.server.UnicastRef.newCall(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
at TextScramblerServer.exportServer(TextScramblerServer.java:57)
at TextScramblerServer.main(TextScramblerServer.java:62)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown Source)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown Source)
... 7 more
java.rmi.NoSuchObjectException: object not exported
at sun.rmi.transport.ObjectTable.unexportObject(Unknown Source)
at java.rmi.server.UnicastRemoteObject.unexportObject(Unknown Source)
at TextScramblerServer.main(TextScramblerServer.java:68)
I can't figure out why this is happening. I think I've tried everything
I ran your code and it worked for me after configuring the security policy.
Your ConnectionRefused exception means that the underlying TCP connection cannot be established. It's network issue, not an RMI issue.
Try running both the server and registry on the same host, and use localhost as the hostname. If it works, the problem is likely a firewall issue between the two hosts.
You can do a simple test of a TCP connection to the specific port using telnet. If the port isn't listening, telnet will give you a similar connection refused message. If the port is listening, you'll get something like this on the terminal:
Connected to localhost.
Escape character is '^]'.
Control-C to get out of the session.
The specific telnet output may vary based on your OS, but they are all about the same.
If it is a firewall issue, you'll have to open up the ports. How to do that depends on OS, but it's easy to find.
Either your Registry has been garbage-collected, you got the IP address wrong, or it is a public IP address and you haven't configured port forwarding.
You need to store the Registry reference in a static object to overcome garbage collection, although what the point of that program is when rmiregistry.exe already exists escapes me completely.
You're barking up the wrong tree anyway. You can only bind to an RMI Registry that is running in the local host. There is therefore never any need to use a Registry hostname other than "localhost" when binding or unbinding.
The reason you got the NoSuchObjectException is that you are trying to unexport the stub, which is referred to by obj, which is the result of UnicastRemoteObject.exportObject(), which returns the stub. See the Javadoc. You need to save the result of new TextScramblerServer() and unexport that.

HSQL Connection Error. Any insight?

I'm trying to connect to HSQL using java. I'm using a tutorial to work with JDBC and hibernate. It's the lynda tutorials. Anyway, here's the code below:
package com.lynda.javatraining.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Main {
private static final String USERNAME = "dbuser";
private static final String PASSWORD = "dbpassword";
private static final String CONN_STRING =
"jdbc:hsqldb://data/explorecalifornia";
public static void main(String[] args) throws SQLException {
//Class.forName("com.mysql.jdbc.Driver");
Connection conn = null;
System.out.println("A");
System.out.println(conn == null);
System.out.println(CONN_STRING);
try {
System.out.println("B1");
conn = DriverManager.getConnection(CONN_STRING, USERNAME, PASSWORD);
System.out.println("B1-2");
System.out.println("Connected!");
} catch (SQLException e) {
System.out.println("B2");
System.err.println(e);
} finally {
System.out.println("B3");
if (conn != null) {
conn.close();
}
}
System.out.println("C");
}
}
Here's the error I'm getting:
A
true
jdbc:hsqldb://data/explorecalifornia
B1
2014-06-27T15:26:27.430-0400 SEVERE could not reopen database
org.hsqldb.HsqlException: Database lock acquisition failure: lockFile: org.hsqldb.persist.LockFile#76d682a[file =/data/explorecalifornia.lck, exists=false, locked=false, valid=false, ] method: openRAF reason: java.io.FileNotFoundException: /data/explorecalifornia.lck (No such file or directory)
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.persist.LockFile.newLockFileLock(Unknown Source)
at org.hsqldb.persist.Logger.acquireLock(Unknown Source)
at org.hsqldb.persist.Logger.openPersistence(Unknown Source)
at org.hsqldb.Database.reopen(Unknown Source)
at org.hsqldb.Database.open(Unknown Source)
at org.hsqldb.DatabaseManager.getDatabase(Unknown Source)
at org.hsqldb.DatabaseManager.newSession(Unknown Source)
at org.hsqldb.jdbc.JDBCConnection.<init>(Unknown Source)
at org.hsqldb.jdbc.JDBCDriver.getConnection(Unknown Source)
at org.hsqldb.jdbc.JDBCDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at com.lynda.javatraining.db.Main.main(Main.java:24)
B2
java.sql.SQLException: Database lock acquisition failure: lockFile: org.hsqldb.persist.LockFile#76d682a[file =/data/explorecalifornia.lck, exists=false, locked=false, valid=false, ] method: openRAF reason: java.io.FileNotFoundException: /data/explorecalifornia.lck (No such file or directory)
B3
C
Can anyone tell e what I"m doing wrong? Thanks.
A database has a lock file explorecalifornia.lck that prevents communication. You should delete lock file and restart the database. This may happens from time to time when you accidentally shutdown the database or system.
See the syntax of the command used from the command line to invoke shutdown. There's also an option how to shutdown server in Java.

Can't use class with external jars in gwt on server side

At the beginning I had an error java.lang.ClassNotFoundException. I solved this problem by adding jars to \war\WEB-INF\lib folder. But then I got java.lang.NoClassDefFoundError: Could not initialize class com.orientechnologies.orient.core.Orient error while applying to database. This is the server code:
public class GreetingServiceImpl extends RemoteServiceServlet implements
GreetingService {
public String greetServer(String input) throws IllegalArgumentException {
RegBugs rb = new RegBugs();
String a = rb.getDbAdres();
try {
//The error is here
ArrayList<String> table = rb.getAllGitRecords();
} catch (ParseException e) {
e.printStackTrace();
}
return a;
}
Compilation is finished successfully. And when I start to call to server I get An error occurred while attempting to contact the server. Please check your network connection and try again. from gwt. How could I solve this problem?
P.S. I use eclipse and gwt-plugin for it
The error occurs when I try to interrupt with orient database.
Trace:
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.orientechnologies.orient.core.Orient
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.google.appengine.tools.development.agent.runtime.RuntimeHelper.checkRestricted(RuntimeHelper.java:70)
at com.google.appengine.tools.development.agent.runtime.Runtime.checkRestricted(Runtime.java:64)
at com.orientechnologies.orient.core.db.raw.ODatabaseRaw.open(ODatabaseRaw.java:108)
at com.orientechnologies.orient.core.db.ODatabaseWrapperAbstract.open(ODatabaseWrapperAbstract.java:53)
at com.orientechnologies.orient.core.db.record.ODatabaseRecordAbstract.open(ODatabaseRecordAbstract.java:127)
at com.orientechnologies.orient.core.db.ODatabaseWrapperAbstract.open(ODatabaseWrapperAbstract.java:53)
at ru.sersem.testgwt.server.RegBugs.getBugRecordsCount(RegBugs.java:192)
at ru.sersem.testgwt.server.GreetingServiceImpl.greetServer(GreetingServiceImpl.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:115)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:561)
... 40 more

Categories