【发布时间】:2016-03-29 13:19:57
【问题描述】:
我正在尝试在 AEM 上公开一些 RESTfull Web 服务。我已按照blog 中的说明进行操作。下面是我的服务类。像 /helloservice/sayhi 这样的简单请求可以完美运行,但是带有路径参数和查询参数的方法(/withparameter/{userid} 和 /query?q=xyz&prod=abc)返回 404 错误页面。请帮我解决这个问题。
我正在使用 AEM 5.6 和 Java 7
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import com.foo.bar.service.SampleResource;
@Service
@Component(metatype=true)
@Path("/helloservice")
public class SampleResourceImpl implements SampleResource{
@GET
@Path("/sayhi")
@Produces({MediaType.APPLICATION_JSON})
public String helloWorld(){
return "Hello World";
}
@GET
@Path("/getoperation")
@Produces({MediaType.TEXT_PLAIN})
public String getServiceOperation(){
return "Hello getoperation!";
}
@GET
@Path("/withparameter/{userid}")
@Produces({MediaType.TEXT_PLAIN})
public String getWithParameter(@PathParam("userid") String userid){
return "Path parameter : "+userid;
}
@GET
@Path("/query")
@Produces({MediaType.TEXT_PLAIN})
public String getURLParameters(@QueryParam("q") String q, @QueryParam("prod") String prod){
return "Query params : "+q+", "+prod;
}
}
任何帮助表示赞赏,谢谢!
【问题讨论】:
-
如何从邮递员那里测试上述服务?我正在尝试访问 localhost:4502/services/helloservice/sayhi 网址。但在邮递员中得到 404