Ejemplo n.º 1
0
    public void onCompletion(Packet response) {
      LOGGER.finer(LocalizationMessages.WSMC_0105_STORING_RESPONSE(clientUID));

      if (response.getMessage() != null) {
        final HeaderList headers = response.getMessage().getHeaders();
        headers.remove(configuration.getAddressingVersion().toTag);
        headers.add(
            Headers.create(
                configuration.getAddressingVersion().toTag,
                configuration.getMcVersion().getWsmcAnonymousAddress(clientUID)));
      }

      responseStorage.store(response, clientUID);
    }
 public void writeTo(ContentHandler contentHandler, ErrorHandler errorHandler)
     throws SAXException {
   contentHandler.setDocumentLocator(NULL_LOCATOR);
   contentHandler.startDocument();
   envelopeTag.writeStart(contentHandler);
   headerTag.writeStart(contentHandler);
   if (hasHeaders()) {
     HeaderList headers = getHeaders();
     int len = headers.size();
     for (int i = 0; i < len; i++) {
       // shouldn't JDK be smart enough to use array-style indexing for this foreach!?
       headers.get(i).writeTo(contentHandler, errorHandler);
     }
   }
   headerTag.writeEnd(contentHandler);
   bodyTag.writeStart(contentHandler);
   writePayloadTo(contentHandler, errorHandler, true);
   bodyTag.writeEnd(contentHandler);
   envelopeTag.writeEnd(contentHandler);
 }
  /**
   * This method should be called when the StreamMessage is created with a payload
   *
   * @param writer
   */
  private void writeEnvelope(XMLStreamWriter writer) throws XMLStreamException {
    writer.writeStartDocument();
    envelopeTag.writeStart(writer);

    // write headers
    HeaderList hl = getHeaders();
    if (hl.size() > 0) {
      headerTag.writeStart(writer);
      for (Header h : hl) {
        h.writeTo(writer);
      }
      writer.writeEndElement();
    }
    bodyTag.writeStart(writer);
    if (hasPayload()) {
      writePayloadTo(writer);
    }
    writer.writeEndElement();
    writer.writeEndElement();
    writer.writeEndDocument();
  }
  public Message copy() {
    try {
      // copy the payload
      XMLStreamReader clone;
      XMLStreamReader clonedReader;

      if (hasPayload()) {
        assert unconsumed();
        consumedAt = null; // but we don't want to mark it as consumed
        MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();

        // the boolean value tells the first body part is written.
        // based on this we do the right thing
        StreamReaderBufferCreator c = new StreamReaderBufferCreator(xsb);
        while (reader.getEventType() != XMLStreamConstants.END_DOCUMENT) {
          String name = reader.getLocalName();
          String nsUri = reader.getNamespaceURI();
          if (name.equals("Body") && nsUri.equals(soapVersion.nsUri)
              || (reader.getEventType() == XMLStreamConstants.END_DOCUMENT)) {
            break;
          }
          c.create(reader);
        }
        XMLStreamReaderFactory.recycle(reader);

        reader = xsb.readAsXMLStreamReader();
        reader = new VerifiedMessageXMLStreamReader(reader, bodyEnvNs);
        clone = xsb.readAsXMLStreamReader();
        clonedReader = new VerifiedMessageXMLStreamReader(clone, bodyEnvNs);
        // advance to the start tag of the first element
        proceedToRootElement(reader);
        proceedToRootElement(clonedReader);
      } else {
        // it's tempting to use EmptyMessageImpl, but it doesn't presere the infoset
        // of <envelope>,<header>, and <body>, so we need to stick to StreamMessage.
        clone = reader;
        clonedReader = reader;
      }

      return new VerifiedStreamMessage(
          envelopeTag,
          headerTag,
          attachmentSet,
          HeaderList.copy(headers),
          bodyTag,
          clone,
          soapVersion,
          this.bodyEnvNs);
    } catch (XMLStreamException e) {
      throw new WebServiceException("Failed to copy a message", e);
    }
  }
Ejemplo n.º 5
0
  private NextAction handleMakeConnectionRequest(Packet request, String clientUID) {
    try {
      LOGGER.entering();

      String selectionUID;
      try {
        MakeConnectionElement mcElement =
            request
                .getMessage()
                .readPayloadAsJAXB(
                    configuration
                        .getMcVersion()
                        .getUnmarshaller(configuration.getAddressingVersion()));
        selectionUID = configuration.getMcVersion().getClientId(mcElement.getAddress().getValue());
      } catch (JAXBException ex) {
        throw LOGGER.logSevereException(
            new RxRuntimeException(
                LocalizationMessages.WSMC_0107_ERROR_UNMARSHALLING_PROTOCOL_MESSAGE(), ex));
      }

      if (selectionUID == null) {
        // TODO return a MissingSelection SOAP fault
        throw LOGGER.logSevereException(
            new RxRuntimeException(LocalizationMessages.WSMC_0108_NULL_SELECTION_ADDRESS()));
      }

      if (!selectionUID.equals(clientUID)) {
        // TODO return a SOAP fault?
        throw LOGGER.logSevereException(
            new RxRuntimeException(
                LocalizationMessages.WSMC_0109_SELECTION_ADDRESS_NOT_MATCHING_WSA_REPLYTO()));
      }

      Packet response = null;
      if (selectionUID != null && responseStorage.hasPendingResponse(selectionUID)) {
        LOGGER.finer(
            LocalizationMessages.WSMC_0110_PENDING_MESSAGE_FOUND_FOR_SELECTION_UUID(selectionUID));
        response = responseStorage.getPendingResponsePacket(selectionUID);
      }

      if (response == null) {
        LOGGER.finer(
            LocalizationMessages.WSMC_0111_NO_PENDING_MESSAGE_FOUND_FOR_SELECTION_UUID(
                selectionUID));
        response = createEmptyResponse(request);
      } else {
        Message message = response.getMessage();
        if (message != null) {
          HeaderList headers = message.getHeaders();
          headers.add(
              Headers.create(
                  configuration.getMcVersion().getJaxbContext(configuration.getAddressingVersion()),
                  new MessagePendingElement(
                      Boolean.valueOf(
                          selectionUID != null
                              && responseStorage.hasPendingResponse(selectionUID)))));
        }
      }

      return super.doReturnWith(response);
    } finally {
      LOGGER.exiting();
    }
  }
 public boolean hasHeaders() {
   return headers != null && !headers.isEmpty();
 }