Errai 支持 JAX-RS,尽管当我尝试将它与提供的Maven 原型一起使用时, GWT 抱怨错误:
No source code is available for type javax.ws.rs.core.PathSegment; did you forget to inherit a required module?
PathSegment 接口似乎是官方 Java EE 标准的一部分,那么为什么这个类不可用呢?
Errai 支持 JAX-RS,尽管当我尝试将它与提供的Maven 原型一起使用时, GWT 抱怨错误:
No source code is available for type javax.ws.rs.core.PathSegment; did you forget to inherit a required module?
PathSegment 接口似乎是官方 Java EE 标准的一部分,那么为什么这个类不可用呢?
一种解决方案是在您的 GWT 项目中创建 javax.ws.rs.core 包,并为您自己包含接口。这些接口是 MultivaluedMap:
package javax.ws.rs.core;
import java.util.List;
import java.util.Map;
/**
* A map of key-values pairs. Each key can have zero or more values.
*
*/
public interface MultivaluedMap<K, V> extends Map<K, List<V>> {
/**
* Set the key's value to be a one item list consisting of the supplied value.
* Any existing values will be replaced.
*
* @param key the key
* @param value the single value of the key
*/
void putSingle(K key, V value);
/**
* Add a value to the current list of values for the supplied key.
* @param key the key
* @param value the value to be added.
*/
void add(K key, V value);
/**
* A shortcut to get the first value of the supplied key.
* @param key the key
* @return the first value for the specified key or null if the key is
* not in the map.
*/
V getFirst(K key);
}
路径段:
package javax.ws.rs.core;
/**
* Represents a URI path segment and any associated matrix parameters. When an
* instance of this type is injected with {@link javax.ws.rs.PathParam}, the
* value of the annotation identifies which path segment is selected and the
* presence of an {@link javax.ws.rs.Encoded} annotation will result in an
* instance that supplies the path and matrix parameter values in
* URI encoded form.
*
* @see UriInfo#getPathSegments
* @see javax.ws.rs.PathParam
*/
public interface PathSegment
{
/**
* Get the path segment.
* <p/>
*
* @return the path segment
*/
String getPath();
/**
* Get a map of the matrix parameters associated with the path segment.
* The map keys are the names of the matrix parameters with any
* percent-escaped octets decoded.
*
* @return the map of matrix parameters
* @see <a href="http://www.w3.org/DesignIssues/MatrixURIs.html">Matrix URIs</a>
*/
MultivaluedMap<String, String> getMatrixParameters();
}
您需要一个 GWT 模块文件(在 javax.ws.rs 包中):
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 1.6//EN"
"http://google-web-toolkit.googlecode.com/svn/releases/1.6/distro-source/core/src/gwt-module.dtd">
<module rename-to="App">
<source path="core"/>
</module>
您需要为您的应用程序 GWT 模块添加一个继承引用:
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 1.6//EN"
"http://google-web-toolkit.googlecode.com/svn/releases/1.6/distro-source/core/src/gwt-module.dtd">
<module rename-to="App">
<inherits name='com.google.gwt.user.User'/>
<inherits name="org.jboss.errai.common.ErraiCommon"/>
<inherits name="org.jboss.errai.ioc.Container"/>
<inherits name="org.jboss.errai.enterprise.Jaxrs"/>
<inherits name="com.redhat.topicindex.rest"/>
<inherits name="javax.ws.rs.core"/>
</module>