File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes A 404 Error, need help configuring web.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "A 404 Error, need help configuring web.xml" Watch "A 404 Error, need help configuring web.xml" New topic
Author

A 404 Error, need help configuring web.xml

Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Hi All,
I'm trying to get a set of servlets to work , these servlets are meant to interact with the foursquare API , and help me authorize a web application to run on their DB.
I try However, I'm getting a resource not found error. This is my web.xml


This is how I intend the flow of servlets to be - The user is authenticated in the Login servlet and then supposed go on to the auth sevlet with a code handle , however I get the error at this point.
Below is the code of the Login servlet



Learning and Learning!-- Java all the way!
Clemens Brunnow
Greenhorn

Joined: Jan 27, 2011
Posts: 10
im not sure, but i think the url-pattern must contain the application name

like this



or maybe

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61417
    
  67

No, the pattern does not include the context path, and yes, it must include the /.

Do the logs show anything? Are you sure that those classes are included in the web app?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Hi Bear,
Thanks for the quick reply! The logs indicate that Login class (responsible for authentication)executes correctly and Im able to print the redirect url , as well

Then the page redirects and loads the required page on foursquare.com, Which asks for a confirmation whether I would like my account to be accessed , and when I do allow it to be accessed, it redirects to the correct url with an authentication code. But the browser throws a 404 error. here's my authentication class , if thats of any help

Update:
And this is the precise error.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61417
    
  67

What happens when you type that URL directly into the browser? (You should have tried this already.)
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Yes. If you meant the same one that gave me the 404 error , I tried doing the same from a browser window(chrome) and it gave me the same error.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61417
    
  67

You never answered about the logs.
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Well Bear , I think I did . In the post above ,(quoted below) and that is all Im printing.
Vic Hood wrote:Hi Bear,
Thanks for the quick reply! The logs indicate that Login class (responsible for authentication)executes correctly and Im able to print the redirect url , as well

Vijay keshava
Ranch Hand

Joined: Jul 05, 2011
Posts: 40
Can you let us know the value of redirect_uri and also the value of the original URL (used to get the login page)?

Regards,
Vijay
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477


@above,
redirect uri is a String value, and its printing value.
And the url for the login page thats generated is

https://foursquare.com/oauth2/authenticate?client_id=NN3TBSPRBCVJMWCDPN1WELO1LOQLXAA31Q40WHW2L1BI5L1X&response_type=code&redirect_uri=http://localhost:8080/FourSquareDemo/auth
Pankaj Kumarkk
Ranch Hand

Joined: Apr 17, 2011
Posts: 108
Can you try replacing the localhost with the actual IP address of machine having the auth servlet.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61417
    
  67

You're sending a URL to foursquare that contains localhost as a server domain? Really? Think about that for a few second.
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Bear Bibeault wrote:You're sending a URL to foursquare that contains localhost as a server domain? Really? Think about that for a few second.


Uh yes. It did strange to me too, however I thought that was the way foursquare expected me to access their endpoint. In fact , Im just trying to implement the auth servlet from a code sample on this blog.
Quoting from the same blog
.

Users accessing your application need to sign-in to their foursquare account. Once they are signed in, your application can access their data.
First step in authentication is to redirect your users to:

https://foursquare.com/oauth2/authenticate?client_id=CLIENT_ID&response_type=code&redirect_uri=REDIRECT_URI;
CLIENT_ID and REDIRECT_URI are your API credentials.

If user signs in, foursquare will send a “CODE” to the path specified in redirect_uri. For instance, if your request_uri is: http://localhost:8080/foursquare/auth , foursquare will send code as GET request to your application: http://localhost:8080/foursquare/auth?code=CODE
This code is then embedded in your request to get “access_token” from foursquare. This “access_token” will be a part of all your requests to foursquare webservice. To get access_token, a GET request is sent:

https://foursquare.com/oauth2/access_token?client_id=CLIENT_ID&client_secret=CLIENT_SECRET&grant_type=authorization_code&redirect_uri=REDIRECT_URI&code=CODE
CLIENT_ID, CLIENT_SECRET and REDIRECT_URI are your API credentials while CODE is the code sent by foursquare when user signs in.

In the sample application, authentication is done by invoking “/login” (login.java). “login” servlet redirects the user to foursquare.

I guess I'm grossly misreading something here.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61417
    
  67

I suspect they want you to send them a callback URL. But sending them localhost won't work because localhost means "whatever system you are currently on". So to them, its their system not yours.

In any case, until you get your servlet working locally, it makes no sense to send anything to foursquare.
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Bear Bibeault wrote:I suspect they want you to send them a callback URL. But sending them localhost won't work because localhost means "whatever system you are currently on". So to them, its their system not yours.
.

Bang on!CallBack URL it is.
Bear Bibeault wrote:In any case, until you get your servlet working locally, it makes no sense to send anything to foursquare.
.
How do you suggest I go ahead with that?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61417
    
  67

Start from scratch explaining how you have everything set up. All this talk of foursquare in this topic is a red herring and is merely clouding the issue. You're not ready to even think of sending anything to them.

Pretend none of this topic has happened, and post your web.xml, and how you have the web app structured.
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Bear Bibeault wrote:Start from scratch explaining how you have everything set up. All this talk of foursquare in this topic is a red herring and is merely clouding the issue. You're not ready to even think of sending anything to them.

Pretend none of this topic has happened, and post your web.xml, and how you have the web app structured.


Okay, well here goes . This is how I 've structured my web app.So far , the user logs on using the Login.java servlet and is supposed to be redirected to the foursquare site asking him for confirmation . I plan to use the same Login class for the same , as I m able to print the redirection url correctly . And this url also does take me to the required link when I run it on a browser ,however when I run the servlet/project,I get a message saying the 'Page cannot be displayed'
So I'm assuming its something wrong with the web.xml
which is as below
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61417
    
  67

Stop with the foursquare info. It's not relevant until you can hit the servlet yourself by typing the address in the URL bar of the browser. Again, keep the red herrings out of the discussion.

There doesn't seem to be anything wrong with the deployment descriptor as written. But where's the rest of the relevant info?

Where did you place the WEB-INF folder? Where did you place the servlet class? How are you deploying the web app?
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Bear Bibeault wrote:Stop with the foursquare info. It's not relevant until you can hit the servlet yourself by typing the address in the URL bar of the browser. Again, keep the red herrings out of the discussion.

There doesn't seem to be anything wrong with the deployment descriptor as written. But where's the rest of the relevant info?

Where did you place the WEB-INF folder? Where did you place the servlet class? How are you deploying the web app?


Well the WEB-INF folder is WebContent and the servlet class is in com.test.foursquare package within the root , Im using an eclipse auto generated dynamic web project structure .I've attached a snip of my structure below. And what other relevant info am I missing out in providing?


[Thumbnail for pic1.PNG]

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61417
    
  67

Oh, eclipse. I thought you were doing this in the real environment.

At this point I'd suggest either having this topic moved to the IDE forum, or having it closed (my recommendation as this topic went way too off-topic for anyone to try and read from the beginning) and post a new topic in the IDEs forum to get eclipse set up correctly.

That's not an appropriate topic for this forum.
Pankaj Kumarkk
Ranch Hand

Joined: Apr 17, 2011
Posts: 108
Do you have only one servlet configured in your system. Can you post the complete web.xml.
The error essentially means that that the server was not able to map the requested url to a valid server side resource.
German Gonzalez-Morris
Ranch Hand

Joined: Nov 16, 2009
Posts: 176

In the URI: https://foursquare.com/oauth2/authenticate?client_id=NN3TBSPRBCVJMWCDPN1WELO1LOQLXAA31Q40WHW2L1BI5L1X&response_type=code&redirect_uri=http://localhost:8080/FourSquareDemo/auth

Does http://localhost:8080/FourSquareDemo/auth exist in your server ?

Does the "FourSquareDemo" context exist in your web container ?

Maybe it is called "FourSquareDemo1" or different name. If you are receiving 404 simply the resource is not deployed in you web container.

Cheers,


http://devwebcl.blogspot.com/
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Ah well, as Bear rightly pointed out , It was a mistake due to misunderstanding the call back url . Will have to get back to the drawing board.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A 404 Error, need help configuring web.xml