From: Jochen S. <sc...@ec...> - 2009-05-12 16:33:39
|
Hi, for my first experience with xins I have create a small service for ocr. As first step I upload a file and store it to a local folder. I declare a function GetText that accept a file as base64 or hex. If I upload the file with hex, everything is fine. If I try it with base64 in most case the file is dammaged. Here a little bit code to see what I'm doing: -----------GetText.fnc---------------- <function name="GetText"> <description>...</description> <input> <param name="documentName" required="true" type="_text"> <description>Der Name der uebergebenen Datei.</description> </param> <param name="documentContentHex" required="false" type="_hex"> <description>HEX-Format.</description> </param> <param name="documentContentBase64" required="false" type="_base64"> <description>Base64-Format.</description> </param> <param-combo type="exclusive-or"> <param-ref name="documentContentHex" /> <param-ref name="documentContentBase64" /> </param-combo> </input> [...] ----------------GetTextImpl.java------- public Result call(Request request) throws Throwable { String FileName = getDestinationFile(request.getDocumentName()); byte[] fileContent = null; if (request.isSetDocumentContentBase64()) { fileContent = request.getDocumentContentBase64(); } else { fileContent = request.getDocumentContentHex(); } String destinationDir = "c:\\temp"; File inputFile = new File(destinationDir, FileName); FileOutputStream fos = new FileOutputStream(inputFile); fos.write(fileContent); fos.close(); ...... ---- my small perl script as client ----------- #!/usr/bin/perl use MIME::Base64; use LWP::UserAgent; my $ua = LWP::UserAgent->new; my $req = HTTP::Request->new(POST => 'http://192.168.130.12:80/ocr/'); $req->content_type('application/x-www-form-urlencoded'); my $filename = "test.pl"; # Just send your self open(INPUTFILE, "< $filename"); binmode(INPUTFILE); my $content=""; while (<INPUTFILE>) { my $strBytes = $_; $content .= $strBytes; } close(INPUTFILE); print encode_base64($content); # Debug output $req->content('_function=GetText&documentName='.$filename.'&documentContentBase64='.encode_base64($content)); --------------------------------- I just send my testscript to the server, but what I get at serversite was this: --------------------------------- #!/usr/bin/perl use MIME::Base64; use LWP::UserAgent; # Create a user agent object my $ua = LWP::UserAgent-^(TM)]ÎÂ,^ÈÜ^(TM)X] [.. lot's mor bin stuff...] ¹Ð¤¤ì('É.Ä´content('_function=GetText&documentName='.$filename.'&documentContentBase64='.encode_base64($content)); # Pass request to the user agent and get a response back my $res = $ua-^(TM)\]Y\Ý ^(TM)\JNÂ,^ÈÚXÚÈ --------------------------------- It looks like that I get a problem everytime if a ">" is encoded in the base64. The base64 itself is clean, there is no problem, but I don't understand what's problem is with an encoded ">", because IMHO xins should nothing interpretate at the variable after decoding, just store it into a variable. (remember, everything works fine with HEX) I use XINS 2.2, deployed on tomcat 6 under Windows and running on java 1.6.0_13 . Any idea what's wrong? Best regards, Jochen |