Exemple #1
0
  /**
   * Save the model into the file
   *
   * @param root the root of the model to save
   * @param file the file to save
   * @throws JAXBException on error
   */
  public void save(Model root, File file) throws JAXBException {
    try {
      final StringWriter strw = new StringWriter();
      marshaller.marshal(unmerge(root), strw);

      /*
       * Customize the file to be handled by the xml2modelica tool
       */
      final StringBuffer buffer = strw.getBuffer();
      final String newline = System.getProperty("line.separator");

      Pattern pat = Pattern.compile("(/\\w*>)(<[\\w/])");
      Matcher m = pat.matcher(buffer);
      while (m.find()) {
        final int index = m.end(1);
        buffer.insert(index, newline);
        m.reset();
      }
      buffer.append(newline);

      new FileOutputStream(file).write(strw.toString().getBytes());
    } catch (FactoryConfigurationError e) {
      Logger.getLogger(Modelica.class.getName()).severe(e.toString());
    } catch (IOException e) {
      Logger.getLogger(Modelica.class.getName()).severe(e.toString());
    }
  }
Exemple #2
0
  /**
   * Function to convert pm request to OMElement
   *
   * @param requestVdo String request to send to pm web service
   * @return An OMElement containing the pm web service request
   */
  public static OMElement getPmPayLoad(String requestVdo) throws Exception {
    OMElement method = null;
    try {
      StringReader strReader = new StringReader(requestVdo);
      XMLInputFactory xif = XMLInputFactory.newInstance();
      XMLStreamReader reader = xif.createXMLStreamReader(strReader);

      StAXOMBuilder builder = new StAXOMBuilder(reader);
      method = builder.getDocumentElement();

      /*
      OMFactory fac = OMAbstractFactory.getOMFactory();
      OMNamespace omNs = fac.createOMNamespace("http://www.i2b2.org/xsd/hive/msg",
      "i2b2");

      method = fac.createOMElement("request", omNs);

      StringReader strReader = new StringReader(requestVdo);
      XMLInputFactory xif = XMLInputFactory.newInstance();
      XMLStreamReader reader = xif.createXMLStreamReader(strReader);

      StAXOMBuilder builder = new StAXOMBuilder(reader);
      //method = builder.getDocumentElement();
      OMElement lineItem = builder.getDocumentElement();
      method.addChild(lineItem);
      */
    } catch (FactoryConfigurationError e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      log.error(e.getMessage());
      throw new Exception(e);
    }
    return method;
  }
Exemple #3
0
  public static void main(String[] args) {
    //	File file = new File("c:/Experiment/h2-2_MS_1_004.img.bz2");
    File file = new File("c:/Experiment/baa5d5/high.mtz");
    String serverLocation = "http://localhost:8161/fileserver/";
    String filename = "";
    String entryType = "ENTRY_CREATE";
    String ID = "c:/Experiment/5d5.mtz";

    URL url = null;

    // Generate checksum for the file here

    byte[] fileContents;
    try {
      fileContents = FileUtil.getBytesFromFile(file);
      filename = "5d5.mtz";
      // FileUtil.getFileName("c:/Experiment/h2-2_MS_1_002.bz2");
      url = new URL(serverLocation + filename);
      MD5ChecksumProcessor c = new MD5ChecksumProcessor();
      String checksum = c.generateChecksum(file);
      String domain = "crystallography";
      ADQueueWriterImpl qu = new ADQueueWriterImpl();

      // upload a file to a webserver
      FileServerClient client = new FileServerClient(url);
      //	boolean uploaded = client.upload(fileContents);

      // If upload is true send a blob message with this file url
      // if (uploaded=true){
      // qu.sendBlobMessage(url,ID,domain,checksum,entryType,"12/10/2010 12:22:22");
      try {
        qu.sendByteArrayMessage(
            fileContents, ID, checksum, domain, "baa5d5", entryType, "12/10/2010 12:22:22");
      } catch (XMLStreamException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      //	}
      // qu.sendMessage(fileContents, ID, entryType, "");

      // qu.sendBlobMessage("c:/Experiment/hello123.xml", "123.xml");

      qu.disconnect();
    } catch (JMSException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      // } catch (XMLStreamException e) {
      // TODO Auto-generated catch block
      //	e.printStackTrace();
    } catch (FactoryConfigurationError e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ChecksumProcessorException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  private void parseCoordElements(final File pom) {
    Reader reader = null;
    XMLStreamReader xml = null;
    try {
      reader = new FileReader(pom);
      xml = XMLInputFactory.newFactory().createXMLStreamReader(reader);

      final Stack<String> path = new Stack<String>();
      while (xml.hasNext()) {
        final int evt = xml.next();
        switch (evt) {
          case START_ELEMENT:
            {
              path.push(xml.getLocalName());
              if (captureValue(path, xml)) {
                // seems like xml.getElementText() traverses the END_ELEMENT event...
                path.pop();
              }

              if (foundPreferredValues()) {
                return;
              }
              break;
            }
          case END_ELEMENT:
            {
              path.pop();
              break;
            }
          default:
            {
            }
        }
      }
    } catch (final IOException e) {
      logger.warn(
          "Failed to peek at POM coordinate for: %s. Reason: %s\n"
              + "This POM will NOT be available as an ancestor to other models during effective-model building.",
          e, pom, e.getMessage());
    } catch (final XMLStreamException e) {
      logger.warn(
          "Failed to peek at POM coordinate for: %s. Reason: %s\n"
              + "This POM will NOT be available as an ancestor to other models during effective-model building.",
          e, pom, e.getMessage());
    } catch (final FactoryConfigurationError e) {
      logger.warn(
          "Failed to peek at POM coordinate for: %s. Reason: %s\n"
              + "This POM will NOT be available as an ancestor to other models during effective-model building.",
          e, pom, e.getMessage());
    } finally {
      if (xml != null) {
        try {
          xml.close();
        } catch (final XMLStreamException e) {
        }
      }

      closeQuietly(reader);
    }
  }
Exemple #5
0
  public static String sendSOAP(
      EndpointReference soapEPR, String requestString, String action, String operation)
      throws Exception {

    ServiceClient sender = PmServiceClient.getServiceClient();
    OperationClient operationClient = sender.createClient(ServiceClient.ANON_OUT_IN_OP);

    // creating message context
    MessageContext outMsgCtx = new MessageContext();
    // assigning message context's option object into instance variable
    Options opts = outMsgCtx.getOptions();
    // setting properties into option
    log.debug(soapEPR);
    opts.setTo(soapEPR);
    opts.setAction(action);
    opts.setTimeOutInMilliSeconds(180000);

    log.debug(requestString);

    SOAPEnvelope envelope = null;

    try {
      SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
      envelope = fac.getDefaultEnvelope();
      OMNamespace omNs =
          fac.createOMNamespace(
              "http://rpdr.partners.org/", //$NON-NLS-1$
              "rpdr"); //$NON-NLS-1$

      // creating the SOAP payload
      OMElement method = fac.createOMElement(operation, omNs);
      OMElement value = fac.createOMElement("RequestXmlString", omNs); // $NON-NLS-1$
      value.setText(requestString);
      method.addChild(value);
      envelope.getBody().addChild(method);
    } catch (FactoryConfigurationError e) {
      log.error(e.getMessage());
      throw new Exception(e);
    }

    outMsgCtx.setEnvelope(envelope);

    operationClient.addMessageContext(outMsgCtx);
    operationClient.execute(true);

    MessageContext inMsgtCtx = operationClient.getMessageContext("In"); // $NON-NLS-1$
    SOAPEnvelope responseEnv = inMsgtCtx.getEnvelope();

    OMElement soapResponse = responseEnv.getBody().getFirstElement();
    //		System.out.println("Sresponse: "+ soapResponse.toString());
    OMElement soapResult = soapResponse.getFirstElement();
    //		System.out.println("Sresult: "+ soapResult.toString());

    String i2b2Response = soapResult.getText();
    log.debug(i2b2Response);

    return i2b2Response;
  }
Exemple #6
0
  protected Message createBlobMessage(
      URL fileURL,
      String ID,
      String checksum,
      String domain,
      String projectName,
      String entryType,
      String dateTime,
      String experimentId,
      ActiveMQSession session) {
    BlobMessage message = null;
    FileInputStream in = null;

    String msgParam;
    try {
      msgParam =
          createXMLParameter(ID, checksum, domain, projectName, entryType, dateTime, experimentId);

      // in = new FileInputStream(fileLocation);
      //	message.setName(name);
      // message = session.createBlobMessage(new File(fileLocation));
      message = session.createBlobMessage(fileURL);
      // message.setName(name);
      message.setObjectProperty("msgParamXML", msgParam);

      // message.setObjectProperty("checksum", checksum);

      // message = session.createBlobMessage(in);
    } catch (JMSException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();

    } catch (XMLStreamException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    } catch (FactoryConfigurationError e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }
    return message;
  }
Exemple #7
0
  /**
   * Builds a SOAPEnvelope from DOM Document.
   *
   * @param doc - The dom document that contains a SOAP message
   * @param useDoom
   * @return
   * @throws WSSecurityException
   */
  public static SOAPEnvelope getSOAPEnvelopeFromDOMDocument(Document doc, boolean useDoom)
      throws WSSecurityException {

    if (useDoom) {
      try {
        // Get processed headers
        SOAPEnvelope env = (SOAPEnvelope) doc.getDocumentElement();
        ArrayList processedHeaderQNames = new ArrayList();
        SOAPHeader soapHeader = env.getHeader();

        if (soapHeader != null) {
          Iterator headerBlocs = soapHeader.getChildElements();
          while (headerBlocs.hasNext()) {

            OMElement element = (OMElement) headerBlocs.next();
            SOAPHeaderBlock header = null;

            if (element instanceof SOAPHeaderBlock) {
              header = (SOAPHeaderBlock) element;

              // If a header block is not an instance of SOAPHeaderBlock, it means that
              // it is a header we have added in rampart eg. EncryptedHeader and should
              // be converted to SOAPHeaderBlock for processing
            } else {
              header = soapHeader.addHeaderBlock(element.getLocalName(), element.getNamespace());
              Iterator attrIter = element.getAllAttributes();
              while (attrIter.hasNext()) {
                OMAttribute attr = (OMAttribute) attrIter.next();
                header.addAttribute(
                    attr.getLocalName(), attr.getAttributeValue(), attr.getNamespace());
              }
              Iterator nsIter = element.getAllDeclaredNamespaces();
              while (nsIter.hasNext()) {
                OMNamespace ns = (OMNamespace) nsIter.next();
                header.declareNamespace(ns);
              }
              // retrieve all child nodes (including any text nodes)
              // and re-attach to header block
              Iterator children = element.getChildren();
              while (children.hasNext()) {
                OMNode child = (OMNode) children.next();
                child.detach();
                header.addChild(child);
              }

              element.detach();

              soapHeader.build();

              header.setProcessed();
            }

            if (header.isProcessed()) {
              processedHeaderQNames.add(element.getQName());
            }
          }
        }
        XMLStreamReader reader = ((OMElement) doc.getDocumentElement()).getXMLStreamReader();
        StAXSOAPModelBuilder stAXSOAPModelBuilder = new StAXSOAPModelBuilder(reader, null);
        SOAPEnvelope envelope = stAXSOAPModelBuilder.getSOAPEnvelope();

        // Set the processed flag of the processed headers
        SOAPHeader header = envelope.getHeader();
        for (Iterator iter = processedHeaderQNames.iterator(); iter.hasNext(); ) {
          QName name = (QName) iter.next();
          Iterator omKids = header.getChildrenWithName(name);
          if (omKids.hasNext()) {
            ((SOAPHeaderBlock) omKids.next()).setProcessed();
          }
        }

        envelope.build();

        return envelope;

      } catch (FactoryConfigurationError e) {
        throw new WSSecurityException(e.getMessage());
      }
    } else {
      try {
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        XMLUtils.outputDOM(doc.getDocumentElement(), os, true);
        ByteArrayInputStream bais = new ByteArrayInputStream(os.toByteArray());

        StAXSOAPModelBuilder stAXSOAPModelBuilder =
            new StAXSOAPModelBuilder(
                XMLInputFactory.newInstance().createXMLStreamReader(bais), null);
        return stAXSOAPModelBuilder.getSOAPEnvelope();
      } catch (Exception e) {
        throw new WSSecurityException(e.getMessage());
      }
    }
  }