cancel
Showing results for 
Search instead for 
Did you mean: 

File to File using Java Mapping in PI 7.1 without NWDS

Former Member
0 Kudos

Hi,

For this File to File scenario java coding is working fine while executing it in command prompt.

But when the jar file or zip file is imported in Imported Archives i get below error "Unable to display class; byte code format invalid"

I have tried with below two command in cmd for generating jar file.

jar cfm FiletoFile.jar manifest.txt FiletoFile.class

jar -cf FiletoFile.jar FiletoFile.class

Attached java code.

Please guide me to resolve this issue.

Thanks & Regards,

Vinoth

Accepted Solutions (1)

Accepted Solutions (1)

pvishnuvardan_reddy
Active Contributor
0 Kudos

Hi Vinoth,

Did you attach your jar file which is having both java file and class file into your imported archive in PI.

Also, make sure that you have compiled the java file with the jdk version less than or equal to your PI jdk version.

Regards

Vishnu

Former Member
0 Kudos

Hi Vishnu,

Thanks for your reply.

Yes. Jar file having both java and class. When i double click the class again it is throwing "Unable to display class; byte code format invalid"

Java file is visible:

And i have compiled it jdk 1.6 wherein PI jdk is 1.4

Error message while testing:

Thanks & Regards,

Vinoth

pvishnuvardan_reddy
Active Contributor
0 Kudos

Hi vinoth,

We need to compile the java code with  the jdk version which is less than or equal to that of PI jdk version.

Can you check on this and let us know if you still having issues.

Regards

Vishnu

Former Member
0 Kudos

Hi Vishnu,

Thanks for your reply.

Now i have compiled the java code in PI jdk version(1.4.2_19).

While testing the code below error occurred.

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.InputStream;

import java.io.OutputStream;

import java.util.Map;

import javax.xml.parsers.DocumentBuilder;

import javax.xml.parsers.DocumentBuilderFactory;

import javax.xml.transform.Transformer;

import javax.xml.transform.TransformerFactory;

import javax.xml.transform.dom.DOMSource;

import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;

import org.w3c.dom.Node;

import org.w3c.dom.NodeList;

public class FiletoFile  {

         

          public static void main(String[] args) {

                  

                   //created a DOM class

                   FiletoFile domParse=new FiletoFile();

                   try

              {

                            

                    //FileInputStream in = new FileInputStream("C:\\H_Back\\Java\\send/input.xml");

                   // FileOutputStream out = new FileOutputStream("C:\\H_Back\\Java\\receive/output.xml");

                    //domParse.execute(in, out); 

                   

              }

              catch(Exception e)

              {

                    e.printStackTrace();

                   

              }

                                     

          }

          public void execute(InputStream in, OutputStream out)

                             {

                   try{

                            

                             String fullName="";

                             /* transforms source to destination object*/

                             TransformerFactory tf=TransformerFactory.newInstance();

                             Transformer transform=tf.newTransformer();

                             /*creates new instance of parser*/

                             DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();

                             //ignore whitespace within document

                             factory.setIgnoringElementContentWhitespace(true);

                             //parser is aware of namespace

                             factory.setNamespaceAware(true);

                             DocumentBuilder builderel=factory.newDocumentBuilder();

                             /*input document in form of XML*/

                             Document docIn=builderel.parse(in);

                             Node temp,x,root,text;

                             NodeList l;

                            

                             //get all nodes with specific tag

                             l=docIn.getElementsByTagName("name");

                            

                            

                             for(int i=0;i<l.getLength();++i)

                             {

                                      //get the root element

                                      root=l.item(i);

                                     

                                      for(temp=root.getFirstChild();temp!=null;temp=temp.getNextSibling())

                                      {

                                                //find the tag with name country

                                                if(temp.getNodeName().equals("country"))

                                                {

                                                          if(temp.getFirstChild().getNodeValue().equalsIgnoreCase("India"))

                                                          {

                                                                  

                                                                   Node p;

                                                                   fullName="";

                                                                   //get firstname

                                                                   p=temp.getParentNode();

                                                                  

                                                                   p=p.getFirstChild();

                                                                  

                                                                   if(p.getFirstChild()!=null)

                                                                   {

                                                                             fullName=p.getFirstChild().getNodeValue()+" ";

                                                                            

                                                                   }

                                                                  

                                                                   //get lastname

                                                                  

                                                                   p=p.getNextSibling();

                                                                   //create full name

                                                                  

                                                                   if(p.getFirstChild()!=null)

                                                                   {

                                                                             fullName+=p.getFirstChild().getNodeValue();

                                                                   }       

                                                                   //create element fullname

                                                                   x=docIn.createElement("fullname");

                                                                   text=docIn.createTextNode(fullName);

                                                                   x.appendChild(text);

                                                                   //append it to root element "employee"

                                                                   root.getParentNode().appendChild(x);

                                                                  

                                                          }

                                                }

                                      }

                             }

                             //now traversing the tree the children of root "employee" from right to left

                                       for(temp=docIn.getElementsByTagName("employee").item(0).getLastChild();temp!=null;)

                                      {

                                          //delete all nodes with name "name"

                                                if(temp.getNodeName().equals("name"))

                                                {

                                                          x=temp.getPreviousSibling();

                                                          temp.getParentNode().removeChild(temp);

                                                          temp=x;

                                                          //normalize structure after deletion

                                                          docIn.normalize();

                                                }

                                                else

                                                {

                                                          temp=temp.getPreviousSibling();

                                                }

                                      }

                            

                             //creating target xml

                             transform.transform(new DOMSource(docIn), new StreamResult(out));

                            

          }

          catch(Exception e)

          {

                   e.printStackTrace();

          }

    

                  

          }

          public void setParameter(Map arg0) {

                                                }

}

Thanks & Regards,

Vinoth

pvishnuvardan_reddy
Active Contributor
0 Kudos

Hi Vinoth,

You need to use PI mapping jar file as it is mandate that every java code which will be written in PI should extend the class StreamTransformation for PI <7.1 or AbstractTransformation for PI>=7.1

Please find below sample java mapping code written in SCN Wiki:

Sample JAVA Mapping code using PI 7.1 API - Process Integration - SCN Wiki

Please use this as reference and accordingly adjust your java code.

Regards

Vishnu

former_member192851
Active Participant
0 Kudos

Your code is not Java Mapping. It is Java Program. It will not work in PI. Use Sample Java Mapping from link, that VISHNU posted.

Answers (3)

Answers (3)

engswee
Active Contributor
0 Kudos

Vinoth

If you don't have access to a proper IDE with a JDK that matches your PI system, perhaps it's best you

Rgds

Eng Swee

gagandeep_batra
Active Contributor
0 Kudos

Hi Vinoth,

You can check below blog that may help you

:

Regrads

GB

iaki_vila
Active Contributor
0 Kudos

Hi Vinoth,

The problem could be in your java version. Download java 1.5 and if you don't want to download the NWDS, at least you can get eclipse and to generate the .class and the jar from there.

Regards.

Former Member
0 Kudos

Hi Inaki Vila,

Thanks for your reply..

I have compiled it in jdk 1.6 wherein my PI jdk version is 1.4

Error message while testing:

Thanks & Regards,

Vinoth