简体   繁体   English

扩展 org.eclipse.equinox.http.registry.servlets 不起作用

[英]Extending org.eclipse.equinox.http.registry.servlets does not work

Im trying to make an servlet extension to org.eclipse.equinox.http.registry.servlets extension point, but cant get it working.我正在尝试对 org.eclipse.equinox.http.registry.servlets 扩展点进行 servlet 扩展,但无法使其正常工作。 Ill try to write down my proccess so maybe someone can tell me what im doing wrong or what i didnt do :)我会试着写下我的过程,所以也许有人可以告诉我我做错了什么或我没有做什么:)

So, first i made just a jetty server with a default servlet.所以,首先我只制作了一个带有默认 servlet 的码头服务器。

Here was my initial pom:这是我最初的pom:

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>myserver</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>myserver</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <bundle.symbolicName>myserver</bundle.symbolicName>
        <bundle.namespace>com.example</bundle.namespace>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.core</artifactId>
            <version>4.3.0</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-servlet</artifactId>
            <version>8.1.10.v20130312</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <extensions>true</extensions>
                <executions>
                    <execution>
                        <id>bundle-manifest</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>manifest</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <manifestLocation>META-INF</manifestLocation>
                    <instructions>
                        <Bundle-SymbolicName>${bundle.symbolicName}</Bundle-SymbolicName>
                        <Bundle-Version>${pom.version}</Bundle-Version>
                        <Bundle-Activator>${bundle.namespace}.myserver.App</Bundle-Activator>
                        <Import-Package>
                            org.osgi.framework,
                            javax.servlet,
                            javax.servlet.http,
                            org.eclipse.jetty.server,
                            org.eclipse.jetty.servlet
                        </Import-Package>
                        <Require-Bundle>
                        </Require-Bundle>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Here is my App thats a bundle activator:这是我的应用程序,它是一个捆绑激活器:

package com.example.myserver;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

public class App implements BundleActivator {

    public void start(BundleContext context) throws Exception {
        Server server = new Server(8080);

        ServletContextHandler c = new ServletContextHandler(server, "/");
        c.addServlet(new ServletHolder(new HelloWorldServlet()),"/test");

        server.start();
        server.join();
    }

    public void stop(BundleContext context) throws Exception {
        // TODO Auto-generated method stub
    }   
}

And here is my servlet:这是我的 servlet:

package com.example.myserver;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HelloWorldServlet extends HttpServlet {

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.getWriter().println("Hello from HelloWorldServlet");
    }
}

Then i launch my configuration with following bundles:然后我使用以下包启动我的配置:

javax.servlet,
org.apache.felix.gogo.command,
org.apache.felix.gogo.runtime,
org.apache.felix.gogo.shell,
org.eclipse.equinox.console,
org.eclipse.jetty.continuation,
org.eclipse.jetty.http,
org.eclipse.jetty.io,
org.eclipse.jetty.security,
org.eclipse.jetty.server,
org.eclipse.jetty.servlet,
org.eclipse.jetty.util,
org.eclipse.osgi

Now when i type in url http://localhost:8080/test then everything works fine and my hello text appears.现在,当我输入 url http://localhost:8080/test一切正常,出现我的 hello 文本。

Now i try to do the same thing with an extension of org.eclipse.equinox.http.registry.servlets.现在我尝试使用 org.eclipse.equinox.http.registry.servlets 的扩展来做同样的事情。

Here is what i do:这是我所做的:

1) Add org.eclipse.equinox.http.registry to Require-Bundle under pom.xml 1)在pom.xml下的Require-Bundle中添加org.eclipse.equinox.http.registry

2) open manifest, select extensions tab, click add, select org.eclipse.equinox.http.registry.servlets extension point, add, under extension details put class com.example.myserver.HelloWorldServlet and /test2 as alias. 2)打开manifest,选择extensions选项卡,点击添加,选择org.eclipse.equinox.http.registry.servlets扩展点,添加,在extension details下放类com.example.myserver.HelloWorldServlet和/test2作为别名。

Following plugin.xml is generated:生成以下 plugin.xml:

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
   <extension
         point="org.eclipse.equinox.http.registry.servlets">
      <servlet
            alias="/test2"
            class="com.example.myserver.HelloWorldServlet">
      </servlet>
   </extension>

</plugin>

Under launch configuration I needed to add these bundles:在启动配置下,我需要添加这些包:

org.eclipse.equinox.http.registry
org.eclipse.osgi.service,
org.eclipse.osgi.services,
org.eclipse.equinox.common,
org.eclipse.equinox.registry,
javax.xml

Then when i run my configuration i get a warning: !MESSAGE The extensions and extension-points from the bundle "myserver" are ignored. The bundle is not marked as singleton.然后,当我运行我的配置时,我收到一条警告: !MESSAGE The extensions and extension-points from the bundle "myserver" are ignored. The bundle is not marked as singleton. !MESSAGE The extensions and extension-points from the bundle "myserver" are ignored. The bundle is not marked as singleton.

... so in pom.xml i change to this: ...所以在 pom.xml 中我改为:

<Bundle-SymbolicName>${bundle.symbolicName};singleton:=true</Bundle-SymbolicName>

... run again, no errors, everything seems nice. ...再次运行,没有错误,一切看起来都很好。

If i run http://localhost:8080/test everything works.如果我运行http://localhost:8080/test一切正常。 If i run http://localhost:8080/test1 i get an not found error.如果我运行http://localhost:8080/test1我会收到一个not found错误。

Maybe i left something undone?也许我没有做些什么? I hope i didnt go into too much detail, but i really hope someone can help me figure this out.我希望我没有详细说明,但我真的希望有人能帮我解决这个问题。 Thanks!谢谢! :) :)

You misplaced, because described alias="/test2", and try with http://localhost:8080/test1你放错地方了,因为描述alias="/test2",用http://localhost:8080/test1试试

You should use http://localhost:8080/test2您应该使用http://localhost:8080/test2

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型“org/eclipse/equinox/http/servlet/HttpServiceServlet”(当前帧,堆栈 [0])不可分配给“javax/servlet/http/HttpServlet” - Type 'org/eclipse/equinox/http/servlet/HttpServiceServlet' (current frame, stack[0]) is not assignable to 'javax/servlet/http/HttpServlet' 适用于Mac的Equinox启动器(org.eclipse.equinox.launcher.carbon.macosx)版本3.4.1在64位Mac中不起作用吗? - Equinox launcher for mac (org.eclipse.equinox.launcher.carbon.macosx) version 3.4.1 doesn't work in 64-bit mac? Equinox 无法解析 org.eclipse.osgi.services 和 org.eclipse.equinox.cm - Equinox can´t resolve org.eclipse.osgi.services and org.eclipse.equinox.cm 日食火星 - eclipse.org.equinox.p2.core.provisionexception - Eclipse Mars - eclipse.org.equinox.p2.core.provisionexception Eclipse Neon版本中缺少org.eclipse.equinox.weaving.aspectj吗? - org.eclipse.equinox.weaving.aspectj missing in Eclipse Neon release? “ org.eclipse.equinox.ds@3:start”背后的魔力? - The magic behind “org.eclipse.equinox.ds@3:start”? 无法找到功能“org.eclipse.equinox.executable” - Unable to locate feature 'org.eclipse.equinox.executable' 动物园管理员只使用春分还是菲利克斯? - Does zookeeper work with equinox or only felix? 解决 Eclipse 中 org.eclipse.equinox.p2.iu 的插件依赖问题 2021-12 - Resolving Plug-In Dependency on org.eclipse.equinox.p2.iu in Eclipse 2021-12 org.osgi.framework.BundleException:找不到bundle:org.eclipse.equinox.console - org.osgi.framework.BundleException: Could not find bundle: org.eclipse.equinox.console
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM