• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

How to convert simple Java Code into amazon's AMI

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
Below is the java code to convert word file into pdf file. I want to have this code run on amazon's EC2. Is there a way to do so please reply.


 
Bartender
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I recall correctly, then Amazon EC2 let's you configure an an entire Linux system image - that would allow you to run an OpenOffice server installation on it, to which this code could connect.
 
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I want to have this code run on amazon's EC2. Is there a way to do so


Do you already have an AWS account? Have you familiarized yourself with EC2? launching an instance....connecting through ssh using a keypair....basic steps like that?
If not, do those steps first using AWS's rather good documentation (GettingStartedGuide)

To answer your question "How to convert java code into AMI",
broadly you search for a base public AMI which is trustworthy (for example, if I want an Ubuntu server instance, I use the official AMI that Canonical has published),
and then install and configure whatever packages (like OpenOffice) you need on it.
Now, if that configured image has to be mirrored to more machines, you can save that configured image as your own custom AMI, and then that custom AMI can be installed on multiple EC2 instances.
Most of this is possible from the AWS Management Console itself. But for connecting to the EC2 instances, a traditional ssh client like putty (if you're on Windows) is more convenient than using the console.

Also, your code as it exists (with hardcoded paths) are a problem. First of all they are Windows paths - do you plan to use a Windows based AMI? If not, you should get rid of the hardcoded paths and accept them via command line args.
 
Palak Agarwal
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi karthik,

thanks for your quick reply..
i am totally new to Ec2 AMI.
Please let me know what do you mean by configuring AMI images. At present, I have the java code ready to covert word to pdf files but do not have any idea on how to create an image out of it. I also dont know why creating
image of this java code is required. Is there is some other way to run the java code on Ec2? Is this way different with the one with the local environment?

Please help. Its really urgent I need this code to run on EC2 server.

Thanks


 
Karthik Shiraly
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Palak Agarwal wrote:
i am totally new to Ec2 AMI.
Please let me know what do you mean by configuring AMI images. At present, I have the java code ready to covert word to pdf files but do not have any idea on how to create an image out of it. I also dont know why creating
image of this java code is required. Is there is some other way to run the java code on Ec2? Is this way different with the one with the local environment?

Please help. Its really urgent I need this code to run on EC2 server.


Hi,
An EC2 instance is just like an actual server machine. If you buy a physical server machine from server vendors like HP or IBM, you would first install an OS on it, then software like java/mysql/tomcat/etc on it, configure them, and deploy your app.
Same idea with an EC2 instance, except that EC2 instances are on Amazon's premises and are usually virtualized servers (though they provide dedicated servers too).
It's very similar to running an actual server machine.

I don't think there's a shortcut around using EC2 (or any technology for that matter) without understanding its basics, its terminologies or why it should be used in the first place.
Please go through that Getting Started link in my previous post.
Their documentation does a fine job of explaining the concepts and even the steps. There's no point in me duplicating their explanation.
If you have any pointed questions after going through those steps, you can ask.

I also dont know why creating image of this java code is required


I don't either. Since it's your requirement, it's for you to tell us why you require it.
 
Palak Agarwal
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi karthik,

I have gone through the get started document and now i am able to logon to AMI through my system.
AMI appears exactly as windows. I want to run above java code in this environment so is it going to run in the same way
as i was running on the local environment or i will be needing AWS plugin to be installed on eclipse.

With regards,
Palak
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's great!
Running anything on an EC2 instance is exactly like on a local server.
You need to install java on that machine if it's not already there, then upload your java class files (I believe uploading is possible via RDC, but not sure since I use only Linux instances),
and run it as normal.
You don't really need the AWS plugin to run any app on EC2.
 
Palak Agarwal
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
karthik while i am uploading the files, the system runs terribly slow . I am using RDC. so is it due to the internet speed or for any other reason?
thanks a lot for your help....
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Probably the remote connection speed. Not used RDC from a long time...can't remember if it's possible to optimize anything.
If your transfers are large, you can upload your files to something like dropbox and download them from that EC2 instance. That instance will have a fast connection to the web.
 
Palak Agarwal
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi karthik ,

Thanks for your reply.
This java code needs to be invoked on EC2 from some other platform so do we need to have EC2 credentials to do so or please tell me
if there is any other alternative to run this java code hosted on EC2 from other platform.

thanks
Palak
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This java code needs to be invoked on EC2 from some other platform so do we need to have EC2 credentials to do so or please tell me


Can you give an overview of your system and what goal you're trying to achieve?
From what I can make out, I'm guessing that you want to provide a platform that converts word documents to PDF en masse using OpenOffice libraries.
You've been advised to use EC2 because it can scale to accommodate large number of documents quickly.
Is this correct?
 
Palak Agarwal
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi karthik,

Actually, I am salesforce(cloud computing) developer and salesforce does not allow conversion of word to pdf. For this reason I have to use EC2. My aim is to send word file to EC2 from salesforce which will be converted into a pdf and send it back to salesforce.

Thanks,
Palak
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since I know zilch about salesforce platform, you'll have to evaluate my answer for feasibility from salesforce point of view. But some cursory googling says salesforce can do HTTP requests.

So assuming that API is feasible for you and you are familiar with servlets, one simplistic solution would be like this:

1. Deploy the conversion code as a servlet in Tomcat on the EC2 instance. It could also be deployed as a servlet based or standalone RESTful web service, if you're more familiar with RESTful services.

2. You need a reliable URL (like "http://yourec2server.yourapp.yourcompany.com" or "http://your-EC2-elastic-IP-address") to address your EC2 instance.
The public DNS name assigned by Amazon is fairly reliable, but it may change everytime your EC2 instance is restarted.
A better option is to get an elastic IP which acts like a static unchanging IP.

3. The salesforce app sends a HTTP POST multipart request to that servlet/webservice URL (let's say "http://your-EC2-elastic-IP-address/convert)", with the Word file as a multipart upload.

4. The servlet/webservice uses OpenOffice API to convert received Word file to PDF, publishes that file in some directory which is served by Tomcat, and returns that published path as a URL (say "http://your-EC2-elastic-IP-address/published/convertedfile.pdf").

5. The salesforce app now sends another HTTP GET request to that published file URL to download the PDF to its environment.

6. Once the salesforce app is done with the PDF, it can send another request to the servlet/ web service to delete the file.

I don't know how many files you expect to convert per hour, but an elastic IP and servlet based solution certainly set you up to scale out to more instances if necessary. If this scaling out is foreseen, then prefer to publish that PDF to a common storage like an S3 bucket which is accessible from all instances, instead of publishing it in a local directory under Tomcat which won't be accessible from other instances.
 
Palak Agarwal
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi karthik,

"Deploy the conversion code as a servlet in Tomcat"

Please can you give the steps to deploy conversion code as servlet and how will I publish the converted file in some directory
of Tomcat.

Thanks a lot you have been really helpful to me.
With Regards,
Palak
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you evaluate the feasibility of sending HTTP requests from salesforce?

In my opinion, the steps would be:
- Stop right now. EC2 can be ignored totally till you have a design working on local servers.
It seems to me that you're jumping into coding - on the advise of somebody on a discussion forum who doesn't know one half of your system at all - without first evaluating the feasibility of that architecture or design! Not good engineering practice at all.

- Familiarize yourself with servlets, servlet API and the tomcat server. This is the most basic step if you want to use servlets in your design. They've been around almost a decade now and there are 1000s of good tutorials on web like this one.

- The conversion code would be much the same as what you have, except that instead of executing in main(), it should execute in servlet's doPost().

- Familiarize yourself with sending multipart HTTP file uploads from the salesforce side (is it even possible? You should certainly check that first), and receiving it in servlet using the "Apache commons fileupload" library.

- Presumably, salesforce apps can be tested locally on some testbed? If so, you should deploy this conversion servlet in Tomcat on some local server, and test locally.

- Once you have it working locally, just install Tomcat on your EC2 and upload the servlet app. Like I said, an EC2 instance works just like a local server. In this case, the fact that that servlet is being deployed on EC2 doesn't matter, because you
don't have to change anything specially to make it work on EC2.




 
Palak Agarwal
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi karthik,

Thanks a lot for your help and guidance.
With the help of servlet we are able to convert word files from salesforce
to pdf now.

Thanks
Palak
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good going, and you're welcome!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic