Eugene Rabii

Ranch Hand
+ Follow
since Apr 24, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Eugene Rabii

That was simpler then I first read it But still fun.

1. A and B, then C and D and then... well yes it get obvious really fast.

Cheers,
Eugene.
14 years ago
I have to say, this is impressive!
I have reached the same code:

x = ( 2*(10^n) - 4 ) / 19

And it was a pleasure getting here!

Cheers, Eugene
14 years ago
This question made my day! Thank you so much!
14 years ago
Yes sir!
14 years ago
Hello dear rachers,

I will ask again since last time I did not get any answers. It has to do with async support of Servlet 3.0.
Now, from what I understand async support has two main purposes : release the http container Thread as soon as possible and support the Comet-like programming.

I want to discuss the first one really. So, the idea is this, every time we send in a request, the container allocates a Thread for it to be processed. If there is a Web Service (for example) that this particular Thread needs to access and this Web Service takes a lot of time to respond, then we "start" the async support: meaning that we start another Thread (not a http container Thread), but a usual Thread and we pass the actual work to this second Thread, while the Http Container thread goes back to the pool. Now this is where I do not get it. We are supposed to resolve the Thread starvation issue and, but we are creating a new Thread... Also, look at the sample below:

AsyncContext context = request.startAsync(request, response);
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(10);
executor.execute(new AsyncRunnable(context));

where AsyncRunnable is nothing more then a slow resource (the Web Service simulated by a Thread that sleeps for 10 seconds). If I am the client and I issue a request , I still have to wait for those 10 seconds to pass before I get my response. I do not really care that the Http Thread was released, then another Thread did my Job, and then the same Http Thread issued my response back.

Basically to me, Async Servlet is just a way to release the Http Container Thread - it is a server side enchantment, if the server is not busy (not even close to Thread starvation), then the user experience will not be any different, right? At the same time this technique can be achieved with synchronous Servlet and a simple Thread - I so not then get it what is the use of async Servlets asnyway?
In case I said something stupid, please correct me.

Thank you,
Eugene.


14 years ago
Servlet 3.0 @MultiPartConfig

JSP page:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Upload File</title>
</head>
<body>
<form action="uploadTest" method="post" enctype="multipart/form-data">
<table>
<tr>
<td>Select File : </td>
<td><input name="fileToUpload" type="file"/> </td>
</tr>
</table>
<p/>
<input type="submit" value="Upload File"/>
</form>
</body>
</html>

Actual Servlet:

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(urlPatterns="/uploadTest")
@MultipartConfig
public class MySecondServlet extends HttpServlet {

private static final long serialVersionUID = 11234354643L;

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response){
try {
String fileName = MySecondServlet.getFileName(request.getPart("fileToUpload").getHeader("content-disposition"));
String outPutFile = this.getServletContext().getRealPath(fileName);
FileOutputStream os = new FileOutputStream(outPutFile);

InputStream is = request.getPart("fileToUpload").getInputStream();
int ch = is.read();
while(ch != -1){
os.write(ch);
ch = is.read();
}
os.close();
response.getWriter().append("Uploaded!");

} catch (IOException e) {
e.printStackTrace();
} catch (ServletException e) {
e.printStackTrace();
}
}

private static String getFileName(String neededHeader){
String fileName = null;
for(String onePiece : neededHeader.split(";") ){
if(onePiece.contains("filename=")){
String myPieces[] = onePiece.split("=");
fileName = myPieces[1].replaceAll("\"", "").trim();
}
}
// If we reach this if, then either the Header is deformated or it does not have the needed format
if(null == fileName) throw new IllegalArgumentException("The Header provided seems to be Invalid!");
return fileName;
}
}
14 years ago
Hello dear ranchers hear is my question,

Trying to understand the Async Servlet for a few days now, no luck yet. May be you could help me. So, what literally happens when we call startAsync()? The request and the response gets somehow put on the server, while the "async" job gets done? For example:

AsyncContext context = request.startAsync();
context.start(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
context.complete();
response.getWriter().print("Done");

So, what this means is that the initial http Thread "releases" the request, some other worker thread picks it up and does the waiting (the async task) and the the http Thread builds the response.

I mean, from what I have read so far, the async support is for releasing some Thread, right? But if we release some Thread, the async job is done by some other Thread anyway. So, where do we win in the first place? Or may be some Threads are not that expensive as others?

P.S. There are no stupid questions, there are silly answers.

Thanks a lot!
Eugene.

14 years ago
Hello to everyone!

I have given an IBM exam a few days ago and waiting for the Certificate. The problem is that I am moving and my home address is changing , is there anyone you can contact for this particular issue from IBM or prometric so that they do not send the certificate to a wrong address? may be like SUN/Oracle has : [email protected]??? Anyone knows about something like that?

Thank you,
Eugene.
Ups! Sorry about Provider stuff - I meant to say "Producer".
True, true about to String, but the problem is a bit misleading since I did not mention the problem as it is! I am sorry for that!

The stuff is actually a bit more complicated as it seems (at least to me) :

Now, here it is : I have made the same method to take as input 2 Objects. I expose the WSDL and build the client. Then I go back to the Producer and change the Objects to String and deploy it. If I try to consume this web service with soapUI (remember that WSDL is still xsd:anyType) , sopaUI does not know how to handle this "any:Type" that actually is a String and puts null instead. If I build a client (Java Code) - and pass two Strings it's all good!

I do not even know who to blame (soapUI for not knowing how to deal with xsd:anyType or ...) - of course I should NOT do stuff like redeploying the producer... but believe it or not this is my case in a future production environment and there is no way to change the WSDL to xsd:string!

Thank you for your help,
Eugene.
Well I guess you are right - SOAP should know how to deal with java.lang.Object,

but why does it not return in to the response? If I change that to String - everything is ok.

I do not get your point about the default value thing...

Thank you,
Eugene.
Hello fellow ranchers!

This is my question - might be something simple , might not..

So here is the input, I made a Web Service Provider - a simple method getPerson , that takes as input two Objects. (java.lang.Object) and output them to the response. Something like :

@WebService
public class Test{
public String getPerson(Object name, Object age){
return "Testing : " + name;
}
}

Deploy it in glassfish v3 (using Netbeans) and Test it, via: htpp://localhost:14200.....?Tester
I give the Web Service two objects that are required, but as a response I am getting "Testing : " null.

Does that mean that SOAP does know how to deal with java.lang.Objects during serialization and deserialization?

Or I do something wrong?

Thank you,
Eugene.
) This is probably the first time I am laughing when somebody confuses me more then I was before

P.S. forwarded a couple of links from here to SUN with result scores below 42 % , waiting for a reply..
This is a copy/paste from what I got from SUN, and of course this raises more questions Who is right ?




Hello Eugene

Thank you for contacting Sun Certification Customer Support. We are happy to assist you.

The information found on our website http://www.sun.com/training/catalog/courses/CX-310-230.xml is correct, the passing grade is 68%

Please let us know if we may be of further assistance. Thank you for choosing Sun products and services.

Sincerely,

Michele Castle
Sun Certification Customer Support
[email protected]
This has probably been asked before, but still I do not have one clear answer, what is the passcore for the SCJWS exam. I connected the person in charge for my country and she said that it's 68% as written on sun.com. But some people here say that it is 42%. Who should I believe?
P.S. Of course I do not want to score below let's say 75% but still, the question is interesting.

Thank you,
Eugen.
Imagine a piece of code written like this:
public static void go(long time) throws InterruptedException{
synchronized(new String("sync")){
if(time>0){ //line1
Thread.sleep(time); // line2
}
}

}

Now imagine that these code is called by 2 threads - Thread1 has the time variable set to 5000 and Thread2 has the variable time set to 1000. If Thread1 is started first (and assume runs first) and it reaches line1 BUT DOES not yet reach line2, but Thread2 has already reached line2 - because the method is static => the first thread (Thread1) might be sleeping for 1 second instead of the 5 seconds desired. I am correct (hope I was clear about the issue that I am facing)? Thank you very much.