Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

java.net.SocketTimeoutException: Read timed out

807606Feb 14 2007 — edited Feb 16 2007
Hello everyone in the forum,
i am new here and i also new to programming in Java (i've studied C++ in my university course)...
Using Eclipse i am creating the java client and server code for an ajax application implemented in Ajax...(through the framework Google web toolkit)
The programs loads an ontology (.owl) in vectors (using Jena libraries), writes it into a hsqldb and then gives the opportunity to make queries...
When i run the application in HOSTED MODE, to load the ontology i get this Error and the ontology file (.owl) gets erased accidentally in parts...Are the 2 things related??? (i guess that the problem could be in the Inputstream...)

StandardWrapperValve[AdminService]: Servlet.service() for servlet AdminService threw exception

[WARN] StandardWrapperValve[AdminService]: Servlet.service() for servlet AdminService threw exception
java.net.SocketTimeoutException: Read timed out
at org.apache.coyote.http11.InternalInputBuffer.fill(InternalInputBuffer.java:747)
at org.apache.coyote.http11.InternalInputBuffer$InputStreamInputBuffer.doRead(InternalInputBuffer.java:777)
at org.apache.coyote.http11.filters.IdentityInputFilter.doRead(IdentityInputFilter.java:115)
at org.apache.coyote.http11.InternalInputBuffer.doRead(InternalInputBuffer.java:712)
at org.apache.coyote.Request.doRead(Request.java:429)
at org.apache.coyote.tomcat5.InputBuffer.realReadBytes(InputBuffer.java:290)
at org.apache.tomcat.util.buf.ByteChunk.substract(ByteChunk.java:374)
at org.apache.coyote.tomcat5.InputBuffer.read(InputBuffer.java:305)
at org.apache.coyote.tomcat5.CoyoteInputStream.read(CoyoteInputStream.java:179)
at com.oreilly.servlet.multipart.BufferedServletInputStream.fill(BufferedServletInputStream.java:64)

THE FIRST CLIENT SIDE CODE IS

package it.poliba.sisinf.Mimmo.client;

import java.util.*;
import com.google.gwt.i18n.*;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.ui.*;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.Timer;

/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class Interface implements EntryPoint {

public void onModuleLoad() {
final Message myResources = (Message) GWT.create(Message.class);
/*myResources is a class that contains all the possible messages printed in the webpage....s18 = Add New Ontology s19 = Add New Individual*/
final Button button = new Button();
final ListBox lb = new ListBox();
final FormPanel form = new FormPanel();
final Label labe = new Label(myResources.s17());
final HTML titolo = new HTML(myResources.s28());
labe.setStyleName("label");
final Image img= new Image("C:\\Mimmo\\gwt-windows-1.1.10\\src\\it\\poliba\\sisinf\\Mimmo\\public\\bar.gif");
lb.setName("type");
form.setAction("/AdminService");
form.setMethod(FormPanel.METHOD_POST);
form.setEncoding(FormPanel.ENCODING_MULTIPART);
final VerticalPanel panel = new VerticalPanel();
form.setWidget(panel);
final FileUpload f = new FileUpload();
f.setName("file");
final TextBox tb = new TextBox();
tb.setName("name");
final Label lab = new Label("");
panel.add(lb);
panel.add(f);
panel.add(lab);
panel.add(tb);
panel.add(button);
lb.addItem("");
lb.addItem(myResources.s18());
lb.addItem(myResources.s19());
lb.addItem(myResources.s23());
button.setVisible(false);
f.setVisible(false);
lab.setVisible(false);
tb.setVisible(false);
labe.setVisible(false);
img.setVisible(false);
lb.addChangeListener(new ChangeListener() {
public void onChange(Widget sender) {
if (lb.isItemSelected(0)){
button.setVisible(false);
tb.setVisible(false);
lab.setVisible(false);
f.setVisible(false);}
if (lb.isItemSelected(1)){
button.setVisible(true);
button.setText(myResources.s21());
tb.setVisible(false);
lab.setVisible(false);
f.setVisible(true);}
if (lb.isItemSelected(2)){
button.setVisible(true);
button.setText(myResources.s22());
tb.setVisible(false);
lab.setVisible(false);
f.setVisible(true);}
if (lb.isItemSelected(3)){
button.setVisible(true);
button.setText(myResources.s23());
tb.setVisible(true);
lab.setText(myResources.s24());
lab.setVisible(true);
f.setVisible(false);}
}
});
button.addClickListener(new ClickListener() {
public void onClick(Widget sender){
form.submit();
}
});
form.addFormHandler(new FormHandler() {
public void onSubmitComplete(FormSubmitCompleteEvent event) {
if(f.isVisible()) {
labe.setVisible(false);
img.setVisible(false);
boolean d = Window.confirm(myResources.s20());
if (d==false)
Window.open("/AdminService", "Database",
"menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes");
}
else
Window.alert(myResources.s25());
}
public void onSubmit(FormSubmitEvent event) {

if(f.isVisible()){
labe.setVisible(true);
img.setVisible(true);

if (f.getFilename().length() == 0) {
Window.alert(myResources.s26());
event.setCancelled(true);
}
}
else
Window.alert(myResources.s27());
}

});
RootPanel.get("titolo").add(titolo);
RootPanel.get("slot").add(labe);
RootPanel.get("slot2").add(img);
RootPanel.get("slot1").add(form);
}

}

THE SERVER SIDE COSE IS
package it.poliba.sisinf.Mimmo.server;

import it.poliba.sisinflab.dig.DIGElement;

import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
import org.apache.commons.fileupload.servlet.*;
import org.apache.commons.fileupload.disk.*;
import org.apache.commons.fileupload.*;

import java.sql.SQLException;
import java.util.List;
import java.util.Iterator;
import java.util.Vector;

import com.hp.hpl.jena.ontology.OntClass;
import com.oreilly.servlet.*;


public class AdminService extends HttpServlet {
public String nome;
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

MultipartRequest multi = new MultipartRequest(req,".");
File f = multi.getFile("file");
String type = multi.getParameter("type");
String fileName = multi.getFilesystemName("file");
try {
if (f!=null)
{
File fOUT = new File("/",fileName);
FileInputStream fIS = new FileInputStream(f);
FileOutputStream fOS = new FileOutputStream(fOUT);
while (fIS.available()>0)
fOS.write(fIS.read());
fIS.close();
fOS.close();
String name = fileName.substring(0,(fileName.length()-4));
if (type.equals("Add New Individual")){
takeIndividual(name, "file:"+ fOUT.getAbsolutePath());
}
if (type.equals("Add New Ontology")){
takeOntology(name, "file:"+ fOUT.getAbsolutePath());
}
}
else {
nome=multi.getParameter("name");
resetDB();
}
} catch (Exception e) {
e.printStackTrace();
}

}
public void doGet (HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
PrintWriter out;
String title = "final page";

response.setContentType("text/html");
response.setHeader("Pragma", "no-cache");

out = response.getWriter();

out.println("<HTML><HEAD><TITLE>");
out.println(title);
out.println("</TITLE></HEAD><BODY>");
out.println("<h1 align=center>Complimenti, il Database � stato generato");
out.println("</BODY></HTML>");
out.close();
}


public void takeOntology(String name , String uri) {
HSQLDBManager.setDefaultDbName(name);
nome=name;
try{
HSQLDBManager man = HSQLDBManager.getInstance();
OntClassificator oc = new OntClassificator(uri);
man.createSchema();
man.topClassesDB(oc.loadTopClasses());
man.classesDB(oc.loadClasses());
man.rulesDB(oc.loadRules());
oc.loadSubClasses(name);
oc.loadRulesProp();
man = null;
man.shutdown();
}catch(Exception e) {
e.printStackTrace();
}

}
public void takeIndividual(String name, String uri) {
HSQLDBManager.setDefaultDbName(nome);
OntClassificator oc = new OntClassificator(uri);
oc.loadIndividual(name);
}
public void resetDB (){
File f = new File("/"+ nome + ".backup");
f.delete();
File f1 = new File("/"+ nome + ".data" );
f1.delete();
File f2 = new File("/"+ nome + ".lck");
f2.delete();
File f3 = new File("/"+ nome + ".script");
f3.delete();
File f4 = new File("/"+ nome + ".properties");
f4.delete();
File f5 = new File("/"+ nome + ".owl");
f5.delete();
File f6 = new File("/"+ nome + ".log");
f6.delete();
File f7 = new File("/"+ nome + "Log.log");
f7.delete();
}

}

Thanks for ur help!

Comments

EJP Feb 14 2007
while (fIS.available()>0)
    fOS.write(fIS.read()); 
Don't do that. Do this:
int count;
byte[] buffer = new byte[8192];
while ((count = fIS.read(buffer) > 0)
    fOS.write(buffer, 0, count); 
Somewhere else you have this:
man = null;
man.shutdown();
A NullPointerException just waiting to happen.

No idea if any of this will fix your original problem ;-)
807606 Feb 15 2007
I changed the while loop into what u suggested, but it still gives me the same warning...and the file still gets erased...
I really have no clue why that happens...
i am starting to think it might be a problem in the way i access the file...:((
807606 Feb 16 2007
How is it possible that my code erases the file i am uploading...i've been surfing the web the whole morning here and i couldn't find any other example of this bug...i still get that warning and that's the only clue i have

The .owl file i need to upload the ontology are usually 200Kb and after i finish uploading they become 8 or 20 Kb...where do the other bytes of chars go??

If u need me to post other code cause u don't understand my question just tell me...
Help please!
1 - 3
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Mar 16 2007
Added on Feb 14 2007
3 comments
1,222 views