holger Hahn

Greenhorn
+ Follow
since Jun 14, 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 holger Hahn

Hi
I'm a beginner in servlet - applet programming

I use an servlet which communicate with an applet over HTTP.
the servlet should send an byte array (represents an png.File) to the applet.(The byte Array comes from an EJB (HelperSession)
I use an DataOutputStream to send this byteArray.
While sending this Byte Array I get the following Exception:

Client Abort Exception:
java.net.SocketException: Software caused connection abort write Error

Please Help me to solve thge problem

Here is the Code:


----------------Applet----------------


private void getFiles() {

// ben�tigte ByteArrays
byte [] picBytes = null;
byte [] keyBytes = null;
SecretKey keyHolder = null;

String docID = getParameter("documentID");
String docSubID = getParameter("documentSubID");

buf.append("docID:" +docID);
buf.append("docSubID: "+docSubID);

try {
URL url = new URL(getCodeBase(),"helper?param=file&docID="+docID+"&docSubID="+docSubID);
buf.append("CodeBase: "+getCodeBase());
URLConnection uc = url.openConnection();
uc.setUseCaches(false);
uc.setDoInput(true);
uc.setDoOutput(false);
DataInputStream dis = new DataInputStream(uc.getInputStream());
int size = dis.readInt();
picBytes = new byte[size];

dis.read(picBytes,0,picBytes.length);

dis.close();

} catch (MalformedURLException mue){
buf.append("MalformedURLException: "+mue.getMessage());
} catch (IOException e) {
buf.append("IOException: "+e.getMessage());

}

try {
URL url2 = new URL(getCodeBase(),"helper?param=key&docID="+docID+"&docSubID="+docSubID);
URLConnection uc2 = url2.openConnection();

uc2.setUseCaches(false);
uc2.setDoInput(true);
uc2.setDoOutput(false);

DataInputStream dis = new DataInputStream(uc2.getInputStream());
int size = dis.readInt();
keyBytes = new byte[size];
int j=0;
dis.read(keyBytes,0,size);

dis.close();
buf.append("Gr��e keybytes: "+size);
System.out.println("Gr��e keybytes: "+size);
this.buf.append("L�nge keyBytes in Applet: "+keyBytes.length);


} catch (MalformedURLException mue){
buf.append("MalformedURLException: "+mue.getMessage());
} catch (IOException e) {
buf.append("IOException: "+e.getMessage());

}
keyHolder = new SecretKeySpec(keyBytes,"DESede");
//byte [] decBytes = decrypt.decryptByteArray(picBytes,keyHolder);
//buf.append("L�nge decBytes: "+decBytes.length);


image = Toolkit.getDefaultToolkit().createImage(picBytes,0,picBytes.length);

}//end getFiles


------------Servlet---------------



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


HelperSessionLocal hsl = null;
param = request.getParameter("param");
System.out.println("Parameter param: "+param);
String docID = request.getParameter("docID");
System.out.println("DocumentID: "+docID);
String docSubID = request.getParameter("docSubID");
System.out.println("DocumentSubID: "+docSubID);
response.setContentType("application/octet-stream");

try {
hsl = hslh.create();
}catch (CreateException ce){
System.out.println("Create Exception in HelperSession!"+
"\nFehler: "+ce.getMessage());
}
try {

if (param.equals("file")){

// picBytes = new byte[(int)hsl.getFile(docID,docSubID).length];
byte [] picBytes = hsl.getFile(docID,docSubID);
System.out.println("picBytes geholt:");
System.out.println("L�nge picBytes in HelperServlet: "+picBytes.length);
response.setContentLength(picBytes.length);
System.out.println("l�nge nach Konvertierung in int"+(int)picBytes.length);
DataOutputStream dos = new DataOutputStream(response.getOutputStream());
dos.writeInt(picBytes.length);
System.out.println("L�nge PicBytes geschrieben: "+(int)picBytes.length);
dos.write(picBytes,0,picBytes.length);
dos.flush();
dos.close();
System.out.println("picBytes geschrieben");



}else if (param.equals("key")){
//keyBytes = new byte[(int)hsl.getFileKey(docID,docSubID).length];
byte []keyBytes = hsl.getFileKey(docID,docSubID);
System.out.println("Keybytes geholt");
response.setContentLength(keyBytes.length);
System.out.println("L�nge keyBytes in HelperServlet: "+keyBytes.length);
DataOutputStream dos = new DataOutputStream(response.getOutputStream());
dos.writeInt(keyBytes.length);
System.out.println("L�nge keyBytes geschrieben"+(int)keyBytes.length);
dos.write(keyBytes,0,keyBytes.length);
dos.flush();
dos.close();
System.out.println("keyBytes geschrieben");

}//end elseif


}catch (IOException e){
System.out.println("IOException in HelperServlet: "+e.getMessage()
+e.getCause());


}catch (Exception e ){
System.out.println("Exception in HelperServlet: "+e.getMessage());

}



}


Thanks for your support in advance
18 years ago
Hello again

i searched in google but i don't find an article for what i need

it is just simple what i want to do. I will explain

I have a servlet which gets an byte array from an Session bean (the byte array contains a png.File) and i only want to send this byte array to the applet. How to do this.

please help me its urgent
18 years ago
Hi @ all

I have a problem to send two byte Arrays from an servlet to an applet

I know i have to use UrlConection and then maybe ObjectOutputstream but i don't know how to serialized the byte Array.

Is it posssible to use ByteArrayOutputStream instead of ObjectOutputStream

any code sugesstions?

Thanks in advance
18 years ago
Hi @ all

I've got a problem while converting from tiff to png

here is the code and the exception
Does annybody know what the error Bad endianness tag mean
or the Error: One factory fails for the operation "tiff"
Occurs in: javax.media.jai.ThreadSafeOperationRegistry

here is the source code and the exceptions I use an ByteInputstream (ByteArraySeekableStream)

public class TestConvert {
public static void main(String []args) {
TestConvert tc = new TestConvert();
String result = tc.ConvTifPng();
System.out.println(result);
}

private String ConvTifPng(){
String sourcefilename = "4711_2.tif";
String targetfilename = "4711_2b.PNG";
File dstFile = new File("d:\\4711_2c.png/");
File srcFile = new File (sourcefilename);
byte picBytes [] = new byte [(int)srcFile.length() ];
ByteArrayOutputStream bs = new ByteArrayOutputStream();
try {

ByteArraySeekableStream bass =
new ByteArraySeekableStream picBytes);

ParameterBlock params = new ParameterBlock();
params.add(bass);
//Specify to TIFF decoder to decode images as they are and
//not to convert unsigned short images to byte images.
TIFFDecodeParam decodeParam = new TIFFDecodeParam();
decodeParam.setDecodePaletteAsShorts(true);
//Create an operator to decode the TIFF file.

RenderedOp image1 = JAI.create("tiff", params);
System.out.println("nach RenderedOP!");
//Find out the first image�s data type.

int dataType = image1.getSampleModel().getDataType();
RenderedOp image2 = null;
System.out.println("nach getSampleModel!");
if (dataType == DataBuffer.TYPE_BYTE) {
//Display the byte image as it is.
System.out.println("TIFF image is type byte.");
image2 = image1;
} else if (dataType == DataBuffer.TYPE_USHORT) {
//Convert the unsigned short image to byte image.
System.out.println("TIFF image is type ushort.");
//Setup a standard window-level lookup table. */
byte[] tableData = new byte[0x10000];
for (int i = 0; i < 0x10000; i++) {
tableData[i] = (byte)(i >> 8);
}
//Create a LookupTableJAI object to be used with the
//�lookup� operator.
LookupTableJAI table = new LookupTableJAI(tableData);
//Create an operator to lookup image1.
image2 = JAI.create("lookup", image1, table);
} else {
System.out.println("TIFF image is type" + dataType +
", and will not be displayed.");
System.exit(0);
}
// Get the width and height of image2.
int width = image2.getWidth();
int height = image2.getHeight();
System.out.println("width: " + width);
System.out.println("height: " + height);
JAI.create("encode",image2,bs,"PNG",null);



System.out.println("size of ByteArrayOutputStream"+ bs.size());
byte [] bytes = new byte[(int)bs.size()];

System.out.println("write bytes!");
bs.write(bytes);
FileOutputStream fos = new FileOutputStream(dstFile);
fos.write(bytes);
bs.close();
fos.close();

} catch (IOException e1) {
System.out.println("IOException: " + e1.getMessage());
e1.printStackTrace();
}

return "convert successfully";
}
}




Exception:
Error: One factory fails for the operation "tiff"
Occurs in: javax.media.jai.ThreadSafeOperationRegistry
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at javax.media.jai.FactoryCache.invoke(FactoryCache.java:130)
at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1682)
at javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:481)
at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:340)
at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:830)
at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:878)
at javax.media.jai.RenderedOp.getSampleModel(RenderedOp.java:2244)
at TestConvert.ConvTifJpg(TestConvert.java:67)
at TestConvert.main(TestConvert.java:40)
Caused by: java.lang.IllegalArgumentException: Bad endianness tag (not 0x4949 or 0x4d4d).
at com.sun.media.jai.codec.TIFFDirectory.getNumDirectories(TIFFDirectory.java:588)
at com.sun.media.jai.codecimpl.TIFFImageDecoder.getNumPages(TIFFImageDecoder.java:105)
at com.sun.media.jai.codecimpl.TIFFImageDecoder.decodeAsRenderedImage(TIFFImageDecoder.java:109)
at com.sun.media.jai.opimage.CodecRIFUtil.create(CodecRIFUtil.java:96)
at com.sun.media.jai.opimage.TIFFRIF.create(TIFFRIF.java:53)
... 13 more
javax.media.jai.util.ImagingException: All factories fail for the operation "tiff"
at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1695)
at javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:481)
at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:340)
at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:830)
at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:878)
at javax.media.jai.RenderedOp.getSampleModel(RenderedOp.java:2244)
at TestConvert.ConvTifJpg(TestConvert.java:67)
at TestConvert.main(TestConvert.java:40)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at javax.media.jai.FactoryCache.invoke(FactoryCache.java:130)
at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1682)
... 7 more
Caused by: java.lang.IllegalArgumentException: Bad endianness tag (not 0x4949 or 0x4d4d).
at com.sun.media.jai.codec.TIFFDirectory.getNumDirectories(TIFFDirectory.java:588)
at com.sun.media.jai.codecimpl.TIFFImageDecoder.getNumPages(TIFFImageDecoder.java:105)
at com.sun.media.jai.codecimpl.TIFFImageDecoder.decodeAsRenderedImage(TIFFImageDecoder.java:109)
at com.sun.media.jai.opimage.CodecRIFUtil.create(CodecRIFUtil.java:96)
at com.sun.media.jai.opimage.TIFFRIF.create(TIFFRIF.java:53)
... 13 more
Exception in thread "main"
18 years ago
Oh Sorry
I will specify what I mean

i have an getter and setter method in my Entity Bean. The parameter of the getter and setter is an byte array. (public abstract byte [] getPicData (); and public abstract void setPicData(byte [] picData);
I use Jboss application Server V4.0 and MySQL V.4
When I read a file in png-Format from the client and write it with the help of my Entity Bean in the database (use CMP). The problem is that the file is 200kb befor i write it in the database and 63kb (65565bytes) when i get it from the database. I don't know why

Please help me
Hi

Does anybody know how to encrypt and decrypt an png-file with TripleDES
(sample code)

thanks for support
18 years ago
Please help me,

I don't know ho to get a tiff-file into an Blob to write it in an DataBase with entity Beans. Can someone give an code example?
Thanks
Hi @all

Is there anybody who can give an code example how to convert a tiff-File to an png with JAI API? The problem is that i need the png not as a file but in an byte arry to encrypt the file at runtime after the convertion

Thank you for your suppor
18 years ago
Hello

I work on a project and we use Enterprise Java Beans with MySql database
The problem is that one table has two primary Keys but in the entity Beans only one primary Key class can be implemented. How to solve the problem if there are more than one primary key

thank you for your support