Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8114083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:02:40+00:00 2026-06-06T03:02:40+00:00

I need to upload a xml file from server side, where the contents of

  • 0

I need to upload a xml file from server side, where the contents of a file is in a string. How can I make this file content to be uploaded (basically save) on the server?

This is what I am trying, which works fine, If i give a file directly to FileBody but how to trick it to have filecontents going to another servlet as multipart request?

private def createConfiguration(def sessiontoken)
{
    def xmlString=""
    HttpClient httpclient = new DefaultHttpClient();
    try {

        HttpPost httppost = new HttpPost(fileParams.create);

        //FileBody bin = new FileBody(new File("C:\\Simon\\myxml.xml"));
        StringBody st = new StringBody(sessiontoken);
        StringBody cfgname = new StringBody(reqParams.c_Cfgname[0]);
        StringBody cfgdesc = new StringBody(reqParams.c_Cfgdesc[0]);
        StringBody cfgtype = new StringBody(reqParams.c_Cfgtype[0]);
        StringBody cfgfile = new StringBody(reqParams.CFGFILE[0]);

        MultipartEntity reqEntity = new MultipartEntity();
        reqEntity.addPart("sessiontoken", st);
        reqEntity.addPart("cfgname", cfgname);
        reqEntity.addPart("cfgdesc", cfgdesc);
        reqEntity.addPart("cfgenv", cfgtype);
        //reqEntity.addPart("cfgfile", bin);
        reqEntity.addPart("cfgfile", cfgfile);

        httppost.setEntity(reqEntity);

        System.out.println("executing request " + httppost.getRequestLine());
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity resEntity = response.getEntity();

        System.out.println("----------------------------------------");
        //System.out.println(response.getStatusLine());
        if (resEntity != null) {
            //System.out.println("Response content length: " + resEntity.getContentLength());
            xmlString=resEntity.getContent().getText()
        }
        EntityUtils.consume(resEntity);
    } finally {
        try { httpclient.getConnectionManager().shutdown(); } catch (Exception ignore) {}
    }
    xmlString
}

If I use the above code I get the below Exception

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



Exception while processing your Request.
No result defined for action com.abc.dc.actions.CreateConfiguration and
 result input

Update

So now after checking the tomcat logs & the other server side code, I came to know that that internally dc is getting cfgfile and setting it to

public void setCfgfile(File cfgfile)
{
    this.cfgfile = cfgfile
}

which gives me

java.lang.NoSuchMethodException: com.abc.dc.actions.CreateConfiguration.setCfgfile([Ljava.lang.String;)

So how can I overload setCfgfile method with public void setCfgfile(String cfgfile) and convert cfgfile into a File object here?

or Even better,

How can I convert this cfgfile string variable into a FileBody object?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T03:02:42+00:00Added an answer on June 6, 2026 at 3:02 am

    Finally here is how I made it to work 🙂

    private def sendRequest(def sessiontoken,def sendUrl)
    {
        logger.debug("Inside sendRequest to: "+sendUrl)
        def xmlString=""
        HttpClient httpclient = new DefaultHttpClient();
        try {
    
            HttpPost httppost = new HttpPost(sendUrl);
    
            def filename=reqParams.filename
            logger.debug("Filename: "+filename)
            FileBody bin = new FileBody(writeToFile(filename,reqParams.cfgfile));
            StringBody st = new StringBody(sessiontoken);
            StringBody cfgid=new StringBody("")
            if(reqParams.containsKey('cfgfile')&&reqParams.cfgid!=null)
            {
                cfgid= new StringBody(reqParams.cfgid);
            }
    
            StringBody cfgname = new StringBody(reqParams.cfgname);
            StringBody cfgdesc = new StringBody(reqParams.cfgdesc);
            StringBody cfgenv = new StringBody(reqParams.cfgenv);
    
            logger.debug("attaching multipart")
            MultipartEntity reqEntity = new MultipartEntity();
            reqEntity.addPart("sessiontoken", st);
            reqEntity.addPart("cfgid", cfgid);
            reqEntity.addPart("cfgname", cfgname);
            reqEntity.addPart("cfgdesc", cfgdesc);
            reqEntity.addPart("cfgenv", cfgenv);
            reqEntity.addPart("cfgfile", bin);
    
            httppost.setEntity(reqEntity);
    
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity resEntity = response.getEntity();
    
            if (resEntity != null) {
                xmlString=resEntity.getContent().getText()
            }
            EntityUtils.consume(resEntity);
        } finally {
            try { httpclient.getConnectionManager().shutdown(); } catch (Exception ignore) {}
        }
        xmlString
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to upload file the server via .php file, and i've got this
I need to upload a text file which contains some data ,from my local
I need to upload a file from the client to an asp.net page. The
We need to upload the attachments(for ex. word document) in xml file. Is there
I need to upload some DATA inside and FTP server. Following stackoverflow posts on
I need to upload a potentially huge plain-text file to a very simple wsgi-app
I need to upload a given image using Amazon S3 I have this PHP:
I need to upload a file in C# using an httpwebrequest. I don't need
I'm parsing an xml file and I can NSLog the parsing, but my problem
I need to make a POST request via cURL from the command line. Data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.