我用的是球衣。我有休息方法:
@PUT
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Path("/create-profile")
public void createProfile (Profile profile) throws UnableTransferToEntity {
EntityManager em = emf.createEntityManager();
try{
em.getTransaction().begin();
em.persist(EntityConversionUtils.transformReporterProfileToSimpleProfileEntity(profile));
em.getTransaction().commit();
}finally{
em.close();
}
}
为此方法生成的 wadl 部分:
<resource path="/create-profile">
<method id="createProfile" name="PUT">
<request>
<representation mediaType="application/json"/>
<representation mediaType="application/xml"/>
</request>
</method>
</resource>
我正在使用 maven-plugin 生成客户端:
<groupId>org.jvnet.ws.wadl</groupId>
<artifactId>wadl-maven-plugin</artifactId>
<version>1.1-SNAPSHOT</version>
问题是没有生成 void 方法 (putApplicationXml Asvoid ),只有期望响应的方法。当我尝试使用它们时,即使预期为 Void.class,我也会捕获异常(返回 204 No Content 的响应状态)。
如果其余方法包含@QueryParam:
@DELETE
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Path("/remove-profile")
public void removeProfile (@QueryParam("id") final int id){
EntityManager em = emf.createEntityManager();
SimpleProfileEntity simpleProfileEntity = em.find(SimpleProfileEntity.class, id);
new NotificationService().removeProfile(simpleProfileEntity.getNotificationProfile().getId());
try{
em.getTransaction().begin();
em.remove(simpleProfileEntity);
em.getTransaction().commit();
}finally{
em.close();
}
}
然后 wadl 看起来像:
<resource path="/remove-profile">
<method id="removeProfile" name="DELETE">
<request>
<param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="id" style="query" type="xs:int"/>
</request>
</method>
</resource>
如您所见,它包含“param”节点。此条目的 void 客户端方法生成良好。
如何为我的 CreateProfile 生成 void 方法?