P. Ingle

Ranch Hand
+ Follow
since Apr 25, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by P. Ingle

Originally posted by Bear Bibeault:
I assume this servlet is being referenced by an <img> tag on the page?



Yes - as
18 years ago
Hi,

I have following method in a servlet. It calls ImgTable.getImage() method which gets Blob data from database, converts it into bytes (using getBytes) and return byte array.
Once I have the byte array in servlet, I just want to display the image.
It is not displaying anything - just shows empty image box with big red X on top left corner.

Please take a look and let me know if I am missing anything.

-------------------------------------------------------------------
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

System.out.println("in doGet method");
try {
ImgTable img = new ImgTable();
// get image data in form of byte array
byte[] buff = img.getImage();
// buff now image data in forma of byte array
if (buff == null) {
System.out.println("failed");
} else {
System.out.println("got byte array of size: " + buff.length);
//display it on browser
response.setContentType("image/jpeg");
ServletOutputStream ostr = response.getOutputStream();
response.setContentLength(buff.length);
ostr.write(buff);
ostr.flush();
ostr.close();
}
} catch (Exception x) {
x.printStackTrace();
}
} // end doGet
18 years ago

Originally posted by Scott Johnson:
.......
Every application has different requirements so serialization could be acceptable for your situation.

What kind of data are you trying to store? For how long will it be stored? Will it need to be updated or queried? What advantages do you see by using serialization vs storing fields into a table schema?

Regards,
Scott



The data I want to store represents configuration of a web tool - instead of storing this data into properties file, I am thinking of putting it in database - to make it better managed. There are going to be few default configs which user should be able to pull out, use and may be upgrade. It will be used as a whole - will never be queried on a single item within the pojo. Table will have id, owner (meaning which user can use it), date_modified and the blob field to hold serialized pojo. It will be stored for a long time - if not for ever.

Serialization will make it less schema dependent - having said that, it will make it pojo design dependent according to your comments. Each time the pojo changes, there will have to be a some kind of seperate process to translate this old data into new object and store it back.

Still the issue of JVM remains - which bothers me the most.

Thanks for you comments.
18 years ago
Why is this so frowned upon? Can you point me to any articles that lay out pros and cons of this approach?

Thanks,
P.Ingle
18 years ago
Hi,

How do I (rather can I) write a pojo in database as object and retrive it back with all the data intact?

pojo is used for holding user specific info which will be used to cofigure the web app according to the set of selections made initially. It has to be updatable.

Can I just write it to database table (DB2 to be specific - may be as blob) and when I retrive it, I cast it to the original pojo type. I am not planning on creating table to map all the attributes of the pojo.

How will this fly in J2EE environment?

Thanks,
P.Ingle
18 years ago

Originally posted by sridhar:
You may need to bounce the app in 2nd instance after changing the Log4j.properties (if this is EAR scope) else you may need to bounce the server 2nd instance. This usually happens if you change the properties after installation and startup of app.



What do you mean by 'bounce' application or server.
You are right on the money about changing log4j.properties after installation. That's what I was doing: both ears have same log4j.properties - hence after I install 2nd ear, I go in, change log4j.properties for that ear and restart the server2 - meaning I Do restart server 2 (I guess that's what you mean by bounce).

I think next thing to try will be:
1. install ear on server2
2. stop server 2
3. go and change log4j.properties
4. restart server 2, hence the application and see where the logs fall

Thanks,
P.Ingle
18 years ago
Hi,

We have one j2ee application with only one ear. We have the log4j.jar
at ear level under lib directory and then we set up LD_LIBRARY_PATH
(through WebSphere - which is done at server scope) to point to that folder
so that our utility jar and war can pick log4j.jar and log4j.properties
from ear/lib. We are running this application on websphere running on
Linux box.

With this configuration, it was running fine, creating our custom log
files at specified location in log4j.properties.

Now, I have created 2 instances of server on the same machine - one for
development, one for testing. I installed the same ear on the newly
created server instance, changed log4j.properties to write log files in
different directory tree. So now, I have 2 instances of websphere servers
running on same machine, running basically same application (with it's
own copy of everything off course).

But, I see that the logs that should be have been created by this 2nd
application are still being written in the log file that was initially
created by 1st instance. The 2nd application never created it's own log
files under the new directory specified in it's own log4j.properties.

As I understand, 2 different instances of server have 2 seperate jvms,
also they have their own copy of log4j. Hence, even if log4j is
singleton, that shouldn't matter and it should have been totally unaware
about the 1st application and hence 1st log4j. Thus the 2nd application
should have created it's own log files and written logs there.

Can anyone shed any light on what I may be missing?

Thanks,
P. Ingle
18 years ago
Hi,

We have a web app installed on WAS 5.0.2 (Base) running on Linux box. We are just using default host
The URL that we have to give is:

<a href="http://<hostname rel="nofollow">:9080/ourAppName" target="_blank">http://<hostname>:9080/ourAppName and

<a href="https://<hostname rel="nofollow">:9443/ourAppName" target="_blank">https://<hostname>:9443/ourAppName after enabling SSL

If I try <a href="http://<hostname rel="nofollow">/ourAppName," target="_blank">http://<hostname>/ourAppName, I get "page not found"

How can I remove the requirement to enter port number after hostname? What configuration do I need to do?

Thanks,
P.Ingle
18 years ago
I have a class that loads native library in static block. All other methods in the class are NOT static methods - so I need to instantiate the class to call methods on it.

------------------------------------------
class MyClass {

static {
System.loadLibrary("MyLibrary");
}

public native string method1();
}

calling program method:
-------------------------------------------
{
.....
MyClass myClass = new MyClass();
String str = myClass.method1();
myClass = null; //allow it to be garbage collected
......
}

calling program method2:

{
.....
MyClass myClass = new MyClass();
String str = myClass.method1();
myClass = null; //allow it to be garbage collected
......
}

-----------------------------------------------------

Please someone tell me if my understanding is wrong:

The native library will be loaded when the class will be instantiated for the first very time. Even if I set the instance to null and if the object really gets garbage collected, because the native library is loaded from a static block, it still remains loaded and next time I instantiate the class (in calling program method2), it won't load that library again - is this thought process right???

Thanks,
P.Ingle
18 years ago
Hi,

Can I throw exception from a static block???

class MyClass throws Exception{
static{
try{
// do some thing like loading some library
System.load("MyLibrary");

} catch (Exception e){
throw new Exception("Failed to load MyLibrary");
}
}//end static

MyClass(){ // constructor }

} // end MyClass

But then I would have to add 'throws Exception' clause after class declaration as shown above - which I don't think is right ( and it also gives me error.)

I am loading native library in static block - which, if fails, shuts JVM all together. I would like to have some graceful way of handling this situation.

How can I do this?

Thanks,
P.Ingle
[ July 08, 2005: Message edited by: P. Ingle ]
18 years ago
Hello,

I have a question regarding WAS and DB2 connectivity.
I have WAS 5.1 installed on Linux box. I have DB2 Universal installed on another windows box. When I try to create DB2 JDBC provider on WAS, it asks me to provide classpath for db2java.zip. Because the linux box having WAS doesn't have DB2 client, it does not have sqllib directory and any of the db2 files including db2java.zip. These files are present on windows box with DB2 on it.

Do those files have to be available locally in order to be able to create JDBC Provider and ultimately the datasource? Can I just copy them from DB2 machine? Or do I need to install DB2 Client on Linux box to establish connectivity between WAS and DB2 database?

Thanks,
P. Ingle
Hello,

our team is developing a web app. One of the *requirements* is to remain stateless. In that case, do we pretty much rule out option of using Entity Bean?

Thanks,
P.Ingle
what about using good ol' static methods with final class?

I have a similar situation - I am using singleton implementation for DAOFactory which instatiates multiple DAOs as required. I don't want to create multiple instances of DAOFactory itself, hence am implementing as Singleton. Would it have same (or any) problems in Clustered env?
and if so, would static methods with final DAOFactory class work?

Thanks,
P.Ingle
ok, I tried following - they both fail at two different points

1.

have crypto.dll, jcrypto.h, jcrypto.class and jcrypto.java in same package com.abc.utils (jcrypto.java declares native methods,loads dll and has main method)

When I run it, it fails to find dll itself - failing at
System.loadLibrary("crypto");
giving me java.lang.UnsatisfiedLinkError: Can't find library crypto (crypto.dll) in java.library.path

By thw way, I also tried moving crypto.dll to c:\dllLib and running jaa code with Djava.library.path=C:\dllLib option - it gives me same error - can't find dll itself.


2. I moved crypto.dll at the same level directory com is
MyJNIProject
|
|-----com (and all package directories below it - com.abc.Utils)
|
|-----crypto.dll

com.abc.Utils has jcrypto.java, jcrypto.class, jcrypto.h

This way, it loads library, goes to 'main' but when I call the native method, it fails there giving me following error:

java.lang.UnsatisfiedLinkError: EncryptString

3.
Whole thing works smoothly when I have everything directly under MyJNIProject (jcrypto.java being in default package)
so MyJNIProject has jcrypto.java, jcrypto.class, jcrypto.h and crypto.dll
directly in it.

Any clue how to work it in case 1 and 2???
No, I am calling native code from simple java class - a utility class.

My code works fine when .java is under default package and as soon as I move everything under com.abc.utils package, it fails to load the library.

So I guess the question is where do dll and .h go and do I need to set any classpath variable for it to find that .h and .dll from code under a package??

Thanks,
P.Ingle