How can I get Syslogging to work on the JVM? - java

I want to do syslogging from Java. There is a log4j appender, but it doesn't seem to work (for me anyway ... though Google results show many others with this issue still unresolved).
I'm trying to debug the appender, so I've written the following script based upon RFC3164
It runs, but no logging appears in the syslog.
// scala
import java.io._
import java.net._
val ds = new DatagramSocket()
val fullMsg = "<11>May 26 14:47:22 Hello World"
val packet = new DatagramPacket(fullMsg.getBytes("UTF-8"), fullMsg.length,
InetAddress.getLocalHost, 514)
ds send packet
ds.close
I also tried using /bin/nc, but it doesn't work either.
echo "<14>May 26 15:23:33 Hello world" > nc -u localhost 514
The Ubuntu command /usr/bin/logger does work, however.
logger -p user.info hello world
# logs: May 26 15:25:10 dsupport2 jem: hello world
What could I be doing wrong?
Edit
Both nc & the scala generate the following packet:
jem#dsupport2:~/projects/log4j$ grep -A 10 514 out
xxx.xxx.xxx.xxx:37920(unknown) -> xxx.xxx.xxx.xxx:514(syslog)
Version: 4 Total Lenght: 63 TTL: 64
Packet Number: 4
---[ UDP Data ]------------------------------------------------------
<14>May 26 15:26:33 Hello world 22
It seems I cannot get /usr/bin/logger (the one that works) to talk remotely. I assume you're supposed to set up the local syslogd as a relay.
Edit
Using nc, wireshark shows the message to be formatted OK, but that the port is unreachable.

The network firewall in Ubuntu needs to be explicitly told to allow traffic to a given port, this includes Syslog.

Have you tried sniffing the local network traffic to see if the log messages are actually sent, if they seem well-formed, etc? You could use nast or something like it.

Syslogd is probaby not listening on an IP socket but a unix domain socket. The standard socket is /dev/log. You will need to use a library such as JUDS to connect to this socket. This will give an OutputStream that you can write the log record to.

Related

How to block java application from sending email during development?

My application sends some emails to our customers to warn them about some errors while we process their files. However, I would like to disable this feature, without altering my code, for development/test purposes.
Is there any argument to pass to my JVM in order to block it from sending emails ?
You can replace the JavaMail provider with one that "mocks" a real provider, just by adding a jar to your classpath. In addition to blocking outbound mail, it allows you to perform unit testing on your application's email functions. This library was created by Kohsuke Kawaguchi, creator of Hudson/Jenkins.
If the SMTP server's hostname is hardcoded in the code, for example:
server = "smtp.example.com"
You could alter the host file at /etc/hosts to override the DNS lookup. Add this to your hosts file:
127.0.0.1 smtp.example.com
This will prevent your program from interacting with the mail server. Make sure to delete that line when you are done.
Otherwise, if the IP address is what's hardcoded, you can use a firewall. The exact procedure will depend on the operating system you are using. If you're running an OS with a Linux kernel, you can use iptables to block that IP address:
iptables -I OUTPUT 1 --destination 1.2.3.4 -j REJECT
Or, for a more specific rule:
iptables -I OUTPUT 1 --destination 1.2.3.4 -p tcp --dport 25 -j REJECT --reject-with tcp-reset
Again, remember to change it back when you're done:
iptables -D OUTPUT 1

Not logged in error message while connecting to ftp server

I am using com.enterprisedt.net.ftp.FTPClient to login my FTPSERVER
using the following command ftpClient.login(USER_NAME,PASSWORD());
am using com.enterprisedt.net.ftp.
But some times am getting "Not logged in" error.
FTP server has a domain name. but i log in only with user name and pwd and host name as the dns name.
In some 10, 15 , 20 minutes I get a "not logged in" error.
It is not occuring always, not in any specific pattern also, but immedietly after the error the connection is succesful.
[INFO] [FTPPull : getFTPConnection] - Error occured while FTP login : Not logged in The host is xxx.yyy.in The port used is 6370 [12] [2011-11-10 14:59:18 CET ]
but next connection was succesful
[INFO] [FTPPull : getFTPConnection] - Login Successful [12] [2011-11-10 15:09:18 CET ]
Please help, not sure why sometimes getting connected and sometimes not connected.
Regards,
Sridevi
Your problem is probably that there is a timeout at the FTP command channel level. When your client detects it, it reconnects automatically, as you have witnessed.
Now, you have to understand where that timeout comes from: either the client side or the server side:
first check the configuration on the server side: can you change the command channel timeout to a higher value, or even to infinite?
then check the API for your client (I personally use Apache Commons' FTP client): does it have a way to set the timeout too?
finally, check in the API whether sockets to the command channel use TCP keepalive; if not, does it have a method to set it? If you pass a Socket yourself to the constructor, make it keepalive before constructing your client instance.
The most likely scenario is however that the FTP server itself closes the command channel. Changing that is implementation dependent.
A good way to check the server side disconnection is to use a command line FTP client to check. I personally use lftp for that:
$ lftp ftp://some.ftp.site/
lftp> debug
# idle, idle...
# if the server times out, it will tell you so

Java - trouble running basic socket networking program

I'm trying to implement Sun's example Socket program, i.e. the KnockKnock server and client found here: http://download.oracle.com/javase/tutorial/networking/sockets/readingWriting.html
So I build the 3 files (EchoClient, KnockKnockServer, KnockKnockProtocol) into a project, build them, then go to cmd to run them:
> java KnockKnockServer
> Could not listen on port: 4444.
Also, I have trouble with the EchoClient (not that it means much since the server doesn't work). I get the following:
> java EchoClient
> Couldn't get I/O for the connection to: localhost
The one thing I changed in EchoClient class was to try and connect to "localhost" instead of their example machine "taranis". I don't understand the I/O error at all though.
So I need to figure this stuff out so I can later adapt it. Here's what I'm wondering: how do I know what port listen for in the KK Server? And if I want to connect to another computer in the EchoClient, would I directly put their (IPv4) IP address instead of "localhost"?
Thank you for any help
Try a different (higher port) because 4444 might already be in use on your machine:
Technical description for port 4444:
The port 4444 is specifically assigned to the Kerberos 5 authentication features particularly the implementation of Kerberos 4 in various systems including those running under the Mac OS X platform. The communication port 4444 is used in the conversion of Kerberos 5 credentials into an acceptable Kerberos 4 format.
source
That tutorial breaks rule #2 about handling exceptions: it makes up its own error message ' Couldn't get I/O for the connection to: ...' instead of printing the actual exception. Change it to do that, then you have some hope of finding out what went wrong.
I complained about that tutorial about eight years ago ;-(
(Rule #1 is print something.)
I had this problem yesterday when I was trying to learn the same thing you are!
1) Make sure both the server and client have the same port for example:
kkSocket = new Socket("localhost", 802); //Client
serverSocket = new ServerSocket(802); //Server
(I ran into this problem by accident)
2) Try changing both the server's port and the clients' port to 10000 or higher
3)The program outputs "Knock! Knock!" and than you need to type the input.(The hang you described might just be the server waiting for an input)
try this:
change taranishost name to localhost
kkSocket = new Socket("localhost", 4444);

RTP, Media packets behind firewall and behind Nat makes life hard to fix it, now i am trying to do the UDP hole punching, to get ride of it

I am trying to make a peer 2 peer audio/video application, but behind NAT and behind firewall causing my application failture, i figure out that Skype does it and other application does also other approach, then i decided to use this approach which will allow my application to work behind NAT office/home.
UDP Hole punching:
So far, tried hping2 and netcat. Server, pc1 behind nat/firewall and pc2 behind nat/firewall
local/1$ nc -u 14141 -l # ME, step 1
remoteServer$ echo "hello" | nc -p 53 -u xx.23.xx.xx 14141 # My server, to say hello
nc: Write error: No route to host
local/2$ hping2 -c 1 -2 -s 14141 -p 53 xx.21.xx.xx # Me from second terminal making a hole
remoteServer$ echo "hello" | nc -p 53 -u xx.23.xx.xx 14141 # My server again say hell
local/1 $ nc -u 14141 -l # ME, step 1 was running and it received "hello" now
hello
But local/1 how to get the hello, without hping2 or what is exactly hping2?
Can anyone suggest? Or how i can just do the A (local) B(server) C(my friend) communicate with peer 2 peer using this method?
Useful links:
http://www.masquerade.cz/en/nat-tunel-metodou-udp-hole-punching-v-jazyce-java/
Follow up:
UPnP is best solution? But it looks for the very next hop, so in that case it will fail for this road map (if i am not wrong):
Me (behind NAT) -> MyOffice (with router, 50 laptops) -> ISP1 -> ISP2 -> FriendOffice (router, 90 laptops) -> Friend (behind NAT)
What many p2p applications do is to connect to the nearest router and ask them to open a port to themselves. Read about UPnP and NAT-PMP protocols.

Error when trying to connect to Jacorb naming service

I'm hoping to get some help with this weird problem. We're running the Jacorb name server and I have a simple client that I'm using to try to connect and do awesome CORBA voodoo. The name server is running, but when I try to start my java app, I get a "Connection failure" error (org.omg.CORBA.COMM_FAILURE, minor code 201, "caused by java.net.ConnectionException: Connection refused: connect").
Here's the weird part. The error reports that it's trying to connect using the default port 900, but I'm passing in an argument to try to override the port number of the name service to match the one being used by the name server. My java command is like this:
java -classpath . HelloClient -Djava.endorsed.dirs="bla bla bla" <br>
-Dorg.omg.CORBA.ORBClass=org.jacorb.orb.ORB
-Dorg.omg.CORBA.ORBSingletonClass=org.jacorb.orb.ORBSingleton
-DORBInitRef.NameService=corbaloc::localhost:2809/StandardNS/NameServer-POA/_root
I also tried the parameters without the first capital D (I've seen it both ways and I don't know the difference).
Now, if I put in -ORBInitialPort 2809, then the client does appear to try to connect, but then I get a corba.OBJECT_NOT_EXIST error.
I could use any help or advice anyone has.
Connection Refused. This sounds like a firewall/program not running issue.
try a telnet <machine> 2809. You should get a "Connected to "
and not a refusal, if everything is running/enabled correctly.
I'm running on a UNIX client so the paths use UNIX style.
jacORB installed properly ? e.g. get the nameservice entry from the
orb.properties file (in ${JAVA_HOME}/jre/lib/
I use "ORBInitRef.NameService=corbaloc::localhost:2809/NameServer"
as "NameServer" is used on the production name server and not the other
string of "Standard...."
The other changes in the properties files are setting the paths to UNIX
style (i.e. e:\NS_Ref -> /tmp/NS_Ref)
jacorb.naming.ior_filename=/tmp/NS_Ref
1a. Setting the http:// in the properties file didn't seem to do anything
in regards to resolving on the client side.
1b. NOTE: start ns with:
ns -DOAPort=2809
Log will show:
2010-05-27 10:00:47.777 FINE Created socket listener on 0.0.0.0/0.0.0.0:2809
2010-05-27 10:00:47.777 FINE Using port 2809
Running:
$ lsof | grep 2809
java 27529 jbsymolo 15u IPv6 693300 TCP *:2809 (LISTEN)
$ lsof -Pnl +M -i6
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
Naming_Se 9678 1000 7u IPv6 45779 TCP *:51148 (LISTEN)
java 27959 1000 15u IPv6 696092 TCP *:2809 (LISTEN)
Not Running: (shows nothing)
ns when started will log where it reads the properties from and it shouldn't
throw any errors. If it does your properties files have issues.
VM arguments. The -D is used to set system properties. Any Java code can
then access any property so defined via System.getProperty(). Even though
I've also seen the "non-D" used, I've been using the D.
-DORBInitRef.NameService=corbaloc::localhost:2809/NameService
-Dorg.omg.CORBA.ORBClass=org.jacorb.orb.ORB
-Dorg.omg.CORBA.ORBSingletonClass=org.jacorb.orb.ORBSingleton
When running the client in Eclipse, I see the following in the Console:
May 27, 2010 10:01:06 AM org.jacorb.config.JacORBConfiguration init
INFO: base configuration loaded from file /usr/lib/java/jdk1.6.0_18/jre/lib/orb.properties
...
2010-05-27 10:01:09.836 FINE Trying to connect to 127.0.0.1:2809 with timeout=90000.
2010-05-27 10:01:09.844 INFO Connected to 127.0.0.1:2809 from local port 45745
2010-05-27 10:01:09.846 FINE wrote 12 bytes to 127.0.0.1:2809
...
Skipping lots of other read/write traffic
I can't be sure without seeing the rest of the code, but I'm pretty sure you need to change the InitRef string to be:
-DORBInitRef.NameService=corbaloc::localhost:2809
When your client connects, this should give you the root naming context for the naming service and then you can traverse the NameContext tree to get to your desired server object.

Categories

Resources