some times you need to copy a file or directory from your machine to another machine using command line, if so you can use the scp command :

suppose that the file needed to be copied /home/mostafa/file.txt, and you have access to the other machine mostafa@nile-sys.com

$ scp /home/mostafa/file.txt  mostafa@nile-sys.com:/home/mostafa/

this command will copy the file.txt to the the path /home/mostafa/file.txt in the remote machine nile-sys.com

also you can copy files between 2 remote machine with the same command as follows:

$ scp mostafa@www.nile-sys.com :/ home/mostafa/file2.sh mostafa@ns1.nile-sys.com:/home/mostafa

sometimes you need to configure the log4j to daily roll the log file, this will help when you trace an error happened in a specific day.

in your log4j.properties file create an appender of type DailyRollingFileAppender:

log4j.appender.R=org.apache.log4j.DailyRollingFileAppender

define the date pattern which will be used in naming the log files:

log4j.appender.R.DatePattern=’-'yyyy-MM-dd’.log’

define the path of your log files:

log4j.appender.R.File=log/application

and configure how logs should appear inside the file:

log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L – %m%n

### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L – %m%n
log4j.rootLogger=debug, stdout, R

now you will have a separate log file for every day and will be in path

log/application-yyyy-MM-dd.log

To set HTTP header in a SOAP message :

SOAPConnectionFactory factory = SOAPConnectionFactory.newInstance();

SOAPConnection soapConnection =factory.createConnection();

SOAPMessage message = MessageFactory.newInstance().createMessage(null,yourInputStream);

message.getMimeHeaders().addHeader("header name", "header value");

soapConnection.call(message, "server url");

some time you need to change the author name of the files you create by eclipse rather than the system user name.

to do so:

1- open eclipse.ini file in the eclipse directory.

2- add the following line after -vmargs line

-Duser.name=your name

References:

http://dev.eclipse.org/newslists/news.eclipse.newcomer/msg07148.html

In this post will explain how to create a CORBA Java server using the Java sdk.

here a pref. description of what needed to be done:

1- create an idl (Interface Description Language) file that will be the contract between the Server and client regarding the object that needed to be referenced from the client and implemented on the server.

2- generate java skeleton from the idl by using idltojava compiler or idlj.

3- create the concrete class that will be instantiated by the server and its objects referenced by the client.

4- instantiate an ORB object to handle all Marshalling and un-Marshalling for the object calls and all IIOP stuff.

5- create naming context object.

6- create naming component for the object that will be exposed by CORBA.

7- bind the object with the name component in the name context.

the following the a sample code for the above steps:

1- create an IDL file: create a file and name it helloWorld.idl and add the following lines into it:

——————————————————-

module helloWorld {
interface Greetings {
string sayHello();
};
};

———————————————————————

in this idl we define one interface called Greetings that interface has one method or operation called sayHello and will return a String.

2- generate server skeleton from the idl by idlj:

in your terminal go to the directory contains the idl file and run the following command

$ idlj  -fserver -oldImplBase helloWorld.idl

the idlj will create the following:

- Greetings interface.

- GreetingsOperations class.

- _GreetingsImplBase class.

3- create a concrete class contains your business:

you need now to create the concrete class which you need its objects to be exposed through CORBA. To do so you need to create GreetingsServer class that extend the _GreetingsImplBase class.

by extending _GreetingsImplBase class you need to implement the sayHello method, here is code sample:

——————————————————————————————–

public class GreetingsServer extends _GreetingsImplBase {

public String sayHello () {

return ” Hello CORBA”;

}

}

———————————————————————————————–

save this class and create a new class the will run as the server for IIOP calls name the new class CorbaServer

————————————————————————————————–

package Corba;

import org.omg.CORBA.ORB;
import org.omg.CORBA.Object;
import org.omg.CORBA.ORBPackage.InvalidName;
import org.omg.CosNaming.NameComponent;
import org.omg.CosNaming.NamingContext;
import org.omg.CosNaming.NamingContextHelper;
import org.omg.CosNaming.NamingContextPackage.AlreadyBound;
import org.omg.CosNaming.NamingContextPackage.CannotProceed;
import org.omg.CosNaming.NamingContextPackage.NotFound;

public class CorbaServer {

/**
* @param args
*/
public static void main(String[] args) {
// 4- create ORB object
ORB orb = ORB.init(args, null);

// create an instance of the GreetingsServer , this instance will be exposed by the ORB

GreetingsServer greetings = new GreetingsServer();
// register the instance to ORB object
orb.connect(greetings);

try {
// create naming context root, the NameService is the root NameService for any ORB
Object initNameService = orb.resolve_initial_references(”NameService”);
// narrowing the naming service object
NamingContext ncRef = NamingContextHelper.narrow(initNameService);
// create a name component for the GreetingsServer object
NameComponent nc = new NameComponent(”Greetings”,”");
// create name component array that will hold the greeting name component

NameComponent[] path = {nc};

// bind the greetings object with name component
ncRef.rebind(path, greetings);
// to keep the application waiting for calls

Thread.currentThread().join();

} catch (InvalidName e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NotFound e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (CannotProceed e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (org.omg.CosNaming.NamingContextPackage.InvalidName e) {
// TODO Auto-generated catch block
e.printStackTrace();
}  catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}
————————————————————————————-

now you have the CORBA server we need to run the naming service that will be used by the CORBA server

$ tnameserv

this will start the naming service

at last you can start your CORBA server name and wait for calls from corba clients that used your idl.

references:

http://members.tripod.com/gsraj/corba/chapter/javaidl_1.html — this was very helpful to me.

http://java.sun.com/j2se/1.4.2/docs/guide/corba/index.html

when you are using tomcat as you application server for not small application you can easy get (out of memory exception). this is because the default heap size tomcat use is small and suitable only for small web applications.

to set the start and maximum heap size run the following command before starting your tomcat:

export CATALINA_OPTS=”-Xms256m -Xmx512m”

or

export JAVA_OPTS=”-Xms256m -Xmx512m”

this will create environment variable called CATALINA_OPTS  or JAVA_OPTS contains the required options to make tomcat start heap size 256M and maximum heap size 512M.

In this post I’ll talk about how to use connection pooling in struts running on tomcat server:

you will need to edit in the following places:

  • META-INF/context.xml
  • WEB-INF/web.xml

first you need to add a context.xml file to your application to be used by tomcat application server when defining and creating your application context.

To do that create a folder called META-INF beside your WEB-INF.

in this folder create file and name it context.xml

open this file and add the following code:

<Context path=”/yourAppPath” docBase=”yourAppDocBase
debug=”5″ reloadable=”true” crossContext=”true”>
<Resource name=”jdbc/resourceName” auth=”Container” type=”javax.sql.DataSource”
maxActive=”100″ maxIdle=”10″ maxWait=”10″
username=”userName” password=”Password” driverClassName=”com.mysql.jdbc.Driver”
url=”jdbc:mysql://localhost:3306/DatabaseName?autoReconnect=true”/>
</Context>

replace names in Bold with your application parameters resourceName is the name of the datasource that you will use. the previous code creates a new database resource on your application context.

now you need to create a reference to the created resource. edit your web.xml and add the following code:

<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/resourceName</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

replace names in Bold with your application parameters.

now you only need to know how to get the datasource from your code:

Context ctx = new InitialContext();

DataSource ds = (DataSource) ctx.lookup(”java:comp/env/jdbc/resourceName“);

Connection connection = ds.getConnection();

and you can enjoy using the new connection

I wish that I made this topic clear and I’ll be happy to receive your comments and questions.

finally e-archive (earth project) version 1 has been finished and implemented on synergy egypt. it is very nice to have your own product.

e-archive is document repository system and information strutcured repository system.

I’ll talk now a little about the observer design pattern, or i can call it the listener design pattern.

the Observer design pattern define a one-to-many relationship between objects that when an object status changes the other dependent objects be notified.

the idea is : there is an object that has a peace of information, many other objects interested in knowing when its state changes.

the way to handle this is creating a way to allow dependent objects to register to be notified when the status changes. here is an imagination of how you can model this situation:

Class Diagram

Class Diagram

From the diagram you can see that we created two interfaces one for the subject object which will contains the information or status other objects needed to be aware about. the Subject interface has 3 methods registerObserver, deregisterObserver and notifyObservers.

registerObserver(): takes an Observer object as a argument and add this object to an internal arraylist or whatever you choose to keep all registered observers on it.

deregisterObserver(): takes an Observer object as a argument and and remove this object from the observers arraylist.

notifyObservers(): call the update() method on all observers exists on the observers arraylist and send the new status(s) as arguments.

The Observer Interface contains one method update()

update(): this method takes the status or information it interested in as argument(s).

so in pref. an subject object has information some observer objects interested in, so the observer objects register themselves on the subject object by calling the register method.

when the data in the subject object changed the notifyObservers() method call and it send the new information by calling update method in all registered observers.

when an observer object decided to stop receiving updates it deregister himself from the subject object by calling deregister() on the subject object.

Hello every one,

few days ago my ubuntu machine started to give me this error every  time i login:

ISD-Server could not start because port 5800 is not available.

i google it but didn’t found a good solution but after while i found one from ubuntu forum:

ica is part of italc.sourceforge.net and it is installed on my machine when i installed edubuntu.

and to stop getting this error message here is what i did:

$sudo apt-get remove libitalc italc-client italc-master

and i never see the error message again.

here is the thread which i found the solution in:

http://ubuntuforums.org/showthread.php?t=749394&page=2

Next Page »