javax.ws.rs.core.PathSegment和Errai

时间:2012-05-28 01:15:11

标签: java-ee-6 jax-rs errai

Errai has support for JAX-RS,虽然当我尝试将其与提供的Maven archetype GWT一起使用时抱怨错误:

No source code is available for type javax.ws.rs.core.PathSegment; did you forget to inherit a required module?

The PathSegment interface appears to be part of the official Java EE standard,为什么这个课程不可用?

1 个答案:

答案 0 :(得分:1)

解决方案是在GWT项目中创建javax.ws.rs.core包,并为自己包含接口。这些接口是多值映射:

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);

}

PathSegment:

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>