cancel
Showing results for 
Search instead for 
Did you mean: 

How to get File path in java code calling web service ?

Former Member
0 Kudos

Hello experts,

                    I am working on SAPWM 6.2 application. I have requirement to consume a web service to upload attachment for Notification on xECM. But to achieve this I need File path to get into my java code. I don't idea how can I can get it in java from Agentry. Also how could I connect my java code consuming web service to SAPWM application. Any suggestion will be very helpful.

Regards

Sudhir

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hello experts

Stephen Streeter

Chandra Ayyagari

        AK K,

                                            I need your help.



Regards

Sudhir

former_member208808
Active Participant
0 Kudos

Hi Sudhir,

Consider this as your development scenario....

1)Client------------------------->Server 

                          |                                             }Here server and client are on same machine

               Repository(HDD)

2)Client------------------------->Server 

    |                                   |             }Here server and client are different machine

Repo.(HDD)               Repo.(HDD)

Ideal setup would/should be like case 2) shown above...

So path that you might be expecting in java code wont be valid.Since you uploaded a file from your client(device) and on server side you are expecting file path which is not available there.

----------------------------------------------------------------------

So

In your java code access transaction value (for external data) using "transaction.<filedata property name>".

This will be a String in java (binary base 64 encoded string).

Then do what you wanted with it like decode it and upload it to another server.

Also i would like to know how you will upload a file from plain java using your web service to server.

Paste some java code that you are using so that we can help,

like you might be using


HttpURLConnection conn = (HttpURLConnection) url.openConnection();

conn.setRequestMethod("POST");

etc....

Regards,

AK

Former Member
0 Kudos

Hi AK K,

      

           Thanks for your suggestions. It leting me know correct things.

    I have attached a doc that contains my Java code which I will going to use. Plz check & let me know how I can use this complete my job.

Regards

Sudhir

former_member208808
Active Participant
0 Kudos

Hi,

If your code in java is able to upload a file "c:\\eye.jpg" to targeted server then your task is almost done.

just add following lines to your code

1) get file data using transaction property

         String data = this._user.getString("transaction.<your filedata property name>");

2) Convert it to bytes array and write to file in server temp dir.

     byte[] bytesData = data.getBytes();

     FileOutputStream strm = new FileOutputStream("C:\\Temp");//----->server side directory and file

     try {

                 strm.write(bytesData);

          }

          catch(Exception ex){

          }

          finally {

                 strm.close();

          }

3) And in your code use same file to upload it.

          File POAFilebyteArray = new File("C:\\Temp"); ------->>> File Path

         reqEntity.addPart("file", new FileBody(POAFilebyteArray));

 

         httppost.setEntity(reqEntity);

 

         System.out.println("executing request " + httppost.getRequestLine());

         HttpResponse response = httpclient.execute(httppost);

And also refer to Steps that Bill Froelich has suggested.

Regards,

AK 

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

Sudhir,

What java path are you trying to get?  The file will arrive at the server Java layer in a transaction property as a binary encoded string.  It is up to you as to what you need to do with that.  If needed you can write it out to a temporary directory prior to sending it up to xECM via the webservice.

Since your code is writing out the file, you will most likely end up with a File handle reference that will have methods to give you the path. 

--Bill

Former Member
0 Kudos

Hi Bill,

            I have attached screenshot which contains File path of atttachment that I needed to have in Java code to upload that doc to xECM server.

  

             //    Supply File path    //

       File POAFilebyteArray = new File("  File path   ") ;

So If possible can I get file path directly in this line of Java code.

Regards

Sudhir

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

Sudhir,

The path you indicate in the screen shot is the local path on the client device.  The Agentry client will use that path to pickup the file from the device and embed it in the transaction.

That data will be sent to the server during the transmit process.  As AK indicates, you can access that through your transaction properties in the Java code.  What happens next is up to you based on the requirements of the web service you are trying to call.

I would anticipate the steps being something like this

  1. SMP Server receives the transaction
  2. Write the attachment out to a temporary location on the SMP server
  3. Call the webservice to login
  4. Call the upload doc webservice
  5. Cleanup the temp file on the SMP server

--Bill