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

Développement Web en Java Discussion :

Get ressources impossible


Sujet :

Développement Web en Java

  1. #1
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2014
    Messages
    96
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 30
    Localisation : France, Val d'Oise (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Octobre 2014
    Messages : 96
    Points : 51
    Points
    51
    Par défaut Get ressources impossible
    Bonsoir,

    Je suis débutant en JavaEE et je n'arrive pas à récupérer ma ressource (Error 404).
    Je m'excuse pour tout le code qui suit mais je suis totalement perdu ..

    Classe ContextListener

    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
     public class ContextListener implements ServletContextListener {
     
    	@Override
    	public void contextInitialized(ServletContextEvent sce) {
    		// TODO Auto-generated method stub
    		BasicConfigurator.configure();
    		CountriesUtil.init(sce.getServletContext());
    	}
     
    	@Override
    	public void contextDestroyed(ServletContextEvent sce) {
    		// TODO Auto-generated method stub
     
    	}
     
    }
    Classe CountriesUtil

    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
    public class CountriesUtil {
    	private static final Logger logger = Logger.getLogger(CountriesUtil.class);
        private static final JSONArray ja =  new JSONArray();
    	private static final Hashtable<String, String> name = new Hashtable<String, String>();
    	private static final Hashtable<String, String> alpha2 = new Hashtable<String, String>();
    	private static final Hashtable<String, String> alpha3 = new Hashtable<String, String>();
    	private static final Hashtable<String, String> e212 = new Hashtable<String, String>();
    	private static final Hashtable<String, String> latlon = new Hashtable<String, String>();
    	private static int size = 5;
    	private static int nbCountries;
     
    	private static String encode(String content) {
    		Charset cs = Charset.forName("UTF-8");
    		ByteBuffer bb = ByteBuffer.wrap(content.getBytes());
    		CharBuffer cb = cs.decode(bb);
    		String s = cb.toString();
    		return s;
        }
    	private static void set(String key, JSONObject jo) {
    		if (alpha2.containsKey(key))
    			logger.info("key: " + key + " existe déjà");
    		alpha2.put(key, "{\"ISO3166_1_Alpha_2\":\"" + (String) jo.get("ISO3166_1_Alpha_2") + "\"}");
    		alpha3.put(key, "{\"ISO3166_1_Alpha_3\":\"" + (String) jo.get("ISO3166_1_Alpha_3") + "\"}");
    		name.put(key, "{\"name\":\"" + (String) jo.get("name") + "\"}");
    		e212.put(key, "{\"ITU_E212\":\"" + (String) jo.get("ITU_E212") + "\"}");
    		latlon.put(key, "{\"lat\":\"" + (String) jo.get("lat") + "\",\"lng\":\"" + (String) jo.get("lng") + "\"}");
    	}
     
    	@SuppressWarnings("unchecked")
    	public static void init(ServletContext servletContext) {
    		try {
     
    			JSONObject jo = new JSONObject();
    			InputStream ips = servletContext.getResourceAsStream("../countries.txt");
    			InputStreamReader ipsr = new InputStreamReader(ips);
    			BufferedReader br = new BufferedReader(ipsr);
    			String ligne;
    			boolean first = true;
    			String[] keys = null;
    			String[] values = null;
    			// create json
    			while ((ligne = br.readLine()) != null) {
    				ligne = encode(ligne);
    				if (first) {
    					first = false;
    					keys = ligne.split(";");
    					for (int i = 0; i < keys.length; i++)
    						logger.info(keys[i]);
     
    				} else {
    					values = ligne.split(";");
    					jo = new JSONObject();
    					for (int i = 0; i < keys.length; i++) {
    						jo.put(keys[i], values[i]);
    					}
    					ja.add(jo);
    					logger.info(((JSONAware) jo).toJSONString());
    				}
    			}
    			nbCountries = ja.size();
     
    			for (int i = 0; i < ja.size(); i++) {
    				jo = (JSONObject) ja.get(i);
    				String CC = (String) jo.get("CC");
    				String NDC = (String) jo.get("NDC");
    				if (!NDC.isEmpty()) {
    					String[] NDCs = NDC.split(",");
    					for (int j = 0; j < NDCs.length; j++) {
    						String CCNDC = CC + NDCs[j];
    						logger.info("CCNDC: " + CCNDC);
    						CCNDC = CCNDC.trim();
    						if (CCNDC.length() > size)
    							size = CCNDC.length() + 1;
    						set(CCNDC, jo);
    					}
    				} else {
    					set(CC, jo);
    					logger.info("CCNDC: " + CC);
    				}
    			}
     
     
     
    			br.close();
    		} catch (Exception e) {
    			logger.info(e.getMessage());
    		}
    	}
     
    public static String getE212(String Number) {
    		for (int i = size; i > 0; i--) {
    			if (Number.length() >= i - 1) {
    				String key = Number.substring(0, i - 1);
    				logger.info("i: " + i + ", number: " + Number.length() + ", key: " + key);
    				if (e212.containsKey(key))
    					return e212.get(key);
    			}
    		}
    		return null;
    	}
    Classe E212

    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
    @Path("/e212")
    @Api(value = "/e212", description = "Get Mobile Code Country (E212) from the phone number")
    @Produces({ "application/json", "application/xml" })
    public class E212 {
     
    	private static final Logger logger = Logger.getLogger(E212.class);
     
    	@GET
    	@Path("/{param}")
    	@ApiOperation(value = "return param", notes = "see ITU-E212", response = E212.class)
    	@ApiImplicitParam(name = "param",value = "id", required = true, dataType = "string", paramType = "path")
    	@ApiResponses({ @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 500, message = "Process error"),
    			@ApiResponse(code = 204, message = "No content") })
    	@Produces(MediaType.TEXT_HTML)
    	public String getSomething(@PathParam("param") String id) {
     
    		logger.info("start");
    		if (logger.isDebugEnabled()) {
    			logger.debug("Start getSomething");
    			logger.debug("data: '" + id + "'");
    		}
    		String response = CountriesUtil.getE212(id);
     
    		if (logger.isDebugEnabled()) {
    			logger.debug("result: '" + response + "'");
    			logger.debug("End getSomething");
    		}
    		return response;
    	}
     
     
    }

    web.xml

    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
     
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" metadata-complete="false" version="3.0">
      <display-name>countrycode</display-name>
      <listener>
        <listener-class>ContextListener</listener-class>
      </listener>
      <context-param>
        <param-name>resteasy.resources</param-name>
        <param-value>
    			E212
          </param-value>
      </context-param>
      <context-param>
        <param-name>resteasy.providers</param-name>
        <param-value></param-value>
      </context-param>
      <listener>
        <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
      </listener>
      <servlet>
        <servlet-name>RestEasyServletAdaptor</servlet-name>
        <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
        <init-param>
          <param-name>resteasy.servlet.mapping.prefix</param-name>
          <param-value>/v1</param-value>
        </init-param>
      </servlet>
      <servlet-mapping>
        <servlet-name>RestEasyServletAdaptor</servlet-name>
        <url-pattern>/v1/*</url-pattern>
      </servlet-mapping>
      <welcome-file-list>
        <welcome-file>index.html</welcome-file>
      </welcome-file-list>
    </web-app>

    Bonne soirée à vous et merci.

  2. #2
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    URL utilisée lor du 404?
    Log du serveur depuis le déploiement de l'application jusqu'à l'erreur?

  3. #3
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2014
    Messages
    96
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 30
    Localisation : France, Val d'Oise (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Octobre 2014
    Messages : 96
    Points : 51
    Points
    51
    Par défaut
    Bonjour,

    Je travail en local (/countrycode/v1/e212/33)

    Log

    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
    [INFO] Scanning for projects...
    [INFO]                                                                         
    [INFO] ------------------------------------------------------------------------
    [INFO] Building countrycode 0.0.1-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO] 
    [INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ countrycode ---
    [debug] execute contextualize
    [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
    [INFO] skip non existing resourceDirectory C:\Users\MAJORELLE\workspace\countrycode\src\main\resources
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ countrycode ---
    [INFO] Nothing to compile - all classes are up to date
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 17.403s
    [INFO] Finished at: Thu Dec 31 12:46:20 CET 2015
    [INFO] Final Memory: 5M/15M
    [INFO] ------------------------------------------------------------------------
    Pom.xml

    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
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>countrycode</groupId>
      <artifactId>countrycode</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <packaging>war</packaging>
      <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
          <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
              <source>1.7</source>
              <target>1.7</target>
            </configuration>
          </plugin>
          <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
              <warSourceDirectory>WebContent</warSourceDirectory>
              <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </project>

  4. #4
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Citation Envoyé par DiR95 Voir le message
    Bonjour,

    Je travail en local (/countrycode/v1/e212/33)
    Ca change rien au fait qu'il y a une url dans le browser pour avoir un 404, donc donne cette url et les logs du serveur depuis le déploiement de l'application jusqu'à l'erreur

  5. #5
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2014
    Messages
    96
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 30
    Localisation : France, Val d'Oise (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Octobre 2014
    Messages : 96
    Points : 51
    Points
    51
    Par défaut
    http://localhost:8080/countrycode/v1/e212/33

    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
    déc. 31, 2015 4:22:00 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
    AVERTISSEMENT: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:CountryCode' did not find a matching property.
    déc. 31, 2015 4:22:00 PM org.apache.catalina.startup.VersionLoggerListener log
    INFOS: Server version:        Apache Tomcat/7.0.65
    déc. 31, 2015 4:22:00 PM org.apache.catalina.startup.VersionLoggerListener log
    INFOS: Server built:          Oct 9 2015 08:36:58 UTC
    déc. 31, 2015 4:22:00 PM org.apache.catalina.startup.VersionLoggerListener log
    INFOS: Server number:         7.0.65.0
    déc. 31, 2015 4:22:00 PM org.apache.catalina.startup.VersionLoggerListener log
    INFOS: OS Name:               Windows 7
    déc. 31, 2015 4:22:00 PM org.apache.catalina.startup.VersionLoggerListener log
    INFOS: OS Version:            6.1
    déc. 31, 2015 4:22:00 PM org.apache.catalina.startup.VersionLoggerListener log
    INFOS: Architecture:          x86
    déc. 31, 2015 4:22:00 PM org.apache.catalina.startup.VersionLoggerListener log
    INFOS: Java Home:             C:\Program Files\Java\jre7
    déc. 31, 2015 4:22:00 PM org.apache.catalina.startup.VersionLoggerListener log
    INFOS: JVM Version:           1.7.0_60-b19
    déc. 31, 2015 4:22:00 PM org.apache.catalina.startup.VersionLoggerListener log
    INFOS: JVM Vendor:            Oracle Corporation
    déc. 31, 2015 4:22:00 PM org.apache.catalina.startup.VersionLoggerListener log
    INFOS: CATALINA_BASE:         C:\Users\MAJORELLE\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
    déc. 31, 2015 4:22:00 PM org.apache.catalina.startup.VersionLoggerListener log
    INFOS: CATALINA_HOME:         C:\Users\MAJORELLE\Desktop\apache-tomcat-7.0.65
    déc. 31, 2015 4:22:00 PM org.apache.catalina.startup.VersionLoggerListener log
    INFOS: Command line argument: -Dcatalina.base=C:\Users\MAJORELLE\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
    déc. 31, 2015 4:22:00 PM org.apache.catalina.startup.VersionLoggerListener log
    INFOS: Command line argument: -Dcatalina.home=C:\Users\MAJORELLE\Desktop\apache-tomcat-7.0.65
    déc. 31, 2015 4:22:00 PM org.apache.catalina.startup.VersionLoggerListener log
    INFOS: Command line argument: -Dwtp.deploy=C:\Users\MAJORELLE\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
    déc. 31, 2015 4:22:00 PM org.apache.catalina.startup.VersionLoggerListener log
    INFOS: Command line argument: -Djava.endorsed.dirs=C:\Users\MAJORELLE\Desktop\apache-tomcat-7.0.65\endorsed
    déc. 31, 2015 4:22:00 PM org.apache.catalina.startup.VersionLoggerListener log
    INFOS: Command line argument: -Dfile.encoding=Cp1252
    déc. 31, 2015 4:22:01 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
    INFOS: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre1.8.0_31/bin/client;C:/Program Files/Java/jre1.8.0_31/bin;C:/Program Files/Java/jre1.8.0_31/lib/i386;C:\Program Files\WinRAR;D:\app\MAJORELLE\product\11.2.0\dbhome_1\bin;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Broadcom\Broadcom 802.11 Network Adapter\Driver;C:\Users\MAJORELLE\AppData\Local\Smartbar\Application\;C:\Program Files\Common Files\GTK\2.0\bin;C:\Program Files\MiKTeX 2.9\miktex\bin\;C:\Program Files\erl6.2\bin;C:\Program Files\doxygen\bin;C:\Program Files\Skype\Phone\;;C:\Users\MAJORE~1\AppData\Local\Temp\Rar$EX66.272\eclipse;;.
    déc. 31, 2015 4:22:02 PM org.apache.coyote.AbstractProtocol init
    INFOS: Initializing ProtocolHandler ["http-bio-8080"]
    déc. 31, 2015 4:22:02 PM org.apache.coyote.AbstractProtocol init
    INFOS: Initializing ProtocolHandler ["ajp-bio-8009"]
    déc. 31, 2015 4:22:02 PM org.apache.catalina.startup.Catalina load
    INFOS: Initialization processed in 5009 ms
    déc. 31, 2015 4:22:02 PM org.apache.catalina.core.StandardService startInternal
    INFOS: Démarrage du service Catalina
    déc. 31, 2015 4:22:02 PM org.apache.catalina.core.StandardEngine startInternal
    INFOS: Starting Servlet Engine: Apache Tomcat/7.0.65
    déc. 31, 2015 4:22:04 PM org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom
    INFOS: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [381] milliseconds.
    déc. 31, 2015 4:22:05 PM org.apache.catalina.startup.TldConfig execute
    INFOS: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
    déc. 31, 2015 4:22:05 PM org.apache.coyote.AbstractProtocol start
    INFOS: Starting ProtocolHandler ["http-bio-8080"]
    déc. 31, 2015 4:22:05 PM org.apache.coyote.AbstractProtocol start
    INFOS: Starting ProtocolHandler ["ajp-bio-8009"]
    déc. 31, 2015 4:22:05 PM org.apache.catalina.startup.Catalina start
    INFOS: Server startup in 2917 ms

  6. #6
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    d'après ces logs, il n'y a aucune application déployée dans ton tomcat, comment as-tu fais le déploiement?

  7. #7
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2014
    Messages
    96
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 30
    Localisation : France, Val d'Oise (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Octobre 2014
    Messages : 96
    Points : 51
    Points
    51
    Par défaut
    Problème réglé. J'ai un return null que j'aperçois dans mon logger, je ne sais pas pourquoi alors que je renvois quelque chose et j'aimerais savoir si je peux envoyer le code ici ou j'ouvre un autre topic?

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Affichage des images et URL get Ressource
    Par yaya_la_rafale dans le forum AWT/Swing
    Réponses: 9
    Dernier message: 10/12/2010, 17h20
  2. Impossible de créer Fichier ressource
    Par laclac dans le forum Visual C++
    Réponses: 2
    Dernier message: 16/12/2007, 22h54
  3. Réponses: 1
    Dernier message: 05/10/2006, 14h31
  4. Réponses: 6
    Dernier message: 19/06/2006, 10h43
  5. Réponses: 16
    Dernier message: 04/05/2006, 23h02

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