| class data sharing subjective test results |
|
 |
Index ‹ java-programmer
|
- Previous
- 2
- What happensHi,
Am a newbie to CORBA. What happens when a CORBA object is destroyed? I
heard that its ORB reference becomes invalid? If this' true, what
exactly is meant by 'invalid'? What if I try to refer the object after
it is destroyed? And also how do I come to know if the object is
destroyed?
Thanks.
- 3
- How to get connection to remote hostHi all,
I am beginner in httpunit i am trying to get resonse from a remote
host, but i am not able to get it
the error is
connnection Exception: connection refused; connect
how can i resolve it
thanks and regards,
Arun
- 4
- Runtime.exec and socketsI submitted this as a bug, but no response. Can anyone help?
FULL PRODUCT VERSION :
java version "1.4.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
Runtime.exec() to start a new java program. The new java program
should create a socket connection to another program.
The socket will connect if created and used from the static main
method. It will also work if placed in a static method called from
main. It will not work if I create an object and have the object
execute the same code (which is what I need); it fails both times if
the method is static or not static.
If I run the java program from the command line and not by using
Runtime.exec, it works beautifully.
If while it is blocking I kill the first vm, then the second vm
continues.
ACTUAL -
Blocking
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class ProgA {
public static void main(String[] args) throws Exception {
Runtime rt = Runtime.getRuntime();
Process p = rt.exec("java ProgB");
p.waitFor();
System.out.println("Process Returned");
}
}
///////////////////////////////////////////////////////////////////////
import java.net.*;
import java.io.*;
public class ProgB {
public void service() throws Exception {
//If I move this body of code to main or another static method,
//the program works.
Socket s = new Socket("127.0.0.1", 5000); //Blocking
OutputStream o = s.getOutputStream();
o.write("test data".getBytes() );
s.close();
}
public static void main(String[] args) throws Exception {
ProgB b = new ProgB();
b.service();
}
}
---------- END SOURCE ----------
- 5
- build failure on yesterday's -currentHi,
Following the threading, gcc, and symbol changes, I removed /usr/local
and /usr/X11R6 and am building everything from scratch.
jdk15 failed with:
bad class file: /usr/ports/java/jdk15/work/control/build/bsd-i586/gensrc/java/nio/channels/AsynchronousCloseException.java
file does not contain class java.nio.channels.AsynchronousCloseException
Please remove or make sure it appears in the correct subdirectory of the classpath.
throws AsynchronousCloseException
^
Note: * uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
2 errors
gmake[7]: *** [.compile.classlist] Error 1
gmake[7]: Leaving directory `/usr/ports/java/jdk15/work/j2se/make/sun/javac/recompile/library'
gmake[6]: *** [optimized] Error 2
gmake[6]: Leaving directory `/usr/ports/java/jdk15/work/j2se/make/sun/javac/recompile/library'
gmake[5]: *** [all] Error 1
gmake[5]: Leaving directory `/usr/ports/java/jdk15/work/j2se/make/sun/javac/recompile'
gmake[4]: *** [all] Error 1
gmake[4]: Leaving directory `/usr/ports/java/jdk15/work/j2se/make/sun/javac'
gmake[3]: *** [all] Error 2
gmake[3]: Leaving directory `/usr/ports/java/jdk15/work/j2se/make/java/javac'
gmake[2]: *** [all] Error 1
gmake[2]: Leaving directory `/usr/ports/java/jdk15/work/j2se/make/java'
gmake[1]: *** [all] Error 1
gmake[1]: Leaving directory `/usr/ports/java/jdk15/work/j2se/make'
gmake: *** [j2se-build] Error 2
*** Error code 2
Stop in /usr/ports/java/jdk15.
*** Error code 1
Stop in /usr/ports/java/jdk15.
stretchlimo/usr/ports/java/jdk15;
This might be known already, but I didn't see a posting on this yet.
If you already know, I'm patient and will wait for a fix.
Thanks,
==ml
--
Michael W. Lucas email***@***.com, email***@***.com
http://www.BlackHelicopters.org/~mwlucas/
Coming Soon: "Absolute FreeBSD" -- http://www.AbsoluteFreeBSD.com
On 5/4/2007, the TSA kept 3 pairs of my soiled undies "for security reasons."
- 7
- Induction question, help needed.Help needed on this question. Any help is appreciated. Thanks in
advance.
Given a binary string (i.e. a finite sequence of 0's and 1's) we
choose any two digit substring 01 and replace it by a string of the
form 100...0 using an arbitrary (but finite) number of zeros. Prove
by induction that this transformation can not be performed infinitely
many times, i.e. this sequence of transformations must terminate for
any input string.
- 7
- Is there a startup banner class?Hello,
I have an application to which I would like to add a startup banner.
Much like other applications that display this banner while performing
a somewhat lenghty (by computing standards) process in the background,
I have the same need.
Is there a class that supplies the panel (banner) and methods to
determine when the background process has completed?
Thanks in advance,
Todd
- 8
- color palletI'm coding up a routine to dispaly a stacked bar graph using
Graphics2D. Each bar is made by a bunch of rectangles representing
each contributor. The color of each contributor should be different.
I need a way to assign these colors. The number of contributors can
change at runtime. Sequential colors should be well differentiated.
Does anyone have any suggestions for accomplishing this? I'd rather
not make the user specify colors at runtime.
Thanks,
Rob
- 8
- JDialog (or any window) sizingI would like my JDialog to pop up with a size that is just adequate to
contain what is within, which includes various components and layouts in
the hierarchy. I'm hoping someone can tell me in a nutshell what
sequence of operations to perform.
- 8
- CFP Reminder: World Congress on Engineering and Computer Science (WCECS 2007)Call for Papers Reminder: World Congress on Engineering and Computer
Science (WCECS 2007)
From: International Association of Engineers (IAENG)
World Congress on Engineering and Computer Science 2007
San Francisco, USA, 24-26 October, 2007
http://www.iaeng.org/WCECS2007
The WCECS 2007 is organized by the International Association of
Engineers (IAENG), a non-profit international association for the
engineers and the computer scientists. The conference has the focus on
the frontier topics in the theoretical and applied engineering and
computer science subjects. Our last IAENG conference has attracted
more than one thousand participants from over 30 countries, and our
IAENG conference committees have been formed with over two hundred
committee members who are mainly research center heads, faculty deans,
department heads, professors, and research scientists from over 20
countries.
WCECS Congress Co-chairs
Prof. Craig Douglas (WCECS Keynote Speaker & Co-chair)
Professor of Computer Science & Professor of Mechanical Engineering,
University of Kentucky
Senior Research Scientist (corresponding to nonteaching full
professor)
Computer Science Department, Yale University, USA
Prof. Warren S. Grundfest, Fellow, AIMBE, SPIE (WCECS co-chair)
Co-Chair, Biomedical Engineering IDP
Professor of Electrical Engineering and Professor of Surgery
The Henry Samueli School of Engineering & Applied Science
University of California, Los Angeles, USA
Former Chair, SPIE Health Care Engineering & Technology Policy
Former Vice Chair, Health Care Engineering Policy Committee, IEEE
Prof. Lee Schruben, Ph.D. Yale (WCECS & ICMSC co-chair)
Professor and Former Department Chairman
Department of Industrial Engineering and Operations Research
University of California, Berkeley, USA
Prof. Jon Burgstone (ICIMT honorary co-chair)
Faculty Chair
Center for Entrepreneurship & Technology
College of Engineering
University of California, Berkeley, USA
Board Member of the Rock Center for Entrepreneurship at Harvard
Business School, Harvard University
Prof. Su-Shing Chen, Fellow, SPIE (ICCB honorary co-chair)
Emeritus Professor, Department of Computer Information Science &
Engineering, University of Florida, USA;
Principal Investigator of Systems Biology Laboratory,
CAS-MPG Partner Institute for Computational Biology (PICB);
Shanghai Institutes for Biological Sciences; Chinese Academy of
Sciences
Prof. Benjamin Friedlander, FIEEE (ICCST honorary co-chair)
Professor of Electrical Engineering
Department of Electrical Engineering, Jack Baskin School of
Engineering,
University of California, Santa Cruz, USA
The IEEE Third Millennium Medal (2000)
Former Vice Chairman of the Bay Area Chapter of the Acoustics, Speech
and Signal Processing Society
Former Associate Editor of the IEEE Transaction on Automatic Control
Prof. Burghard B. Rieger (ICMLDA honorary co-chair)
Professor of Computational Linguistics
Former Dean (1999-2001) of Faculty of Languages and Literature
Former Head of Department of Linguistic Computing, University of
Trier, Germany
President (1989-93) of the German Society for Linguistic Computing
(GLDV)
Vice-President (1990-94) of the International Society for Terminoly
and Knowledge Engineering (GTW)
Prof. Lei Xu (ICSCA honorary co-chair)
IEEE Fellow and IAPR Fellow,
Member of European Academy of Sciences,
Chair Professor, Department of Computer Science and Engineering,
The Chinese University of Hong Kong, Hong Kong
The conference proceedings will be published by IAENG (ISBN:
978-988-98671-6-4) in hardcopy. The full-text congress proceeding will
be indexed in major database indexes so that it can be assessed
easily. The accepted papers will also be considered for publication in
the special issues of the journal Engineering Letters and other IAENG
journals. Revised and expanded version of the selected papers may also
be included as book chapters in the standalone edited books under the
framework of cooperation between IAENG and Springer. Dr. Mark de
Jongh, Senior Publishing Editor, Springer SBM NL, will also give a
presentation about book publishing with Springer. Dr. Mark de Jongh
will also be available during the conference period to talk to
potential authors whom may have a new book idea/proposal.
The WCECS 2007 is composed of the following 15 conferences (all will
be held at the same location and date):
ICCB'07
International Conference on Computational Biology 2007
ICCE'07
International Conference on Chemical Engineering 2007
ICCS'07
International Conference on Circuits and Systems 2007
ICCSA'07
International Conference on Computer Science and Applications 2007
ICCST'07
International Conference on Communications Systems and Technologies
2007
ICEEA'07
International Conference on Electrical Engineering and Applications
2007
ICEIT'07
International Conference on Education and Information Technology 2007
ICIAR'07
International Conference on Intelligent Automation and Robotics 2007
ICIMT'07
International Conference on Internet and Multimedia Technologies 2007
ICMHA'07
International Conference in Modeling Health Advances 2007
ICMLDA'07
International Conference on Machine Learning and Data Analysis 2007
ICMSC'07
International Conference on Modeling, Simulation and Control 2007
ICSCA'07
International Conference on Soft Computing and Applications 2007
ICSEEM'07
International Conference on Systems Engineering and Engineering
Management 2007
ICSPIE'07
International Conference on Signal Processing and Imaging Engineering
2007
=========
Submission:
WCECS 2007 is now accepting manuscript submissions. Prospective
authors are invited to submit their draft paper in full paper (any
appropriate style) to WCECS{at}iaeng.org by 6 July, 2007. The
submitted file can be in MS Word format, PS format, or PDF formats.
The first page of the draft paper should include:
(1) Title of the paper;
(2) Name, affiliation and e-mail address for each author;
(3) A maximum of 5 keywords of the paper.
Also, the name of the conference that the paper is being submitted to
should be stated in the email.
=============
Important Dates:
Draft Paper Submission Deadline: 6 July, 2007
Camera-Ready Papers Due & Registration Deadline: 30 July, 2007
WCECS 2007: 24-26 October, 2007
It is our target that the reviewing process and the result
notification for each submitted manuscript can be completed within one
month from its submission. The reviewing process is to ensure the
quality of the accepted papers in the WCE congress. The conferences
have enjoyed high reputation among many research colleagues ( for
example, see the http://cs.conference-ranking.net/ or http://www.conference-ranking.com/
or http://www.conference-ranking.org/cs.html ).
More details about the WCECS 2007 can be found at:
http://www.iaeng.org/WCECS2007/index.html
http://www.iaeng.com/WCECS2007/index.html
http://www.iaeng.net/WCECS2007/index.html
More details about the International Association of Engineers, and the
IAENG International Journal of Computer Science, and the IAENG
International Journal of Applied Mathematics can be found at:
http://www.iaeng.org/about_IAENG.html
http://www.iaeng.org/IJCS/index.html
http://www.iaeng.org/IJAM/index.html
The official journal web site of Engineering Letters at:
http://www.engineeringletters.com
Other Engineering Letters web sites at:
http://www.engineeringletters.com
http://www.engineeringletters.net
http://www.engineeringletters.org
http://www.engineeringletter.com
http://www.engineerletters.com
http://www.engineerletter.com
********
It will be highly appreciated if you can circulate these calls for
papers to your colleagues.
- 9
- Problem with update Manager in eclipseHi
I have been trying to access the eclipse update site.
Unfortunately when I go on the newly created eclipse item
in the feature updates pane things seem to stop. A
message
Connecting... Connecting to
"http://update.eclipse.org/updates"
appears but nothing happens and the screen kind of hangs
until i press the red button (cancel current operation
option). I work from behind a proxy. I did the
appropriate settings in the preferences (entering the proxy name and
port). I expect to be asked for my username and password and
subsequently
be shown the builds. But nothing seems to be
happening.
But if I go to the eclipse item, right click and in
the properties select "website" instead of the "update
site" everything seems to work fine....as in i access the site
(updates still missing)
What is the reason of this behavior could i be doing
something wrong? I am new to eclipse....could anybody please help.
regards
- 15
- Logging APIHello,
I have been using the logging API to log HTTP requests. I have an
object, which resembles a HTTP request and has methods to extract the
typical fields of a HTTP request.
Now, I have noticed that you can only pass log messages as a String and
not as an object. Also I saw that Formatters format "around" this
String. I think that is quite a limitation for my purpose.
What's if I have different Log Formats, which I would like to apply.
For example, there are different levels of verbosity. The apache log
format "combined" sends more output then "common". Maybe I also want to
define my own custom ones.
Then I would like to have a Formatter for each output Format. Do do
that, however, Formatters would have to be able to work on those HTTP
objects, which contain the fields.
That does not seem to be possible under the current logging API or am I
missing someting here? I really don't understand, why the message is
not being stored as an Object but a String - that only limits the use
of the Formatter.
Can somebody elaborate on this. Maybe it should be brought up with Sun?
- 15
- list jar contentsI am trying to list the contents of a jar file.
I should be able to run
jar -t -f myjar.jar
but when I run this the command does not return and does not display
any thing.
I have to ctrl-c to terminate the app.
I can get the contents if I use the command line version of winzip.
I have tried
jar -t myjar.jar
and
jar -t -f myjar.jar
thanks for the help
john
- 16
- JSP vs XSLT?Which is better JSP or XSLT? I prefer JSP for two reasons performance
and less complicated to learn.
JSPs are compiled one time, then cached, unless the code changes. This
not the case with XSLT, as I understand it.
XSLT is very complicated to learn, in my opinion.
See this article by IBM on JSP vs XSLT:
http://www-106.ibm.com/developerworks/websphere/techjournal/0405_brown/0405_brown.html#sec9
- 16
- i18n in Swing, trouble.Hi,
I am building my first Gui with Swing, and in the same time I need to
use the i18n to make it work in Japanese and English.
I use Eclipse and its great Visual Editor to save time, all my files are
utf8 encoded. And, I am under WinXp...
My trouble is the following :
-> If I make a jMenu with some japanese hardcoded text, it appears fine
in my application.
-> If I use a ResourceBundle to get the text, I have garbage. I use the
following line: myMenu.setText(myBundleResource.getString("myTest"));
The .properties files for the japanese is also in Utf8
Do you have any idea why the text in the .properties file is not passed
correctly ? Any help would be really appreciated.
Best Regards,
Schlum
- 16
- Open Source Document Management in JavaHas anybody tried "Corendal DocSide" from http://www.corendal.com ? It
looks like a pretty clean electronic document management application.
Any experience with this tool ? (demo at
http://www.corendal.com/java-corendal/docside/home/)
|
| Author |
Message |
jeanlutrin@yahoo.fr

|
Posted: 2005-1-24 16:27:00 |
Top |
java-programmer, class data sharing subjective test results
Hi all,
I made some tests with the new "Class Data Sharing" function
provided by the JVM (since version 1.5.0 / 5.0) and decided
to share my class data sharing discoveries with the group
(this topic is not often discussed here).
The tests were made on an Un*x system (Linux Fedora Core 3).
First of all, the performance gain is very real, especially
when launching lots of small apps.
Basically, it comes down to using the parameter/value
"-Xshare:off", "-Xshare:on" or "-Xshare:auto" (which is
the default) when calling the JVM.
The command line: "java -Xshare:dump" can be used to
force the creation of the memory-mapped archive file
(the shared classes). (btw this step is apparently
necessary on some Un*x systems!?. My system would
/not/ default to using the sharing, I had to
-Xshare:dump once and then add -Xshare:on to force my
application sharing the classes.)
I had some "text file utilities" I wrote in Java which I'm
used to call from the command line (or from shell scripts).
This is clearly one area where the JVM's startup time
is a problem. I noticed gain of about 30% in this case
(using a non-scientific approach repeated many case, with
and without CDS).
If the JVM is installed in userland, each user will have his
own "cached" file (classes.jsa, about 11 Mb on my machine).
If only one JVM is installed for all the users, all the
users will share the same classes.jsa file (JSA for "Java
Shared Archive").
It may be possible to force different identical JVM
installed in different userland to use the same classes.jsa
but I didn't try to do this (simply copying the classes.jsa
file from one user on top of the classes.jsa file of another
user doesn't work, although the files have the same
length [but different checksums]).
I was pleasingly surprised by those first results and I
decided to force all my apps to use the JVM 1.5.0 and its
class data sharing feature, including IntelliJ IDEA (which
comes with its own JRE and refuse to run with an 1.5 JRE
without some hacking).
After days of "switching" to an 1.5 JVM and forcing all my
apps to use class data sharing, I can tell that overall
everything "Java related" is a little bit more responsive.
It is particularly noticeable when calling Java utilities
from the command line (which is no surprise) but also when
running unit tests (I tend to launch my test(s) quite often).
The memory footprint is also reduced compared to 1.4.2
(when running several apps).
I'm curious about your results too :)
See you all very soon (and "hi" to the c.l.j.p. regular
I met on freenode's #java saturday ;),
Jean
P.S : If I understood correctly, Apple made their
own class data sharing "hack" for Java (way before 1.5)
and Sun basically copied their "idea". Whatever... This
means that developers using MacOS X benefits automagically
from "class sharing" since quite some time and have
nothing particular to do in order to use it.
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- aliasHi,
I may be jumping guns here. I mean I'm totally new to java and yet, I
feel the need to do something like this for typing much less,
o = System.out.println; // problem, what data type for var of o here?
undefined.
or
alias o = System.out.println; // alias is supposed to be a special
command or the sort?
then, I do something like this
for (int i=0; i < 5; i++) {
switch(i)
case 0:
case 2:
case 4:
o(i + " is an even number"); // instead of System.out.println(i +
" is an even number");
break;
case 1:
case 3:
case 5:
o(i + " is an odd number"); // instead of System.out.println(i + "
is an odd number");
break;
default:
o(i + " is neither an odd nor even number");
// instead of System.out.println(i + " is neither an odd nor even
number");
}
Doable? How? TIA.
- 2
- Hashtable qWhen traversing an Enumeration of Hashtable keys, I know that modifying the
HT can cause problems. But is doing lookups okay? E.g., in the following
code:
<assume ht is a reference to a Hashtable object>
Enumeration e = ht.keys();
Object o;
while(e.hasmore()) {
o = e.next();
System.out.println(o + ": " + ht.get(o));
}
Is this guaranteed to print out all of the key-value pairs?
- 3
- RPN CalculatorI've searched the web for a couple of hours for a calculator with this
requirements
It has to
0) be free to download and use
1) be able of RPN
2) be able to run in a standalone window (i.e. not in a web browser)
3) be written in java
4) preferably be open source
Someone who can give me a hint???
- 4
- JTextField : limit number of input charactersHi,
How can I do limit the number of character into a JTextField component ? I'm
a Newbie, and I've some problem with this.
Other question, in a JTable, how can I do to put a DropDown into a field
from a column ?
Thanks for all
Bernard
- 5
- Array reference in for loopI have a validate method in a bean class that works and now I want to
condense it into a for loop.
Here is what I have:
//firstname and lastname are declared earlier
public boolean validate()
{
boolean allOk=true;
if (firstName.equals("")) {
errors.put("firstName","Please enter your first name");
allOk=false;
}
if (lastName.equals("")) {
errors.put("lastName","Please enter your last name");
allOk=false;
}
return allOk;
}
My attempt doesnt work because I cant seem to figure out how to put
the array reference in the key part of the errors.put method:
public boolean validate()
{
boolean allOk=true;
String [] myarray = {firstname, lastname}
for(int i=0;i < myarray.length;i++)
{
if (myarray[i].equals("")) {
errors.put(myarray[i],"Please enter your " + myarray[i]);
allOk=false;
}
}
return allOk;
}
The results dont validate any of my data so I assume I have something
wrong with my array. Please advise.
- 6
- Swing - how to catch all eventsProgramming in java for a while now, but I still have this silly
problem that I don't know if the experts has a simple answer.
I have a Swing app. Yes, simple stuff eh. Next, user logins to use
the app. If they don't do anything (mouse move, key press) for a
while, then I log out. The think is that detecting a mouse event, I
have to register with each of the tabpane of the app. I don't like
that. Also, I have to register with each components within the panel.
The same for keyboard. For keyboard, it seems I can register event
for just any component (with appropriate modifer to get the input map
and action map). However, I still have to register all keys which are
alot. I want the ability to catch the event from top down. Anyevent
would goes through my filters first. Would this be possible? How do
I solve this simple and common problem? Thank you very much in
advance.
- 7
- converting paper space to model space in dxf filesHello wise guys!
I'm writing a piece of code (java) that shold parse and draw the
content of a DXF file. The trouble is that some blocks (usually texts
or legend) are given in paper space. Can anyone give me a hint how
paper coordinates should be converted to model coordinates? Thanks a
lot!
Adrian
- 8
- 9
- Bug or featureHi, can someone explain the behaviour of that snip
public class Test
{
public static void main(String[] args)
{
try
{
Class c = Class.forName("BUG");
}
catch (ClassNotFoundException e)
{
}
System.out.println("Everything works?");
try
{
Class c = Class.forName("NotbUg");
}
catch (ClassNotFoundException e)
{
}
System.out.println("Still works?");
try
{
Class c = Class.forName("bUg");
}
catch (ClassNotFoundException e)
{
}
System.out.println("Everything works!!");
}
}
class BUG
{
}
In not works on JDK 1.4.2 but JDK 1.1.4. Bug or feature that question is.
Thanks in advance.
Serge
- 10
- Final member troubleimport java.awt.Image;
import javax.imageio.ImageIO;
import java.io.*;
public class FinalTryCatch {
final Image someImage;
public FinalTryCatch() {
try {
someImage = ImageIO.read(new File("someImageFile.gif"));
} catch (IOException ioe) {
someImage = null;
}
}
public static void main(String[] args) {
FinalTryCatch f = new FinalTryCatch();
// Do some stuff
}
}
This fails to compile with "variable someImage might already have been
assigned" on "someImage = null;". Remove that line and it complains,
"variable someImage might not have been initialized". Obviously. What would
you do in this situation? Make the variable non-final? Have the constructor
throw IOException? Something else?
- 11
- "this" statement?The "this" statement that is used in the method "exitRoom" and "explore" is
that synonymous with an "Explorer" object?
public class Explorer implements PlayerBehavior {
private String my_name;
private String my_secret_word;
private RoomBehavior where_I_am_now;
public Explorer(String name, String word){
my_name = name;
my_secret_word = word;
where_I_am_now = null;
}
public String speak(){
return my_secret_word; }
public void exitRoom(){
if ( where_I_am_now != null )
{ where_I_am_now.exit(this);
where_I_am_now = null;
}
}
public boolean explore(RoomBehavior r){
if ( where_I_am_now != null )
{ exitRoom(); }
boolean went_inside = r.enter(this);
if ( went_inside )
{ where_I_am_now = r; }
return went_inside;
}
public RoomBehavior locationOf(){
return where_I_am_now; }
}
- 12
- Long delay using SSLSocketFactoryHi all,
I need to do HTTPS requests from a WLS container through a proxy which
requires encoded username/password authentication. Therefore, I am
using an extension of SSLSocketFactory (part of SUN's JSSE), which
does the proxy authentication for me and the tunnel handshake as well.
Principally, the solution I thought of works. However, after starting
the WLS, the very first connection to the proxy takes more than two
minutes. Running the test once again, the connection to the proxy is
established almost instantaneously. Can anyone explain the long delay
in the first connection? It occurs when invoking method
SSLSocketFactory.getDefault() (see the below code snippet).
I scanned the port of the proxy and found no activity during the
delay. Neither, there are any outgoing TCP packages from the source
machine (where the JVM is running). So I assume that the delay is not
due to a network problem; it must be somewhere in the depths of the
JSSE classes.
Best regards,
Thomas Mantay
Here is the code I am using:
import java.net.*;
import java.io.*;
import java.security.*;
import sun.misc.BASE64Encoder;
import javax.net.*;
import javax.net.ssl.*;
public class SSLTunnelSocketFactory extends SSLSocketFactory {
private String tunnelHost;
private int tunnelPort;
private SSLSocketFactory dfactory;
private String tunnelPassword;
private String tunnelUserName;
private boolean socketConnected = false;
private int falsecount = 0;
/**
* Constructor for the SSLTunnelSocketFactory object
*
*@param proxyHost The url of the proxy host
*@param proxyPort the port of the proxy
*@param proxyUserName username for authenticating with the
proxy
*@param proxyPassword password for authenticating with the
proxy
*/
public SSLTunnelSocketFactory(String proxyHost, int proxyPort,
String proxyUserName, String proxyPassword) {
NLUtil.ldebug("SSLTunnelSocketFactory", "Constructor", "creating
Socket Factory with password/username");
tunnelHost = proxyHost;
tunnelPort = proxyPort;
tunnelUserName = proxyUserName;
tunnelPassword = proxyPassword;
NLUtil.ldebug("SSLTunnelSocketFactory", "Constructor", "before
getDefault()");
Here is the line that causes the delay:
dfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
NLUtil.ldebug("SSLTunnelSocketFactory", "Constructor", "after
getDefault()");
}
/**
* Gets the supportedCipherSuites attribute of the
SSLTunnelSocketFactory
* object
*
*@return The supportedCipherSuites value
*/
public String[] getSupportedCipherSuites() {
return dfactory.getSupportedCipherSuites();
}
/**
* Gets the defaultCipherSuites attribute of the
SSLTunnelSocketFactory
* object
*
*@return The defaultCipherSuites value
*/
public String[] getDefaultCipherSuites() {
return dfactory.getDefaultCipherSuites();
}
/**
* Gets the socketConnected attribute of the
SSLTunnelSocketFactory object
*
*@return The socketConnected value
*/
public synchronized boolean getSocketConnected() {
return socketConnected;
}
/**
* Creates a new SSL Tunneled Socket
*
*@param s Ignored
*@param host destination host
*@param port destination port
*@param autoClose wether to close the socket
automaticly
*@return proxy tunneled socket
*@exception IOException raised by an IO error
*@exception UnknownHostException raised when the host is
unknown
*/
public Socket createSocket(Socket s, String host, int port,
boolean autoClose)
throws IOException, UnknownHostException {
Socket tunnel = new Socket(tunnelHost, tunnelPort);
doTunnelHandshake(tunnel, host, port);
SSLSocket result = (SSLSocket) dfactory.createSocket(tunnel,
host, port, autoClose);
result.addHandshakeCompletedListener(
new HandshakeCompletedListener() {
public void handshakeCompleted(HandshakeCompletedEvent
event) {
NLUtil.ldebug("SSLTunnelSocketFactory", "handshakeCompleted",
"Handshake Finished!");
NLUtil.ldebug("SSLTunnelSocketFactory", "handshakeCompleted",
"CipherSuite :" + event.getCipherSuite());
NLUtil.ldebug("SSLTunnelSocketFactory", "handshakeCompleted",
"SessionId: " + event.getSession());
NLUtil.ldebug("SSLTunnelSocketFactory", "handshakeCompleted",
"PeerHost: " + event.getSession().getPeerHost());
setSocketConnected(true);
}
});
// thanks to David Lord in the java forums for figuring out
this line is the problem
// result.startHandshake(); //this line is the bug which stops
Tip111 from working correctly
return result;
}
/**
* Creates a new SSL Tunneled Socket
*
*@param host destination host
*@param port destination port
*@return tunneled SSL Socket
*@exception IOException raised by IO error
*@exception UnknownHostException raised when the host is
unknown
*/
public Socket createSocket(String host, int port)
throws IOException, UnknownHostException {
return createSocket(null, host, port, true);
}
/**
* Creates a new SSL Tunneled Socket
*
*@param host Destination Host
*@param port Destination Port
*@param clientHost Ignored
*@param clientPort Ignored
*@return SSL Tunneled Socket
*@exception IOException Raised when IO error occurs
*@exception UnknownHostException Raised when the destination
host is
* unknown
*/
public Socket createSocket(String host, int port, InetAddress
clientHost,
int clientPort)
throws IOException, UnknownHostException {
return createSocket(null, host, port, true);
}
/**
* Creates a new SSL Tunneled Socket
*
*@param host destination host
*@param port destination port
*@return tunneled SSL Socket
*@exception IOException raised when IO error occurs
*/
public Socket createSocket(InetAddress host, int port)
throws IOException {
return createSocket(null, host.getHostName(), port, true);
}
/**
* Creates a new SSL Tunneled Socket
*
*@param address destination host
*@param port destination port
*@param clientAddress ignored
*@param clientPort ignored
*@return tunneled SSL Socket
*@exception IOException raised when IO exception occurs
*/
public Socket createSocket(InetAddress address, int port,
InetAddress clientAddress, int clientPort)
throws IOException {
return createSocket(null, address.getHostName(), port, true);
}
/**
* Sets the socketConnected attribute of the
SSLTunnelSocketFactory object
*
*@param b The new socketConnected value
*/
private synchronized void setSocketConnected(boolean b) {
socketConnected = b;
}
/**
* Description of the Method
*
*@param tunnel tunnel socket
*@param host destination host
*@param port destination port
*@exception IOException raised when an IO error occurs
*/
private void doTunnelHandshake(Socket tunnel, String host, int
port) throws IOException {
NLUtil.ldebug("SSLTunnelSocketFactory", "doTunnelHandshake",
"doTunnelHandshake start");
OutputStream out = tunnel.getOutputStream();
//generate connection string
String msg = "CONNECT " + host + ":" + port + " HTTP/1.0\n"
+ "User-Agent: "
+ sun.net.www.protocol.http.HttpURLConnection.userAgent;
if (!tunnelUserName.equals("") && !tunnelPassword.equals(""))
{
NLUtil.ldebug("SSLTunnelSocketFactory", "doTunnelHandshake",
"Using proxy authencation with username '" + tunnelUserName + "' and
password '" + tunnelPassword + "'.");
//add basic authentication header for the proxy
sun.misc.BASE64Encoder enc = new sun.misc.BASE64Encoder();
String encodedPassword = enc.encode((tunnelUserName + ":"
+ tunnelPassword).getBytes());
msg = msg + "\nProxy-Authorization: Basic " +
encodedPassword;
}
msg = msg + "\nContent-Length: 0";
msg = msg + "\nPragma: no-cache";
msg = msg + "\r\n\r\n";
NLUtil.ldebug("SSLTunnelSocketFactory", "doTunnelHandshake", "msg:
" + msg);
byte b[];
try {
//we really do want ASCII7 as the http protocol doesnt
change with locale
b = msg.getBytes("ASCII7");
} catch (UnsupportedEncodingException ignored) {
//If ASCII7 isn't there, something is seriously wrong!
b = msg.getBytes();
}
out.write(b);
out.flush();
byte reply[] = new byte[200];
int replyLen = 0;
int newlinesSeen = 0;
boolean headerDone = false;
InputStream in = tunnel.getInputStream();
boolean error = false;
while (newlinesSeen < 2) {
int i = in.read();
if (i < 0) {
throw new IOException("Unexpected EOF from Proxy");
}
if (i == '\n') {
headerDone = true;
++newlinesSeen;
} else
if (i != '\r') {
newlinesSeen = 0;
if (!headerDone && replyLen < reply.length) {
reply[replyLen++] = (byte) i;
}
}
}
//convert byte array to string
String replyStr;
try {
replyStr = new String(reply, 0, replyLen, "ASCII7");
} catch (UnsupportedEncodingException ignored) {
replyStr = new String(reply, 0, replyLen);
}
//we check for connection established because our proxy
returns http/1.1 instead of 1.0
if (replyStr.toLowerCase().indexOf("200 connection
established") == -1) {
NLUtil.ldebug("SSLTunnelSocketFactory", "doTunnelHandshake",
"replyStr: " + replyStr);
System.err.println(replyStr);
throw new IOException("Unable to tunnel through " +
tunnelHost + ":" + tunnelPort + ". Proxy returns\"" + replyStr +
"\"");
}
//tunneling hanshake was successful
}
}
- 13
- how to map from display metrics to physical metrics...Suppose I have a screen which is 1024x768, how can I map this rectangle in
pixels into physical world dimensions in meters or in inches? Actually I
want to know the physical size of the viewable area of the monitor...
Please help me...
- 14
- CloneableWould have been possible to some how redefine Cloneable so that clone
did not return an object but rather at object of the type implementing
clone?
--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm
Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
- 15
- JavaScript for MaximizationHi. I want onLoad(), to make my current IE window "maximized." I can resize
the window to Screen.width/height but the problem with that is that it
includes the full screen height (including the task-bar) and I need it to be
without the task bar. Any way to do this? Preferably a way that's
browser-independant but IE-specific if need be.
Alex
|
|
|