congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
BaseTenantService
Code IndexAdd Tabnine to your IDE (free)

How to use
BaseTenantService
in
org.eclipse.hono.service.tenant

Best Java code snippets using org.eclipse.hono.service.tenant.BaseTenantService (Showing top 17 results out of 315)

origin: eclipse/hono

@Override
public final void get(final X500Principal subjectDn,
    final Handler<AsyncResult<TenantResult<JsonObject>>> resultHandler) {
  get(subjectDn, NoopSpan.INSTANCE, resultHandler);
}
origin: eclipse/hono

/**
 * {@inheritDoc}
 *
 * This default implementation simply returns an empty result with status code 501 (Not Implemented).
 * Subclasses should override this method in order to provide a reasonable implementation.
 */
@Override
public void get(final String tenantId, final Span span,
    final Handler<AsyncResult<TenantResult<JsonObject>>> resultHandler) {
  handleUnimplementedOperation(resultHandler);
}
origin: eclipse/hono

final JsonObject payload = request.getJsonPayload();
final Span span = newChildSpan(SPAN_NAME_GET_TENANT, request.getSpanContext(), tenantId);
final Future<EventBusMessage> resultFuture;
if (tenantId == null && payload == null) {
  span.log("using deprecated variant of get tenant request");
  resultFuture = processGetByIdRequest(request, tenantId, span);
  final String tenantIdFromPayload = getTypesafeValueForField(String.class, payload,
      TenantConstants.FIELD_PAYLOAD_TENANT_ID);
  final String subjectDn = getTypesafeValueForField(String.class, payload,
      TenantConstants.FIELD_PAYLOAD_SUBJECT_DN);
    log.debug("retrieving tenant [id: {}]", tenantIdFromPayload);
    span.setTag(MessageHelper.APP_PROPERTY_TENANT_ID, tenantIdFromPayload);
    resultFuture = processGetByIdRequest(request, tenantIdFromPayload, span);
  } else {
    span.setTag(TAG_SUBJECT_DN_NAME, subjectDn);
    resultFuture = processGetByCaRequest(request, subjectDn, span);
return finishSpanOnFutureCompletion(span, resultFuture);
origin: org.eclipse.hono/hono-service-base

Future<EventBusMessage> processGetRequest(final EventBusMessage request) {
  final String tenantId = request.getTenant();
  final JsonObject payload = request.getJsonPayload();
  if (tenantId == null && payload == null) {
    log.debug("request does not contain any query parameters");
    return Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST));
  } else if (tenantId != null) {
    // deprecated API
    log.debug("retrieving tenant [{}] using deprecated variant of get tenant request", tenantId);
    return processGetByIdRequest(request, tenantId);
  } else {
    final String tenantIdFromPayload = getTypesafeValueForField(String.class, payload,
        TenantConstants.FIELD_PAYLOAD_TENANT_ID);
    final String subjectDn = getTypesafeValueForField(String.class, payload,
        TenantConstants.FIELD_PAYLOAD_SUBJECT_DN);
    if (tenantIdFromPayload == null && subjectDn == null) {
      log.debug("payload does not contain any query parameters");
      return Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST));
    } else if (tenantIdFromPayload != null) {
      log.debug("retrieving tenant [id: {}]", tenantIdFromPayload);
      return processGetByIdRequest(request, tenantIdFromPayload);
    } else {
      return processGetByCaRequest(request, subjectDn);
    }
  }
}
origin: eclipse/hono

/**
 * Processes a Tenant API request message received via the vert.x event bus.
 * <p>
 * This method validates the request payload against the Tenant API specification
 * before invoking the corresponding {@code TenantService} methods.
 * 
 * @param request The request message.
 * @return A future indicating the outcome of the service invocation.
 * @throws NullPointerException If the request message is {@code null}.
 */
@Override
public Future<EventBusMessage> processRequest(final EventBusMessage request) {
  Objects.requireNonNull(request);
  switch (TenantConstants.TenantAction.from(request.getOperation())) {
  case get:
    return processGetRequest(request);
  default:
    return processCustomTenantMessage(request);
  }
}
origin: org.eclipse.hono/hono-service-base

private Future<EventBusMessage> processGetByCaRequest(final EventBusMessage request, final String subjectDn) {
  try {
    final X500Principal dn = new X500Principal(subjectDn);
    log.debug("retrieving tenant [subject DN: {}]", subjectDn);
    final Future<TenantResult<JsonObject>> getResult = Future.future();
    get(dn, getResult.completer());
    return getResult.map(tr -> {
      final EventBusMessage response = request.getResponse(tr.getStatus())
          .setJsonPayload(tr.getPayload())
          .setCacheDirective(tr.getCacheDirective());
      if (tr.isOk() && tr.getPayload() != null) {
        response.setTenant(getTypesafeValueForField(String.class, tr.getPayload(),
            TenantConstants.FIELD_PAYLOAD_TENANT_ID));
      }
      return response;
    });
  } catch (final IllegalArgumentException e) {
    // the given subject DN is invalid
    log.debug("cannot parse subject DN [{}] provided by client", subjectDn);
    return Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST));
  }
}
origin: eclipse/hono

/**
 * Verifies that the base service routes a deprecated request for retrieving
 * a tenant by its identifier to the corresponding <em>get</em> method.
 * 
 * @param ctx The vert.x test context.
 */
@Test
public void testDeprecatedGetByIdSucceeds(final TestContext ctx) {
  final EventBusMessage request = EventBusMessage.forOperation(TenantConstants.TenantAction.get.toString())
      .setJsonPayload(new JsonObject().put(TenantConstants.FIELD_PAYLOAD_TENANT_ID, "my-tenant"));
  tenantService.processRequest(request).setHandler(ctx.asyncAssertSuccess(response -> {
    ctx.assertEquals(HttpURLConnection.HTTP_OK, response.getStatus());
    ctx.assertEquals("getById", response.getJsonPayload().getString("operation"));
  }));
}
origin: org.eclipse.hono/hono-service-base

/**
 * Processes a Tenant API request message received via the vert.x event bus.
 * <p>
 * This method validates the request payload against the Tenant API specification
 * before invoking the corresponding {@code TenantService} methods.
 * 
 * @param request The request message.
 * @return A future indicating the outcome of the service invocation.
 * @throws NullPointerException If the request message is {@code null}.
 */
@Override
public Future<EventBusMessage> processRequest(final EventBusMessage request) {
  Objects.requireNonNull(request);
  switch (TenantConstants.TenantAction.from(request.getOperation())) {
  case get:
    return processGetRequest(request);
  default:
    return processCustomTenantMessage(request);
  }
}
origin: eclipse/hono

private Future<EventBusMessage> processGetByCaRequest(final EventBusMessage request, final String subjectDn,
    final Span span) {
  try {
    final X500Principal dn = new X500Principal(subjectDn);
    log.debug("retrieving tenant [subject DN: {}]", subjectDn);
    final Future<TenantResult<JsonObject>> getResult = Future.future();
    get(dn, span, getResult.completer());
    return getResult.map(tr -> {
      final EventBusMessage response = request.getResponse(tr.getStatus())
          .setJsonPayload(tr.getPayload())
          .setCacheDirective(tr.getCacheDirective());
      if (tr.isOk() && tr.getPayload() != null) {
        final String tenantId = getTypesafeValueForField(String.class, tr.getPayload(),
            TenantConstants.FIELD_PAYLOAD_TENANT_ID);
        span.setTag(MessageHelper.APP_PROPERTY_TENANT_ID, tenantId);
        response.setTenant(tenantId);
      }
      return response;
    });
  } catch (final IllegalArgumentException e) {
    TracingHelper.logError(span, "illegal subject DN provided by client: " + subjectDn);
    // the given subject DN is invalid
    log.debug("cannot parse subject DN [{}] provided by client", subjectDn);
    return Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST));
  }
}
origin: eclipse/hono

/**
 * Verifies that the base service routes a request for retrieving
 * a tenant by its trusted certificate authority to the corresponding
 * <em>get</em> method.
 * 
 * @param ctx The vert.x test context.
 */
@Test
public void testGetByCaSucceeds(final TestContext ctx) {
  final EventBusMessage request = EventBusMessage.forOperation(TenantConstants.TenantAction.get.toString())
      .setJsonPayload(new JsonObject().put(TenantConstants.FIELD_PAYLOAD_SUBJECT_DN, "CN=test"));
  tenantService.processRequest(request).setHandler(ctx.asyncAssertSuccess(response -> {
    ctx.assertEquals(HttpURLConnection.HTTP_OK, response.getStatus());
    ctx.assertEquals("getByCa", response.getJsonPayload().getString("operation"));
  }));
}
origin: eclipse/hono

/**
 * {@inheritDoc}
 *
 * This default implementation simply returns an empty result with status code 501 (Not Implemented).
 * Subclasses should override this method in order to provide a reasonable implementation.
 */
@Override
public void get(final X500Principal subjectDn, final Span span,
    final Handler<AsyncResult<TenantResult<JsonObject>>> resultHandler) {
  handleUnimplementedOperation(resultHandler);
}
origin: eclipse/hono

@Override
public final void get(final String tenantId, final Handler<AsyncResult<TenantResult<JsonObject>>> resultHandler) {
  get(tenantId, NoopSpan.INSTANCE, resultHandler);
}
origin: eclipse/hono

/**
 * Verifies that the base service routes a request for retrieving
 * a tenant by its identifier to the corresponding <em>get</em> method.
 * 
 * @param ctx The vert.x test context.
 */
@Test
public void testGetByIdSucceeds(final TestContext ctx) {
  final EventBusMessage request = createRequest(TenantConstants.TenantAction.get, null);
  tenantService.processRequest(request).setHandler(ctx.asyncAssertSuccess(response -> {
    ctx.assertEquals(HttpURLConnection.HTTP_OK, response.getStatus());
    ctx.assertEquals(TEST_TENANT, response.getJsonPayload().getString(TenantConstants.FIELD_PAYLOAD_TENANT_ID));
  }));
}
origin: org.eclipse.hono/hono-service-base

/**
 * {@inheritDoc}
 *
 * This default implementation simply returns an empty result with status code 501 (Not Implemented).
 * Subclasses should override this method in order to provide a reasonable implementation.
 */
@Override
public void get(final String tenantId, final Handler<AsyncResult<TenantResult<JsonObject>>> resultHandler) {
  handleUnimplementedOperation(resultHandler);
}
origin: org.eclipse.hono/hono-service-base

private Future<EventBusMessage> processGetByIdRequest(final EventBusMessage request, final String tenantId) {
  final Future<TenantResult<JsonObject>> getResult = Future.future();
  get(tenantId, getResult.completer());
  return getResult.map(tr -> {
    return request.getResponse(tr.getStatus())
        .setJsonPayload(tr.getPayload())
        .setTenant(tenantId)
        .setCacheDirective(tr.getCacheDirective());
  });
}
origin: org.eclipse.hono/hono-service-base

/**
 * {@inheritDoc}
 *
 * This default implementation simply returns an empty result with status code 501 (Not Implemented).
 * Subclasses should override this method in order to provide a reasonable implementation.
 */
@Override
public void get(final X500Principal subjectDn,
    final Handler<AsyncResult<TenantResult<JsonObject>>> resultHandler) {
  handleUnimplementedOperation(resultHandler);
}
origin: eclipse/hono

private Future<EventBusMessage> processGetByIdRequest(final EventBusMessage request, final String tenantId,
    final Span span) {
  final Future<TenantResult<JsonObject>> getResult = Future.future();
  get(tenantId, span, getResult.completer());
  return getResult.map(tr -> {
    return request.getResponse(tr.getStatus())
        .setJsonPayload(tr.getPayload())
        .setTenant(tenantId)
        .setCacheDirective(tr.getCacheDirective());
  });
}
org.eclipse.hono.service.tenantBaseTenantService

Javadoc

a Base class for implementing TenantService.

In particular, this base class provides support for receiving service invocation request messages via vert.x' event bus and routing them to specific methods accepting the query parameters contained in the request message.

Most used methods

  • finishSpanOnFutureCompletion
  • get
    This default implementation simply returns an empty result with status code 501 (Not Implemented). S
  • getTypesafeValueForField
  • handleUnimplementedOperation
    Handles an unimplemented operation by failing the given handler with a ClientErrorException having a
  • newChildSpan
    Creates a new OpenTracing span for tracing the execution of a tenant service operation. The returned
  • processCustomTenantMessage
    Processes a request for a non-standard operation. Subclasses should override this method in order to
  • processGetByCaRequest
  • processGetByIdRequest
  • processGetRequest
  • processRequest
    Processes a Tenant API request message received via the vert.x event bus. This method validates the

Popular in Java

  • Making http post requests using okhttp
  • addToBackStack (FragmentTransaction)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • getSharedPreferences (Context)
  • BigDecimal (java.math)
    An immutable arbitrary-precision signed decimal.A value is represented by an arbitrary-precision "un
  • SimpleDateFormat (java.text)
    Formats and parses dates in a locale-sensitive manner. Formatting turns a Date into a String, and pa
  • List (java.util)
    An ordered collection (also known as a sequence). The user of this interface has precise control ove
  • NoSuchElementException (java.util)
    Thrown when trying to retrieve an element past the end of an Enumeration or Iterator.
  • Queue (java.util)
    A collection designed for holding elements prior to processing. Besides basic java.util.Collection o
  • Reflections (org.reflections)
    Reflections one-stop-shop objectReflections scans your classpath, indexes the metadata, allows you t
  • Top 12 Jupyter Notebook Extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now