コード例 #1
0
ファイル: RESTComponent.java プロジェクト: vedina/RESTNet
  public RESTComponent(Context context, Application[] applications) {
    super();
    this.getClients().add(Protocol.FILE);
    this.getClients().add(Protocol.HTTP);
    this.getClients().add(Protocol.HTTPS);

    for (Application application : applications) {
      application.setContext(context == null ? getContext().createChildContext() : context);
      getDefaultHost().attach(application);
    }
    getInternalRouter().attach("/", applications[0]);
  }
コード例 #2
0
 @Before
 public void setUp() throws Exception {
   createProgrammes();
   TVProgrammeMetadataServer mockServer = mock(TVProgrammeMetadataServer.class);
   when(mockServer.getProgrammeStore()).thenReturn(store);
   Application.setCurrent(mockServer);
 }
コード例 #3
0
ファイル: PSCPServices.java プロジェクト: ideaesb/pscp
  @Override
  public synchronized void start() throws Exception {
    // restlet servlet engine will pass parameters from web.xml via the context parameters
    Series<Parameter> parameters = getContext().getParameters();
    dataSource = PSCPDataSource.createDataSource(parameters);
    daoFactory = PGDaoFactory.createPGDaoFactory(dataSource);
    lookupCache = new LookupCache(daoFactory);
    secretResolver = new SecretResolver();
    adminPage = parameters.getFirstValue("pscp.web.admin");
    urls = new URLS(adminPage);
    // links out to website
    urls.putStatic(
        new Template(getSlashedURL(parameters, "pscp.web.products")), URLS.Name.PRODUCT_LOCATION);
    urls.putStatic(
        new Template(getSlashedURL(parameters, "pscp.web.root")), URLS.Name.STATIC_MEDIA);

    // @todo how to deal with this?
    baseURIs = new ArrayList<String>(Arrays.asList("localhost:8080"));

    Map<String, Object> contextAttributes = getContext().getAttributes();
    contextAttributes.put(BaseResource.CONTEXT_ATTRIBUTE_DAO_FACTORY, daoFactory);
    contextAttributes.put(BaseResource.CONTEXT_ATTRIBUTE_URL_MAPPER, urls);
    contextAttributes.put(BaseResource.CONTEXT_ATTRIBUTE_LOOKUP_CACHE, lookupCache);
    contextAttributes.put(
        BaseResource.CONTEXT_ATTRIBUTE_PRODUCT_ROOT,
        getRootDir(BaseResource.CONTEXT_ATTRIBUTE_PRODUCT_ROOT, "pscp-products"));
    contextAttributes.put(
        BaseResource.CONTEXT_ATTRIBUTE_UPLOAD_ROOT,
        getRootDir(BaseResource.CONTEXT_ATTRIBUTE_UPLOAD_ROOT, "pscp-uploads"));

    super.start();
  }
コード例 #4
0
ファイル: Resource.java プロジェクト: peterlynch/spice
  /**
   * Returns the preferred variant according to the client preferences specified in the request.
   *
   * @return The preferred variant.
   */
  public Variant getPreferredVariant() {
    Variant result = null;
    final List<Variant> variants = getVariants();

    if ((variants != null) && (!variants.isEmpty())) {
      Language language = null;
      // Compute the preferred variant. Get the default language
      // preference from the Application (if any).
      final Application app = Application.getCurrent();

      if (app != null) {
        language = app.getMetadataService().getDefaultLanguage();
      }

      result = getRequest().getClientInfo().getPreferredVariant(variants, language);
    }

    return result;
  }
コード例 #5
0
ファイル: NioUtils.java プロジェクト: jerrevds/ODS
  /**
   * Returns a readable byte channel based on the given representation's content and its
   * write(WritableByteChannel) method. Internally, it uses a writer thread and a pipe channel.
   *
   * @param representation the representation to get the {@link OutputStream} from.
   * @return A readable byte channel.
   * @throws IOException
   */
  public static ReadableByteChannel getChannel(final Representation representation)
      throws IOException {
    ReadableByteChannel result = null;
    if (Edition.CURRENT != Edition.GAE) {
      final java.nio.channels.Pipe pipe = java.nio.channels.Pipe.open();
      org.restlet.Application application = org.restlet.Application.getCurrent();

      // Get a thread that will handle the task of continuously
      // writing the representation into the input side of the pipe
      Runnable task =
          new Runnable() {
            public void run() {
              try {
                WritableByteChannel wbc = pipe.sink();
                representation.write(wbc);
                wbc.close();
              } catch (IOException ioe) {
                Context.getCurrentLogger()
                    .log(Level.FINE, "Error while writing to the piped channel.", ioe);
              }
            }
          };

      if (application != null && application.getTaskService() != null) {
        application.getTaskService().execute(task);
      } else {
        new Thread(task).start();
      }

      result = pipe.source();
    } else {
      Context.getCurrentLogger()
          .log(
              Level.WARNING,
              "The GAE edition is unable to return a channel for a representation given its write(WritableByteChannel) method.");
    }
    return result;
  }
コード例 #6
0
  @Override
  public Representation toRepresentation(Status status, Request request, Response response) {
    TemplateRepresentation representation = null;
    // Create the data model
    Map<String, Object> dataModel = new TreeMap<String, Object>();
    dataModel.put("applicationName", Application.getCurrent().getName());
    dataModel.put("statusReasonPhrase", response.getStatus().getReasonPhrase());
    dataModel.put("statusDescription", response.getStatus().getDescription());
    Representation thyFtl =
        new ClientResource(
                LocalReference.createClapReference(getClass().getPackage()) + "/RestStatus.vtl")
            .get();

    try {
      representation = new TemplateRepresentation(thyFtl, dataModel, MediaType.TEXT_HTML);

    } catch (IOException e) {
      e.printStackTrace();
    }

    return representation;
  }
コード例 #7
0
 private String getMainNav(BundleContext bundleContext) {
   StringBuilder sb = new StringBuilder();
   List<Application> applications = ApplicationsService.getApplications(bundleContext);
   for (Application application : applications) {
     if (application.getName().equalsIgnoreCase("static")
         || application.getName().equalsIgnoreCase("default")) {
       continue;
     }
     String name =
         application.getName().substring(0, 1).toUpperCase() + application.getName().substring(1);
     sb.append("<li><a href='/")
         .append(application.getName())
         .append("'>")
         .append(name)
         .append("</a></li>\n");
   }
   return sb.toString();
 }
コード例 #8
0
ファイル: PSCPServices.java プロジェクト: ideaesb/pscp
 @Override
 public void setContext(Context context) {
   super.setContext(context);
 }
コード例 #9
0
 @Override
 public void setContext(Context context) {
   super.setContext(context);
   this.jaxRsRestlet.setContext(context);
 }
コード例 #10
0
 /**
  * Constructor using the current application.
  *
  * @return A new application service
  * @see Application#getCurrent()
  */
 public static ApplicationService create() {
   return create(Application.getCurrent());
 }
コード例 #11
0
ファイル: Engine.java プロジェクト: florhaf/ravent
 /** Clears the thread local variables set by the Restlet API and engine. */
 public static void clearThreadLocalVariables() {
   Response.setCurrent(null);
   Context.setCurrent(null);
   org.restlet.routing.VirtualHost.setCurrent(null);
   org.restlet.Application.setCurrent(null);
 }