简体   繁体   中英

restlet: Using Server and Client restlet Jars in same web application

I am not able to use restlet server and client jars in same java web application. The problem is some jars of server and client have the same name. If I try to remove duplicate jars I get errors like

java.lang.NoSuchMethodError: org.restlet.Context.getClientDispatcher()Lorg/restlet/Restlet;
  org.restlet.resource.ClientResource.createNext(ClientResource.java:503)
  org.restlet.resource.ClientResource.getNext(ClientResource.java:829)
  org.restlet.resource.ClientResource.handleOutbound(ClientResource.java:1221)
  org.restlet.resource.ClientResource.handle(ClientResource.java:1068)
  org.restlet.resource.ClientResource.handle(ClientResource.java:1044)
  org.restlet.resource.ClientResource.post(ClientResource.java:1453)
  com.xxxxxx.web.restletclient.services.CommonService.sendRequest(CommonService.java:25)
  com.xxxxxx.web.restletclient.services.adminService.execute(adminService.java:24)
  com.xxxxxx.web.restletclient.client.adminLoginClient.connect(AdminLoginClient.java:41)
  com.xxxxxx.web.action.operator.adminLoginAction.performAction(adminLoginAction.java:75)
  com.xxxxxx.common.action.AbstractBaseAction.execute(AbstractBaseAction.java:137)
  org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
  org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
  org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
  org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

My scenario is such that my web application can work as a web service client as well as server. So I am looking for an option where I can use restlet client and server jars in same web application. I have searched over the net, but did not find any solution yet which will work.

Thank you for your help.

In fact, the core jar of Restlet supports both client and server sides. That said extensions (jar files with the name org.restlet.extension.XXX ) can be specified to one or other side or both. It depends on the extension.

Could you give me the list of jars we tried to use?

Here is a sample pom file you could use to initialize the dependencies of your Restlet project:

<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>org.restlet</groupId>
    <artifactId>restlet-war</artifactId>
    <name>${project.artifactId}</name>
    <packaging>war</packaging>
    <version>1.0.0-snapshot</version>

    <properties>
        <java-version>1.7</java-version>
        <restlet-version>2.3.1</restlet-version>
        <wtp-version>2.0</wtp-version>
    </properties>

    <dependencies>
        <!-- Restlet core -->
        <dependency>
            <groupId>org.restlet.jee</groupId>
            <artifactId>org.restlet</artifactId>
            <version>${restlet-version}</version>
        </dependency>

        <!-- To embed Restlet within a servlet container -->
        <dependency>
            <groupId>org.restlet.jee</groupId>
            <artifactId>org.restlet.ext.servlet</artifactId>
            <version>${restlet-version}</version>
        </dependency>

        <!-- To use HTTP Client to actual make HTTP
             requests under the hood -->
        <dependency>
            <groupId>org.restlet.jee</groupId>
            <artifactId>org.restlet.ext.httpclient</artifactId>
            <version>${restlet-version}</version>
        </dependency>
    </dependencies>

    <repositories>
        <repository>
            <id>maven-restlet</id>
            <name>Public online Restlet repository</name>
            <url>http://maven.restlet.com</url>
        </repository>
    </repositories>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${java-version}</source>
                    <target>${java-version}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>install</id>
                        <phase>install</phase>
                        <goals>
                            <goal>sources</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <configuration>
                    <wtpapplicationxml>true</wtpapplicationxml>
                    <wtpversion>${wtp-version}</wtpversion>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Hope it helps you, Thierry

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM