gpt4 book ai didi

java - ReSTLet 教程示例

转载 作者:行者123 更新时间:2023-11-29 06:19:09 24 4
gpt4 key购买 nike

我在获取 tutorial 时遇到问题在 GAE 上工作的示例。 AppEngine 日志说:

"GET /contacts/123 HTTP/1.1" 404 598 - "Restlet-Framework/2.1snapshot,gzip(gfe)"
javax.servlet.ServletContext log: ContactRestlet: [Restlet] Attaching application: com.sem.server.rest.ContactApp@1bbc779 to URI: /contacts/123
This request caused a new process to be started for your application, and thus caused your application code to be loaded for the first time. This request may thus take longer and use more CPU than a typical request for your application.

我无法从我的 android 客户端或浏览器访问它。感谢您的帮助!

web.xml如下

<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">

<context-param>
<param-name>org.restlet.clients</param-name>
<param-value>CLAP FILE</param-value>
</context-param>

<servlet>
<servlet-name>PoiServiceImpl</servlet-name>
<servlet-class>com.sem.server.PoiServiceImpl</servlet-class>
</servlet>

<servlet>
<servlet-name>PoiRestlet</servlet-name>
<servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
<init-param>
<param-name>org.restlet.application</param-name>
<param-value>com.sem.server.rest.PoiApp</param-value>
</init-param>
</servlet>

<servlet>
<servlet-name>ContactRestlet</servlet-name>
<servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
<init-param>
<param-name>org.restlet.application</param-name>
<param-value>com.sem.server.rest.ContactApp</param-value>
</init-param>
</servlet>

<servlet>
<servlet-name>CatRestlet</servlet-name>
<servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
<init-param>
<param-name>org.restlet.application</param-name>
<param-value>com.sem.server.rest.CatApp</param-value>
</init-param>
</servlet>

<servlet-mapping>
<servlet-name>PoiServiceImpl</servlet-name>
<url-pattern>/sem10/PoiService</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>PoiRestlet</servlet-name>
<url-pattern>/poi</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>ContactRestlet</servlet-name>
<url-pattern>/contacts/123</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>CatRestlet</servlet-name>
<url-pattern>/cat</url-pattern>
</servlet-mapping>


<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>Sem10.html</welcome-file>
</welcome-file-list>

</web-app>

联系应用

import java.io.File;    
import org.restlet.Application;
import org.restlet.Component;
import org.restlet.Restlet;
import org.restlet.data.LocalReference;
import org.restlet.data.Protocol;
import org.restlet.resource.Directory;
import org.restlet.routing.Router;

public class ContactApp extends Application {

/**
* When launched as a standalone application.
*
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
Component component = new Component();
component.getClients().add(Protocol.FILE);
component.getServers().add(Protocol.HTTP, 8080);
component.getDefaultHost().attach(new ContactApp());
component.start();
}

@Override
public Restlet createInboundRoot() {
Router router = new Router(getContext());
getConnectorService().getClientProtocols().add(Protocol.FILE);

// Serve the files generated by the GWT compilation step.
File warDir = new File("");
if (!"war".equals(warDir.getName())) {
warDir = new File(warDir, "war/");
}

Directory dir = new Directory(getContext(), LocalReference
.createFileReference(warDir));
router.attachDefault(dir);


router.attach("/contacts/123", ContactServResource.class);

return router;
}
}

最佳答案

Dev-Mailinglist 友善地回答了我的问题:

here

关于java - ReSTLet 教程示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3863935/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com