Servlet only run once !
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   lionel_lemaire
Posted On:   Tuesday, April 20, 2004 08:54 AM

Did I forget anything or what ? The first request everything works fine, on the second request nothing happens, it just sleeps like nobody asked anything. As you can see I thaught it might be a memory issue so I used the System.gc() in the end of the doGet method. nothing happened...help ! import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.*; import be.certipost.eidtestcards.samples.validator.EIDValidator; import be.certipost.eidtestcards.samples.Credential; import java.util.*; import java.io.*; import java.beans.*; import java.security.*; import java.security.cert.*; import java.security.cert.X509   More>>

Did I forget anything or what ? The first request everything works fine, on the second request nothing happens, it just sleeps like nobody asked anything. As you can see I thaught it might be a memory issue so I used the System.gc() in the end of the doGet method. nothing happened...help !

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import be.certipost.eidtestcards.samples.validator.EIDValidator;
import be.certipost.eidtestcards.samples.Credential;



import java.util.*;
import java.io.*;
import java.beans.*;



import java.security.*;
import java.security.cert.*;
import java.security.cert.X509Certificate;
import iaik.asn1.structures.*;
import iaik.cms.*;
import iaik.utils.*;



public class verify extends HttpServlet {
static EIDValidator validator;
static SignedDataStream sds;
Integer length;
String validation;
String result_validation;
boolean verified;
String signername;
String serialnumber;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");



Enumeration paramNames = request.getParameterNames();
String paramName = (String) paramNames.nextElement();
System.out.println(paramName);
System.out.println("-------------------");
Integer length_input = new Integer(request.getHeader("Content-Length"));
String ret = "";
// let's fetch the base64 encoded signature from the applet
String data_recup = new String(paramName);
// now let's get the length in order to be able to decode it

// can't cast from string to int but from String to Integer it's ok

// decoding
// watch out, we don't want a String, we want a byte array (hi Omer !)

String base64 = new String(paramName);
ByteArrayInputStream fis = new ByteArrayInputStream(base64.getBytes());
Base64InputStream base64is = new Base64InputStream(fis);
byte[] data = new byte[length_input.intValue()];

// String result = "";
int r;
try {
while ((r = base64is.read(data)) != -1) {
//the old xml is stored in String result for processing
System.out.println(new String(data));
// result = new String(data);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

//The signature data from the applet is now stored in the byte[] data
// which we will give to the SignedDataStream in order to verify it

try {
sds = new SignedDataStream(new ByteArrayInputStream(data));

InputStream in = sds.getInputStream();
// FileOutputStream fos3 = new FileOutputStream("c:\temp2.txt");
byte[] buffer = new byte[1000];
for (int readed = 0;(readed = in.read(buffer)) >= 0;) {

//uncomment this to extract the original data to a file

// if (fos3 != null)
// fos3.write(buffer, 0, readed);
}

// if (fos3 != null) {
// fos3.flush();
// fos3.close();
// }

} catch (Exception e) {
verified = false;
e.printStackTrace();
}
SignerInfo[] infos = sds.getSignerInfos();

for (int i = 0; i < infos.length; i++) {
try {
X509Certificate signer = sds.verify(i);
// System.out.println(
// "Signature "
// + i
// + " verified ("
// + signer.getSubjectDN().getName()
// + ")");
ret =
"Signature "
+ i
+ " verified ("
+ signer.getSubjectDN().getName()
+ ")";
verified = true;
System.out.println(ret);
result_validation = signer.getSubjectDN().getName();
signername =
result_validation.substring(
result_validation.indexOf("givenName=")
+ "givenName=".length(),
result_validation.indexOf(",SN"));
serialnumber =
result_validation.substring(
result_validation.indexOf("serialNumber=")
+ "SerialNumber=".length(),
result_validation.indexOf(",givenName="));

try {
validator.validateChain(new X509Certificate[] { signer });
} catch (Exception d) {
System.out.println(
"Invalid signer certificate : " + d.getMessage());
validation =
"Invalid signer certificate : " + d.getMessage();
System.gc();

}

} catch (SignatureException se) {
System.out.println("Signature " + i + " not verified");

} finally {
System.out.println("let's clean up everything");
System.gc();
response.reset();
}
}
System.gc();
response.reset();
}

public void doPost(
HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
response.setContentType("text/xml");
ServletOutputStream out = response.getOutputStream();
out.println(
" "
+ verified
+ " "
+ Increment.getI()
+ " "
+ " "
+ signername
+ " "
+ " "
+ serialnumber
+ " "
+ " ");

}
}    <<Less

Re: Servlet only run once !

Posted By:   Eelco_Cramer  
Posted On:   Tuesday, April 27, 2004 08:22 AM

Try to repost your question using
 and  tags to format your code block. I can't make anything off this mess... Sorry.
About | Sitemap | Contact