Commons HTTPClient : Sending file as well as parameters

Hi,
I want to send some parameters as well as a file in request body. I have been doing this via PostMethod by Commons HTTPClient.
Client Code:
          HttpClient client = new HttpClient();
               PostMethod method = new PostMethod("http://localhost:7080/exchange/receive");
               //Parameters
               method.addParameter("username","test");
               method.addParameter("password","a311xhq23");
               //File
               String strXML = FileTest.readTextFile("C:/in.xml");
               method.setRequestBody(strXML);
               int statusCode = client.executeMethod(method);
               if (statusCode != HttpStatus.SC_OK) {
                    System.err.println("Method failed: " + method.getStatusLine());
               String responseString = method.getResponseBodyAsString();
               System.out.println("Response : \n\n"+responseString);Server Code:
                String username = request.getParameter("username");
              System.out.println("Username : "+username);
          InputStream is = request.getInputStream();
          byte buf[]=new byte[1024];
          int len;
          OutputStream out = new FileOutputStream(new File("c:/out.xml"));
          while((len=is.read(buf))>0)
                 out.write(buf,0,len);
          out.close();
          is.close();Here the file is written successfully but request parameters are null. What could be the issue?
Is it right way to send both parameters as well as file?
In http client I haven't specify content type. So what will be default content type? is it multipart request?
Thank is advance.
Regards,
Amit
Edited by: amit_patel_java on Apr 14, 2010 11:38 PM

I'd say your setRequestBody() call is overwriting the parameters. Read the javadocs of the API to get more details about how they work.
What you are trying to mimic is a multipart request, where you can send a file as part of the request to the server. HttpClient should have capabilities to do a multipart request, and on the server side you can use the FileUpload API to read the file and the parameters back.
[http://hc.apache.org/httpclient-3.x/methods/multipartpost.html|http://hc.apache.org/httpclient-3.x/methods/multipartpost.html]
[http://commons.apache.org/fileupload/using.html|http://commons.apache.org/fileupload/using.html]

Similar Messages

  • Sender File Adapter missing processing parameters

    Hi All,
    On my Dev box in ID for configurations of Sender File adapter I am able to see the following options:
    1)    Handling of Empty Files
    2) Archive Source Files with Errors
    But I am unable to see them on QA box.What could be the error.

    Hi All,
    I checked the metadata in IR in Dev and QA.
    They are different.
    In QA i dont see the " Handling of Empty Files"
    What could be the problem
    Thanks

  • Not able to send file Using FTP in SSIS 2005

    I am using SSIS 2005
    I am trying to send file to ftp server using FTP task in SSIS but i am getting following error.
    Error Message-:An error occurred in the requested FTP operation.
    Detailed Description-:550 /FileName.txt: Access is denied.
    RemotefilePath is /
    I need a advice.
    Thanks in advance.

    I got this error recently from the FTP task in SSIS:
         Unable to send files using "FTP".
    I had everything correct, by the book.  I was trying to send a file, but I got the same error when trying to receive a file. 
    I already verified that I could send the file via command line FTP, so the FTP was not "secure FTP" (which wouldda required FileZilla or WinSCP or something similar) and my credentials were fine. 
    But I still got the above error.  Heck, I was beginning to thing that the FTP task in SQL Server 2008 was broken and just couldn't send files.
    Well, this issue is now resolved.  The problem was in the
    destination folder.  I was assuming that the root folder for my FTP account held the files. 
    So I entered the destination folder as this:   
    /data_in/
    But... the FTP task sees the root folder as one up from that. 
    So I had to use my account name in the path... meaning I had to change the destination folder to this:    
        /myaccountname/data_in/
        (where "myaccountname" was my login to the FTP site.)
    I hope this post helps someone else.
    Donna

  • Sending File for Shared Review

    I want to send a number of captivate files for shared review. Do I need to create a seperate email for each file and log in each time. Or is there a way to bundle a few of the captivate files together and jsut send them in one email.
    Or can I give someone access to a folder on my workspace in the Adobe area.
    Thanks
    Jo

    Is the bundled Reviewer not waht you want? The reviewers do not need to have Captivate installed, just have to download the reviewer which is free.
    You can post files on workspaces.acrobat.com and share the workspace or files with other people. Or you can use the service SendNow to send files as well.
    Lilybiri

  • Sender Agreement not needed when in httpclient to file scenario.

    Hi,
      I will like to understand why in the httpclient to file scenario, a sender agreement is not needed?
      Thanks.

    HI
    Integrattion server - IS expects the messages in XML format. If you see the HTTP request you will see that we pass all the info contained in the Sender areement in the the HTTP request itself , namely - Message interface, message type and the namespace (along with login parameters). For IDOCs the the IDOC- XML are are sent to the IS (through IDOC port configuration at the source system.
    When send a message to XI the sender knows that XI system parameters, but when at the reciver end there could be any any system that is reciving the IDOc/HTTTp message. you specify those message through a commumication channel and this channel is associated to a receiver agreement.
    For more information you can search in sdn.
    Regards
    Goli Sridhar

  • How do i extract Delimited falt file-Sender File adapter FCC Parameters

    Hello,
    I'm trying to extract data from a flat file. The file is built as tab delimited. I cant find the option of tab delimited in the XI Sender File adapter FCC Parameters. How do i extract tab delimited file?
    Please Advice,
    Rajesh

    HI,
    You can use Fieldseperator as '0X09'...
    Look at this blog...........you can solve this problem...
    NAB the TAB (File Adapter)                              
    Thanks,
    Madhu
    Edited by: Madhu sudhan Reddy on Jul 28, 2008 9:02 AM

  • Orabpel vs commons-httpclient

    Hi,
    I am working on embedded oc4j with jdeveloper10.1.3.
    I am using BPM Workflow library in my project. Which includes orabpel.jar.
    At the same time, I want to use the few of the functionality like HttpMethodRetryHandler, NoHttpResponseException… from commons-httpclient-3.0-rc4.jar.
    While I am using both jar files at the same time, I am getting the runtime class ambiguity in org.apache.commons.httpclient package.
    Can you help me out to overcome on the issue?
    Thanks,

    I'd say your setRequestBody() call is overwriting the parameters. Read the javadocs of the API to get more details about how they work.
    What you are trying to mimic is a multipart request, where you can send a file as part of the request to the server. HttpClient should have capabilities to do a multipart request, and on the server side you can use the FileUpload API to read the file and the parameters back.
    [http://hc.apache.org/httpclient-3.x/methods/multipartpost.html|http://hc.apache.org/httpclient-3.x/methods/multipartpost.html]
    [http://commons.apache.org/fileupload/using.html|http://commons.apache.org/fileupload/using.html]

  • Problem in Sender File Adapter using FCC with Variable structure

    Hi Experts,
    Hi Experts,
    I have facing an issues while using FCC in Sender File adapter. Below are the configs for the same:-
    Recordset structure required is ==HEADER,1,DATA,*,TRAILER,1
    Recordset per message == *
    Key Field Name == Key
    (Sorry i dont know how to insert screen shot here..pls tell me how can i insert screen shots here on sdn)
    HEADER.fieldSeparator           ,
    HEADER.endSeparator           u2018nlu2019
    HEADER.fieldNames               Key,x,y,zu2026
    HEADER.keyFieldValue          1
    HEADER.keyFieldInStructure      ignore
    HEADER.fieldContentFormatting     trim
    HEADER.additionalLastFields     ignore
    HEADER.missingLastFields     ignore
    DATA.fieldSeparator
    DATA.endSeparator
    DATA.fieldNames
    DATA.keyFieldValue
    DATA.keyFieldInStructure
    DATA.fieldContentFormatting
    DATA.additionalLastFields
    DATA.missingLastFields
    Using same variables for Trailer record as well.
    Source CSV file which i am picking:-
    ADSE ,RASD,replan  Contact ,2  0080509 0 8:43:25   ,        
    EMPL ,0011111,  S Top Up ,20080401  ,20080430  ,sdf  ,                          00000000431250  ,2007                                    ,  ,  ,  ,  ,  ,20080414  18:07:35,
    EMPL ,0222222,  r Cash Award ,20070701  ,20070703  ,ded  ,                          00000000023509  ,2007                                    ,  ,  ,  ,  ,  ,20080414  18:09:31,
    EMPL ,0233333,   Cash Award ,20070801  ,20070831  ,df  ,                          00000000044057  ,2007                                    ,  ,  ,  ,  ,  ,20080414  18:10:56,
    EMPL ,0244444,   Cash Award ,20080101  ,20080111  ,sf  ,                          00000000026717  ,2007                                    ,  ,  ,  ,  ,  ,20080414  18:08:29,
    BTRL ,   5140, 
    When i tested the scenario and monitored it using MDT in CC monitoring tool its giving me below mentioned error.
    The XML page cannot be displayed
    Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
    XML document must have a top level element. Error processing resource 'http://myurlname/mdt/me...
    However if i change the occurence of DATA as some specific value for eg 4 instead of * it works fine.
    Kindly help me in solving this problem.
    Thanks,
    Aditya Verma

    Hi Madan,
    Thanks a lot for giving me the way to this. But when i tested this with the below file its giving me the same error. Please let me know if i need to do any changes to the parameters mentioned above:-
    ADSE ,ASDA,Sha  replan Fr ont Feed Contact ,2  0080509 0 8:43:25   ,        
    EMPL ,0011111,   Cash Top Up ,20080401  ,20080430  ,TPV  ,                          00000000431250  ,2007                                    ,  ,  ,  ,  ,  ,20080414  18:07:35,
    EMPL ,0222222,   r Cash Award ,20070701  ,20070703  ,TPV  ,                          00000000023509  ,2007                                    ,  ,  ,  ,  ,  ,20080414  18:09:31,
    EMPL ,0233333,  r Cash Award ,20070801  ,20070831  ,TPV  ,                          00000000044057  ,2007                                    ,  ,  ,  ,  ,  ,20080414  18:10:56,
    EMPL ,0244444,   Cash Award ,20080101  ,20080111  ,TPV  ,                          00000000026717  ,2007                                    ,  ,  ,  ,  ,  ,20080414  18:08:29,
    EMPL ,0255555,   Cash Award ,20080301  ,20080320  ,TPV  ,                          00000000027870  ,2007                                    ,  ,  ,  ,  ,  ,20080414  18:08:25,
    EMPL ,0266666,   Cash Award ,20071001  ,20071020  ,TPV  ,                          00000000020681  ,2007                                    ,  ,  ,  ,  ,  ,20080414  18:09:31,
    EMPL ,0877777,   Cash Top Up ,20080401  ,20080430  ,TPV  ,                          00000000036000  ,2007                                    ,  ,  ,  ,  ,  ,20080414  18:07:05,
    EMPL ,0888888,   Leaver Cash Award ,20071201  ,20071231  ,TPV  ,                          00000000157200  ,2007                                    ,  ,  ,  ,  ,  ,20080414  18:11:29,
    EMPL ,0899999,  S Leaver Cash Award ,20080301  ,20080331  ,TPV  ,                          00000000153530  ,2007                                    ,  ,  ,  ,  ,  ,20080414  18:07:42,
    EMPL ,0800000,  S Leaver Cash Award ,20070701  ,20070731  ,TPV  ,                          00000000012234  ,2007                                    ,  ,  ,  ,  ,  ,20080414  18:08:34,
    BTRL ,   5140,
    This the original csv file which i'll get in live. Kindly suggest as ur solution worked with other file but not working with this scv file.
    Thanks a lot,
    Aditya.

  • Sender File(FTP protocol) Adapter not able to pick multiple files(eg *.xml)

    Dear Experts,
    I have SAP PI 7.0 installed on HP-UX. I installed Guild FTP on my Windows Vista machine.Configured File to File scenario. Sender File adapter(FTP Transport Protocol)is able to process the 'input.xml' file placed in FTP INBOX folder.
    I want to process all/multiple XML files. For this I have changed File Access Parameters in Sender Communication channel as:
    Source Directory -   /INBOX
    File Name          -   *.xml
    Immediately Sender Communication status went into red with error log messages :
    Error occurred while connecting to the FTP server "172.XX.XX.XX:21": java.lang.NullPointerException
    Please let me know what is the issue. Thanks in Advance.

    Hi
    It should work with *.xml
    Check with the connectivity as well.
    If this is still unable to process files then check with the FTP server compatibility.
    J2EE File adapter is based on RFC 959 and if GUILD FTP is non compatible to RFC format then exclusion mask may not work.
    Thanks
    Gaurav

  • Sender File Adapter - Content Conversion

    HI Friends,
    I got a scenario where I need to convert the File to XML document through Sender file adapter..
    My file looks like below.
    BATCH1234........
    12DASER123142JMM
    237DSAFDLKC839890
    45SDFLASJ90011
    BATCH3455...
    132FGAR
    SD21352525
    BATCH998898...
    123145DSRTW
    12FSTS
    So there is a Header and Body for each record set..
    My XML Structure is as follows.
    <TimeStructure>
      <TimeRecord>
         <ControlRec>
             <Field1>BATCH </Field1>   
             <Field2> ...</Field2>
         </ControlRec>
         <DataRec>
             <F1> ...... </F1>
             <F2> ...... </F2>
         </DataRec>
      </TimeRecord>
      <TimeRecord>
         <ControlRec>
             <Field1> BATCH  </Field1>   
             <Field2> ADFAS  </Field2>
         </ControlRec>
         <DataRec>
             <F1> ...... </F1>
             <F2> ...... </F2>
         </DataRec>
       </TimeRecord>
    </TimeStructure>
    The blog <a href="/people/shabarish.vijayakumar/blog/2006/02/27/content-conversion-the-key-field-problem:///people/shabarish.vijayakumar/blog/2006/02/27/content-conversion-the-key-field-problem
    is somewhat relevant to my requirement.
    But the problem is I have the keyfield "BATCH" for my header file but don't have any <b>key field in the data record</b> of the input file.
    Please help me out how to mention the configuration parameters.
    Regards,
    Kumar

    Hi,
    If you don't have constant key value for your detail records, then you can not directly get the required xml.
    So in this case, you can read all the records in a common Row model, i.e each record will be considered as a one row with all the values, and then split this row with Substring or java functions in the mapping.
    Even you can do this in the Adapter module .
    If you have key value for each record to identify then you can try with content conversion.
    Regards,
    Moorthy

  • How to raise Alerts for Sender File Channel

    Hi All,
    For Sender File Channels , we can find out the status of the adapter through RWB as to whether it is Content Conversion related exception or Folder path not found exception & etc .
    I wanted to know as to whether there is any way where can rasie alerts for Sender File Channels (similar to what we do for Reciever File Channels) as well.
    Regards
    Vinay P.

    I found it myself .
    In Alert Configuration while we are adding alerts for a particular aler category , the following parameters needs to be checked .
    Connected to Message : Not Relevant
    Sender Service/Party/Interface/Namespace needs to be mentioned.
    Adapter Type should be selected as File

  • Sender File Channel unable to process

    Hi,
    I have a scenario where we are using a sender file channel. It polls every 1 hour at the source directory.
    Suddenly yesterday the channel stopped processing and never polled again automatically.
    It started the processing but did not finish the processing. (There is no error)
    Now when I manually restart the channel it directly goes to the polling interval and gives the log :
    "Polling interval started. Length: 3600.0 seconds" every 1 hour. It does not start the processing of channel.
    As an additional information I checked that the Server to which it is polling had some error at the time when it stop processing.
    Please help how could I start the channel processing now? Is there some kind of lock issue or anything else.
    Thanks,
    Vikas

    Hello Vikas,
    In addition to the previous posts, check the following as well.
    1)
    As I donu2019t know which SP level your system is on, please check the note below and apply the patch accordingly.
    > 1317686 - Adapter Framework Scheduler may fail to remove a job
    2)
    Check whether you have deployed on your system the patches described in this note (as as mentioned in the post above).
    > 1083488u2013 XI FTP/JDBC sender channel stop polling indefinitely
    3)
    Please check if there are locks (as as mentioned in the post above) for this channel according to section u201CHow to manually delete hanging Enqueue-Locksu201C in note:
    > 821267 - FAQ: XI 3.0 / PI 7.0/ PI 7.1 File Adapter
    Follow the instructions and delete the lock related to the stopped communication channel.
    For the 7.1 versions, please note that the Lock Manager is under the /nwa/locks, or on the location "Availability and Performance Management -> Locks".
    4)
    Configure a timeout for the FTP connection.
    In more recent support packages you can set the "Timeout" parameter available in the "FTP Connection Parameters" section.
    Alternatively, please enable the "Advanced Mode" for the respective FTP communication channel in the Integration Directory and add an entry "ftp.timeout"=timeoutSecs (without any quotation marks) to the "Additional Parameters" section, where timeoutSecs is the desired FTP timeout in seconds.
    Please refer to the note below for further details on this.
    > 849089 - XI 3.0 / PI 7.0 File Adapter: FTP Timeout Handling
    Cheers,
    Jorge Eidelwein

  • FileName in Sender File Adapter Module

    Hi Folks,
    In my sender file adapter have written a module to read the picked file name. The protocol used is NFS.
    Notice that the file name read in the module has the absolute path, including the directory path. E.g The file name xyz has to be picked from source directory
    XIServer\Outbound. In the module when I retrieve the file name, it comes up as
    XIServer\Outbound\xyz. Is this expected behaviour?
    I was expecting just the file name<xyz> to be retrieved.
    Thanks,
    Anand

    HI,
    Create an UDF and write this code.
    DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
    DynamicConfigurationKey key =
    DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
    String ourSourceFileName = conf.get(key);
    return  ourSourceFileName;
    in Adapter u will have Adapter specific parameters check the file name check box.
    Using this UDF u will get the file name at target side.
    Regards,
    Phani.

  • Advance select for source file in Sender File Adapter

    Hi
    I am trying to utilise the parameter 'Advance Selection for source file' on a sender file adapter to pick the file from multiple folders
    My problem is that this parameter that is listed on the SAP help is not getting in File accessing Parameters.
    I am running PI 7.02 (NW702_07_Rel)
    Service pack 07
    Has anyone come across this before?
    any suggestions on how to do this?

    Hi,
    In PI7.0 the property exists. I have used it previously. I think SP was 13.
    Regards,
    Nutan
    Edited by: nutan champia on Nov 24, 2011 10:42 AM

  • Key Field Value in Sender File Adapter

    Hi,
    I am having a File>XI>File scenerio.
    The incoming file is having a fixed length content and is coming in as a single Header and multiple Line Item records. The single header is the first record and the rest are line item.
    The problem is that we do not have a keyfield, for the header as well as the Item records.
    Is there any possible configuration that I can do to still read the file; without specifying the parameters, xml.header.keyFieldName & xml.Header.keyFieldValue for the header and xml.Item.keyFieldName & xml.Item.keyFieldValue for the Item structures in which I would like to read my data.
    I am curretly using SP12.
    Regards,
    Anshul

    Hi Mohan,
    The Source File is coming like below:
    121000248      xyz      20051215120158
    9600193091        1000000      1000000      JEN'S TEST 9600193091        1000001      1000001     
    9600193091        1000002      1000002      HSI METAL 9600193091        1000003      1000003     
    First record will always be a header and the rest of the records will be Item records.
    Note: There will always be one header in the File.
    The problem is that we do not have a keyfield, for the header as well as the Item records
    Is there any possible configuration that I can do to still read the file; without specifying the parameters, xml.header.keyFieldName & xml.Header.keyFieldValue for the header and xml.Item.keyFieldName & xml.Item.keyFieldValue for the Item structures in which I would like to read my data.
    Data type Structure is like :
    <b>Header</b>
      bankl
      name
    <b>Item</b>
      AcountNo
      CheckNo
      Payee
    If you need further clarification please do let me know.

Maybe you are looking for

  • Inutilizar nota com status 252: Ambiente informado difere do de recebimento

    Boa tarde! Colocamos o GRC apontando para o ambiente de produção, porém no ECC ainda estava apontando para homologação. Como resultado disso, tivemos uma nota gerada que retornou com o seguinte erro: 252 - Rejeição: Ambiente informado diverge do Ambi

  • How do I get rid of the 'Waiting for Activation' on IPhone 5?

    I got the iPhone 5 today and set everything up using my Apple ID I created for my Ipod Touch 5 Under IMessage and FaceTime, it says it's 'waiting for activation' I can't receive any messages and would like to know hot to fix this

  • Active X, MS Office Spreadsheet 11.0 Memory Leak

    Hi, Can anyone see what I'm doing to cause a memory leak?  I am using LabVIEW 2011 (and this happens in 8.2.1 also). Is the last Close Ref. needed because there's an allocation evey loop? Is it bad that there's a buffer allocation on the right side o

  • HT5262 I need to update ios5 in my IPAD one but I don't know how??

    Every time I Truro go on itune, iBook what ever it show me this message I need to update my iOS 5 and idont know how??

  • Make to Stock - MD01

    Hi PP Gurus, I am doing MRP run through MD01 for a plant & I have the following requirements :- 1. System should not consider any open sales orders for plan 2. System should not consider any open STO for plan 3. System should not consider any stock a