コード例 #1
0
  @Override
  public void processError(ODataServerError error, ErrorResponse response) {
    int logLevel = error.getStatusCode() >= 500 ? MessageLevel.ERROR : MessageLevel.WARNING;
    Throwable ex = getRoot(error.getException());
    // many exceptions in TeiidServiceHandler default as INTERNAL_SERVER_ERROR
    // so we make a better check for codes here
    if (ex instanceof TeiidNotImplementedException) {
      error.setException((TeiidNotImplementedException) ex);
      error.setCode(((TeiidNotImplementedException) ex).getCode());
      error.setStatusCode(501);
      logLevel = MessageLevel.DETAIL;
    } else if (ex instanceof TeiidProcessingException) {
      error.setException((TeiidProcessingException) ex);
      error.setCode(((TeiidProcessingException) ex).getCode());
      error.setStatusCode(400);
      logLevel = MessageLevel.WARNING;
    } else if (ex instanceof TeiidException) {
      error.setException((TeiidException) ex);
      error.setCode(((TeiidException) ex).getCode());
      error.setStatusCode(500);
      logLevel = MessageLevel.ERROR;
    } else if (ex instanceof TeiidRuntimeException) {
      error.setException((TeiidRuntimeException) ex);
      error.setCode(((TeiidRuntimeException) ex).getCode());
      error.setStatusCode(500);
      logLevel = MessageLevel.ERROR;
    }

    if (ex != error.getException() && ex.getMessage() != null) {
      if (LogManager.isMessageToBeRecorded(LogConstants.CTX_ODATA, MessageLevel.DETAIL)
          || logLevel <= MessageLevel.ERROR) {
        LogManager.log(
            logLevel,
            LogConstants.CTX_ODATA,
            error.getException(),
            ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16050, error.getMessage(), ex.getMessage()));
      } else {
        LogManager.log(
            logLevel,
            LogConstants.CTX_DQP,
            ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16051, error.getMessage(), ex.getMessage()));
      }
    } else {
      if (LogManager.isMessageToBeRecorded(LogConstants.CTX_ODATA, MessageLevel.DETAIL)
          || logLevel <= MessageLevel.ERROR) {
        LogManager.log(
            logLevel,
            LogConstants.CTX_ODATA,
            error.getException(),
            ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16052, error.getMessage()));
      } else {
        LogManager.log(
            logLevel,
            LogConstants.CTX_DQP,
            ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16053, error.getMessage()));
      }
    }
    response.writeError(error);
  }
コード例 #2
0
 private Throwable getRoot(Throwable t) {
   if (t.getCause() != null && t.getCause() != t) {
     if (t.getCause() instanceof TeiidException || t.getCause() instanceof TeiidRuntimeException) {
       return t.getCause();
     }
     return getRoot(t.getCause());
   }
   return t;
 }
コード例 #3
0
  private <T extends ServiceResponse> void invokeOperation(
      final OperationRequest request, OperationParameterValueProvider parameters, T response)
      throws ODataApplicationException, ODataLibraryException {

    checkExpand(request.getUriInfo().asUriInfoResource());

    final ODataSQLBuilder visitor =
        new ODataSQLBuilder(
            odata,
            getClient().getMetadataStore(),
            this.prepared,
            true,
            request.getODataRequest().getRawBaseUri(),
            this.serviceMetadata,
            this.nameGenerator);
    visitor.setOperationParameterValueProvider(parameters);
    visitor.visit(request.getUriInfo());

    final OperationResponseImpl queryResponse;
    try {
      if (visitor.getContext() instanceof NoDocumentNode) {
        NoDocumentNode cdn = (NoDocumentNode) visitor.getContext();
        ProcedureReturn procReturn = cdn.getProcedureReturn();
        queryResponse = new OperationResponseImpl(procReturn);
        getClient().executeCall(cdn.getQuery(), visitor.getParameters(), procReturn, queryResponse);

      } else {
        Query query = visitor.selectQuery();
        queryResponse =
            (OperationResponseImpl) executeQuery(request, request.isCountRequest(), visitor, query);
      }
    } catch (Throwable e) {
      throw new ODataApplicationException(
          e.getMessage(),
          HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(),
          Locale.getDefault(),
          e);
    }

    /*
    try {
        MetadataStore store = getClient().getMetadataStore();
        ProcedureSQLBuilder builder = new ProcedureSQLBuilder(store.getSchema(schemaName), request);
        ProcedureReturn procedureReturn = builder.getReturn();
        result = new OperationResponseImpl(procedureReturn);

        getClient().executeCall(builder.buildProcedureSQL(), builder.getSqlParameters(), procedureReturn, result);
    } catch (SQLException e) {
        throw new ODataApplicationException(e.getMessage(),
                HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(),
                Locale.getDefault(), e);
    } catch (TeiidException e) {
        throw new ODataApplicationException(e.getMessage(),
                HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(),
                Locale.getDefault(), e);
    }
    */
    final OperationResponseImpl operationResult = queryResponse;
    response.accepts(
        new ServiceResponseVisior() {
          @Override
          public void visit(PropertyResponse response)
              throws ODataLibraryException, ODataApplicationException {
            Property property = (Property) operationResult.getResult();
            Object value = property.getValue();
            if (value instanceof SQLXML || value instanceof Blob || value instanceof Clob) {
              try {
                handleLobResult(getClient().getProperty(Client.CHARSET), value, response);
              } catch (SQLException e) {
                LogManager.logDetail(LogConstants.CTX_ODATA, e);
                response.writeServerError(true);
              }
            } else {
              response.writeProperty(request.getReturnType().getType(), property);
            }
          }
        });
  }
コード例 #4
0
  @Override
  public <T extends ServiceResponse> void read(final DataRequest request, T response)
      throws ODataLibraryException, ODataApplicationException {

    final ODataSQLBuilder visitor =
        new ODataSQLBuilder(
            odata,
            getClient().getMetadataStore(),
            this.prepared,
            true,
            request.getODataRequest().getRawBaseUri(),
            this.serviceMetadata,
            this.nameGenerator);
    visitor.visit(request.getUriInfo());

    final BaseResponse queryResponse;
    try {
      Query query = visitor.selectQuery();
      queryResponse = executeQuery(request, request.isCountRequest(), visitor, query);
    } catch (Throwable e) {
      throw new ODataApplicationException(
          e.getMessage(),
          HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(),
          Locale.getDefault(),
          e);
    }

    response.accepts(
        new ServiceResponseVisior() {
          public void visit(CountResponse response)
              throws ODataLibraryException, ODataApplicationException {
            org.teiid.odata.api.CountResponse cr =
                (org.teiid.odata.api.CountResponse) queryResponse;
            response.writeCount(cr.getCount());
          }

          public void visit(PrimitiveValueResponse response)
              throws ODataLibraryException, ODataApplicationException {
            EntityCollection entitySet = (EntityCollection) queryResponse;
            Entity entity = entitySet.getEntities().get(0);

            EdmProperty edmProperty = request.getUriResourceProperty().getProperty();
            Property property = entity.getProperty(edmProperty.getName());
            if (property == null) {
              response.writeNotFound(true);
            } else if (property.getValue() == null) {
              response.writeNoContent(true);
            }
            response.write(property.getValue());
          }

          public void visit(PropertyResponse response)
              throws ODataLibraryException, ODataApplicationException {
            EntityCollection entitySet = (EntityCollection) queryResponse;
            if (!entitySet.getEntities().isEmpty()) {
              Entity entity = entitySet.getEntities().get(0);

              EdmProperty edmProperty = request.getUriResourceProperty().getProperty();
              Property property = entity.getProperty(edmProperty.getName());
              response.writeProperty(edmProperty.getType(), property);
            } else {
              response.writeNotFound(true);
            }
          }

          public void visit(StreamResponse response)
              throws ODataLibraryException, ODataApplicationException {
            EntityCollectionResponse entitySet = (EntityCollectionResponse) queryResponse;

            EdmProperty edmProperty = request.getUriResourceProperty().getProperty();
            Object value = entitySet.getStream(edmProperty.getName());
            if (value == null) {
              response.writeNoContent(true);
            } else {
              try {
                handleLobResult(getClient().getProperty(Client.CHARSET), value, response);
              } catch (SQLException e) {
                LogManager.logDetail(LogConstants.CTX_ODATA, e);
                response.writeServerError(true);
              }
            }
          }

          public void visit(EntityResponse response)
              throws ODataLibraryException, ODataApplicationException {
            EntityCollection entitySet = (EntityCollection) queryResponse;
            if (entitySet.getEntities().isEmpty()) {
              if (visitor.hasNavigation()) {
                response.writeNoContent(true);
              } else {
                response.writeNotFound(true);
              }
            } else {
              response.writeReadEntity(
                  visitor.getContext().getEdmEntityType(), entitySet.getEntities().get(0));
            }
          }

          public void visit(EntitySetResponse response)
              throws ODataLibraryException, ODataApplicationException {
            sendResults(request, visitor, queryResponse, response);
          }
        });
  }