IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Services Web Java Discussion :

Service web REST


Sujet :

Services Web Java

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2014
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2014
    Messages : 12
    Points : 6
    Points
    6
    Par défaut Service web REST
    Bonjour,

    Dans mes premiers essais de création d'un web service sous eclipse jee, ça ne marche pas, quand j'exécute la classe java pour tester "http://localhost:8080/testBiblio/Bibbli/city?City_id=1" la réponse est que la page web et introuvable, ci joint le code de ma classe java.

    Et merci de m'aider pour résoudre le problème est avancer dans mon application.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    package testBiblio;
     
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.PropertyResourceBundle;
    import java.util.ResourceBundle;
     
    import javax.ws.rs.*;
    import javax.ws.rs.core.MediaType;
     
    import org.codehaus.jettison.json.JSONArray;
    import org.codehaus.jettison.json.JSONException;
    import org.codehaus.jettison.json.JSONObject;
     
    import java.sql.Statement;
     
    @Path("/Bibbli")
    public class biblioTestWS {
     
    	// Connection CONSTANTS
    	private static String LOGIN = null;
    	private static String PASSWORD = null;
    	private static String DRIVER = null;
    	private static String URL = null;
     
    	public static Connection getConnection() {
     
    		ResourceBundle rb = PropertyResourceBundle
    				.getBundle("testBiblio.DBConf");
     
    		LOGIN = rb.getString("login");
    		PASSWORD = rb.getString("password");
    		DRIVER = rb.getString("driver");
    		URL = rb.getString("url");
     
    		Connection maConnection = null;
     
    		try {
    			Class.forName(DRIVER);
    		} catch (ClassNotFoundException e) {
    			// TODO Auto-generated catch block
    			System.out
    					.println("---------------------------------------------------------------------");
    			System.out.println("----------DRIVER CONNECTION");
    			e.printStackTrace();
    			System.out
    					.println("---------------------------------------------------------------------");
     
    		}
     
    		try {
    			maConnection = DriverManager.getConnection(URL, LOGIN, PASSWORD);
    		} catch (SQLException e) {
    			// TODO Auto-generated catch block
    			System.out
    					.println("---------------------------------------------------------------------");
    			System.out.println("----------DATA BASE ACCESS");
    			e.printStackTrace();
    			System.out
    					.println("---------------------------------------------------------------------");
     
    		}
     
    		return maConnection;
    	}
     
    	@GET
    	@Path("/ville")
    	@Produces(MediaType.APPLICATION_JSON)
    	public String getVille(@QueryParam("City") String city_id) {
     
    		Connection dbCon = null;
    		dbCon = getConnection();
     
    		Statement stmt;
    		try {
    			stmt = dbCon.createStatement();
     
    			String query = "SELECT lib_name FROM library where city_id = '"
    					+ city_id + "';";
     
    			System.out.println(query);
     
    			ResultSet rs = stmt.executeQuery(query);
     
    			JSONArray jsonArray = new JSONArray();
    			System.out
    			.println("---------------------------------------------------------------------");
    			System.out
    			.println("------------------------- LISTE DES BIBLIO   ------------------");
     
    			while (rs.next()) {
     
    				String lib_name = rs.getString("lib_name");
     
    				System.out
    				.println("-------->>>>>> "+lib_name);
     
    				JSONObject jsonObject = new JSONObject();
    				try {
    					jsonObject.put("library", lib_name);
    					jsonArray.put(jsonObject);
    				} catch (JSONException e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				}
     
    			}
     
     
    			System.out
    			.println("---------------------------------------------------------------------");
     
    			return jsonArray.toString();
    		} catch (SQLException e1) {
    			// TODO Auto-generated catch block
    			e1.printStackTrace();
     
    		}
    		return null;
     
    	}
     
    }

  2. #2
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    22
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 22
    Points : 17
    Points
    17
    Par défaut
    Ne serait-ce plutôt la requête suivante ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    http://localhost:8080/testBiblio/Bibbli/ville/City=1

  3. #3
    Membre émérite
    Avatar de Mickael_Istria
    Homme Profil pro
    Développeur Expert Eclipse IDE/RCP, pour Red Hat
    Inscrit en
    Juillet 2008
    Messages
    1 469
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur Expert Eclipse IDE/RCP, pour Red Hat
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 469
    Points : 2 997
    Points
    2 997
    Par défaut
    2 conseils, completement distincts:
    * Quand tu postes, utilise la balise [ CODE]public MonCode { ... }[/CODE] pour que ton code soit plus lisible
    * Pour Jax-RS sous Eclipse, je te conseille d'utilise JBoss Tools, qui as plein de petits trucs pour faciliter le developpement
    Pour du HTML, CSS, JavaScript, TypeScript, JSon, Yaml, Node... dans Eclipse IDE, installe Eclipse Wild Web Developer
    Pour du Rust dans Eclipse IDE, installe Eclipse Corrosion
    Follow me on twitter

  4. #4
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2014
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2014
    Messages : 12
    Points : 6
    Points
    6
    Par défaut service web Rest
    concernant la requête c'est la même;

    pour les conseils je vous remercie, je suis débutant et j'ai besoin de tout conseil et remarque

  5. #5
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    22
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 22
    Points : 17
    Points
    17
    Par défaut
    Je me suis trompé dans la requête proposée.
    - Ta racine est /Bibbli
    - L'uri de ton service est "ville" (et non "city") et prends un paramètre d'url "City" (et non city_id qui est le nom de l'attribut de ta méthode java)

    Ta requête doit donc être

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    http://localhost:8080/testBiblio/Bibbli/ville?City=1

  6. #6
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2014
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2014
    Messages : 12
    Points : 6
    Points
    6
    Par défaut
    Même avec cette requête ça ne marche pas !!!

Discussions similaires

  1. [1.x] Services web REST et insertion de données
    Par gavelin dans le forum Symfony
    Réponses: 1
    Dernier message: 20/09/2010, 12h27
  2. Service web REST et c++
    Par toopac dans le forum C++/CLI
    Réponses: 9
    Dernier message: 18/06/2010, 18h37
  3. Service web REST en VB.NET Hey!Spread
    Par hbhhhbhh dans le forum Services Web
    Réponses: 0
    Dernier message: 21/05/2010, 14h54
  4. Implémenter un service web RESTful en Java
    Par Arnaud_03 dans le forum REST
    Réponses: 4
    Dernier message: 21/04/2009, 18h06
  5. Implémenter un service web RESTful
    Par Arnaud_03 dans le forum Services Web
    Réponses: 4
    Dernier message: 21/04/2009, 18h06

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo