How to Java SNMP Programming
Hello all,
I'm new to SNMP and I am trying to create an SNMP agent using JAVA to monitor my applications, I'm looking for tutorials on SNMP java programming and code samples, any suggestions/guiding/advising is welcomed.
Regards,
Hussam Galal
I'm not new to SNMP, and I wouldn't attempt to write an agent in Java. You need access to low level information in the system, which Java is unable to get. A subagent is an easier task, you could look at using the the Agent X subagent protocol. Many agents support this. There is an AgentX implementation written in Java.
Here's a self contained class that logs traps received from a Linksys router. It knows the format of the trap and doesn't use the MIB, it only deals with the bits of BER that it needs. To go further you would need to write a MIB compiler and a BER interpreter.
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
public class LinksysTrap extends Thread
DatagramSocket dgSocket = null;
Thread recvThread = null;
boolean running = false;
String filefmt;
String enterprise;
String fname="";
File outfile=null;
FileWriter outWrite = null;
SimpleDateFormat stf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
SimpleDateFormat sdf;
// the packet
byte [] data = new byte[32768];
int ofs, end; // values for packet
// current token
int tlen, ttype, tofs; // values for current token
// trap fields
int ver;
String comm;
String ent;
String ipa;
int gtt, stt, tt;
String oid;
String val;
LinksysTrap(String e, String p)
enterprise = e;
filefmt = p;
sdf = new SimpleDateFormat(filefmt);
private boolean startup(int port)
try
dgSocket = new DatagramSocket(port);
System.out.println("bound to port="+port);
if(openFile(new Date()))
running = true;
this.start();
else dgSocket.close();
catch(IOException e){e.printStackTrace(); running = false;}
return running;
public void run()
doRecv();
private void doRecv()
DatagramPacket pkt = new DatagramPacket(data,32768);
while(running)
try
dgSocket.receive(pkt);
end = pkt.getLength();
ofs = 0;
// System.out.println("packet received from:"+pkt.getAddress()+" port="+pkt.getPort()
// +" length="+end);
decode();
catch(IOException e){e.printStackTrace(); running = false;}
dgSocket.close();
static public void main(String [] args)
int port = 162;
String ent ="1.3.6.14.1152.21.2.2.1";
String filefmt="'traps'yyyyMM'.csv'";
for(int i = 0; i<args.length; i++)
String arg = args;
if(arg.length() > 2)
char c0 = arg.charAt(0);
if(c0 == '-')
char c1 = arg.charAt(1);
arg = arg.substring(2);
switch(c1)
case 'p': // port
try{port = new Integer(arg).intValue();}
catch(NumberFormatException exc){badCmd();}
break;
case 'e': // enterprise
ent = arg;
break;
case 'f': // file prefix
filefmt = arg;
break;
default:
badCmd();
break;
}else badCmd();
}else badCmd();
LinksysTrap st = new LinksysTrap(ent, filefmt);
if(!st.startup(port))System.exit(0);
private static void badCmd()
System.out.println("LinksysTrap -pport -eenterprise -ffilenameformat");
System.out.println(" default -p162 -e1.3.6.14.1152.21.2.2.1 -f'traps'yyyyMM'.csv'");
System.exit(0);
private void decode()
try
getSeq(0x30); // packet
ver = getInt(0x02); // version
comm = getString(); // community
getSeq(0xa4); // trap pdu
ent = getOID(); // enterprise
if(! ent.equals(enterprise))
System.out.println("trap ignored from enterprise="+ent);
return;
ipa = getIPA(); // ip address
gtt = getInt(0x02); // generic trap type
stt = getInt(0x02); // specific trap type
tt = getInt(0x43); // time up
getSeq(0x30); // varbind list
getSeq(0x30); // varbind
oid = getOID(); // trap oid
val = getString(); // trap value
catch (IllegalArgumentException e)
System.out.println("decoding error ofs="+ofs);
display(data,0,end);
e.printStackTrace();
// System.out.println("trap received from enterprise="+ent);
// System.out.println(" val="+val);
record(val);
private boolean openFile(Date dt)
String fn = sdf.format(dt);
if(!fn.equals(fname))
if(outWrite != null)
try{outWrite.close();} // close output writer
catch(IOException ce){ce.printStackTrace();}
finally {outWrite = null;}
fname = fn;
System.out.println("Opening file="+fname);
outfile = new File(fname);
try
outWrite = new FileWriter(fname,true);
if(0 == outfile.length())
outWrite.write("Timestamp,Direction,Source Address,Source Port,Destination Address,Destination Port\n");
outWrite.flush();
catch (IOException e)
e.printStackTrace();
if(outWrite != null)
try{outWrite.close();}catch(Exception ce){}
outWrite= null;
return outWrite != null;
private void record(String val)
Date dt = new Date();
String ts = stf.format(dt);
if(openFile(dt))
String cs="";
int i = 0;
int j = 0;
int z = val.length();
if(val.charAt(0) == '@')i = 1;
while(i < z)
if(' '==val.charAt(i))i++;
else
j = val.indexOf(' ',i);
if(j == -1)j = z;
cs += ","+val.substring(i,j);
i=j+1;
if(cs.charAt(cs.length()-1) != '\n')cs+='\n';
cs = ts+cs;
System.out.println("cs="+cs);
try
outWrite.write(cs);
outWrite.flush();
catch(IOException we){we.printStackTrace();}
else running = false;
private void getSeq(int type)
{getHeader(type);}
// get an integer, this should deal with sign but doesn't yet ********* TBD
private int getInt(int type)
getHeader(type);
int len = tlen;
int r = 0;
while(0 < len--)r = (256*r)+getUByte();
return r;
private String getString()
getHeader(0x04);
String s = new String(data, tofs, tlen);
ofs+=tlen;
return s;
private String getOID()
String s = "";
getHeader(0x06);
int i = getUByte(); // get first byte
if(i >= 40){s = "1."; i -=40;}
s += (i+".");
int len = tlen-1;
while(0 < len--)
i = getUByte();
s+=i;
if(i>1)s+=".";
return s;
private String getIPA()
String s = "";
getHeader(0x40);
int i;
int len = tlen;
while(0 < len--)
i = getUByte();
s+=i;
if(i>1)s+=".";
return s;
// get token header
private void getHeader(int type)
int i,n;
ttype = getUByte(); // token type
if(type != 0 && type != ttype)
System.out.println("ofs="+ofs+" ttype="+ttype);
throw new IllegalArgumentException("invalid type");
n = getUByte();
if(n >= 128)
i = n-128;
n = 0;
while(0 < i--)n=(n*256)+getUByte();
tofs = ofs;
tlen = n;
// System.out.println("tofs="+tofs+ " tlen="+tlen+" ttype="+ttype);
// get an unsigned byte from data
private int getUByte()
if(ofs >= end)throw new IllegalArgumentException("data too short");
int b = data[ofs++];
if(b < 0)b+=256;
return b;
private static final String HexValue[]={"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"};
public static void display(byte[]ba, int ofs, int len)
int dlen;
String dstr;
while(len>0)
if(len < 16)
dlen = len;
char[] c48 = new char[48];
java.util.Arrays.fill(c48, ' ');
String fill48 = String.valueOf(c48);
dstr = fill48.substring(0,3*(16-dlen));
else
dlen = 16;
dstr = "";
dstr = tohex4(ofs)+": "+atohex(ba,ofs,dlen)+dstr+": "+atochar(ba,ofs,dlen);
System.out.println(dstr);
ofs+=dlen;
len-=dlen;
public static String atochar(byte[]ba, int ofs, int len)
String s="";
char ch;
byte b;
for(int i=ofs;i<(ofs+len);i++)
b = ba[i];
if(b < 32 || b >126)ch = '.';
else ch = (char)b;
s+=ch;
return s;
public static String atohex(byte[]ba, int ofs, int len)
String s="";
for(int i=ofs;i<(ofs+len);i++)
s += (tohex2(ba[i])+" ");
return s;
public static String tohex2(int b)
int i = b;
if(i<0)i+=256;
return HexValue[i/16]+HexValue[i%16];
public static String tohex4(int i)
if(i<0)i+=32768;
i = i%32768;
return tohex2(i/256)+tohex2(i%256);
Similar Messages
-
How can i get the source code from java concurrent program in R12
Hi 2 all,
How can i get the source code from java concurrent program in R12? like , "AP Turnover Report" is java concurrent program, i need to get its source code to know its logic. how can i get its source code not the XML template?
Regards,
Zulqarnainuser570667 wrote:
Hi 2 all,
How can i get the source code from java concurrent program in R12? like , "AP Turnover Report" is java concurrent program, i need to get its source code to know its logic. how can i get its source code not the XML template?
Regards,
ZulqarnainDid you see old threads for similar topic/discussion? -- https://forums.oracle.com/forums/search.jspa?threadID=&q=Java+AND+Concurrent+AND+Source+AND+Code&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
Thanks,
Hussein -
How to call a BPEL process from Oracle Apps Java Concurrent program
Hello,
I need to trigger a BPEL process from Oracle Apps. Can anybody tell me how to do that? I have two triggering option--
1. On button click from a Form 6i screen
2. Using Java Concurrent program.
Thanks in advance.
DebkantaI am not sure how concurrent program works, but may be one of the way might work out, let me know if Java Concurrent Program works a bit different way
- [if async] Through concurrent program, you can insert message token to db or aq, and BPEL can be instantiated from there
or
- If it supports pure java call, then you can look at multiple documents (e.g. http://www.oracle.com/technology/products/ias/bpel/pdf/orabpel-Tutorial7-InvokingBPELProcesses.pdf) to invoke your process
- You can also use oracle db utility to invoke soap operation and get the result back
HTH,
Chintan -
How to call a java script program in a vi?
Hi,
I have to call a script in java script with arguments. This script
contains 4 functions, and need an array to works. This array is
produced by my vi. It returns a float.
How can I call this script with parameters in my vi?
Thanks.
BD.
~ La programmeuse compile le C. ~
http://www.pmeonline.fr.st
http://www.nihon-fr.com
http://www.cinemasie.com
http://ippai.free.frNo, my java script program is composed of several functions. I just want to call the functions in my vi, with arguments, etc.
I don't know if it is easy to use
~ La programmeuse compile le C. ~
http://www.pmeonline.fr.st
http://www.nihon-fr.com
http://www.cinemasie.com
http://ippai.free.fr -
How to integrate a class with template.java - Java Concurrent Program. 11i
Hello, I have a java class I got from a vendor. This java class needs to run through as concurrent program. As per metalink note *How To Create a Java Concurrent Program? [ID 827563.1]* it says that, we must require template.java to wrap around the custom class. I have done that in the following java code. However, being a new java guy, I really dont know how to connect these two classes and constructor.
Any suggestions about how do I make these classes work in order to run from a concurrent program?
package oracle.apps.fnd.cp.request;
import oracle.apps.fnd.util.*;
import oracle.apps.fnd.cp.request.*;
import java.io.BufferedReader;
import java.io.IOException;
import javax.net.ssl.SSLSocketFactory;
public class cyberBatch implements JavaConcurrentProgram {
// Optionally provide class constructor without any arguments.
// If you provide any arguments to the class constructor then while running the program will fail.
public void runProgram(CpContext pCpContext) {
ReqCompletion lRC = pCpContext.getReqCompletion();
String CompletionText = "";
// This class is to upload files but can be expanded to download files also.
public class SSLFileTransfer {
Properties props =
new Properties(); // stores properties from property file
* SSLFileTransfer(): constructor
public SSLFileTransfer() {
* init(): initialization (load property file)
* @param propsFile properties needed for file transfer
public void init(String propsFile) {
try {
props.load(new BufferedInputStream(new FileInputStream(new File(propsFile))));
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
* usage()
public static void usage() {
System.out.println("USAGE: java SSLFileTransfer <full path property file name>");
System.exit(-1);
* getFactory(): get factory for authentication
* @throws IOException if exception occurs
private SSLSocketFactory getFactory() throws IOException {
try {
SSLContext ctx;
KeyManagerFactory kmf;
KeyStore ks, ks1;
char[] passphrase =
props.getProperty("passPhrase").toCharArray();
ctx = SSLContext.getInstance("TLS");
kmf = KeyManagerFactory.getInstance("SunX509");
ks = KeyStore.getInstance("PKCS12", "BC");
ks1 = KeyStore.getInstance("JKS");
ks.load(new FileInputStream(props.getProperty("key")),
passphrase);
ks1.load(new FileInputStream(props.getProperty("keyStore")),
passphrase);
kmf.init(ks, passphrase);
TrustManagerFactory tmf =
TrustManagerFactory.getInstance("SunX509");
tmf.init(ks1);
ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
return ctx.getSocketFactory();
} catch (Exception e) {
e.printStackTrace();
throw new IOException(e.getMessage());
* getHost(): Get host from property file
private String getHost() {
return props.getProperty("host", "localhost");
* getPort(): Get port from property file
private int getPort() {
return Integer.parseInt(props.getProperty("port"));
* sendRequest(): Send request (file) to the server
* @param out stream to send the data to the server
* @throws Exception if an error occurs.
private void sendRequest(PrintWriter out) throws Exception {
String path = props.getProperty("path");
out.println("POST " + path + " HTTP/1.0");
final String BOUNDARY = "7d03135102b8";
out.println("Content-Type: multipart/form-data; boundary=" +
BOUNDARY);
String uploadFile = props.getProperty("uploadFile");
String authString =
props.getProperty("bcUserName") + ":" + props.getProperty("bcPassword");
String encodedAuthString =
"Basic " + new sun.misc.BASE64Encoder().encode(authString.getBytes());
out.println("Authorization: " + encodedAuthString);
final String CRLF = "\r\n";
StringBuffer sbuf = new StringBuffer();
sbuf.append("--" + BOUNDARY + CRLF);
sbuf.append("Content-Disposition: form-data; name=\"upfile\"; filename=\"" +
uploadFile + "\"" + CRLF);
sbuf.append("Content-Type: text/plain" + CRLF + CRLF);
FileReader fi = new FileReader(uploadFile);
char[] buf = new char[1024000];
int cnt = fi.read(buf);
sbuf.append(buf, 0, cnt);
sbuf.append(CRLF);
sbuf.append("--" + BOUNDARY + "--" + CRLF);
int sz = sbuf.length();
out.println("Content-Length: " + sz);
out.println();
out.println(sbuf);
out.flush();
// Make sure there were no surprises
if (out.checkError())
System.out.println("SSLFileTransfer: java.io.PrintWriter error");
* readResponse(): reads response from the server
* @param in stream to get the data from the server
* @throws Exception if an error occurs.
private void readResponse(BufferedReader in) throws Exception {
boolean successful = false;
String inputLine;
while ((inputLine = in.readLine()) != null) {
if (inputLine.startsWith("HTTP") &&
inputLine.indexOf("200") >= 0)
successful = true;
System.out.println(inputLine);
System.out.println("UPLOAD FILE " +
(successful ? "SUCCESSFUL" : "FAILED") +
"!!!\n");
* upload(): upload file to server
* @throws Exception if an error occurs.
public void upload() throws Exception {
try {
SSLSocketFactory factory = getFactory();
SSLSocket socket =
(SSLSocket)factory.createSocket(getHost(), getPort());
PrintWriter out =
new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())));
BufferedReader in =
new BufferedReader(new InputStreamReader(socket.getInputStream()));
socket.startHandshake();
sendRequest(out);
readResponse(in);
out.close();
in.close();
socket.close();
} catch (Exception e) {
e.printStackTrace();
throw e;
* main(): main method to start file transfer
* @param args command line arguments (property file, see usage())
* @throws Exception if an error occurs.
public static void main(String[] args) throws Exception {
if (args == null || args.length != 1)
usage();
SSLFileTransfer fileXfer = new SSLFileTransfer();
fileXfer.init(args[0]);
fileXfer.upload();
lRC.setCompletion(ReqCompletion.NORMAL,CompletionText) ;
}Thanks,
RI believe the OP is aware of this :) -- Re: Oracle 11i - 11.5.10.2 - and Java
Thanks,
Hussein -
How to Compile & Deploy the Java Concurrent Program File
Hi,
There is a requirement to create the Java Concurrent Program in Oracle eBusiness. I am able to create the Java Concurrent Program file. But unable to do the following things:
1.Since it is custom file, which location I will deploy the file?
2. How to compile the file?
3. In the execution file path and executable file name what should I specify for JCP?
Please guide me.
ThanksPlease see (How to register and execute Java Concurrent Program ?in Oracle Applications R11i ? [ID 186301.1]) for the complete steps (i.e. define concurrent program and add it to the request group, .etc.) -- This is also applicable to R12.
You may also see:
Classpath Setting of Third Party Jar Files in R12 Java Concurrent Program (JCP) [ID 1292694.1]
Integrating Custom Applications with Oracle Applications [ID 176852.1]
Java Concurrent Program FAQ [ID 827575.1]
https://forums.oracle.com/forums/search.jspa?threadID=&q=Java+AND+Concurrent+AND+Program&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
Thanks,
Hussein -
How to customize the Java Concurrent Program(PO Output for Communication)
Hi,
How to customize the Java Concurrent Program(PO Output for Communication)
I need to add the Line level Ship To Address ,Line Notes and Extended Price fields on Java Concurrent Program.
Please any body help/guide me in this regard.Hi,
Changing Java Conc. program for "PO Output for Communication" is difficult.
Actually, if you observe closely, "PO Output for Communication" program uses PO<HEADER/LINES..>_XML views.
So if you could change these views and add your requireed columns to it, you can automatically see your changes in XML data file.
See if the following link will you to get there.. http://chandramatta.blogspot.com/
thanks,
Matt -
How to get Source code of a Schedular Java concurrent program in Payments
Hi Experts,
I am very new to Java Concurrent program.
I need java source code of a schedule java concurrent program.Following are the details of Executable.
Executable :Format Payment Instructions
Short Name :IBY_FD_PAYMENT_FORMAT
Application : Payments
Execution Method :Java Concurrent Program
Execution File Name:FDExtractAndFormatting
Execution File Path : oracle.apps.iby.scheduler
I searched in execution file path,but i am unable to find required java source.
Please someone help regarding this issue..
It's Urgent Issue.
Regards
AmarHi Srini,
Thanks for reply...
In the attached template of concurrent program "Format Payment Instructions", i need to add voucher number in the template.
How can i do this?how to decompile the executable?
It is a check printing.
Please give me suggestions..
Regards
Amar -
How to get the source code of Java Concurrent Program?
Hi,
How to get the source code of Java Concurrent Program?
Example
Programe Name:Format Payment Instructions
Executable:Format Payment Instructions
Execution File Name:FDExtractAndFormatting
Execution File Path:oracle.apps.iby.scheduler
Thanks in advance,
SenthilGo on Unix box at $JAVA_TOP/oracle/apps/iby/scheduler
You will get class file FDExtractAndFormatting.
Decompile it to get source code.
Thanks, Avaneesh -
How to Invoke Extensions in Java Concurrent Programs - Urgent
hi all,
can any one help me in understanding how to invoke Extensions (attached to Rules) in Java Concurrent Programs (part of autoconfig)
it is migration task from FC to Extensions
Please suggest
thanks,
Srikanthif you want to invoke the rule, that triggers the Extension, create a rule which invoke the rule, like "ALWAYS TRUE" REQ Extension. Then as soon as the Model in instaniated, the Extension will be executed.
-
How to copy the java concurren program in oracle application
Hi All
I am working in oracle Apps R12.
In AP (Account Analysis Report) is registered as java concurrent Program.
Now i need to customize this concurrent program and add two new column and two parameter in that.
Could any one pls provide me the steps that how to copy the Java concurrent,and make a new customized program.
Whether copying a java concurrent program is same as cp registered as oracle report.
Thanks & Regards
SrikkanthHi Sir,
Thanks for your reply.
I have find the xml file form data definition and in that they have written Sql query and they have called a Package.
And the i have also taken the class file from the path as mentioned.
Now i need to customize this report by adding two parameter and i need to add two new column to display in the rtf.
Can you pls tell me the steps to copy or how to customize this report.
Regards
Srikkanth -
How can java programs execute automatically when it connects to network
Good Day dears...
How can java programs execute automatically when it connects to network.
Thanks in Advance friends Shackir884924 wrote:
Good Day dears...
How can java programs execute automatically when it connects to network.What is "it"? That is, execute when what connects to the network?
Your computer? If that's what you mean, this is not a Java question. It's an OS operational/administrative question. Executing any program, whether written in Java or not, based on some system event has to do with that system, not with the program. If it's possible to do this, you'd do it exactly the same way for a Java program as you would for any other program.
Or is "it" the program itself? If this is what you mean, then it's a nonsensical question. For the program to connect to the network and detect that it has connected to the network, it must already be executing, so asking how to execute it at that point is meaningless.
Finally, I'll point out that "connecting to the network" is a pretty meaningless phrase. Or rather, it has so many potentially valid meanings that it's impossible to know which one you're referring to when you use that phrase. And I'd be willing to bet you don't have a clear picture of that yourself. -
HOW TO WRITE ABAP PROGRAMMING IN JAVA BY USING NETWEAVER
HI,
i am working with bapi(mean is calling bapis in my java programs).
please tell me the how to write abap programs in nwds
Thanqqqqqqqqq
GuruHi,
Refer the following links..
http://manuals.sybase.com/onlinebooks/group-iaw/iag0203e/iadgen2/@Generic__BookTextView/24685
and this blog
/people/kathirvel.balakrishnan2/blog/2005/07/26/remote-enable-your-rfchosttoip-to-return-host-ip-to-jco
Regards,
Uma -
How to run native program with Java program?
Hello
I've got following problem. I'd like to write file browser which would work for Linux and
Windows. Most of this program would be independent of the system but running programs not. How to run Linux program from Java program (or applet) and how to do it in Windows?.
CheersTry this:
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("ls -l");
InputStream stream = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(stream);
BufferedReader br = new BufferedReader(isr);
String line = null;
while ( (line = br.readLine()) != null) .....
"if the program you launch produces output or expects input, ensure that you process the input and output streams" (http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html) -
How to do set apps context in java concurrent program
Hi,
Can any body help me in setting apps context in Java Concurrent program. I tried using AppsContext class and methods but did not work.
Thanks for help in advance
PavanGo on Unix box at $JAVA_TOP/oracle/apps/iby/scheduler
You will get class file FDExtractAndFormatting.
Decompile it to get source code.
Thanks, Avaneesh
Maybe you are looking for
-
I developed code modules from CVI 7.0, and test sequence from TestStand 3.0. Now I want to deploy all to a test system. Should I create distribution kits for CVI and TestStand, and install to a target PC? Do each kit include the RTE? How do the runti
-
I am unable to use my ITunes gift card while playing Fairway Solitaire. I need help.
-
CRM/BW - Are there any CRM/BW related "How To Do ..." Guides
Hello, I searched BW InfoIndex and have not found any thing useful? Can somebody help me? Thanks JM
-
5800 XpressMusic Mass Storage issue
I've been quite happily using my 5800 XpressMusic as an mp3 player by attaching it to my PC with the USB cable, copying over the songs/book, and then deleting them when done. Suddenly, I'm no longer able to do this, and the contents of one of the fo
-
I'm trying to install i-tunes software included in my new i-pod. It doesn't work at all. The message is "String PRODUCT_NAME was not found in string table", and then, "Error Number: 0x80040706 - Description: Object reference not set......... set up w