Location of logs for java.util.logger - java

I am on windows, and using squirrel client to access a database on informix.
On my jsp pages there are code that open the databse informix for query.
Other than out printing the error message on the webpage where the code is eg: the code is in file DB123.jsp, then the error message can be printed out at //100.100.100.100/DB123.jsp on browser.
My question is if I have a java.sql.SQLException, where else can I look at more detailed error message, or what configuration should I make to have it enabled? Because sometimes sql error unable to be printed on the webpage.
The code at DB123.jsp with the log:
public Logger myLog = Logger.getLogger("DB123.jsp");
{...}
catch(SQLException sqle){
strMsg = "failed";
strMsgDesc = ERR_SERVICE_NOT_AVAILABLE+sqle;  //this one out print on webpage
myLog.error(sqle.getMessage());  //This line i dont know where it logs to
}...
array.put("msgdesc", strMsgDesc);
out.print(array);
/***end****/
If there is a syntax error on sql statement, the flow of the program should stopped at sql.executeQuery(); right? So the logging of error should be on the dev environment server, there wont be any thing to be debug at informix server right? So IBM interactive debugger would not help here.
Whenever I google 'location of logs of java.util.logging' or a similar phrase, I could not get any good explanation. Many searches returns codes of how to setup the logger, but not where the logs are.
Any help is much appreciated.

Related

How can I capture query sent from Java (tomcat) to an Oracle DB?

I have an application written by a 3rd party which uses Java/Tomcat talking to an Oracle 12c (12.2.0.1) DB. In its logs it reports "Error inserting into table" but provides no details. In talking with the author's support staff they indicate it is old code and they have no way to give more detail. They say the application is better supported with MSSQL which we do not support in our shop.
I would like to see what the insert statement going to the Oracle DB looks like, but haven't been able to find it in v$sqltext. As an alternative, I was hoping to find a tool like fiddler to view the outbound traffic on port 1521.
Is there specific tool that would allow trapping this traffic which is not encrypted so I can see the "query" sent and the response coming back from the Oracle DB?
A general sniffer may work, but they generally get a lot of extraneous traffic and require a fair amount of mucking about to find what you want.
Note:
As I mentioned in the comments I am not a Tomcat/Java person. I think I found where the classpath is set. Given the windows batch file below, is the "driver" that needs to be replaced bcprov-jdk16-138.jar?
set PROJLIB=..\..
set JAVA_HOME=%PROJLIB%\jdk\
set libDIR=%PROJLIB%\appserver\webapps\receiver\WEB-INF\lib
set consoleDIR=%PROJLIB%\bin\lib
set endorsedLibDir=%PROJLIB%\appserver\endorsed
set CPATH= %consoleDIR%\console.jar;%libDIR%\ebxml.jar;%libDIR%\commons-io-1.1.jar;%libDIR%\bcprov-jdk16-138.jar;%libDIR%\xercesImpl.jar
set CLASSPATH=%CPATH%
set PATH=%JAVA_HOME%\bin;%SystemRoot%;%SystemRoot%\system32
Additional Notes:
The above file is called setenv.bat.
Regarding trying to capture the SQL from the database, the application is not a windows app, it is an app which accepts data from the network and writes it to the DB. This makes knowing precisely when to start and stop monitoring difficult. It seems to be connected for a very short period. It does seem to be able to read data, but not insert.
Assuming that you are using the Oracle JDBC driver and that you have the ability to replace the JDBC driver in some environment in order to debug the problem, Oracle provides versions of the JDBC driver that can be configured to log the SQL statements that are executed.
An alternative would be to create a servererror trigger in the database that logs the SQL statements that fail. I believe that would require that the SQL statement that is failing is well-formed which isn't guaranteed if the third party app is encountering an error dynamically assembling the statement. If the statement never lands in v$sql that may indicate that it isn't well-formed but it's worth a try.
If you're licensed to use the AWR/ ASH tables, you could also try querying dba_hist_active_sess_history. Oracle samples the active sessions every second. If the failing statement happens to be caught in the sampling, you'd see it there. If this is a typical OLTP application doing single-row inserts, you may need to run through a lot of samples in order to catch an active session with that statement but that may be reasonable.
The simples approach is, if you can localize your database session (using gv$session selecting your connection USERNAME).
Get the SID and SERIAL# of the connection and activate the 10046 trace using the following statement. (substutite SID for session_id and SERIAL# for serial_num)
EXEC DBMS_MONITOR.session_trace_enable(session_id =>271, serial_num=>46473, binds=>TRUE);
Note that you need permissions for both querying gv$session and executing DBMS_MONITOR so DBA access is required to grant them to your user.
Than check the trace file on the database server in folder trace, the trace file has a name such as xe_m005_1336.trc
Grep for the table name, you schould see someting like this I simulated for failed insert on the table my_table
=====================
PARSING IN CURSOR #854854488 len=38 dep=0 uid=104 oct=2 lid=104 tim=380974114197 hv=1259660490 ad='7ff08904d88' sqlid='1ttgvst5j9t6a'
insert into my_table(col1) values(:1 )
END OF STMT
PARSE #854854488:c=0,e=495,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=1,plh=0,tim=380974114195
=====================
PARSE ERROR #854854488:len=39 dep=0 uid=104 oct=2 lid=104 tim=380974117361 err=904
insert into my_table(col1) values(:1 )
Note that this is example of an exception
java.sql.SQLSyntaxErrorException: ORA-00904: "COL1": invalid identifier
so the statement fails with an PARSE ERROR
If the insert fails due to some constraint vialotation, you will see such sequence
=====================
PARSING IN CURSOR #715594288 len=37 dep=0 uid=104 oct=2 lid=104 tim=382407621534 hv=3290870806 ad='7ff0032e238' sqlid='17t3q0v22dd0q'
insert into my_table(col) values(:1 )
END OF STMT
PARSE #715594288:c=0,e=245,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=1,plh=0,tim=382407621532
=====================
The cursor id is #715594288so check with this id further in the trace file
BINDS #715594288:
Bind#0
oacdty=02 mxl=22(22) mxlc=00 mal=00 scl=00 pre=00
oacflg=03 fl2=1000000 frm=01 csi=873 siz=24 off=0
kxsbbbfp=2aa71a00 bln=22 avl=02 flg=05
value=7
=====================
Here you see the bind variables passed in the insert, it was the value = 7 that caused the failure.
EXEC #715594288:c=0,e=4614,p=0,cr=7,cu=0,mis=1,r=0,dep=0,og=1,plh=0,tim=382407626259
ERROR #715594288:err=2290 tim=382407626283
The statement failed in the execution with exception such as
java.sql.SQLIntegrityConstraintViolationException: ORA-02290: check constraint (XXXX.SYS_C0012357) violated
Check the documentation for further details
If you have db access via sqldeveloper....
Go to reports tab, then drill down through data dictionary, database administration, sessions, and finally sessions.
In that view, look for your app's active module(s) and look at the Active SQL tab.
One of them should have your insert statement....
This might help as well...
https://docs.oracle.com/cd/E17781_01/server.112/e18804/monitoring.htm#ADMQS252
The ultimate approach is to trace the JDBC connection on the client. Please find the full documentation here
In the first step you must get the logging JDBC driver on the CLASSPATH. The logging driver has a suggix _g in the name, e.g. ojdbc8_g.jar if you use ojdbc8.jar
The driver can be found in the Oracle installation in the folder jdbc/lib/
Further you must define a properties file say jdbcLogging.properties with following content
.level=SEVERE
oracle.jdbc.level=ALL
oracle.jdbc.handlers=java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level=FINE
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
Finally when you run the Java application you must define two properties
java -Doracle.jdbc.Trace=true -Djava.util.logging.config.file=jdbcLogging.properties ...
This will produce a trace file om the error output where you can find the executed statements.
Example
INFO: DRCP Enabled: false
Mar 23, 2021 10:40:31 PM oracle.jdbc.driver.OracleStatement logSQL
CONFIG: BAB2F1 SQL: insert into my_table(col1) values(?)
What I ended up doing was downloading WireShark, a sniffer, and monitored the TCP/IP packets.

Rserve connection fails

I am using WPS4R provided by 52north
Up to 3 days ago everything was fine and WPS could connect to R by use of Rserve properly but now this connection can not be made. I uninstalled everything, including Apache Tomcat,R and Java JDK, and then installed everything again. the problem still exists. This is the error that I get when I send the request. I am sure the code I used is correct, because it used to work and I did not chang any thing .
This is the error:
An R Connection Error occoured:
class org.rosuda.REngine.Rserve.RserveException - eval failed,
request status: error code: 127 null
The 127 is a parse error that is coming from R, this is not a workspace issue. If you want to get the error message back. Wrap the call to execute your script/r command with the following to get the error message. I have used this in the past and it works well. See the FAQ for more information.
http://www.rforge.net/Rserve/faq.html
c.assign(".tmp.", myCode);
REXP r = c.parseAndEval("try(eval(parse(text=.tmp.)),silent=TRUE)");
if (r.inherits("try-error")) System.err.println("Error: "+r.toString())
else { // success .. }

How to handle client side exceptions in GWT/GXT?

I am using GWT. if any server side exception is generated, we are sending an email with error details(have used log4j SMTPAppender). Based on the line number, we can fix the issue..
My scenario is, if any exception is generated in the client package code, as of now, we are giving generic message saying "Some Exception has Occured". But is it possible to display error stack trace along with the exception cause and line number? my code is as below:
GWT.setUncaughtExceptionHandler(new
GWT.UncaughtExceptionHandler() {
public void onUncaughtException(Throwable e) {
Window.alert("Some Exception has Occured");
}
});
I dont think it is possible as client package is converted into Javascript in web mode. Please suggest me if there is any approach to display exception cause and line number where it has occured.
You can read this page
Basically, you have to use JUL to do your logging, and it's client logging : firebug, JS console, etc... You may do some smarter things with the RemoteLogging but i can't help you on that.
The main problem is that log4j is not supported. Maybe with a bridge between JUL and log4j you will be able to achieve everything you want
I would recommend using gwt-log:
Project Page
gwt-log has support for an 'UncaughtExceptionHandler' and a RemoteLogger to send messages/exception to the server.
in gwt-log, you can also turn on the "emulated stack", which is exactly what you want to do:
Wiki Page - Emulated Stack
please note however that this adds a LOT of code to the compiled JS-script

show message in log file with php

I need to know how to show a message in the log in apache with php, I know that java has this instruction
System.out.println
and in tcl
ns_log notice
but there are some equivalent in php?
Thanks!!!
Use the syslog function:
http://php.net/manual/en/function.syslog.php
You can use error_log to output directly to the error log.
Use error_log() function to set custom error messages
error_log("Oracle database not available!", 0);
Or you can save the errors to custom log file as
error_log("Oops, something went wrong!", 3, "/var/tmp/my-errors.log");
You have to set the level of logging on your PHP.ini, to debug or warming. Then use error_log or syslog to print to php_error.log or what ever u configure ur logging file is.

Flex+JPA/Hibernate+BlazeDS+MySQL how to debug this monster?

Ok so I'm making a "simple" web app using the technologies from the topic, recently I found http://www.adobe.com/devnet/flex/articles/flex_hibernate.html so I'm following it and I try to apply it to my app, the only difference being I'm working on a Mac and I'm using MAMP for the database (so no command line for me).
The thing is I'm having some trouble with retrieving/connecting to the database.
I have the remoting-config.xml, persistance.xml, a News.java class (my Entity), a NewsService.java class, a News.as class - all just like in the tutorial. I have of course this line in one of my .mxmls:
<mx:RemoteObject id="loaderService" destination="newsService" result="handleLoadResult(event)" fault="handleFault(event)" showBusyCursor="true" />
And my remoting-config.xml looks like this (well part of it):
<destination id="newsService">
<properties><source>com.gamelist.news.NewsService</source></properties>
</destination>
NewsService has a method:
public List<News> getLatestNews() {
EntityManagerFactory emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT);
EntityManager em = emf.createEntityManager();
Query findLatestQuery = em.createNamedQuery("news.findLatest");
List<News> news = findLatestQuery.getResultList();
return news;
}
And the named query is in the News class:
#Entity
#Table(name="GLT_NEWS")
#NamedQueries({
#NamedQuery(name="news.findLatest", query="from GLT_NEWS order by new_date_added limit 5 ")
})
The handledLoadResult looks like this:
private function handleLoadResult(ev:ResultEvent):void {
newsList = ev.result as ArrayCollection;
newsRecords = newsList.length;
}
Where:
[Bindable]
private var newsList:ArrayCollection = new ArrayCollection();
But when I try to trigger:
loaderService.getLatestNews();
nothing happens, newsList is empty.
Few things I need to point out:
1) as I said I didn't install mysql manually, but I'm using MAMP (yes, the server's running), could this cause some trouble?
2) I already have a "gladm" database and I have a "GLT_NEWS" table with all the fields, is this bad?
Basically the question is how am I suppose to debug this thing so I can find the mistake I'm making? I know that loadData() is executed (did a trace()), but I have no idea what happens with loaderService.getLatestNews()...
#EDIT: ok so I see I'm getting an error in the "fault handler" which says
"Error: Client.Error.MessageSend - Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Status 404: url: 'http://localhost:8080/WebContent/messagebroker/amf' - "
#EDIT2: Ok i solved the problem, as it turns out my ContextRoot was incorrect, the funny thing is I couldn't edit it by going to Project properties->Flex Server as it was uneditable! I had to find the .flexProject file and edit it (obviously my Flex Navigator didn't show it and by accident I noticed it was being filtered).
To answer your question as to, in general, debug this monster...here is what I do.
Set break points in my Java code
Start up the Java application server with the appropriate debug JVM properties set (e.g. -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n)
From Eclipse, I attach a remote debugger to the app server on the default port 8000. The Java Debugger will open up when a break point is hit.
Set breakpoints in my Flex application (or one of its modules).
From Eclipse (with Flash Builder) I launch a debug configuration for my Flex app. The Flex Debugger will open up when a break point is hit.
At this point I have two debuggers open and everything work great. Two other things I do:
a) extend the transaction system timeout, so it doesn't get trigger while I am sitting there think for a few minutes
b) use Charles Proxy (in reverse proxy mode) inbetween the client and server to watch the AMF traffic and view payloads, etc.
Hope this helps.
your error means you are not calling the server on the right way. Something is wrong there, the url the web.config file or other BlazeDS config files.

Categories