473,549 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sending Image bytes through Java webservice

2 New Member
Hello All,

Scenario: Sending an image through webservice as byte array to an Java webservice.

The Problem1: The webservice method image property expects (data type) SByte rather than Byte array. Thus i'm converting a byte array to sbyte array and sending through web service. The converted SByte contains negative numbers wihch are resulting in an error "java.lang.Arra yIndexOutOfBoun dsException: -106"

Byte[] => SByte[]...error "java.lang.Arra yIndexOutOfBoun dsException: -106"

The Problem2: Also if i before converting Byte array to SByte array Encode the the Byte array and then later convert to Sbyte then the java web service method save the file on the server but it isn't recognised as an Image type file.

Byte[] => Encode base64 => SByte...Saved file isn't an Image(valid/original) file type.

If any one have dealth with similar set of situtation before, kindly post your answer.

-106
java.lang.Array IndexOutOfBound sException: -106
at org.apache.comm ons.codec.binar y.Base64.isBase 64(Base64.java: 137)
at org.apache.comm ons.codec.binar y.Base64.discar dNonBase64(Base 64.java:478)
at org.apache.comm ons.codec.binar y.Base64.decode Base64(Base64.j ava:374)
at com.recare.ws.s canning.Scanned PageWTO.initDTO (Unknown Source)
at com.recare.ws.s canning.Scanned DocWTO.initDTO( Unknown Source)
at com.recare.ws.s canning.ScanDoc WebService.save NewDocument(Unk nown Source)
at com.recare.ws.s canning.ScanDoc WebServiceImpl. saveNewDocument (Unknown Source)
at com.recare.ws.s canning.ScanDoc WebServiceMessa geReceiverInOut .jibxReceiver0( Unknown Source)
at com.recare.ws.s canning.ScanDoc WebServiceMessa geReceiverInOut .invokeBusiness Logic(Unknown Source)
at org.apache.axis 2.receivers.Abs tractInOutMessa geReceiver.invo keBusinessLogic (AbstractInOutM essageReceiver. java:40)
at org.apache.axis 2.receivers.Abs tractMessageRec eiver.receive(A bstractMessageR eceiver.java:10 0)
at org.apache.axis 2.engine.AxisEn gine.receive(Ax isEngine.java:1 76)
at org.apache.axis 2.transport.htt p.HTTPTransport Utils.processHT TPPostRequest(H TTPTransportUti ls.java:275)
at org.apache.axis 2.transport.htt p.AxisServlet.d oPost(AxisServl et.java:133)
at javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java:709)
at javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java:802)
at org.apache.cata lina.core.Appli cationFilterCha in.internalDoFi lter(Applicatio nFilterChain.ja va:252)
at org.apache.cata lina.core.Appli cationFilterCha in.doFilter(App licationFilterC hain.java:173)
at org.apache.cata lina.core.Stand ardWrapperValve .invoke(Standar dWrapperValve.j ava:213)
at org.apache.cata lina.core.Stand ardContextValve .invoke(Standar dContextValve.j ava:178)
at org.apache.cata lina.core.Stand ardHostValve.in voke(StandardHo stValve.java:12 6)
at org.apache.cata lina.valves.Err orReportValve.i nvoke(ErrorRepo rtValve.java:10 5)
at org.apache.cata lina.core.Stand ardEngineValve. invoke(Standard EngineValve.jav a:107)
at org.apache.cata lina.connector. CoyoteAdapter.s ervice(CoyoteAd apter.java:148)
at org.apache.coyo te.http11.Http1 1Processor.proc ess(Http11Proce ssor.java:856)
at org.apache.coyo te.http11.Http1 1Protocol$Http1 1ConnectionHand ler.processConn ection(Http11Pr otocol.java:744 )
at org.apache.tomc at.util.net.Poo lTcpEndpoint.pr ocessSocket(Poo lTcpEndpoint.ja va:527)
at org.apache.tomc at.util.net.Lea derFollowerWork erThread.runIt( LeaderFollowerW orkerThread.jav a:80)
at org.apache.tomc at.util.threads .ThreadPool$Con trolRunnable.ru n(ThreadPool.ja va:684)
at java.lang.Threa d.run(Thread.ja va:595)

Thanks in advance
Ksheera Sagar
Jul 4 '09 #1
2 9772
ksheerasagar17
2 New Member
Ahh God !! Thank u... i figured it out at last and also thanks to my Project Manager. I re-Tried the a code snipet sent by him. The funda being it is absolutely possible to send an image as bytes through a webservice but if encoded correctly.
In my case i had to send in image as sbytes rather than bytes.
Below is the code snipet which Encodes byte array to Base64 and returns/converts the byte array to sbyte array.

Hope it works for u as well.

Expand|Select|Wrap|Line Numbers
  1.  /// <summary>
  2.         /// Encodes a byte array to Base64 and returns an sbyte array
  3.         /// </summary>
  4.         /// <param name="data">byte array</param>
  5.         /// <returns>sbyte array</returns>
  6.         public sbyte[] ToBase64SbyteFrombyte(byte[] data)
  7.         {
  8.             int length = data == null ? 0 : data.Length;
  9.             //if (length == 0)
  10.             //    return String.Empty;
  11.  
  12.             int padding = length % 3;
  13.             if (padding > 0)
  14.                 padding = 3 - padding;
  15.             int blocks = (length - 1) / 3 + 1;
  16.  
  17.             sbyte[] s = new sbyte[blocks * 4];
  18.  
  19.             for (int i = 0; i < blocks; i++)
  20.             {
  21.                 bool finalBlock = i == blocks - 1;
  22.                 bool pad2 = false;
  23.                 bool pad1 = false;
  24.                 if (finalBlock)
  25.                 {
  26.                     pad2 = padding == 2;
  27.                     pad1 = padding > 0;
  28.                 }
  29.  
  30.                 int index = i * 3;
  31.                 byte b1 = data[index];
  32.                 byte b2 = pad2 ? (byte)0 : data[index + 1];
  33.                 byte b3 = pad1 ? (byte)0 : data[index + 2];
  34.  
  35.                 byte temp1 = (byte)((b1 & 0xFC) >> 2);
  36.  
  37.                 byte temp = (byte)((b1 & 0x03) << 4);
  38.                 byte temp2 = (byte)((b2 & 0xF0) >> 4);
  39.                 temp2 += temp;
  40.  
  41.                 temp = (byte)((b2 & 0x0F) << 2);
  42.                 byte temp3 = (byte)((b3 & 0xC0) >> 6);
  43.                 temp3 += temp;
  44.  
  45.                 byte temp4 = (byte)(b3 & 0x3F);
  46.  
  47.                 index = i * 4;
  48.                 s[index] = (sbyte)SixBitToChar(temp1);
  49.                 s[index + 1] = (sbyte)SixBitToChar(temp2);
  50.                 s[index + 2] = (sbyte)(pad2 ? '=' : SixBitToChar(temp3));
  51.                 s[index + 3] = (sbyte)(pad1 ? '=' : SixBitToChar(temp4));
  52.             }
  53.  
  54.             return s;
  55.         }
  56.  
  57.         static private char SixBitToChar(byte b)
  58.         {
  59.             char c;
  60.             if (b < 26)
  61.             {
  62.                 c = (char)((int)b + (int)'A');
  63.             }
  64.             else if (b < 52)
  65.             {
  66.                 c = (char)((int)b - 26 + (int)'a');
  67.             }
  68.             else if (b < 62)
  69.             {
  70.                 c = (char)((int)b - 52 + (int)'0');
  71.             }
  72.             else if (b == 62)
  73.             {
  74.                 c = s_CharPlusSign;
  75.             }
  76.             else
  77.             {
  78.                 c = s_CharSlash;
  79.             }
  80.             return c;
  81.         }
  82.  
  83.         static private char s_CharPlusSign = '+';
  84.  
  85.         /// <summary>
  86.         /// Gets or sets the plus sign character.
  87.         /// Default is '+'.
  88.         /// </summary>
  89.         static public char CharPlusSign
  90.         {
  91.             get
  92.             {
  93.                 return s_CharPlusSign;
  94.             }
  95.             set
  96.             {
  97.                 s_CharPlusSign = value;
  98.             }
  99.         }
  100.  
  101.         static private char s_CharSlash = '/';
  102.  
  103.         /// <summary>
  104.         /// Gets or sets the slash character.
  105.         /// Default is '/'.
  106.         /// </summary>
  107.         static public char CharSlash
  108.         {
  109.             get
  110.             {
  111.                 return s_CharSlash;
  112.             }
  113.             set
  114.             {
  115.                 s_CharSlash = value;
  116.             }
  117.         }
Jul 9 '09 #2
Simply ad 128 if SByte Value is negative

Byte lByte
If (sByteValue < 0)
lByte = sByteValue+128
Oct 2 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
3462
by: Kumar T via .NET 247 | last post by:
Could you please explain me the steps for consuming JavaWebservice through .NET client. I know how to connect through.NET webservice and I followed the same steps for this, but itdid not work out. In the Add web reference dialog I entered theJava webservice url, it returned the Messages "Sorry, I don'tspeak via HTTP GET- you have to use HTTP...
7
4967
by: Christian Wilhelm | last post by:
Hi! I'm trying to call a Java WebService out of a .net Client. There are two Methods, one Method requires one Parameter of type Parameter, the other Method requires one Parameter of type Parameter. I can call the first Method without Problems, the Parameter can be deserialized by the WebService. But if I want to call the second Method and...
4
21374
by: luckyabhishek | last post by:
Hi I am using a java webservice in a .NET application. The xml type of a field in this webservice is xsd:datetime. When i call the webservice from the application i get a deserialization error on the java webservice side. It says "Can not create instance of from string with schema type http://www.w3.org/2001/XMLSchema]". Can anyone let me...
2
1952
by: Pablo | last post by:
Hi at all! How can i send a DATA (not a DataTime) Type to a Java WebService? In .NET we have only a DataTime that is incompatible with the Data (calendar) Type of Java! How can i resolve this problem? I can't modify the java web-service and i need to send a simple data!!! AAARGH :P Help me! Tnx at all!
0
1165
by: Andrej | last post by:
hi, i have a java webservice which i would like to invoke from .net Application. i am able to generate the proxy class, but if i try to invoke the webservice i got an exception of type "java.lang.Nullpointer". if i run the webservice in the debugmode i got an exception: Message="Tried to invoke method public byte...
2
1832
by: zmbharmal | last post by:
I have a .NET client My vendor has a Axis/Java Webservice I am able to pass the parameters to their webmethod. They can read it. When they return a Response, it is coming as NULL. The webservice from the vendor is sending the right SOAP response and it is logged by the vendor. What have I tried so far to resolve: First i was creating the...
0
1228
jeffbroodwar
by: jeffbroodwar | last post by:
hi, i need help about consuming webservice created in java with vb6. i've created the webservice in netbeans with sun java server bundle and used MS Soap toolkit 3.0 on the client side. i've attached the sample client source code in vb6 : __________________________________________________________________ '********************* Created...
2
2779
jeffbroodwar
by: jeffbroodwar | last post by:
hi, i need help about consuming webservice created in java with vb6. i've created the webservice in netbeans with sun java server bundle and used MS Soap toolkit 3.0 on the client side. i've attached the sample client source code in vb6 : __________________________________________________ ________________ '********************* Created...
3
6113
by: zion | last post by:
Hello, How can I return image link with webservice that I could see it in web page? The image is on my hard disk and <img src="c:\pictures\test.jpg" /does not work. If I use <img src=http://My comuter/Virtual directory/test.jpg /it's working but I can't use this because the image path is in DB with phisycal location. Thanks
0
7451
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7720
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7810
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5369
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3501
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3483
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1944
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
764
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.