Skip to Content

NB: This procedure has been tested in a SAP XI 3.0 SP 14 environment; I think it could easily be adapted to other release (PI 7.0/7.1), but not tested yet

I get disappointed when I realized that I couldn’t generate ABAP Proxy from Message Interface referencing an External Imported message(e.g via XSD, for instance)…I was needing it absolutely!!! 

So, I did a lot of reverse engineering…and I wrote a simple java webDynpro application that generated the data type from an XSD schema (with some arrangements, as stated below)

Let’s examine the solution point-by-point:

 1 – the XSD schema

your xsd file could look like the one below, according to the W3C standards:

image

As you can see, the element is declared as *’REF=…’, *use a simple text editor to replace this declaration with the *’TYPE=…’ *statement:

image

This is necessary to create the right xsd schema element on XI.

After that, you can begin to create your web dynpro.

2 – Create a new java WebDynpro project

Use SAP NWDS to create a new webdynpro project that should have the following PROPERTIES:

WEB DYNPRO REFERENCES

Declare references to the following libraries and services:

image

image

image

EDIT JAVA BUILD PATH

Insert the following library inside the java build path:

image

The RM…libraries are located usually in your local machine under: C:\Documents and Settings\Application Data\Sun\Java\Deployment\javaws\cache\http\D\P\DMrep\DMrepositoryDeclare all of them as ‘String‘ except for the ‘bindata’ (the content of your xsd file to be uploaded) which must be ‘binary

Bind the context components to the layout controls:

namespace-InputField

username-InputField 

password-InputField (password field)

swdc-

InputField

log-TextEdit

Insert also a FileUpload control that must be bounded to your *bindata *context components and also a BUTTON named ‘Run’ which must raise an action ‘run’ when pressed.

My webDynpro looks like this:

image

In the onActionRun function you should paste the following code: 

  public void onActionrun(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

  {

    //@@begin onActionrun(ServerEvent)

     IWDAttributeInfo attributeInfo =

     wdContext.getNodeInfo().getAttribute(

     IPrivateWdXiXsd2DTView.IContextElement.BINDATA);

//        get modifiable binary type from the attribute info,

//        requires type cast.

     IWDModifiableBinaryType binaryType =

     (IWDModifiableBinaryType) attributeInfo.getModifiableSimpleType();

     IPrivateWdXiXsd2DTView.IContextElement element =

     wdContext.currentContextElement();

//        if a file in the ‘FileResource’ attribute exists

     if (element.getBindata() != null) {

     try {

     String mimeType = binaryType.getMimeType().toString();

     byte[] file = element.getBindata();

//        get the size of the uploaded file

//     element.setFileSize(this.getFileSize(file));

////        get the extension of the uploaded file

//     element.setFileExtension(

//     binaryType.getMimeType().getFileExtension());

////        NOTE: context attribute ‘FileName’ must not be set

////        because the FileUpload-UI-element property ‘fileName’

////        is bound to it. Consequently the fileName is automatically

////        written to the context after file upload.

////        set the details visibility attribute

//     element.setDetailsVisibility(WDVisibility.VISIBLE);

//        report success message

//     wdComponentAPI.getMessageManager().reportMessage(

//     IMessageFileUpDownloadComp.SF_UPLOAD,

//     new Object[] { binaryType.getFileName()},

//     false);

     } catch (Exception e) {

     throw new WDRuntimeException(e);

     }

     }

//        if no file in the ‘FileResource’ attribute exists

     else {

//        set the details visibility attribute, hide details

//     element.setDetailsVisibility(WDVisibility.NONE);

//        report error message

     IWDMessageManager msgMgr = wdComponentAPI.getMessageManager();

//     msgMgr.reportContextAttributeMessage(

//     element,

//     attributeInfo,

//     IMessageFileUpDownloadComp.NO_FILE,

//     new Object[] { “” },

//     true);

     }

//        clear the FileResource context value attribute

     //element.setFileResource(null);

    byte[] bin = element.getBindata();

     Properties prop = new Properties();

     //String lSlt = System.getProperty(“com.sap.aii.ib.slt”);

     LanguageSettings laS = LanguageSettings.getLoginLanguage();

     try

     {

          LoginSessionContext lct;

          InitialContext ctx;

          prop.put(“java.naming.factory.initial”, “com.sap.engine.services.jndi.InitialContextFactoryImpl”);

          prop.put(Context.PROVIDER_URL, “1.2.0.155:50004”);

          prop.put(Context.SECURITY_PRINCIPAL, wdContext.currentContextElement().getUsername());

          prop.put(Context.SECURITY_CREDENTIALS,wdContext.currentContextElement().getPassword());

          ctx = new InitialContext(prop);

          System.out.print(ctx.SECURITY_PRINCIPAL);

          Object  beanLogin = ctx.lookup(“sap.com/com.sap.xi.repository/RepLoginServiceBean”);

          LoginServiceHome lsh = (LoginServiceHome)PortableRemoteObject.narrow(beanLogin,LoginServiceHome.class);

          LoginServiceRemote lsr = lsh.create();

          Language lingua = Language.EN;

          String logon = lsr.login(Language.EN);

//     

               XiTypeId typeId;

               typeId = XiTypeId.DATA_TYPE;

//

//               //          typeId = XiTypeId.MESSAGE_TYPE;

//               //          typeId = XiTypeId.DT_ENHANCEMENT;

//               

//               

//               XiKey key = XiKey.getNameInstance(typeId, name, namespace);

          VersionContext myvc = null;

     IGUID swc=null;

          try

          {

               IGUID swcGuids[] = ApplDepServiceProvider.getApplDepService().getAllSWCGuids();

               for(int i=0;i<swcGuids.length;i++)

               {

                    if(swcGuids[i].toString().replaceAll(“-“,””).compareTo(wdContext.currentContextElement().getSwdc())==0)

                    {

                         myvc = VersionContext.Factory.getSwcInstance(swcGuids[i]);

                         swc = swcGuids[i];

                         break;

                    }

               }

               //myvc = VersionContext.Factory.getSwcInstance(swcGuids[10]);

               //swc = swcGuids[10];

               String a = swc.toString();

               String p=null;

          }

          catch(Exception e)

          {

               System.out.println(e.toString());

          }

          Object bean = ctx.lookup(“sap.com/com.sap.xi.repository/RepObjectAccessBean”);

//          

          ObjectAccessHome oab = (ObjectAccessHome)PortableRemoteObject.narrow(bean,ObjectAccessHome.class);

          ObjectAccessRemote oar = oab.create();

          ObjectAccessBI oabi = (ObjectAccessBI) oar;

          String message=””;

          for(int i=0; i<bin.length; i++){

          message+=( char )bin[ i ];

          }

     String messageNew=message.replaceFirst(“xsd:element type=\””,”xsd:element name=\””message.substring(message.indexOf(“xsd:element type=”)18,message.indexOf(“xsd:element type=”)18message.substring(message.indexOf(“xsd:element type=\””)18).indexOf(“\””))“\” type=\””);;

   while (message.compareTo(messageNew)!=0)

   {

     message = messageNew;

     messageNew = messageNew.replaceFirst(“xsd:element type=\””,”xsd:element name=\””message.substring(message.indexOf(“xsd:element type=”)18,message.indexOf(“xsd:element type=”)18message.substring(message.indexOf(“xsd:element type=\””)18).indexOf(“\””))“\” type=\””);

   }

   XsdHandler handler = new XsdHandler();

     byte currentXMLBytes[] = message.getBytes();

     ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(currentXMLBytes);

     XsdSchema xsdS = handler.parseSchema(byteArrayInputStream);     

     List lista = xsdS.getElements();          

     XiKeyImpl xki;

     String log=””;

     for(int i=0;i<lista.size();i++)

     {

       XsdElement xsdE = (XsdElement)lista.get(i);

       String nomeO = xsdE.getName();

       nomeO = nomeO.replace(‘.’,’_’);

       String namespaceO = wdContext.currentContextElement().getNamespace();

       XiKey keyO = XiKey.getNameInstance(typeId, nomeO, namespaceO);

       //XiKey keyCont = XiKey.getNameInstance(XiTypeId,namespaceO,namespaceO);

       //public RetValContainer create(XiKey key, VersionContext versionContext, Language lang, XiKey containerKey)

       try

       {

       XsdSchema schema;

       XsdQName qName;

       XsdTypeDef typeDef;

       XsdSchema mySchema = new XsdSchema();

       int tipo = xsdE.getTypeRefKind();

//     //SIMPLE TYPE     

       if(tipo == 2)

       {

       //xsdE.setGlobalTypeName();

            qName = xsdE.getQName();

            //XsdSimpleType xsdST = (XsdSimpleType) xsdE.getTypeDef();

            XsdSimpleType xsdst = new XsdSimpleType();

            xsdst.setBaseTypeName(xsdE.getGlobalTypeName());

            xsdst.setName(xsdE.getName());

            mySchema.addTypeDef(xsdst);

            XiReference linkO = com.sap.aii.ib.bom.gen.XiReference.Factory.getInstance(keyO,myvc);

            RetValContainer reto = oabi.create(keyO,myvc,Language.IT,keyO);

            //RetValContainer reto = oabi.read(linkO,laS);

            XiObject xioo = reto.getXiObject();

            BabelMessage bm = BabelMessage.createFromString(“Messaggio”);

            WarnMessageOption wmo = new WarnMessageOption(“”,bm);

            IGUID myGUID = GUIDGeneratorFactory.getInstance().createGUIDGenerator().createGUID();

            IGUID gVS = GUIDGeneratorFactory.getInstance().createGUIDGenerator().createGUID();

            XiObjectManipulator om = XiObjectManipulator.getInstanceOf(new Object());

            om.setVersionId(xioo,myGUID);

            om.setVersionSpecifier(xioo,VersionSpecifier.Factory.getInstance(4,gVS));

            xioo.setDescription(“DataType:”+xsdE.getName());

            DataType dtO = (DataType) xioo;

            dtO.setSchema(mySchema);

            xioo = (XiObject) dtO;

            PersistService ps = PersistServiceProvider.getPersistService();

            ps.writeObjectVersion(oabi.getDefaultChangelist(linkO),dtO);

            oabi.update(dtO,oabi.getDefaultChangelist(linkO),wmo);

            oabi.close(dtO);     

            log = log + “Created Simple Datatype “xsdE.getName()“\n”;

            String locName = qName.getLocalName();

       }

       }

       catch(Exception e)

       {

            System.out.println(e);

       }

     }

     for(int i=0;i<lista.size();i++)

     {

       XsdElement xsdE = (XsdElement)lista.get(i);

       String nomeO = xsdE.getName();

       nomeO = nomeO.replace(‘.’,’_’);

       String namespaceO = wdContext.currentContextElement().getNamespace();

       XiKey keyO = XiKey.getNameInstance(typeId, nomeO, namespaceO);

       //XiKey keyCont = XiKey.getNameInstance(XiTypeId,namespaceO,namespaceO);

       //public RetValContainer create(XiKey key, VersionContext versionContext, Language lang, XiKey containerKey)

       try

       {

       XsdSchema schema;

       XsdQName qName;

       XsdTypeDef typeDef;

       XsdSchema mySchema = new XsdSchema();

       int tipo = xsdE.getTypeRefKind();

       if (tipo==4)

       {

            XiReference linkO = com.sap.aii.ib.bom.gen.XiReference.Factory.getInstance(keyO,myvc);

            RetValContainer reto = oabi.create(keyO,myvc,Language.IT,keyO);

            //RetValContainer reto = oabi.read(linkO,laS);

            XiObject xioo = reto.getXiObject();

            IGUID myGUID = GUIDGeneratorFactory.getInstance().createGUIDGenerator().createGUID();

            IGUID gVS = GUIDGeneratorFactory.getInstance().createGUIDGenerator().createGUID();

            BabelMessage bm = BabelMessage.createFromString(“Messaggio”);

            WarnMessageOption wmo = new WarnMessageOption(“”,bm);

            XiObjectManipulator om = XiObjectManipulator.getInstanceOf(new Object());

            om.setVersionId(xioo,myGUID);

            om.setVersionSpecifier(xioo,VersionSpecifier.Factory.getInstance(4,gVS));

            xioo.setDescription(“DataType:”+xsdE.getName());

            DataType dtO = (DataType) xioo;

            XsdComplexType xsdct = (XsdComplexType) xsdE.getTypeDef();

            xsdct.setName(xsdE.getName());

            mySchema.addTypeDef(xsdct);

            dtO.setSchema(mySchema);

            xioo = (XiObject) dtO;

            PersistService ps = PersistServiceProvider.getPersistService();

            ps.writeObjectVersion(oabi.getDefaultChangelist(linkO),dtO);

            oabi.update(dtO,oabi.getDefaultChangelist(linkO),wmo);

            oabi.close(dtO);          

          log = log + “Created Complex Datatype “xsdE.getName()“\n”;

       }

       }

       catch(Exception e)

       {

            System.out.println(e);

       }

     }

     wdContext.currentContextElement().setLog(log);

     }

     catch(Exception ex)

     {

     }

    //@@end

  }

In the SWDC InputField you should insert the GUID of your Software Component which you can find easily in the Integration Repository:

!https://weblogs.sdn.sap.com/weblogs/images/251718833/swcGUID.JPG|height=195|alt=image|width=600|src=https://weblogs.sdn.sap.com/weblogs/images/251718833/swcGUID.JPG|border=0!</body>

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

  1. Anonymous
    Hi Paolo,

    I’m very impressed about your reverse engineering. I suppose you spend some long evenings in debugging sessions to get this work. However, I suspect a port to PI 7.1 will be difficult as you used a lot of internal API’s which will change very likely. Nevertheless you have shown the rigth way. Create work and create blog.

    Best regards, Falk

    (0) 
    1. Paolo Romano Post author
      Hi Falk,

      thanks for your very appreciated comment, I believe in sharing knowledge, as this is the only way to improve.

      Best Regards,
      Paolo

      (0) 

Leave a Reply