本文整理汇总了Java中org.restlet.Server类的典型用法代码示例。如果您正苦于以下问题:Java Server类的具体用法?Java Server怎么用?Java Server使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Server类属于org.restlet包,在下文中一共展示了Server类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.restlet.Server; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
// Create a new Component.
Component component = new Component();
// Add a new HTTP server listening on port 8182.
Server server = component.getServers().add(Protocol.HTTP, 8182);
server.getContext().getParameters().add("useForwardedForHeader", "true");
ShindigApplication application = new ShindigApplication(server.getContext());
// Attach the sample application.
component.getDefaultHost().attach("/shindig", application);
server.getContext().getAttributes().put(Constants.CONTEXT_PATH_KEY, "/shindig");
server.getContext().getAttributes().put(Constants.BASE_URL_KEY, "http://localhost:8182");
// Start the component.
component.start();
}
示例2: main
import org.restlet.Server; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
final int port = 8182;
createDevelopmentDatabase();
// Set up a Restlet service
final Router router = new Router();
router.attachDefault(HttpListener.class);
org.restlet.Application myApp = new org.restlet.Application() {
@Override
public org.restlet.Restlet createInboundRoot() {
Context ctx = getContext();
ctx.getParameters().add("databaseDir", databaseDir);
ctx.getParameters().add("port", Integer.toString(port));
router.setContext(ctx);
return router;
};
};
Component component = new Component();
component.getDefaultHost().attach("/", myApp);
new Server(Protocol.HTTP, port, component).start();
}
示例3: registerHelpers
import org.restlet.Server; //导入依赖的package包/类
/**
* Registers the helpers for a given bundle.
*
* @param bundle
* The bundle to inspect.
*/
private void registerHelpers(Bundle bundle) {
// Register server helpers
registerHelper(bundle, Engine.getInstance().getRegisteredServers(),
Server.class, Engine.DESCRIPTOR_SERVER_PATH);
// Register client helpers
registerHelper(bundle, Engine.getInstance().getRegisteredClients(),
Client.class, Engine.DESCRIPTOR_CLIENT_PATH);
// Register authentication helpers
registerHelper(bundle, Engine.getInstance()
.getRegisteredAuthenticators(), null,
Engine.DESCRIPTOR_AUTHENTICATOR_PATH);
// Register converter helpers
registerHelper(bundle, Engine.getInstance().getRegisteredConverters(),
null, Engine.DESCRIPTOR_CONVERTER_PATH);
}
示例4: main
import org.restlet.Server; //导入依赖的package包/类
public static void main( String[] args )
throws Exception
{
Energy4Java polygene = new Energy4Java( );
Server server = new Server( Protocol.HTTP, 8888 );
Application app = polygene.newApplication( new ForumAssembler(), new MetadataService() );
app.activate();
ContextRestlet restlet = app.findModule( "REST", "Restlet" ).newObject( ContextRestlet.class, new org.restlet.Context() );
ChallengeAuthenticator guard = new ChallengeAuthenticator(null, ChallengeScheme.HTTP_BASIC, "testRealm");
MapVerifier mapVerifier = new MapVerifier();
mapVerifier.getLocalSecrets().put("rickard", "secret".toCharArray());
guard.setVerifier(mapVerifier);
guard.setNext(restlet);
server.setNext( restlet );
server.start();
}
示例5: setUp
import org.restlet.Server; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
component = PowerMockito.mock(Component.class, RETURNS_DEEP_STUBS);
ServerList list = PowerMockito.mock(ServerList.class);
PowerMockito.doReturn(list).when(component).getServers();
PowerMockito.doReturn(mock(Server.class)).when(list).add(any(Protocol.class), anyInt());
VirtualHost host = PowerMockito.mock(VirtualHost.class);
PowerMockito.doReturn(host).when(component).getDefaultHost();
PowerMockito.doReturn(mock(TemplateRoute.class))
.when(host).attach(anyString(), any(RMrouterApplication.class));
PowerMockito.doNothing().when(component).start();
PowerMockito.whenNew(Component.class).withNoArguments().thenReturn(component);
OdenOsPropertyLoader loader = PowerMockito.spy(OdenOsPropertyLoader.getInstance());
Whitebox.setInternalState(OcnRMServ.class, "loader", loader);
dummyLogger = mock(Logger.class);
Whitebox.setInternalState(OcnRMServ.class, "logger", dummyLogger);
}
示例6: LRSystemComponent
import org.restlet.Server; //导入依赖的package包/类
/**
* Constructor.
*
* @throws Exception
*/
public LRSystemComponent() throws Exception {
// Set basic properties
setName("License Recognition Server");
setDescription("License Recognition");
setOwner("Software college");
setAuthor("Justin Yang");
// Add connectors
getClients().add(new Client(Protocol.CLAP));
getClients().add(new Client(Protocol.FILE));
Server server = new Server(new Context(), Protocol.HTTP, 8183);
// Tracing
getServers().add(server);
LRSystemApplication app = new LRSystemApplication();
// Configure the default virtual host
VirtualHost host = getDefaultHost();
// Attach the application to the default virtual host
host.attachDefault(app);
}
示例7: createLowResourceMonitor
import org.restlet.Server; //导入依赖的package包/类
/**
* Creates a Jetty low resource monitor.
*
* @param server
* A Jetty server.
* @return A Jetty low resource monitor or null.
*/
private LowResourceMonitor createLowResourceMonitor( org.eclipse.jetty.server.Server server )
{
final int period = getLowResourceMonitorPeriod();
if( period > 0 )
{
final LowResourceMonitor lowResourceMonitor = new LowResourceMonitor( server );
lowResourceMonitor.setMonitoredConnectors( Arrays.asList( server.getConnectors() ) );
lowResourceMonitor.setPeriod( period );
lowResourceMonitor.setMonitorThreads( getLowResourceMonitorThreads() );
lowResourceMonitor.setMaxConnections( getLowResourceMonitorMaxConnections() );
lowResourceMonitor.setMaxMemory( getLowResourceMonitorMaxMemory() );
lowResourceMonitor.setMaxLowResourcesTime( getLowResourceMonitorMaxTime() );
lowResourceMonitor.setLowResourcesIdleTimeout( getLowResourceMonitorIdleTimeout() );
lowResourceMonitor.setStopTimeout( getLowResourceMonitorStopTimeout() );
server.addBean( lowResourceMonitor );
return lowResourceMonitor;
}
return null;
}
示例8: main
import org.restlet.Server; //导入依赖的package包/类
public static void main(String[] args) {
Server server = new Server(Protocol.HTTP, port, new RestletApplication());
System.out.println("Start catalog search REST Server...");
try {
server.start();
} catch (Exception e) {
e.printStackTrace();
}
}
示例9: main
import org.restlet.Server; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
Component component = new Component();
component.getClients().add(Protocol.FILE);
//TODO: To test with the restlet 2.1 Maybe the maxTotalConnections could be avoided
// see: http://restlet-discuss.1400322.n2.nabble.com/rejectedExecution-td4513620.html
//component.getServers().add(Protocol.HTTP, SERVER_PORT);
Server server = new Server(Protocol.HTTP, 8111);
component.getServers().add(server);
server.getContext().getParameters().add("maxTotalConnections", "50");
//end TODO
Engine.getInstance().getRegisteredServers().clear();
Engine.getInstance().getRegisteredServers().add(new HttpServerHelper(server));
component.getClients().add(Protocol.FILE);
component.getDefaultHost().attach(new FreedomRestServer());
component.start();
}
示例10: start
import org.restlet.Server; //导入依赖的package包/类
@Override
public void start() throws UnknownHostException {
if (isEnabled) {
final boolean isRunning = this.isRunning.getAndSet(true);
if (!isRunning) {
if (isEnabled && port <= 0) {
this.isEnabled = false;
TestServerConsole.log("Could not start RestService. Parameter missing: 'server.service.rest.port'", 1, TestServerServiceEnum.TEST_SERVER);
}
Component component = new Component();
Server s = component.getServers().add(isSsl ? Protocol.HTTPS : Protocol.HTTP, InetAddress.getLocalHost().getHostAddress(), port);
if (isSsl) {
Series<Parameter> parameters = s.getContext().getParameters();
parameters.add("keystorePath", QOS_KEY_FILE_ABSOLUTE);
parameters.add("keystorePassword", TestServer.QOS_KEY_PASSWORD);
parameters.add("keyPassword", TestServer.QOS_KEY_PASSWORD);
parameters.add("keystoreType", TestServer.QOS_KEY_TYPE);
}
component.getDefaultHost().attach("", new RestletApplication());
try {
component.start();
TestServerConsole.log("[" + getName() + "] started: " + toString(), 1, TestServerServiceEnum.TEST_SERVER);
} catch (Exception e) {
TestServerConsole.error(getName(), e, 0, TestServerServiceEnum.TEST_SERVER);
}
}
}
}
示例11: createRestletComponent
import org.restlet.Server; //导入依赖的package包/类
public OAuthEndpoint createRestletComponent() {
emailExtensionApplication = new EmailExtensionApplication(tokenManager, extConfigManager);
final OAuthEndpoint endpoint = new OAuthEndpoint(emailExtensionApplication);
try {
final URL url = new URL(extensionInfoData.getBaseUrl());
final int port = url.getPort();
if (Protocol.HTTP.getSchemeName().equals(url.getProtocol())) {
if (port > 0) {
endpoint.getServers().add(Protocol.HTTP, port);
} else {
endpoint.getServers().add(Protocol.HTTP);
}
} else if (Protocol.HTTPS.getSchemeName().equals(url.getProtocol())) {
Server server;
if (port > 0) {
server = endpoint.getServers().add(Protocol.HTTPS, port);
} else {
server = endpoint.getServers().add(Protocol.HTTPS);
}
final Series<Parameter> parameters = server.getContext().getParameters();
parameters.add("sslContextFactory", "org.restlet.engine.ssl.DefaultSslContextFactory");
parameters.add("keyStorePath", extensionProperties.getSSLKeyStorePath());
parameters.add("keyStorePassword", extensionProperties.getSSLKeyStorePassword());
parameters.add("keyPassword", extensionProperties.getSSLKeyPassword());
parameters.add("keyStoreType", extensionProperties.getSSLKeyStoreType());
} else {
logger.error("URL scheme {} not supported. Not starting the email extension. ", url.getProtocol());
}
} catch (final MalformedURLException e) {
logger.error("createRestletComponent error with base URL", e);
}
return endpoint;
}
示例12: createServer
import org.restlet.Server; //导入依赖的package包/类
void createServer(final int port, final String dbname) throws Exception {
final String databaseDir = Files.createTempDirectory(null).toAbsolutePath().toString();
databaseDirs.put(port, databaseDir);
DatastoreManager manager = DatastoreManager.getInstance(databaseDir);
Datastore ds = manager.openDatastore(dbname);
ds.close();
Runnable r = new Runnable()
{
@Override
public void run()
{
final Router router = new Router();
router.attachDefault(HttpListener.class);
org.restlet.Application myApp = new org.restlet.Application() {
@Override
public org.restlet.Restlet createInboundRoot() {
Context ctx = getContext();
ctx.getParameters().add("databaseDir", databaseDir);
ctx.getParameters().add("port", Integer.toString(port));
router.setContext(ctx);
return router;
};
};
Component component = new Component();
component.getDefaultHost().attach("/", myApp);
try {
new Server(Protocol.HTTP, port, component).start();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
new Thread(r).start();
}
示例13: onCreate
import org.restlet.Server; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AndroidLoggingHandler.reset(new AndroidLoggingHandler());
java.util.logging.Logger.getLogger(HttpListener.class.getCanonicalName()).setLevel(Level.FINEST);
try {
// create datastore
final File databaseDir = getApplicationContext().getDir("datastores", MODE_PRIVATE);
final DatastoreManager manager = DatastoreManager.getInstance(databaseDir.getAbsolutePath());
Datastore ds = manager.openDatastore("mydb");
ds.close();
// Set up a Restlet service
final Router router = new Router();
router.attachDefault(HttpListener.class);
org.restlet.Application myApp = new org.restlet.Application() {
@Override
public org.restlet.Restlet createInboundRoot() {
Context ctx = getContext();
ctx.getParameters().add("databaseDir", databaseDir.getAbsolutePath());
ctx.getParameters().add("port", Integer.toString(PORT));
router.setContext(ctx);
return router;
};
};
Component component = new Component();
component.getDefaultHost().attach("/", myApp);
new Server(Protocol.HTTP, PORT, component).start();
} catch (Exception e) {
Log.e("snowch.MyActivity", "Error", e);
throw new RuntimeException(e);
}
}
示例14: RiapServerHelper
import org.restlet.Server; //导入依赖的package包/类
/**
* Constructor.
*
* @param server
* The server to help.
*/
public RiapServerHelper(Server server) {
super(server);
getProtocols().add(Protocol.RIAP);
// Lazy initialization with double-check.
if (server != null && RiapServerHelper.instance == null) {
synchronized (this.getClass()) {
if (RiapServerHelper.instance == null) {
RiapServerHelper.instance = this;
}
}
}
}
示例15: ServerHelper
import org.restlet.Server; //导入依赖的package包/类
/**
* Constructor.
*
* @param server
* The client to help.
*/
public ServerHelper(Server server) {
super(server);
// Clear the ephemeral port
getAttributes().put("ephemeralPort", -1);
}