Tag: jax rs

javax.ws.rs.NotFoundException:使用RESTEasy和Wildfly 8.1.0.Final找不到完整路径的资源

我面临以下问题。 我已经花了3天多的时间,但找不到解决方案。 请指导我在这里做错了什么。 我是野生蝇新来的Resteasy。 这是堆栈跟踪 19:05:57,610 WARN [org.jboss.resteasy.core.ExceptionHandler] (default task-14) failed to execute: javax.ws.rs.NotFoundException: Could not find resource for full path: http://localhost:8080/admin-ws/services/user/getUser at org.jboss.resteasy.core.registry.ClassNode.match(ClassNode.java:73) [resteasy-jaxrs-3.0.8.Final.jar:] at org.jboss.resteasy.core.registry.RootClassNode.match(RootClassNode.java:48) [resteasy-jaxrs-3.0.8.Final.jar:] at org.jboss.resteasy.core.ResourceMethodRegistry.getResourceInvoker(ResourceMethodRegistry.java:444) [resteasy-jaxrs-3.0.8.Final.jar:] at org.jboss.resteasy.core.SynchronousDispatcher.getInvoker(SynchronousDispatcher.java:234) [resteasy-jaxrs-3.0.8.Final.jar:] at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:171) [resteasy-jaxrs-3.0.8.Final.jar:] at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220) [resteasy-jaxrs-3.0.8.Final.jar:] at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56) [resteasy-jaxrs-3.0.8.Final.jar:] at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51) [resteasy-jaxrs-3.0.8.Final.jar:] at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final] at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final] at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final] […]

找不到Jersey + Json媒体类型应用程序/ json

我正在尝试简单的Jersey + JSON示例,但我得到以下错误message body writer for Java class com.test.jsonexample and MIME media type application/json was not found 我把以下jar文件用于获得适当的结果 asm-3.1.jar jackson-core-asl-1.9.9.jar jackson-jaxrs-1.9.9.jar jackson-mapper-asl-1.9.9.jar jackson-xc-1.9.9.jar jersey-client-1.9.jar jersey-core-1.9.1.jar jersey-json-1.9.jar jersey-server-1.9.1.jar jettison-1.3.2.jar jsr311-api-1.1.1.jar 为什么我会收到此类错误? 错误日志在这里: SEVERE: Mapped exception to response: 500 (Internal Server Error) javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException: A message body writer for Java class com.test.Jsonexample, and Java type class com.test.Jsonexample, […]

在JAX-RS中使用@ Context,@ Provider和ContextResolver

我刚刚熟悉使用JAX-RS在Java中实现REST Web服务,我遇到了以下问题。 我的一个资源类需要访问存储后端,后端在StorageEngine接口后面被抽象出来。 我想将当前的StorageEngine实例注入到为REST请求提供服务的资源类中,我认为这样做的好方法是使用@Context注释和适当的@Context类。 这是我到目前为止: 在MyResource.java : class MyResource { @Context StorageEngine storage; […] } 在StorageEngineProvider.java : @Provider class StorageEngineProvider implements ContextResolver { private StorageEngine storage = new InMemoryStorageEngine(); public StorageEngine getContext(Class type) { if (type.equals(StorageEngine.class)) return storage; return null; } } 我正在使用com.sun.jersey.api.core.PackagesResourceConfig自动发现提供程序和资源类,并根据日志,它很好地获取StorageEngineProvider类(故意留下时间戳和不必要的东西): INFO: Root resource classes found: class MyResource INFO: Provider classes found: class […]

DropWizard Auth by Example

我试图了解DropWizard中的身份validation和授权是如何工作的。 我已经阅读了他们的auth指南以及GitHub上的dropwizard-security项目,但我觉得我仍然缺少一些重要的概念。 public class SimpleCredential { private String password; public SimpleCredential(String password) { super(); this.password = password; } } public class SimplePrincipal { pivate String username; public SimplePrincipal(String username) { super(); this.username = username; } } public class SimpleAuthenticator implements Authenticator { @Override public Optional authenticate(SimpleCredential credential) throws AuthenticationException { if(!”12345″.equals(credential.getPassword())) { throw new AuthenticationException(“Sign […]

什么是rest服务的应用程序类生命周期?

大家好我是新来的rest和jax-rs所以我的问题是每个rest服务开始扩展该应用程序类和定义应用程序路径。 现在我的问题是该应用程序类本身的生命周期是什么? 这是一个例子: import javax.ws.rs.core.Application; @javax.ws.rs.ApplicationPath(“resources”) public class ApplicationConfig extends Application {} 这是一个servlet吗? 它总是活着吗? 我怎么理解这堂课? 它是一个cdi豆? 服务器是否在每个请求上创建此类?

获取ContainerRequestFilter中的资源类注释值

我正在努力理解rest拦截器注释如何添加稍后在filter中可见的不同值。 鉴于下面的代码,我希望在filter中,权限值将包含foo和bar,但它们是空的。 任何帮助将不胜感激。 注解 package edu.psu.swe.fortress.poc.interceptor; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import javax.enterprise.util.Nonbinding; import javax.ws.rs.NameBinding; @NameBinding @Target({ElementType.TYPE, ElementType.METHOD}) @Retention(value=RetentionPolicy.RUNTIME) public @interface FortressProtected { @Nonbinding String[] permissions() default {}; } 过滤 package edu.psu.swe.fortress.poc.interceptor; import java.io.IOException; import java.lang.annotation.Annotation; import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.container.ContainerRequestFilter; import javax.ws.rs.ext.Provider; @Provider @FortressProtected public class FortressAuthorizer implements ContainerRequestFilter { @Override public […]

设置JAX-RS 2.0客户端API的请求超时

我编写了简单的REST Web服务客户端类,它使用JAX-RS 2.0客户端API来发出REST请求。 我试图弄清楚如何为每次调用设置请求超时。 以下是请求的代码: Client client = ClientBuilder.newBuilder().build(); WebTarget resourceTarget = client.target(restServiceUrl) .path(“{regsysID}/{appointmentID}/”) .resolveTemplate(“regsysID”, regSysId) .resolveTemplate(“appointmentID”, apptId); Invocation invocation = resourceTarget.request(MediaType.APPLICATION_JSON).buildPut(null); String createSessionJson = invocation.invoke(String.class);

使用JAX-RS的FileUpload

我尝试从JavaScript客户端上传文件到JAX-RS Java服务器。 我在我的服务器上使用以下REST上传function: @POST @Produces(‘application/json’) UploadDto upload( @Context HttpServletRequest request, @QueryParam(“cookie”) String cookie) { def contentType byte [] fileBytes log.debug “upload – cookie: “+cookie try{ if (request instanceof MultipartHttpServletRequest) { log.debug “request instanceof MultipartHttpServletRequest” MultipartHttpServletRequest myrequest = request CommonsMultipartFile file = (CommonsMultipartFile) myrequest.getFile(‘file’) fileBytes = file.bytes contentType = file.contentType log.debug “>>>>> upload size of the […]

如何在运行grizzly的java se上启用web服务(jaxrs / jersey)中的CDI注入?

如何允许CDI将资源注入到宁静的Web服务资源中? 我使用焊接2(cdi),泽西(jaxrs)和灰熊(web服务器)在标准java上运行。 这是我简单的网络资源: import training.student.StudentRepository; import javax.inject.Inject; import javax.ws.rs.*; @Path(“student”) public class StudentWebResource { @Inject private StudentRepository studentRepository; @GET @Path(“count”) @Produces(MediaType.TEXT_PLAIN) public Integer getCount() { return studentRepository.studentCount(); } } 以下是我如何通过简单的Web服务器启动焊接: public class Main { public static void main(String[] args) throws Exception { startCdiApplication(); } public static void startCdiApplication() throws Exception { Weld weld = new […]

如何处理Spring Boot重定向到/ error?

我遇到了与此问题相同的问题,使用Spring Boot 1.3.0并且没有使用@RestController注释我的控制器,只有@Path和@Service 。 正如该问题中的OP所说, 对我来说,这不是明智的事 我也无法理解他们为什么会重定向到/错误。 我很可能错过了一些东西 ,因为我只能向客户回馈404或200。 我的问题是他的解决方案似乎不适用于1.3.0,所以我有以下请求流:让我们说我的代码抛出NullPointerException 。 它将由我的一个ExceptionMapper处理 @Provider public class GeneralExceptionMapper implements ExceptionMapper { private static final Logger LOGGER = LoggerFactory.getLogger(GeneralExceptionMapper.class); @Override public Response toResponse(Throwable exception) { LOGGER.error(exception.getLocalizedMessage()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } } 我的代码返回500,但不是将其发送回客户端,而是尝试将其重定向到/ error。 如果我没有其他资源,它会发回404。 2015-12-16 18:33:21.268 INFO 9708 — [nio-8080-exec-1] o.glassfish.jersey.filter.LoggingFilter : 1 * Server has received a request […]