1
我正在使用球衣。 我得休息法:無法從wadl生成球衣客戶端的無效方法
@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的插件生成客戶端:
<groupId>org.jvnet.ws.wadl</groupId>
<artifactId>wadl-maven-plugin</artifactId>
<version>1.1-SNAPSHOT</version>
問題是沒有void方法(putApplicationXml Asvoid)生成,只有需要響應的方法。當我嘗試使用它們,即使使用Void.class,我也會捕獲異常(返回響應狀態204無內容)。
如果其他方法包含@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>
正如你可以看到它包含 「參數」 節點。 此條目的無效客戶端方法生成良好。
如何爲我的CreateProfile生成void方法?