Jira Gadget:对 REST 资源的简单调用不起作用
Posted
技术标签:
【中文标题】Jira Gadget:对 REST 资源的简单调用不起作用【英文标题】:Jira Gadget: Simple call to REST resource doesn't work 【发布时间】:2011-09-17 01:13:42 【问题描述】:我试图在 jira 插件中编写一个小工具,即使是一个非常简单的插件,我也遇到了一些问题。目前我正在尝试从我编写的一个简单的 java 类中获得响应。以下代码位于我的 gadget.xml 中:
Hello Gadget<br />
#requireResource("com.atlassian.gadgets.publisher:ajs-gadgets")
#requireResource("com.tngtech.gadgets.jira-complain-gadget-plugin:web-resources")
#includeResources()
#oauth
<script type="text/javascript">(function ()
var gadget = AJS.Gadget(
baseUrl: "__ATLASSIAN_BASE_URL__",
view:
onResizeAdjustHeight: true,
enableReload: true,
template: function(args)
var gadget = this;
window.alert("1");
gadget.getView().html(args.hello);
window.alert("2");
,
args: [
key: "hello",
ajaxOptions: function ()
return
url: "/rest/jira-rest/1.0/ComplainChart/HelloWorld"
;
]
);
)();
</script>
]]></Content>
我处理的 Java 类如下所示:
@Path("/ComplainChart")
@AnonymousAllowed
@Produces(MediaType.TEXT_HTML)
public class ComplainChart
public ComplainChart()
@GET
@Path("/HelloWorld")
@Produces(MediaType.TEXT_HTML)
public Response getVersionsForProject()
return Response.ok("Hello Java<br/>").build();
URL 可能是正确的,get 请求的 firebug 输出如下所示:
throw 1; < don't be evil' >"http://localhost:1990/jira/rest/jira-rest/1.0/complainChart/HelloWorld?cacheBuster=1308293636385":"headers":"set-cookie":["JSESSIONID=5652167D4DADE39719C4FED0C7174A03;Path=/","atlassian.xsrf.token=BV8N-OK2J-IQUQ-YNNK|b52c0f4b28944d7d11561aed079093f767448aca|lin; Path=/jira"],"body":"Hello Java<br/>","rc":200
即使没有 gadget.getView 部分,警报也不会执行(它们没有 args 部分),并且我在 atlas-run 终端中获得了巨大的堆栈跟踪
[INFO] [talledLocalContainer] com.atlassian.util.concurrent.LazyReference$InitializationException: com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.
[INFO] [talledLocalContainer] at com.atlassian.util.concurrent.LazyReference.getInterruptibly(LazyReference.java:152)
[INFO] [talledLocalContainer] at com.atlassian.util.concurrent.LazyReference.get(LazyReference.java:115)
[INFO] [talledLocalContainer] at com.atlassian.plugin.servlet.DefaultServletModuleManager.getFilter(DefaultServletModuleManager.java:358)
[INFO] [talledLocalContainer] at com.atlassian.plugin.servlet.DefaultServletModuleManager.getFilters(DefaultServletModuleManager.java:212)
.............
谁能帮帮我?
亚历克斯
编辑:这里是我的 pom 文件,我不确定,完全正确:
<dependencies>
<dependency>
<groupId>com.atlassian.gadgets</groupId>
<artifactId>atlassian-gadgets-api</artifactId>
<version>3.1.7</version>
</dependency>
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>atlassian-jira</artifactId>
<version>$jira.version</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-func-tests</artifactId>
<version>$jira.version</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-rest-plugin</artifactId>
<version>$jira.version</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.atlassian.plugins.rest</groupId>
<artifactId>atlassian-rest-common</artifactId>
<version>2.5.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.atlassian.sal</groupId>
<artifactId>sal-api</artifactId>
<version>2.1.0.beta1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-jira-plugin</artifactId>
<version>3.5-SNAPSHOT</version>
<extensions>true</extensions>
<configuration>
<productVersion>$jira.version</productVersion>
<productDataVersion>$jira.data.version</productDataVersion>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<jira.version>4.3.4</jira.version>
<jira.data.version>4.3.4</jira.data.version>
</properties>
【问题讨论】:
【参考方案1】:找到解决方案:您需要返回一个自己的类的对象,并带有如下注释:
@XmlRootElement
public static class HelloClass
@XmlElement
String output;
HelloClass()
output = "Hello";
HelloClass(String who)
output = "Hello " + who;
【讨论】:
“自己的班级”是什么意思?我正在返回一个对象,但仍然收到此错误。【参考方案2】:我在更改 REST API 实现后遇到了同样的问题。首先,我恢复了我的更改,但没有奏效(我不明白为什么)。比我按照这里的建议添加了 XmlRootElement ,但它也不起作用。重新启动服务器,重新编译一个干净的插件,......没有任何效果。
所以我绝望地删除了 /target 文件夹并重新启动了操作系统。只有那对我有用。
【讨论】:
是的,maven 中损坏的构建依赖项会花费很多时间。以上是关于Jira Gadget:对 REST 资源的简单调用不起作用的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 JIRA Cloud REST API 创建对 jira 问题的内部评论