Skip to Content
0
Former Member
Dec 01, 2008 at 04:51 PM

Can't fill ByteArray in EJB-Method with generated Model-Class from WD-Model

26 Views

Hello everybody,

i try to call an ejb-method with data from an FileUpload-UI-Element in WD. The EJB-Method is receiving the byte-data to create a document in KM via a Web-Service.

The ebj-methid has the following signature:

public FObject putFileDataSimple (byte [] btContent, String fullFileName, String username, String password) 

After importing the Model and creating a context node i have the following structure:

Request_X_putFileDataSimple
+---btContent (Node)
      +-- item
+ fullFileName
+ username
+ password

btContent is of the generated Type Byte_Item, which is itself a generated Model-Class of modelClassType ARRAY

item is of Type byte

But i simply have problems to fill the context node (or the binded model-object). i tried different ways and looked at thread [https://www.sdn.sap.com/irj/scn/thread?messageID=1954223] but i cant get it work.

So my Method in WD looks like this to fill the structure and start the ejb-method:

public boolean putKMDataSimple( com.sap.tc.webdynpro.services.sal.datatransport.api.IWDResource fin )  {
try
{
  wdContext.currentRequest_X_putFileDataSimpleElement().setFullFileName("abc");
  wdContext.currentRequest_X_putFileDataSimpleElement().setUsername("def");
  wdContext.currentRequest_X_putFileDataSimpleElement().setPassword("xxx");
  byte[] buffer = new byte[1];
  InputStream in = fin.read(false);
  int i = 1;
  int j = 0;
  while (i!=-1)
     {
     i = in.read(buffer);
     if (i!=-1)
          {
	  Byte_Item bi = new Byte_Item(mAlf);     // mAlf ist global defined Model-Class-Instance
	  bi.setItem(buffer[0]);
	   wdContext.currentRequest_X_putFileDataSimpleElement().modelObject().addBtContent(bi);
	  }
  }
  wdContext.currentRequest_X_putFileDataSimpleElement().modelObject().execute();
}  

Doing this results in Error-Messages like:

Model-Object is not a complex type for every byte added this way.

And finally an IllegalArgumentException at java.lang.reflect.Array.set(Native Method)

The second way i tried is:

public boolean putKMDataSimple( com.sap.tc.webdynpro.services.sal.datatransport.api.IWDResource fin )  {
try
{
  wdContext.currentRequest_X_putFileDataSimpleElement().setFullFileName("abc");
  wdContext.currentRequest_X_putFileDataSimpleElement().setUsername("def");
  wdContext.currentRequest_X_putFileDataSimpleElement().setPassword("xxx");
  byte[] buffer = new byte[1];
  ArrayList<Byte> btlist = new ArrayList<Byte>();
  InputStream in = fin.read(false);
  int i = 1;
  int j = 0;
  while (i!=-1)
     {
     i = in.read(buffer);
     if (i!=-1)
          {
          btList.add(buffer[0]);
	  }
  }
  wdContext.currentRequest_X_putFileDataSimpleElement().modelObject().setBtContent(btList);
  wdContext.currentRequest_X_putFileDataSimpleElement().modelObject().execute();
}  

Trying so results in:

java.lang.ClassCastException: class java.lang.Byte:null incompatible with interface com.sap.tc.cmi.model.ICMIModelClass:library:com.sap.tc.cmi(at-sign)com.sap.engine.boot.loader.ResourceMultiParentClassLoader@da4a1c9@alive

whenn calling the setBtContent Method

I don't what to do now to fill the context/model-object the right way.

Any helpfull hints are very welcome 😊

Edited by: Matthias Hayk on Dec 1, 2008 5:51 PM

Edited by: Matthias Hayk on Dec 2, 2008 10:56 AM