コード例 #1
0
ファイル: Utils.java プロジェクト: Johanes/platform
  public static void readConfigFile() {

    InputStream in;
    try {
      String configFilePath =
          CarbonUtils.getCarbonConfigDirPath()
              + File.separator
              + "advanced"
              + File.separator
              + STREAMDEFN_XML;
      in = FileUtils.openInputStream(new File(configFilePath));
    } catch (Exception e) {
      in = Utils.class.getClassLoader().getResourceAsStream(STREAMDEFN_XML);
    }

    OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(in);

    OMElement documentElement = builder.getDocumentElement();

    OMElement replicationFactorEl =
        documentElement.getFirstChildWithName(new QName("ReplicationFactor"));
    if (replicationFactorEl != null) {
      replicationFactor = Integer.parseInt(replicationFactorEl.getText());
    }

    OMElement readLevelEl =
        documentElement.getFirstChildWithName(new QName("ReadConsistencyLevel"));
    if (replicationFactorEl != null) {
      readConsistencyLevel = readLevelEl.getText();
    }

    OMElement writeLevelEl =
        documentElement.getFirstChildWithName(new QName("WriteConsistencyLevel"));
    if (writeLevelEl != null) {
      writeConsistencyLevel = writeLevelEl.getText();
    }

    globalConsistencyLevelPolicy =
        new StreamDefnConsistencyLevelPolicy(readConsistencyLevel, writeConsistencyLevel);

    OMElement strategyEl = documentElement.getFirstChildWithName(new QName("StrategyClass"));
    if (strategyEl != null) {
      strategyClass = strategyEl.getText();
    }
  }
コード例 #2
0
ファイル: AddPayloads.java プロジェクト: phax/Holodeck-B2B
  /**
   * Adds the payload content to the SOAP message. How the content is added to the message depends
   * on the <i>containment</i> of the payload ({@link IPayload#getContainment()}).
   *
   * <p>The default containment is {@link IPayload.Containment#ATTACHMENT} in which case the payload
   * content as added as a SOAP attachment. The payload will be referred to from the ebMS header by
   * the MIME Content-id of the MIME part. This Content-id MUST specified in the message meta-data
   * ({@link IPayload#getPayloadURI()}).
   *
   * <p>When the containment is specified as {@link IPayload.Containment#EXTERNAL} no content will
   * be added to SOAP message. It is assumed that transfer of the content takes place out of band.
   *
   * <p>When {@link IPayload.Containment#BODY} is specified as containment the content should be
   * added to the SOAP Body. This requires the payload content to be a XML document. If the
   * specified content is not, an exception is thrown.<br>
   * <b>NOTE:</b> A payload included in the body is referred to from the ebMS header by the <code>id
   * </code> attribute of the root element of the XML Document. The submitted message meta data
   * however can also included a reference ({@see IPayload#getPayloadURI()}). In case both the
   * payload and the message meta data included an id the submitter MUST ensure that the value is
   * the same. If not the payload will not be included in the message and this method will throw an
   * exception.
   *
   * @param p The payload that should be added to the message
   * @param mc The Axis2 message context for the outgoing message
   * @throws Exception When a problem occurs while adding the payload contents to the message
   */
  protected void addContent(IPayload p, MessageContext mc) throws Exception {
    File f = null;

    switch (p.getContainment()) {
      case ATTACHMENT:
        log.debug("Adding payload as attachment. Content located at " + p.getContentLocation());
        f = new File(p.getContentLocation());

        // Use specified MIME type or detect it when none is specified
        String mimeType = p.getMimeType();
        if (mimeType == null || mimeType.isEmpty()) {
          log.debug("Detecting MIME type of payload");
          mimeType = Utils.detectMimeType(f);
        }

        log.debug("Payload mime type is " + mimeType);
        // Use Axiom ConfigurableDataHandler to enable setting of mime type
        ConfigurableDataHandler dh = new ConfigurableDataHandler(new FileDataSource(f));
        dh.setContentType(mimeType);

        // Check if a Content-id is specified, if not generate one now
        String cid = p.getPayloadURI();
        if (cid == null || cid.isEmpty()) {
          log.warn("Content-id missing for payload.");
          throw new Exception("Content-id missing for payload");
        }

        log.debug("Add payload to message as attachment with Content-id: " + cid);
        mc.addAttachment(cid, dh);
        log.info("Payload content located at '" + p.getContentLocation() + "' added to message");

        return;
      case BODY:
        log.debug("Adding payload to SOAP body. Content located at " + p.getContentLocation());
        f = new File(p.getContentLocation());

        try {
          log.debug("Parse the XML from file so it can be added to SOAP body");
          OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(new FileReader(f));
          OMElement documentElement = builder.getDocumentElement();

          // Check that refence and id are equal if both specified
          String href = p.getPayloadURI();
          String xmlId = documentElement.getAttributeValue(new QName("id"));
          if (href != null && xmlId != null && !href.equals(xmlId)) {
            log.error(
                "Payload reference ["
                    + href
                    + "] and id of payload element ["
                    + xmlId
                    + "] are not equal! Can not create consistent message.");
            throw new Exception(
                "Payload reference ["
                    + href
                    + "] and id of payload element ["
                    + xmlId
                    + "] are not equal! Can not create consistent message.");
          } else if (href != null && Utils.isNullOrEmpty(xmlId)) {
            log.debug(
                "Set specified reference in meta data [" + href + "] as xml:id on root element");
            OMNamespace xmlIdNS =
                documentElement.declareNamespace(
                    EbMSConstants.QNAME_XMLID.getNamespaceURI(), "xml");
            documentElement.addAttribute(EbMSConstants.QNAME_XMLID.getLocalPart(), href, xmlIdNS);
          }

          log.debug("Add payload XML to SOAP Body");
          mc.getEnvelope().getBody().addChild(documentElement);
          log.info("Payload content located at '" + p.getContentLocation() + "' added to message");
        } catch (OMException parseError) {
          // The given document could not be parsed, probably not an XML document. Reject it as body
          // payload
          log.error("Failed to parse payload located at " + p.getContentLocation() + "!");
          throw new Exception(
              "Failed to parse payload located at " + p.getContentLocation() + "!", parseError);
        }
        return;
    }
  }