Rak*_*esh 4 java rest jax-ws aem
我试图在AEM上公开一些RESTfull Web服务.我已按照此博客中的说明操作.以下是我的服务类.像/ 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;
}
}
Run Code Online (Sandbox Code Playgroud)
任何帮助表示感谢,谢谢!
目前正在讨论如何在基于Apache Sling(包括AEM)的系统中使用JAX-RS ,网址为https://issues.apache.org/jira/browse/SLING-2192.从这个讨论,https://github.com/wcm-io-caravan/caravan-jaxrs在我看来就像一个很好的解决方案在OSGi环境中使用JAX-RS资源.该项目的集成测试在Sling上运行,因此它很可能在AEM上运行.
| 归档时间: |
|
| 查看次数: |
2192 次 |
| 最近记录: |