mercredi 8 mai 2019

Tomcat 8 404 error in rest services

I have an issue with Tomcat 8 server when deploying web servers writteb in java. Code working fine on Glassfish makes Tom return 404 error- not found. Below is my code and URL link i use to access service:

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.mycompany.projectitc_2019;

import java.util.Set; import javax.ws.rs.ApplicationPath; import javax.ws.rs.core.Application;

/** * * @author mragl */ @ApplicationPath("/rest") public class ApplicationConfig extends Application {

public ApplicationConfig(){}

@Override
public Set<Class<?>> getClasses() {
    Set<Class<?>> resources = new java.util.HashSet<>();
    addRestResourceClasses(resources);
    return resources;
}

/**
 * Do not modify addRestResourceClasses() method.
 * It is automatically populated with
 * all resources defined in the project.
 * If required, comment out calling this method in getClasses().
 */
private void addRestResourceClasses(Set<Class<?>> resources) {
    resources.add(com.mycompany.projectitc_2019.GenericResource.class);
    resources.add(com.mycompany.projectitc_2019.TestService.class);
}}

@Path("/restful") public class TestService {

@Context
private UriInfo context;

/**
 * Creates a new instance of TestService
 */
public TestService() {
}

/**
 * Retrieves representation of an instance of com.mycompany.projectitc_2019.TestService
 * @return an instance of java.lang.String
 */
@GET
@Produces(MediaType.TEXT_HTML)
public String getHtml() {
    //TODO return proper representation object
    return "some text";

// throw new UnsupportedOperationException(); }

/**
 * PUT method for updating or creating an instance of TestService
 * @param content representation for the resource
 */
@PUT
@Consumes(MediaType.TEXT_HTML)
public void putHtml(String content) {
}

}

my project name is ProjectITC_2019 , so I try to use this URL link

http://localhost:8080/ProjectITC_2019/rest/restful/

but I get error

HTTP Status 404 – Not Found Type Status Report

Message /ProjectITC_2019/rest/restful/

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

Apache Tomcat/8.5.40

I want to know what is wrong with service cause root site opens and works

http://localhost:8080/ProjectITC_2019/

I tried putting and removing slashes but it was of no help




Aucun commentaire:

Enregistrer un commentaire