请教,为什么我的restlet的HelloWorld没有响应
下面是从网上copy的例子,我只是用独立的java文件运行,显示:
十一月 18, 2013 10:37:36 上午 org.restlet.engine.connector.ServerConnectionHelper start
信息: Starting the internal [HTTP/1.1] server on port 8080
但是输入http://localhost:8182/hello后没有反应,最后直到超时不能连接,why?
我不是专业的,只是工作上要用到现学现用的,第一次在CSDN上提问啊有木有
资源文件:
package firstSteps;
import org.restlet.data.MediaType;
import org.restlet.representation.Representation;
import org.restlet.representation.StringRepresentation;
import org.restlet.representation.Variant;
import org.restlet.resource.Get;
import org.restlet.resource.ResourceException;
import org.restlet.resource.ServerResource;
/**
* Resource which has only one representation.
*/
public class HelloWorldResource extends ServerResource {
@Override
protected void doInit() throws ResourceException {
//添加资源代表描述符变量且规定媒体类型是application/json和application/xml类型
getVariants().add(new Variant(MediaType.TEXT_PLAIN));
//初始化资源状态,默认情况下什么也不做
super.doInit();
}
@Get
public Representation getRepresentation(Variant variant) {
Representation representation = new StringRepresentation(
"hello, world", MediaType.TEXT_PLAIN);
return representation;
}
}
应用文件:
package firstSteps;
import org.restlet.Application;
import org.restlet.Context;
import org.restlet.Restlet;
import org.restlet.routing.Router;
public class FirstStepsApplication extends Application {
public FirstStepsApplication(Context parentContext) {
super(parentContext);
}
/**
* Creates a root Restlet that will receive all incoming calls.
*/
@Override
public synchronized Restlet createInboundRoot() {
// Create a router Restlet that routes each call to a new instance of HelloWorldResource.
Router router = new Router(getContext());
// Defines only one route
router.attach("hello", HelloWorldResource.class);
return router;
}
}
main函数文件:
package firstSteps;
import org.restlet.Server;
import org.restlet.data.Protocol;