jira插件开发| servlet问题

fumotvh3  于 2021-07-23  发布在  Java
关注(0)|答案(0)|浏览(225)

我是一个为jira开发插件的学生,在让servlet读取html文件时遇到了麻烦。所以现在我想知道哪些注解是正确的,哪些依赖关系是正确的?。我没有收到任何错误消息,只是无法打开index.vm页。
如果有人能看看我的代码,我附上下面,或只是帮助我找到合适的人谁是在这个领域的知识。
谢谢你的帮助//rickard
我的servlet

package com.i3tex.plugin.servlet;

import com.atlassian.jira.issue.IssueManager;
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
import com.atlassian.templaterenderer.TemplateRenderer;
import com.atlassian.velocity.VelocityManager;
import com.atlassian.webresource.api.assembler.PageBuilderService;
import com.google.common.collect.Maps;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import javax.inject.Inject;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@Component
public class SumalizerServlet extends HttpServlet {

    @ComponentImport
    private final VelocityManager velocityManager;
    @ComponentImport
    private PageBuilderService pageBuilderService;
    private IssueManager im;
    private TemplateRenderer tr;

    private static final Logger log = LoggerFactory.getLogger(
            SumalizerServlet.class
    );

    @Inject
    public SumalizerServlet(VelocityManager velocityManager, PageBuilderService pageBuilderService, IssueManager im, TemplateRenderer tr) {
        this.velocityManager = velocityManager;
        this.pageBuilderService = pageBuilderService;
        this.im = im;
        this.tr = tr;
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.pageBuilderService
                .assembler()
                .resources()
                .requireWebResource("com.i3tex.plugin.Sumalizer:test-resource");

        Map<String, Object> context = Maps.newHashMap();
        context.put("ic", this.im.getIssueCount());

        String content = this.velocityManager.getEncodedBody("/templates/", "index.vm", "UTF-8", context);

        response.setContentType("text/html;charset=utf-8");
        response.getWriter().write(content);
        response.getWriter().close();
    }
}

atlassian-plugin.xml文件

<?xml version="1.0" encoding="UTF-8"?>

<atlassian-plugin key="${atlassian.plugin.key}" name="${project.name}" plugins-version="2"> 
  <plugin-info> 
    <description>${project.description}</description>  
    <version>${project.version}</version>  
    <vendor name="${project.organization.name}" url="${project.organization.url}"/>  
    <param name="plugin-icon">images/pluginIcon.png</param>  
    <param name="plugin-logo">images/pluginLogo.png</param> 
  </plugin-info>  

  <resource type="i18n" name="i18n" location="Sumalizer"/>  
  <web-resource key="Sumalizer-resources" name="Sumalizer Web Resources"> 
    <resource type="download" name="Sumalizer.css" location="/css/Sumalizer.css"/>  
    <resource type="download" name="Sumalizer.js" location="/js/Sumalizer.js"/>  
    <resource type="download" name="images/" location="/images"/>  
    <context>Sumalizer</context>
  </web-resource>  

  <!--  Menu link to my servlet  -->
  <web-item name="Sumalizer" i18n-name-key="sumalizer.name" key="sumalizer" section="find_link/issues_new" weight="1000"> 
    <description key="sumalizer.description">The Sumalizer Plugin</description>  
    <label key="sumalizer.label"/>  
    <link linkId="sumalizer-link">/plugins/servlet/sumalizer</link> 
  </web-item>

  <!--  This is my servlet  -->
  <servlet name="Sumalizer Servlet" i18n-name-key="sumalizer-servlet.name" key="sumalizer-servlet" class="com.i3tex.plugin.servlet.SumalizerServlet">
    <description key="sumalizer-servlet.description">The Sumalizer Servlet Plugin</description>  
    <url-pattern>/sumalizer</url-pattern> 
  </servlet>

  <!--  My test resource  -->
  <web-resource key="test-resource" name="test-resource">
    <resource type="download" name="test.css" location="/css/test.css"/>
    <resource type="download" name="test.js" location="/js/test.js"/>
  </web-resource>

</atlassian-plugin>

这是我的pom.xml

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.i3tex.plugin</groupId>
    <artifactId>Sumalizer</artifactId>
    <version>0.0.1</version>
    <organization>
        <name>i3tex</name>
        <url>http://www.i3tex.com/</url>
    </organization>
    <name>Sumalizer</name>
    <description>This is the Sumalizer plugin.</description>
    <packaging>atlassian-plugin</packaging>
<dependencies>
    <dependency>
        <groupId>com.atlassian.templaterenderer</groupId>
        <artifactId>atlassian-template-renderer-api</artifactId>
        <version>4.1.1</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>com.atlassian.jira</groupId>
        <artifactId>jira-api</artifactId>
        <version>${jira.version}</version>
        <scope>provided</scope>
        <exclusions>
            <exclusion>
                <groupId>jta</groupId>
                <artifactId>jta</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>com.atlassian.sal</groupId>
        <artifactId>sal-api</artifactId>
        <version>2.0.17</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.4</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.6</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>com.atlassian.plugin</groupId>
        <artifactId>atlassian-spring-scanner-annotation</artifactId>
        <version>${atlassian.spring.scanner.version}</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <version>1</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.1.1</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.plugins</groupId>
        <artifactId>atlassian-plugins-core</artifactId>
        <version>5.3.5</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>5.3.4</version>
        <scope>provided</scope>
    </dependency>

</dependencies>
    <build>
        <plugins>
         <plugin>
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>jira-maven-plugin</artifactId>
                <version>${amps.version}</version>
                <extensions>true</extensions>
                <configuration>
                    <productVersion>${jira.version}</productVersion>
                    <productDataVersion>${jira.version}</productDataVersion>
                    <enableQuickReload>true</enableQuickReload>

                    <instructions>
                        <Atlassian-Plugin-Key>${atlassian.plugin.key}</Atlassian-Plugin-Key>

                        <Export-Package>
                            com.i3tex.api,
                        </Export-Package>

                        <Import-Package>
                            org.springframework.osgi.*;resolution:="optional",
                            org.eclipse.gemini.blueprint.*;resolution:="optional",
                            *
                        </Import-Package>

                        <Spring-Context>*</Spring-Context>
                    </instructions>
                </configuration>
            </plugin>

            <plugin>
                <groupId>com.atlassian.plugin</groupId>
                <artifactId>atlassian-spring-scanner-maven-plugin</artifactId>
                <version>${atlassian.spring.scanner.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>atlassian-spring-scanner</goal>
                        </goals>
                        <phase>process-classes</phase>
                    </execution>
                </executions>
                <configuration>
                    <includeExclude>+com.atlassian.jira.plugins.issue.create.*</includeExclude>
                    <scannedDependencies>
                        <dependency>
                            <groupId>com.atlassian.plugin</groupId>
                            <artifactId>atlassian-spring-scanner-external-jar</artifactId>
                        </dependency>
                    </scannedDependencies>
                    <verbose>false</verbose>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <properties>
        <jira.version>7.13.18</jira.version>
        <amps.version>8.1.0</amps.version>
        <osgi.javaconfig.version>0.2.0</osgi.javaconfig.version>
        <spring.version>4.2.5.RELEASE</spring.version>
        <plugin.testrunner.version>2.0.1</plugin.testrunner.version>
        <atlassian.spring.scanner.version>2.2.0</atlassian.spring.scanner.version>
        <atlassian.plugin.key>${project.groupId}.${project.artifactId}</atlassian.plugin.key>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <repositories>
        <repository>
            <releases>
                <enabled>true</enabled>
                <checksumPolicy>warn</checksumPolicy>
            </releases>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
                <checksumPolicy>warn</checksumPolicy>
            </snapshots>
            <id>atlassian-public</id>
            <url>https://maven.atlassian.com/repository/public</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <releases>
                <enabled>true</enabled>
                <checksumPolicy>warn</checksumPolicy>
            </releases>
            <snapshots>
                <updatePolicy>never</updatePolicy>
                <checksumPolicy>warn</checksumPolicy>
            </snapshots>
            <id>atlassian-public</id>
            <url>https://maven.atlassian.com/repository/public</url>
        </pluginRepository>
    </pluginRepositories>

</project>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题