• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A 404 Error, need help configuring web.xml

 
Ranch Hand
Posts: 477
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
im not sure, but i think the url-pattern must contain the application name

like this



or maybe

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happens when you type that URL directly into the browser? (You should have tried this already.)
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You never answered about the logs.
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 477
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

@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
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you try replacing the localhost with the actual IP address of machine having the auth servlet.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 477
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 477
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 477
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 477
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
pic1.PNG
[Thumbnail for pic1.PNG]
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 376
2
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
There are 29 Knuts in one Sickle, and 17 Sickles make up a Galleon. 42 tiny ads in a knut:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic