This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes URL Constructors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "URL Constructors" Watch "URL Constructors" New topic
Author

URL Constructors

Joe Ridener
Ranch Hand

Joined: Jul 16, 2012
Posts: 86
I am trying to get some networking practice in. Right now I am working on ftp and trying to up and download files using it. Requesting user info is the excepotion it is thrown. In all my studies it does not give very much information on cooking up URL Strings beyond scheme, port file and authority with great detail. Basically the question is how to arrange the arguments for more advanced techniques involving URL's such as userinfo. The String I tried went like this

ftp for the scheme then the authority followed by the file then put a # followed by userinfo.

Have a clue what I am doing but missing the mark. Can you please refer me to a good resource for URL Strings and constructor calls.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

I would not start with FTP, its a complex protocol that uses two separate TCP/IP ports.

Why is the standard not meeting your needs?
Joe Ridener
Ranch Hand

Joined: Jul 16, 2012
Posts: 86
Pat Farrell wrote:I would not start with FTP, its a complex protocol that uses two separate TCP/IP ports.

Why is the standard not meeting your needs?



Well no .... that is not worded correctly ... I am posting a web-site and thought a URL would make a good network connection from the browser clients to the server. I am not familiar with ftp and would like to be. Often when asking these types of questions ppl from this thread have been resourcefull.

URL Strings is kind of a lightly touched upon topic in all my books and kind of getting to the point where userinfo is going to be needed if I want to kind of break the mold, so to speak.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

If you want your program to pretend that its a human with a browser, that is completely different. And its done all the time.

Don't reinvent the wheel, go download the Apache HTTP client library and use it. It works, is well tested and documented. There is a lot of subtlety in the HTTP protocol that you will learn (the hard way) that takes a lot of code to handle. Apache does it all for you.
Joe Ridener
Ranch Hand

Joined: Jul 16, 2012
Posts: 86
Pat Farrell wrote:If you want your program to pretend that its a human with a browser, that is completely different. And its done all the time.

Don't reinvent the wheel, go download the Apache HTTP client library and use it. It works, is well tested and documented. There is a lot of subtlety in the HTTP protocol that you will learn (the hard way) that takes a lot of code to handle. Apache does it all for you.



Ok what I am trying to do is create a contact form on my site. First web-site. I do not know scripting very well but... on way is use a URL and communicate with the server once the form data has been entered.

I am creating all the GUI components from scratch, text fields and text areas; however, the form has no network functionality as of yet.

I know stream sockets and class URL quite well almost a year of practice with both these. However, I do not know methods POST and GET and kind of need to for this operation.

I need to engineer a way to drop of a .txt file in a directory or use a URL object to connect to a database to retrieve form data of ppl whom contact me. As I do not know the standard cgi directory using JS on the html and do not want to take it all on learning. I was want to add network functionality so that potential clients and employers ( or whoever else) can contact me.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

Joe Ridener wrote:Ok what I am trying to do is create a contact form on my site. First web-site. I do not know scripting very well but... on way is use a URL and communicate with the server once the form data has been entered.

I am creating all the GUI components from scratch, text fields and text areas; however, the form has no network functionality as of yet.


People use Java to create forms for customers/users to fill in all the time. We never deal the sockets, URLs or internet protocols.

First, you need to create an HTML page with a form on it. Have lots of fields on it. This is standard HTML stuff, been around since the '90s. The form will use the POST method to some target for processing. Modern Java programs typically write a JavaBean to process the command. This is all run under a package that handles all the ugly protocols, retrys, etc. Typical packages are tomcat, glassfish, jboss, etc. There are forum sections here that talk about these.

We generally really write JSP pages, which are simply HTML pages that are renamed and have a few magic tags.

There are lots of packages that will overcomplicate this whole process. Struts is one. The ranch's own Bear Bibeaul's Frontman is the one I use, its much simplier and easier to use and understand than Struts.

If you want to write a standard web-appliation with forms and flow from one page to the next, you can work at a much higher level of abstraction, without all the details.

I think you should step back and think about what you are really trying to do. Then learn the terminology that the industry uses for it. This will help you find help.

Joe Ridener
Ranch Hand

Joined: Jul 16, 2012
Posts: 86
Pat Farrell wrote:

I think you should step back and think about what you are really trying to do. Then learn the terminology that the industry uses for it. This will help you find help.



I have been programming in Java for two years and attended UC/SD for Java programming and 3 creditds from my regular degree... I know the terminology.

Filezilla displays the protocol communication in a box at the top of the UI. When uploading the file to a server which is what I need to do ... it's what the problem is.

When you connect to my web-server for a transmission it assumes the URL object contais userinfo

my String to constructo call .... new URL("ftp","www.joerdesigner.net","/directoryName#username:password",21);

I knew this string would most likely not work as I have never appended userinfo to the filename in a URL object ... although it has to be close.

The user enters data to the form...

The form is a JApplet ... not a form tag with other input tags...

I designed the components from scratch... tha animation the GUI and the event handling.

There are no industry standards outside of adding your own network functionality unless you embedd param tags into an object or applet tag that the applet resides in that I am aware of. Been programming for years... Every day... I'll know what your talking about if you tell me a simple way to append info to an existing file or to place a file onto my server once the user enters data onto my form...

Creating a file object on a remote server is difficult... As I do not know how to spur a program into action such as a .jar file or .class outside of the oject or applet tag on the html file that it resides on. It has never came up until now and I have no one to ask. To simply crerate a new file on a server remotly, to invoke a program and spur it into action or append to an existing file from a browser using an applet is what I am trying to do here. So that way..

Until I can learn methods POST and GET and engineer my own litte http standard custom design... but for now I just want to enable clients/employers ect to contact.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

JApplet? As in Java applet? why in the world would anyone write an applet in 2013?

(p.s. your quotes aren't quite right above)
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

Joe Ridener wrote:Creating a file object on a remote server is difficult...


Its more than difficult, it is supposed to be impossible.

You can never trust what you get from a browser. The last thing that your server wants is to allow a foreign piece of code to create anything on your server. Creating a file means that they might be able to exploit file-system security bugs on your server's OS. That could be a disaster. You never want to do that.

What you do is design your code to accept a POST request (usually from an HTML form) and then your server code handles the data, storing it in a DBMS or wherever.
Joe Ridener
Ranch Hand

Joined: Jul 16, 2012
Posts: 86
Pat Farrell wrote:
Joe Ridener wrote:Creating a file object on a remote server is difficult...



What you do is design your code to accept a POST request (usually from an HTML form) and then your server code handles the data, storing it in a DBMS or wherever.


Now were getting somewhere...

Creating a Record object with instance vars. such as fName, lName message ect and storing it on a DB is FARRRRRR more my style then using a scripting language. Could you refer me to a link that will get me using method POST by the end of the night?? As it has been very vaguely put to me so far.


Pat Farrell wrote:[
Its more than difficult, it is supposed to be impossible.
.



Not so.... at least, it actually being impossible is not true.... As their are isntructions located in the dialog box of filezilla with each and every file transfer. Just the technical details are left out such as where to place the userinfo to establish the connection when creatinga URL. But actually very possible to place a file on the server.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

Joe Ridener wrote:Not so.... at least, it actually being impossible is not true.... As their are isntructions located in the dialog box of filezilla with each and every file transfer. Just the technical details are left out such as where to place the userinfo to establish the connection when creatinga URL. But actually very possible to place a file on the server.



FileZilla is simply a GUI front end to FTP. Which brings you back to writing your own client for FTP. Are you sure you want to do that? If all you want is FileZilla, just use it?

There are tons of details on the RFC for FTP. You should google for them. Its a fairly complex protocol, because it uses two TCP/IP ports and hands off connections from one to the other. It is not even vaguely similar to the HTTP protocol, even if all it takes for a user is to type ftp:// instead of http://

I recommend that you first ignore the details, and write a normal Java web program that accepts a normal HTTP form post. From scratch, this usually takes me a day. Get that going, and then go surf the web for the RFC and see if there are existing libraries, perhaps even from Apache, that do the work.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

Joe Ridener wrote:Not so.... at least, it actually being impossible is not true.... As their are isntructions located in the dialog box of filezilla with each and every file transfer. Just the technical details are left out such as where to place the userinfo to establish the connection when creatinga URL. But actually very possible to place a file on the server.


All the technical details are in the RFCs.

But your code does NOT create files on the host server. Your code requests that the FTP server that is already running on the server do this function for you. It may feel like a distinction without a difference, but its a critical difference for the host's security. You pass data to the host server, your code does not do anything but ask the server to do what you ask. It may, or it may not.

Also, note that most hosts are moving away from FTP because it exchanges credentials using clear text, so user-ids and passwords are passed in the clear. Most modern hosts require SFTP or SSH+FTP
Joe Ridener
Ranch Hand

Joined: Jul 16, 2012
Posts: 86
Pat Farrell wrote:

There are tons of details on the RFC for FTP. You should google for them. Its a fairly complex protocol, because it uses two TCP/IP ports and hands off connections from one to the other. It is not even vaguely similar to the HTTP protocol, even if all it takes for a user is to type ftp:// instead of http://

I recommend that you first ignore the details, and write a normal Java web program that accepts a normal HTTP form post. From scratch, this usually takes me a day. Get that going, and then go surf the web for the RFC and see if there are existing libraries, perhaps even from Apache, that do the work.


Pat Farrell wrote:

FileZilla is simply a GUI front end to FTP. Which brings you back to writing your own client for FTP. Are you sure you want to do that?
If all you want is FileZilla, just use it?





I know I use FileZilla all the time... I know exaclty what it is...
I believe I was referring to the dialog box that shows the communication between the FZ client and the server.
Commands that look very similar to SQL such as STOR, PASV ect.. looked quite easy.
FZ simply will not work for posting an online form from a JApplet
Note: I am not using form/input tags ... I custom designed my form with a paint method and a Graphics2D object.

Having display issues w/ some browsers...
feel free to check it out...

http://www.hoerdesigner.net

Pat Farrell wrote:

Its a fairly complex protocol, because it uses two TCP/IP ports and hands off connections from one to the other. It is not even vaguely similar to the HTTP protocol, even if all it takes for a user is to type ftp:// instead of http://



Is why I would create a URL object oppsed to a Socket object. Then simply call method open stream or get content.

Back to the orignal question before this turns into a lecture of ftp:

"... I custom designed my form with a paint method and a Graphics2D object." <-----------On a JApplet

Next step:
Gather user input...
Create a record object within the Java programming code

Things your recomending will not work from me.

The next step is to establish a netwrok connection....
As you said creating a .obj file could be problematic as it is on a server.

I simply need to save this data so clients/employers ect.. can use my online form and I can pick it up...



Joe Ridener
Ranch Hand

Joined: Jul 16, 2012
Posts: 86
http://www.joerdesigner.net
Sorry typoed
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

Joe Ridener wrote:I know I use FileZilla all the time... I know exaclty what it is...

I'm sorry, I don't think I'm communicating well. FileZilla is a program with a GUI that implements the FTP, SFTP, and SSH+FTP protocols.
The internals are non-trivial.

Joe Ridener wrote:Is why I would create a URL object oppsed to a Socket object. Then simply call method open stream or get content.


I have no idea what you are trying to convey here.

Joe Ridener wrote:Things your recomending will not work from me.
The next step is to establish a netwrok connection....
I simply need to save this data so clients/employers ect.. can use my online form and I can pick it up...


No, you don't need to "simply" do anything. If you want to implement FTP, you need to read the RFCs and understand them. Its not a simple problem. Or find a library that does the dirty work for you.

Its not a matter of changing a URL from http://www.coderanch.com to ftp://www.coderanch.com

Just opening a socket and passing data is about 5% of the job. The next step is not to open a network connection, its to understand what you need to do.



Joe Ridener
Ranch Hand

Joined: Jul 16, 2012
Posts: 86
I think looking up how to preform a POST method might be the best idea.

I have googled this before without much luck... any referall?
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

Joe Ridener wrote:I think looking up how to preform a POST method might be the best idea.

Again, write a trivial HTML page with a normal HTML form that does a POST.
Get that to work so you understand the basics.

Kill the idea of using applets, etc.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60732
    
  65

POST is an HTTP method; it has nothing at all to do with FTP.

I know I'm dropping in late to the party, but why any thoughts about FTP and FileZilla at all? If you are doing this from a web page, HTTP is the lingua franca of the Internet.

And since you mention applets (the dinosaurs of the web, as I mentioned in another topic) I assume you want to post from Java code, rather than an HTML form, or under JavaScript control. In that case, while HTTP is a far simpler protocol than FTP, it's still not trivial and I'd use an existing tool like HttpClient rather than rolling my own.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Joe Ridener
Ranch Hand

Joined: Jul 16, 2012
Posts: 86
Bear Bibeault wrote:POST is an HTTP method; it has nothing at all to do with FTP.

I know I'm dropping in late to the party, but why any thoughts about FTP and FileZilla at all? If you are doing this from a web page, HTTP is the lingua franca of the Internet.

And since you mention applets (the dinosaurs of the web, as I mentioned in another topic) I assume you want to post from Java code, rather than an HTML form, or under JavaScript control. In that case, while HTTP is a far simpler protocol than FTP, it's still not trivial and I'd use an existing tool like HttpClient rather than rolling my own.


FZ and FTP were mentioned by me as possible solutions to take a form.

Designed from scratch and placed on an Applet.. networking functionality has to be provided by me. The only way I know to upload a file is via FTP although it is prolly a pretty complex way to do it. Simply trying to turn the form info into a file or a record to be stored on a database or server. Its that simple.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

Joe Ridener wrote:FZ and FTP were mentioned by me as possible solutions to take a form.

Designed from scratch and placed on an Applet.. networking functionality has to be provided by me. The only way I know to upload a file is via FTP although it is prolly a pretty complex way to do it. Simply trying to turn the form info into a file or a record to be stored on a database or server. Its that simple.


But they don't take a form, they are programs and protocols.

You dont' want to use an applet. Seriously. No one should every use applets in 2013. You want to use HTML and forms, which are how its done on the Internet.

There is nothing simple about what you are talking about, and lots that is simple in what @bear and I are talking about.
 
wood burning stoves
 
subject: URL Constructors
 
Similar Threads
Urgent Ftp Command Problem
Apache Common VFS
FTP behind proxy
delete using ftp protocol
FTP in Java