Esempio n. 1
0
 public String getXMLString(FolderType folder) throws Exception {
   StringWriter strWriter = new StringWriter();
   try {
     PatientSetJAXBUtil.getJAXBUtil().marshaller((Object) folder, strWriter);
   } catch (JAXBUtilException e) {
     log.error("Error marshalling Workplace folder");
     throw new JAXBUtilException(e.getMessage(), e);
   }
   return strWriter.toString();
 }
 /**
  * Function to build Ont Request message type and return it as an XML string
  *
  * @param GetChildrenType parentData (get children of this parent node)
  * @return A String data type containing the Ont RequestMessage in XML format
  */
 public String doBuildXML(GetReturnType returnData) {
   String requestString = null;
   try {
     MessageHeaderType messageHeader = getMessageHeader();
     RequestHeaderType reqHeader = getRequestHeader();
     BodyType bodyType = getBodyType(returnData);
     RequestMessageType reqMessageType = getRequestMessageType(messageHeader, reqHeader, bodyType);
     requestString = getXMLString(reqMessageType);
   } catch (JAXBUtilException e) {
     log.error(e.getMessage());
   }
   return requestString;
 }
Esempio n. 3
0
 public FoldersType doReadFolders() {
   FoldersType folders = null;
   try {
     BodyType bodyType = respMessageType.getMessageBody();
     JAXBUnWrapHelper helper = new JAXBUnWrapHelper();
     if (bodyType != null)
       folders = (FoldersType) helper.getObjectByClass(bodyType.getAny(), FoldersType.class);
   } catch (JAXBUtilException e) {
     log.error(e.getMessage());
     ;
   }
   return folders;
 }
  /**
   * Function to build Ont Request message type and return it as an XML string
   *
   * @param ConfigureType parentData (get children of this parent node)
   * @return A String data type containing the Ont RequestMessage in XML format
   */
  public String doBuildXML(String password) {
    String requestString = null;
    try {
      MessageHeaderType messageHeader = getMessageHeader();

      messageHeader.setSecurity(securityType);
      RequestHeaderType reqHeader = getRequestHeader();
      BodyType bodyType = getBodyType(password);
      RequestMessageType reqMessageType = getRequestMessageType(messageHeader, reqHeader, bodyType);
      requestString = getXMLString(reqMessageType);
    } catch (JAXBUtilException e) {
      log.error(e.getMessage());
    }
    return requestString;
  }
  public I2B2RequestMessageHelper(String requestXml) throws I2B2Exception {
    this.requestXml = requestXml;
    unWrapHelper = new JAXBUnWrapHelper();
    try {
      jaxbElement = jaxbUtil.unMashallFromString(requestXml);

      if (jaxbElement == null) {
        throw new I2B2Exception("null value in after unmarshalling request string ");
      }
      requestMessageType = (RequestMessageType) jaxbElement.getValue();
    } catch (JAXBUtilException jaxbUtilEx) {
      log.error("Error processing request xml [" + requestXml + "]", jaxbUtilEx);
      throw new I2B2Exception(jaxbUtilEx.getMessage());
    }
  }
  /**
   * Function to build PM Request message type and return it as an XML string
   *
   * @param GetUserConfigurationType (user config data)
   * @return A String data type containing the PM RequestMessage in XML format
   */
  public String doBuildXML(GetUserConfigurationType userConfig, MessageHeaderType header) {
    String requestString = null;
    try {
      MessageHeaderType messageHeader = getMessageHeader();

      messageHeader.setSecurity(header.getSecurity());
      messageHeader.setProjectId(header.getProjectId());

      RequestHeaderType reqHeader = getRequestHeader();
      BodyType bodyType = getBodyType(userConfig);
      RequestMessageType reqMessageType = getRequestMessageType(messageHeader, reqHeader, bodyType);
      requestString = getXMLString(reqMessageType);
    } catch (JAXBUtilException e) {
      log.error(e.getMessage());
    }
    return requestString;
  }
Esempio n. 7
0
  public StatusType processResult(String response) {
    StatusType status = null;
    try {
      JAXBElement jaxbElement = PatientSetJAXBUtil.getJAXBUtil().unMashallFromString(response);
      respMessageType = (ResponseMessageType) jaxbElement.getValue();

      // Get response message status
      ResponseHeaderType responseHeader = respMessageType.getResponseHeader();
      status = responseHeader.getResultStatus().getStatus();
      String procStatus = status.getType();
      String procMessage = status.getValue();

      if (procStatus.equals("ERROR")) {
        log.error("Error reported by Workplace web Service " + procMessage);
      } else if (procStatus.equals("WARNING")) {
        log.error("Warning reported by Workplace web Service" + procMessage);
      }

    } catch (JAXBUtilException e) {
      log.error(e.getMessage());
    }
    return status;
  }
  /** @see edu.harvard.i2b2.crc.delegate.RequestHandlerDelegate#handleRequest(java.lang.String) */
  public String handleRequest(String requestXml, RequestHandler requestHandler)
      throws I2B2Exception {
    String response = null;
    JAXBUtil jaxbUtil = CRCLoaderJAXBUtil.getJAXBUtil();

    try {
      JAXBElement jaxbElement = jaxbUtil.unMashallFromString(requestXml);
      RequestMessageType requestMessageType = (RequestMessageType) jaxbElement.getValue();
      BodyType bodyType = requestMessageType.getMessageBody();

      if (bodyType == null) {
        log.error("null value in body type");
        throw new I2B2Exception("null value in body type");
      }

      // Call PM cell to validate user
      StatusType procStatus = null;
      ProjectType projectType = null;
      String projectId = null;
      SecurityType securityType = null;
      try {

        if (requestMessageType.getMessageHeader() != null) {
          if (requestMessageType.getMessageHeader().getSecurity() != null) {
            securityType = requestMessageType.getMessageHeader().getSecurity();
          }
          projectId = requestMessageType.getMessageHeader().getProjectId();
        }
        if (securityType == null) {
          procStatus = new StatusType();
          procStatus.setType("ERROR");
          procStatus.setValue("Request message missing user/password");
          response =
              I2B2MessageResponseFactory.buildResponseMessage(requestXml, procStatus, bodyType);
          return response;
        }

        PMServiceDriver pmServiceDriver = new PMServiceDriver();
        projectType = pmServiceDriver.checkValidUser(securityType, projectId);
        if (projectType == null) {
          procStatus = new StatusType();
          procStatus.setType("ERROR");
          procStatus.setValue("Invalid user/password for the given domain");
          response =
              I2B2MessageResponseFactory.buildResponseMessage(requestXml, procStatus, bodyType);
          return response;
        }

        log.debug("project name from PM " + projectType.getName());
        log.debug("project id from PM " + projectType.getId());
        if (projectType.getRole().get(0) != null) {
          log.debug("Project role from PM " + projectType.getRole().get(0));
          this.putRoles(
              projectId,
              securityType.getUsername(),
              securityType.getDomain(),
              projectType.getRole());

          Node rootNode = CacheUtil.getCache().getRoot();
          List<String> roles =
              (List<String>)
                  rootNode.get(
                      securityType.getDomain()
                          + "/"
                          + projectId
                          + "/"
                          + securityType.getUsername());
          if (roles != null) {
            System.out.println("roles size !!1 " + roles.size());
          }

        } else {
          log.warn("project role not set for user [" + securityType.getUsername() + "]");
        }

      } catch (AxisFault e) {
        procStatus = new StatusType();
        procStatus.setType("ERROR");
        procStatus.setValue("Could not connect to server");
        response =
            I2B2MessageResponseFactory.buildResponseMessage(requestXml, procStatus, bodyType);
        return response;
      } catch (I2B2Exception e) {
        procStatus = new StatusType();
        procStatus.setType("ERROR");
        procStatus.setValue("Message error connecting Project Management cell");
        response =
            I2B2MessageResponseFactory.buildResponseMessage(requestXml, procStatus, bodyType);
        return response;
      } catch (JAXBUtilException e) {
        procStatus = new StatusType();
        procStatus.setType("ERROR");
        procStatus.setValue("Message error from Project Management cell");
        response =
            I2B2MessageResponseFactory.buildResponseMessage(requestXml, procStatus, bodyType);
        return response;
      }

      JAXBUnWrapHelper unWrapHelper = new JAXBUnWrapHelper();

      BodyType responseBodyType = null;
      if (requestHandler instanceof PublishDataRequestHandler) {

        String irodsStorageResource = null;
        for (ParamType paramType : projectType.getParam()) {

          if (paramType.getName().equalsIgnoreCase("SRBDefaultStorageResource")) {
            irodsStorageResource = paramType.getValue();
            log.debug("param value for SRBDefaultStorageResource" + paramType.getValue());
          }
        }
        ((PublishDataRequestHandler) requestHandler)
            .setIrodsDefaultStorageResource(irodsStorageResource);
      }

      responseBodyType = requestHandler.execute();

      procStatus = new StatusType();
      procStatus.setType("DONE");
      procStatus.setValue("DONE");

      response =
          I2B2MessageResponseFactory.buildResponseMessage(
              requestXml, procStatus, responseBodyType, true);

    } catch (JAXBUtilException e) {
      log.error("JAXBUtil exception", e);
      StatusType procStatus = new StatusType();
      procStatus.setType("ERROR");
      procStatus.setValue(requestXml + "\n\n" + StackTraceUtil.getStackTrace(e));
      try {
        response = I2B2MessageResponseFactory.buildResponseMessage(null, procStatus, null);
      } catch (JAXBUtilException e1) {
        e1.printStackTrace();
      }
    } catch (I2B2Exception e) {
      log.error("I2B2Exception", e);
      StatusType procStatus = new StatusType();
      procStatus.setType("ERROR");
      procStatus.setValue(StackTraceUtil.getStackTrace(e));
      try {
        response = I2B2MessageResponseFactory.buildResponseMessage(requestXml, procStatus, null);
      } catch (JAXBUtilException e1) {
        e1.printStackTrace();
      }
    } catch (Throwable e) {
      log.error("Throwable", e);
      StatusType procStatus = new StatusType();
      procStatus.setType("ERROR");
      procStatus.setValue(StackTraceUtil.getStackTrace(e));
      try {
        response = I2B2MessageResponseFactory.buildResponseMessage(requestXml, procStatus, null);
      } catch (JAXBUtilException e1) {
        e1.printStackTrace();
      }
    }
    return response;
  }