我想让我的JAX-RX应用程序从根上下文开始,所以我的URL将是
http://example.com/restfullPath
并不是
http://example.com/rest/restfullPath
我从这里切换了我的应用程序注释
@ApplicationPath("/rest/*")
Run Code Online (Sandbox Code Playgroud)
对此
@ApplicationPath("/*")
Run Code Online (Sandbox Code Playgroud)
但它似乎接管了服务文件,如/index.html
有没有办法在根应用程序上下文中运行JAX-RS但仍然提供静态页面?
看来这是之前在JBOSS论坛上提出的,但解决方案并不实用
我有一个Web应用程序,为客户提供30多个REST服务(使用Jersey).是否可以为我的应用程序自动创建WADL文档?
我需要这个,以便我可以在SoapUI中配置它来测试各种场景并保存以供以后使用.
我正在验证Jersey中REST资源端点中的POJO:
public class Resource {
@POST
public Response post(@NotNull @Valid final POJO pojo) {
...
}
}
public class POJO {
@NotNull
protected final String name;
@NotNull
@Valid
protected final POJOInner inner;
...
}
public class POJOInner {
@Min(0)
protected final int limit;
...
}
Run Code Online (Sandbox Code Playgroud)
这似乎工作正常.
但是,@Min(0)仅当字段inner具有@Valid注释时才会验证注释.将@Valid注释添加到不是基元的每个字段是不正确的.
有没有办法告诉bean验证器自动递归继续验证,即使没有@Valid注释?我希望我POJO如下:
public class POJO {
@NotNull
protected final String name;
@NotNull
protected final POJOInner inner;
...
}
Run Code Online (Sandbox Code Playgroud) JAX-RS 1.1规范在第6页说:
如果没有Application子类,则添加的servlet必须命名为:
Run Code Online (Sandbox Code Playgroud)javax.ws.rs.core.Application
添加的servlet是什么?它可能是一个任意的servlet吗?
如果存在Application子类,并且已经定义了一个servlet具有名为的servlet初始化参数:
Run Code Online (Sandbox Code Playgroud)javax.ws.rs.Application
再说一次,这里的"servlet"是什么?
如果存在未由现有servlet处理的Application子类,则ContainerInitializer添加的servlet必须使用Application子类的完全限定名称命名.
"由ContainerInitializer添加的servlet"是否意味着自动添加servlet?配置如何?
目前我既不使用Application类也不使用web.xml,它可以使用(使用GlassFish 3.1).这种部署机制是否需要完整的类路径扫描,这对于大型库来说可能会很慢?
如何在Servlet容器上部署?
Web中存在令人困惑的配置选项.在web.xml中使用context params查看此示例(对我来说不起作用!).部署JAX-RS应用程序的首选方法是什么?
我已经读过,我可以创建一个javax.ws.rs.ext.ExceptionMapper将抛出的应用程序异常映射到Response对象的实现.
我创建了一个简单的示例,如果持久化对象时手机长度超过20个字符,则抛出异常.我期望将异常映射到HTTP 400(错误请求)响应; 但是,我收到HTTP 500(内部服务器错误),但有以下异常:
java.lang.ClassCastException: com.example.exception.InvalidDataException cannot be cast to java.lang.Error
Run Code Online (Sandbox Code Playgroud)
我错过了什么?任何意见是极大的赞赏.
异常映射器:
@Provider
public class InvalidDataMapper implements ExceptionMapper<InvalidDataException> {
@Override
public Response toResponse(InvalidDataException arg0) {
return Response.status(Response.Status.BAD_REQUEST).build();
}
}
Run Code Online (Sandbox Code Playgroud)
例外类:
public class InvalidDataException extends Exception {
private static final long serialVersionUID = 1L;
public InvalidDataException(String message) {
super(message);
}
...
}
Run Code Online (Sandbox Code Playgroud)
实体类:
@Entity
@Table(name="PERSON")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class Person {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="ID")
private Long id;
@Column(name="NAME")
private String name;
@Column(name="PHONE")
private …Run Code Online (Sandbox Code Playgroud) 我们可以@Path为同一个REST方法使用多个注释,即执行的方法是相同的,但它是在访问多个URL时执行的吗?
例如:我要运行的searchNames()两个方法http://a/b/c和http://a/b.
我尝试启动应用程序,但使用Tomcat 7,我有这样的例外.
我认为这可以是一些东西Maven dependency,但我确定.如果有人知道发生了什么,请回答:)
例外:
message Servlet execution threw an exception
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Servlet execution threw an exception
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.lang.AbstractMethodError: javax.ws.rs.core.UriBuilder.uri(Ljava/lang/String;)Ljavax/ws/rs/core/UriBuilder;
javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:119)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:651)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.50 logs.
Run Code Online (Sandbox Code Playgroud)
Maven POM:
<properties>
<application.version>1.0</application.version>
<spring.version>4.0.0.RELEASE</spring.version>
<spring.security.version>3.2.0.RELEASE</spring.security.version>
<jersey.version>1.18.1</jersey.version>
</properties>
<dependencies>
<dependency>
<groupId>climbing-portal-facade</groupId>
<artifactId>climbing-portal-facade</artifactId>
<version>${application.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>${jersey.version}</version> …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个RESTful Web服务,我创建了一个,但我得到了一个
找不到媒体类型= application/json错误的MessageBodyWriter
我的Todo班级:
package com.jersey.jaxb;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import org.pojomatic.Pojomatic;
import org.pojomatic.annotations.AutoProperty;
@XmlRootElement
@XmlType(name = "todo")
@XmlAccessorType(XmlAccessType.FIELD)
@AutoProperty
public class Todo {
@XmlElement(name = "summary")
private final String summary;
@XmlElement(name = "description")
private final String description;
public String getSummary() {
return summary;
}
public String getDescription() {
return description;
}
public Todo() {
this(new Builder());
}
public Todo(Builder builder) {
this.summary = builder.summary;
this.description = builder.description;
}
@Override
public …Run Code Online (Sandbox Code Playgroud) 关于何时应该使用URL的路径参数而不是应该使用查询参数时,是否有经验法则?
说我有一个表发票与字段公司(PK),InvoiceNo(PK),Invoiceline,invoiceValue,noOfLines,salesPerson
我目前的想法是你的网址应该是这样的
/Invoice/
Run Code Online (Sandbox Code Playgroud)
哪个会显示所有发票
/Invoice/{company}
Run Code Online (Sandbox Code Playgroud)
这将显示公司的所有发票.
/Invoice/{company}/{InvoiceNo}
Run Code Online (Sandbox Code Playgroud)
显示特定发票和
/Invoice/{company}/{InvoiceNo}?invoiceLineNo=23
Run Code Online (Sandbox Code Playgroud)
仅显示第23行.
我想的方式是主键字段应该是路径的一部分,你要过滤的任何其他字段都是查询参数的一部分.
这听起来像是区分两者的合理方式吗?
我正在尝试使用异步响应构建REST Web服务.
我在网上查看了这个错误,但是,没有一个解决方案对我有用.我不确定如何去做.
这是REST服务的代码,它有AsyncResponse,@Suspended它取自pom.xml我指定的jar文件,我将在下面提供.问题是,在部署战争时,我得到一个例外:
java.lang.AbstractMethodError: javax.ws.rs.core.UriBuilder.uri(Ljava/lang/String;)Ljavax/ws/rs/core/UriBuilder;
javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:119)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:651)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.50 logs
Run Code Online (Sandbox Code Playgroud)
我的班级如下:
package com.crudapp;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import javax.annotation.Generated;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
//import javax.ws.rs.core.UriBuilder;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.google.gson.Gson;
import com.mysql.jdbc.StringUtils;
import dao.User;
import dao.UserDAO;
import dao.UserDAOImpl;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
@Path("/crudpath") …Run Code Online (Sandbox Code Playgroud)