我们正在使用IBM捆绑的Apache Wink为我们的应用程序提供JAXRS端点.我们正在编写Websphere 8.5.5.由于我们符合servlet 3.0,因此我们使用"编程"方式配置JaxRS应用程序,这意味着web.xml中没有条目,我们依赖类扫描来注释jax rs资源.一般来说它工作正常.
@ApplicationPath("/api/v1/")
public class MyApplication extends Application{
Run Code Online (Sandbox Code Playgroud)
这个版本的Websphere和Apache Wink一起使用Jackson 1.6.x进行JSON de/serialization,一般来说效果很好.我们希望改变Object Mapper的一些默认值
因此,我们定义了一个客户上下文解析器,只需更改一些se/deserialzation属性.
@Provider
@Produces(MediaType.APPLICATION_JSON)
public class CustomJackssonConverter implements ContextResolver<ObjectMapper> {
final ObjectMapper defaultObjectMapper;
public AibasJackssonConverter() {
defaultObjectMapper = createDefaultMapper();
}
...
mapper.getSerializationConfig().set(SerializationConfig.Feature.INDENT_OUTPUT, true);
Run Code Online (Sandbox Code Playgroud)
在JAX-RS调用期间,我们可以看到容器注册了新的Provider,没有错误
问题是,配置没有"跟随",从日志中我可以看到Wink引擎正在查找WinkJacksonProvider,而这反过来又回复了一个遵循Jackson(s)默认值的JacksonProvider?
有没有办法只更改此默认值?
我试图更改此处所示的Application对象的实现,以便以编程方式配置Providers,但它不起作用.
http://www.ibm.com/developerworks/java/library/wa-aj-jackson/index.html
任何提示或提示?
非常感谢
我一直在使用Apache Wink编写基于JAX-RS的ReST应用程序,我理解了路径参数与资源句柄类之间的关联概念.在这里,我看到,我们可以使用@Path注释和相应的资源来定义路径,这些资源将基于HTTP方法被调用.
现在我正在寻找类似资源的东西,应该调用可变数量的路径参数.
例如,我希望我的单个资源类CollegeResource应该像URI那样被调用,/rest/college, /rest/college/subject, /rest/college/subject/teachers, 并且它可以达到任意数量的路径参数.
如果我知道之前路径参数的数量,那么我可以使用类似的东西实现这一目标/rest/college/{param1}/{param2}.但路径参数的数量是未知的.所以我觉得(我可能错了)不能使用这种方法.
我仍然可以使用的另一种方法是使用查询参数.但我希望这只能作为路径参数.
有没有办法使用apache wink与任何其他配置完成此操作?如果不是在Apache wink中,任何其他JAX-RS实现都支持这个吗?
我有一个Maven项目,其中包含下面列出的依赖项:

wink.version = 1.1.3-incubating和spring.version = 3.0.5.RELEASE
Spring中的应用上下文包括:
<bean class="org.apache.wink.spring.Registrar">
<property name="classes">
<set value-type="java.lang.Class">
</set>
</property>
<property name="instances">
<set>
<ref local="restexample" />
</set>
</property>
</bean>
<bean id="restexample" class="com.example.rest.ExampleRest"></bean>
Run Code Online (Sandbox Code Playgroud)
web.xml包括:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:META-INF/wink/wink-core-context.xml
classpath:applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>restServlet</servlet-name>
<servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>restServlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)
Rest Java Class包括:
@Path("/ex")
public class ExampleRest {
@GET
@Produces(MediaType.APPLICATION_JSON)
public String example() throws IOException {
return "{ 'id':'test' }";
}
}
Run Code Online (Sandbox Code Playgroud)
查看日志我没有看到任何异常或问题,正在创建'restexample'bean但是...... 当我尝试调用REST服务时,我得到了404.
我认为Apache Wink没有注册ExampleRest.
任何的想法 ?
更新02/14:在日志中,我注意到Apache …
是否可以在JAX-RS资源上有效使用JSR303(Bean Validation)注释?
例如,如果我有一个资源成员,我注释了@NotEmpty,如果不满足此约束,则会向客户端生成错误?
这似乎是显而易见的事情,但也乐于被告知更好的方式(我不想将验证移到ORM /数据库级别)
我尝试通过需要身份验证的https连接到服务器.此外,我在中间有一个http代理,也需要身份验证.我使用ProxyAuthSecurityHandler对代理进行身份验证,使用BasicAuthSecurityHandler对服务器进行身份验证.
接收java.io.IOException:无法通过代理隧道.
Proxy returns "HTTP/1.1 407 Proxy Auth Required"
at sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnection.java:1525)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect (AbstractDelegateHttpsURLConnection.java:164)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:133)
at org.apache.wink.client.internal.handlers.HttpURLConnectionHandler.processRequest(HttpURLConnectionHandler.java:97)
Run Code Online (Sandbox Code Playgroud)
我注意到ProxyAuthSecurityHandler的实现期待响应代码407但是,在调试期间,由于抛出了IOException,我们永远不会到达第二部分.
代码快照:
ClientConfig configuration = new ClientConfig();
configuration.connectTimeout(timeout);
MyBasicAuthenticationSecurityHandler basicAuthProps = new MyBasicAuthenticationSecurityHandler();
basicAuthProps.setUserName(user);
basicAuthProps.setPassword(password);
configuration.handlers(basicAuthProps);
if ("true".equals(System.getProperty("setProxy"))) {
configuration.proxyHost(proxyHost);
if ((proxyPort != null) && !proxyPort.equals("")) {
configuration.proxyPort(Integer.parseInt(proxyPort));
}
MyProxyAuthSecurityHandler proxyAuthSecHandler =
new MyProxyAuthSecurityHandler();
proxyAuthSecHandler.setUserName(proxyUser);
proxyAuthSecHandler.setPassword(proxyPass);
configuration.handlers(proxyAuthSecHandler);
}
restClient = new RestClient(configuration);
// create the createResourceWithSessionCookies instance to interact with
Resource resource = getResource(loginUrl);
// Request body is empty
ClientResponse response = …Run Code Online (Sandbox Code Playgroud) 我想能够将一个GET请求传递给我的服务器suh:
http://example.com/?a[foo]=1&a[bar]=15&b=3
Run Code Online (Sandbox Code Playgroud)
当我得到查询参数'a'时,它应该被解析为HashMap,如下所示:
{'foo':1, 'bar':15}
Run Code Online (Sandbox Code Playgroud)
编辑:好的,要清楚,这是我想要做的,但在Java,而不是PHP:
任何想法如何实现这一目标?
我认为这是一个关于JAX-RS的一个非常基本的问题,但我不知道怎么也找不到答案.
我正在尝试重构REST服务,该服务使用"标准"Javax servlet - 将请求手动路由到方法 - 进入"更干净"的JAX-RS实现.当前应用程序在servlet init()期间设置一些变量.它将它们分配为HttpServlet类的属性,以便它们在每个doGet()期间可用,并且可以作为参数传递给请求处理方法.为清楚起见,其中一个是ConcurentHashMap,它充当缓存.
现在,使用JAX-RS,我可以扩展Application来设置我的资源类.我还可以在每个资源实现中使用@Context注释在处理请求时注入ServletContext之类的东西.但我不知道如何在应用程序初始化期间类似地注入变量集.
我正在使用JAX-RS的Apache Wink 1.3.0实现.
我需要从 Java REST 服务返回 Microsoft Excel 文件。我正在使用 WebSphere 8.5,它本质上使用 Apache Wink,因为它是 JAX-RS 实现;这是我无法改变的要求。我也在使用 Java 7 JDK。这是我收到的错误:
org.apache.wink.server.internal.handlers.FlushResultHandler handleResponse 系统找不到 com.somewhere.else.message.core.BaseResponseMessage 类型和应用程序的 javax.ws.rs.ext.MessageBodyWriter 或 DataSourceProvider 类/ vnd.ms-excel 媒体类型。确保在 JAX-RS 应用程序中存在指定类型和媒体类型的 javax.ws.rs.ext.MessageBodyWriter。
这是我的 Java Resource 类方法:
@GET
@Path("/report")
@Produces("application/vnd.ms-excel")
public Response getReport() {
int fileSize = 0;
byte[] reportByteArray = null;
ResponseBuilder responseBuilder = null;
InputStream report = null;
BaseResponseMessage<InputStream> baseResponseMessage = new
BaseResponseMessage<InputStream>();
Path reportPath = null;
String localPath = "C:/Users/me/Report.xls";
responseBuilder = Response.ok(baseResponseMessage);
responseBuilder.header("Content-Description", "File Transfer");
responseBuilder.header("Content-Disposition", "attachment;
filename=Report.xls");
responseBuilder.header("Content-Transfer-Encoding", …Run Code Online (Sandbox Code Playgroud) 我正在尝试设置一个玩具应用程序(有一天可能会转向真正的应用程序).我遇到了Wink和Jackson的问题.我有两个应用程序:一个在jetty上运行wink-server,似乎提供了一些JSON数据就好了; 一个在jetty上运行wink-client并且接收JSON数据就好了.问题在于将JSON数据自动反序列化回我的Java bean.
这是我在wink客户端操作中使用的代码:
RestClient client = new RestClient();
Resource resource = client.resource("http://localhost:8081/helloworld");
User user = resource.accept(MediaType.APPLICATION_JSON).get(User.class);
Run Code Online (Sandbox Code Playgroud)
这是我尝试运行Struts操作时收到的错误:
java.lang.RuntimeException: No javax.ws.rs.ext.MessageBodyReader found for type class my.package.structure.User and media type application/json. Verify that all entity providers are correctly registered.
org.apache.wink.client.internal.handlers.ClientResponseImpl.readEntity(ClientResponseImpl.java:123)
org.apache.wink.client.internal.handlers.ClientResponseImpl.getEntity(ClientResponseImpl.java:65)
org.apache.wink.client.internal.handlers.ClientResponseImpl.getEntity(ClientResponseImpl.java:52)
org.apache.wink.client.internal.ResourceImpl.invoke(ResourceImpl.java:186)
org.apache.wink.client.internal.ResourceImpl.get(ResourceImpl.java:294)
my.package.structure.action.HelloWorldAction.execute(HelloWorldAction.java:29)
...
Run Code Online (Sandbox Code Playgroud)
如果我用下面的代码替换第一个代码片段中的最后一行,一切都运行正常,花花公子.
String message = resource.accept(MediaType.APPLICATION_JSON).get(String.class);
ObjectMapper mapper = new ObjectMapper();
User user = mapper.readValue(message, User.class);
Run Code Online (Sandbox Code Playgroud)
很明显,数据很好,但问题似乎在于JacksonJsonProvider类没有在Wink客户端注册.我已经看到很多方法用Wink服务器注册提供程序,但不是Wink客户端.
是否可以使第一个代码段正常运行?如果是这样,怎么样?
(顺便说一句,另一个问题可能是我在我的User类上缺少注释.现在没有任何注释.也许我需要一些......)
我们正在研究使用哪个REST框架以及在何处运行它.
鉴于现有的WebSphere(6.1.0.17)环境,您会使用Jersey of Wink吗?
或者你会推荐一个不同的平台?
我正在尝试在OSGI中运行Apache Wink并使用Felix Whiteboard注册资源作为服务.在极简主义的OSGI环境中,捆绑包按预期工作.但是,然后我将捆绑包移动到Eclipse Equinox环境中,我正在开发一个依赖它的插件.我开始收到这个错误.
May 22, 2013 11:19:59 AM org.apache.wink.server.internal.application.ApplicationProcessor processWinkApplication
SEVERE: An exception occurred during processing of the com.yarcdata.rest.Repositories instance. This instance is ignored.
java.lang.IllegalArgumentException: interface javax.servlet.http.HttpServletRequest is not visible from class loader
at java.lang.reflect.Proxy.getProxyClass0(Proxy.java:461)
at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:690)
at org.apache.wink.common.internal.registry.ContextAccessor.getContextFromAccessor(ContextAccessor.java:92)
Run Code Online (Sandbox Code Playgroud)
我想我已经安装了所有必需的软件包,如果我开始寻找导出HttpServletRequest的软件包,我会看到:
g! lb | grep ervlet
311|Resolved | 4|Servlet API Bundle (3.0.0.v201112011016)
394|Starting | 4|Http Services Servlet (1.1.300.v20120912-130548)
444|Resolved | 4|Jetty :: Servlet Handling (8.1.3.v20120522)
578|Resolved | 4|jersey-servlet (1.12.0)
580|Resolved | 4|jersey-servlet (1.17.1)
588|Active | 4|Java Servlet API (3.0.1)
589|Resolved …Run Code Online (Sandbox Code Playgroud)