Пример #1
0
 /**
  * removes the listener from the list of Persistent Search listeners of the asynchronous seach for
  * the given search ID.
  *
  * @param request The request returned by the addListener
  * @supported.api
  */
 protected void removeListener(Request request) {
   LDAPConnection connection = request.getLDAPConnection();
   if (connection != null) {
     if (debugger.messageEnabled()) {
       debugger.message(
           "EventService.removeListener(): Removing "
               + "listener requestID: "
               + request.getRequestID()
               + " Listener: "
               + request.getListener());
     }
     try {
       if ((connection != null) && (connection.isConnected())) {
         connection.abandon(request.getId());
         connection.disconnect();
       }
     } catch (LDAPException le) {
       // Might have to check the reset codes and try to reset
       if (debugger.warningEnabled()) {
         debugger.warning(
             "EventService.removeListener(): " + "LDAPException, when trying to remove listener",
             le);
       }
     }
   }
 }
Пример #2
0
  protected void checkRequest(boolean addedNewRecords, Request newRequest) {
    try {
      if (!addedNewRecords) {
        Repox2Sip repox2sip = RepoxContextUtil.getRepoxManager().getDataManager().getRepox2sip();
        List<Request> requestList = repox2sip.getDataSetRequests(this.getIdDb());

        Collections.sort(requestList, new DateSorter());
        for (Request request : requestList) {
          if (request.getStatus().equals(RequestStatus.IMPORT_COMPLETED)) {
            Long myId = request.getId();
            repox2sip.addMetadataRecords(
                newRequest.getId(), repox2sip.getRequestMetadataRecords(myId));
            break;
          }
        }
      }
    } catch (Repox2SipException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    }
  }
Пример #3
0
  /**
   * Add MDRecord to database
   *
   * @param request
   * @param ingestedRecords
   */
  protected void addMdRecord2Database(Request request, List<RecordRepox> ingestedRecords) {
    try {
      Repox2Sip repox2Sip = RepoxContextUtil.getRepoxManager().getDataManager().getRepox2sip();
      List<MetadataRecord> allMetadataRecords = new ArrayList<MetadataRecord>();
      for (RecordRepox rp : ingestedRecords) {
        allMetadataRecords.add(rp.createRecordSip());
        // rp.addRecord2DataBase(request.getId(), repox2Sip);
      }
      repox2Sip.addMetadataRecords(request.getId(), allMetadataRecords);

    } catch (Repox2SipException e) {
      log.error("Could not add MetadataRecord to Data Base", e);
      e.printStackTrace();
    }
  }
Пример #4
0
  public void csLeave() {
    tokenInUse = false;
    if (requestMade) {
      token.LN[my_id] = RN[my_id];
      requestMade = false;
    }

    // Checking if the queue is not empty
    if (hastoken && !token.getQueue().isEmpty()) {
      MutexReqRec.sendToken();
      tokenRecvd = false;
      hastoken = false;
      Request request = token.getQueue().poll();
      // Updating the LN, ie., LN[id] = RN[id]

      // Sending the Token to the next Request in the queue
      try {

        Node node = nodes.get(Integer.toString(request.getId()));
        System.out.println("Sending token from cs to " + node.getHostname());
        Socket client = new Socket(node.getHostname(), Integer.parseInt(node.getPort()));
        OutputStream os = client.getOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(os);
        oos.writeObject(token);
        oos.close();
        os.close();
        client.close();
        // token = null;

        // requestMade = false;
        // tokenInUse = false;
      } catch (IOException e) {
        e.printStackTrace();
      }
      // tokenInUse = false;
    }
  }
Пример #5
0
 @Override
 public Identifier getId() {
   return req.getId();
 }
  @Override
  public void invokeServer(RestfulServer theServer, Request theRequest)
      throws BaseServerResponseException, IOException {

    // Pretty print
    boolean prettyPrint = RestfulServerUtils.prettyPrintResponse(theServer, theRequest);

    // Narrative mode
    NarrativeModeEnum narrativeMode = RestfulServerUtils.determineNarrativeMode(theRequest);

    // Determine response encoding
    EncodingEnum responseEncoding =
        RestfulServerUtils.determineResponseEncodingNoDefault(theRequest.getServletRequest());

    // Is this request coming from a browser
    String uaHeader = theRequest.getServletRequest().getHeader("user-agent");
    boolean requestIsBrowser = false;
    if (uaHeader != null && uaHeader.contains("Mozilla")) {
      requestIsBrowser = true;
    }

    Object requestObject = parseRequestObject(theRequest);

    // Method params
    Object[] params = new Object[getParameters().size()];
    for (int i = 0; i < getParameters().size(); i++) {
      IParameter param = getParameters().get(i);
      if (param != null) {
        params[i] = param.translateQueryParametersIntoServerArgument(theRequest, requestObject);
      }
    }

    Object resultObj = invokeServer(theRequest, params);

    Integer count = RestfulServerUtils.extractCountParameter(theRequest.getServletRequest());
    boolean respondGzip = theRequest.isRespondGzip();
    HttpServletResponse response = theRequest.getServletResponse();
    switch (getReturnType()) {
      case BUNDLE:
        {
          if (getMethodReturnType() == MethodReturnTypeEnum.BUNDLE_RESOURCE) {
            IResource resource;
            if (resultObj instanceof IBundleProvider) {
              IBundleProvider result = (IBundleProvider) resultObj;
              resource = result.getResources(0, 1).get(0);
            } else {
              resource = (IResource) resultObj;
            }

            /*
             * We assume that the bundle we got back from the handling method may not have everything populated
             * (e.g. self links, bundle type, etc) so we do that here.
             */
            IVersionSpecificBundleFactory bundleFactory =
                theServer.getFhirContext().newBundleFactory();
            bundleFactory.initializeWithBundleResource(resource);
            bundleFactory.addRootPropertiesToBundle(
                null,
                theRequest.getFhirServerBase(),
                theRequest.getCompleteUrl(),
                count,
                getResponseBundleType());

            for (int i = theServer.getInterceptors().size() - 1; i >= 0; i--) {
              IServerInterceptor next = theServer.getInterceptors().get(i);
              boolean continueProcessing =
                  next.outgoingResponse(
                      theRequest,
                      resource,
                      theRequest.getServletRequest(),
                      theRequest.getServletResponse());
              if (!continueProcessing) {
                ourLog.debug("Interceptor {} returned false, not continuing processing");
                return;
              }
            }
            RestfulServerUtils.streamResponseAsResource(
                theServer,
                response,
                resource,
                responseEncoding,
                prettyPrint,
                requestIsBrowser,
                narrativeMode,
                Constants.STATUS_HTTP_200_OK,
                respondGzip,
                theRequest.getFhirServerBase(),
                isAddContentLocationHeader());
            break;
          } else {
            Set<Include> includes = getRequestIncludesFromParams(params);

            IBundleProvider result = (IBundleProvider) resultObj;
            if (count == null) {
              count = result.preferredPageSize();
            }

            IVersionSpecificBundleFactory bundleFactory =
                theServer.getFhirContext().newBundleFactory();
            bundleFactory.initializeBundleFromBundleProvider(
                theServer,
                result,
                responseEncoding,
                theRequest.getFhirServerBase(),
                theRequest.getCompleteUrl(),
                prettyPrint,
                0,
                count,
                null,
                getResponseBundleType(),
                includes);
            Bundle bundle = bundleFactory.getDstu1Bundle();
            if (bundle != null) {
              for (int i = theServer.getInterceptors().size() - 1; i >= 0; i--) {
                IServerInterceptor next = theServer.getInterceptors().get(i);
                boolean continueProcessing =
                    next.outgoingResponse(
                        theRequest,
                        bundle,
                        theRequest.getServletRequest(),
                        theRequest.getServletResponse());
                if (!continueProcessing) {
                  ourLog.debug("Interceptor {} returned false, not continuing processing");
                  return;
                }
              }
              RestfulServerUtils.streamResponseAsBundle(
                  theServer,
                  response,
                  bundle,
                  responseEncoding,
                  theRequest.getFhirServerBase(),
                  prettyPrint,
                  narrativeMode,
                  respondGzip,
                  requestIsBrowser);
            } else {
              IBaseResource resBundle = bundleFactory.getResourceBundle();
              for (int i = theServer.getInterceptors().size() - 1; i >= 0; i--) {
                IServerInterceptor next = theServer.getInterceptors().get(i);
                boolean continueProcessing =
                    next.outgoingResponse(
                        theRequest,
                        resBundle,
                        theRequest.getServletRequest(),
                        theRequest.getServletResponse());
                if (!continueProcessing) {
                  ourLog.debug("Interceptor {} returned false, not continuing processing");
                  return;
                }
              }
              RestfulServerUtils.streamResponseAsResource(
                  theServer,
                  response,
                  (IResource) resBundle,
                  responseEncoding,
                  prettyPrint,
                  requestIsBrowser,
                  narrativeMode,
                  Constants.STATUS_HTTP_200_OK,
                  theRequest.isRespondGzip(),
                  theRequest.getFhirServerBase(),
                  isAddContentLocationHeader());
            }

            break;
          }
        }
      case RESOURCE:
        {
          IBundleProvider result = (IBundleProvider) resultObj;
          if (result.size() == 0) {
            throw new ResourceNotFoundException(theRequest.getId());
          } else if (result.size() > 1) {
            throw new InternalErrorException("Method returned multiple resources");
          }

          IResource resource = result.getResources(0, 1).get(0);

          for (int i = theServer.getInterceptors().size() - 1; i >= 0; i--) {
            IServerInterceptor next = theServer.getInterceptors().get(i);
            boolean continueProcessing =
                next.outgoingResponse(
                    theRequest,
                    resource,
                    theRequest.getServletRequest(),
                    theRequest.getServletResponse());
            if (!continueProcessing) {
              return;
            }
          }

          RestfulServerUtils.streamResponseAsResource(
              theServer,
              response,
              resource,
              responseEncoding,
              prettyPrint,
              requestIsBrowser,
              narrativeMode,
              Constants.STATUS_HTTP_200_OK,
              respondGzip,
              theRequest.getFhirServerBase(),
              isAddContentLocationHeader());
          break;
        }
    }
  }