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

  • Home
  • SEARCH
  • 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 7032351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:55:26+00:00 2026-05-28T00:55:26+00:00

I am new to web services. I have written a rest web service which

  • 0

I am new to web services. I have written a rest web service which creates and returns pdf file. My code is as follows

@Path("/hello")
public class Hello {

@GET
    @Path("/createpdf")
    @Produces("application/pdf")
    public Response getpdf() {
        synchronized(this){

         try {
                OutputStream file = new FileOutputStream(new File("c:/temp/FirstPdf5.pdf"));

                Document document = new Document();
                PdfWriter.getInstance(document, file);
                document.open();
                document.add(new Paragraph("Hello Kiran"));
                document.add(new Paragraph(new Date().toString()));

                document.close();
                file.close();

            } catch (Exception e) {

                e.printStackTrace();
            }

        File file1 = new File("c:/temp/FirstPdf5.pdf");

        ResponseBuilder response = Response.ok((Object) file1);
        response.header("Content-Disposition",
                "attachment; filename=new-android-book.pdf");
        return response.build();
        }
    }

}

If multiple clients try to call the web service simultaneousy , Does it impact on my code?
I mean , if client A using the web service and at the same time if client B tries to use the web service will the pdf file gets over writted.

If my question is not proper,Please let me know

Thanks

  • 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-05-28T00:55:27+00:00Added an answer on May 28, 2026 at 12:55 am

    As you are writing the file to the hard disk multiple calls to the service will cause the file to be overwritten or cause exceptions where the file is already in use.

    If the file is the same for all users then you would only need to read the file rather than write it every time.

    However if the file is different for each user you might try one of the 2 following options:

    You could build the file in memory and then write the binary response directly to the response stream.

    Alternatively you could create the file using a unique name, this could be a GUID or a random number this would ensure that you never have a clash between the multiple calls arriving at the server.

    I would also ensure that you remove the files

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a REST web service with Jersey Server (that totally rocks !).
I have written REST web service in netbean IDE using jersey framework and java.
I have written a sample web service, which consist of certain .aspx pages. I
I have a web service which requires me to send file data to HTTP
I have a web service written in PHP, that returns JSON results. It works
I am new to iPhone application development, i have used the web services and
I have written a service that I would like expose both via rest and
I've written a windows service application that exposes a WCF REST web service. The
I have ADAM set-up & I've written web-services to complete admin tasks like adding
I have a web service written in C# using SOAP. A client has requested

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.