Java 类javax.xml.soap.SOAPEnvelope 实例源码

项目:xrd4j    文件:AbstractHeaderSerializer.java   
private void serializeClient(final SOAPHeader header, final AbstractMessage message, final SOAPEnvelope envelope) throws SOAPException {
    LOGGER.debug("Generate \"Client\" element.");
    ObjectType clientObjectType = MessageHelper.getObjectType(message.getConsumer());
    SOAPElement clientHeader = header.addChildElement(Constants.NS_XRD_ELEM_CLIENT, Constants.NS_XRD_PREFIX);
    clientHeader.addAttribute(envelope.createQName(Constants.NS_ID_ATTR_OBJECT_TYPE, Constants.NS_ID_PREFIX), clientObjectType.toString());
    SOAPElement xRoadInstance = clientHeader.addChildElement(Constants.NS_ID_ELEM_XROAD_INSTANCE, Constants.NS_ID_PREFIX);
    xRoadInstance.addTextNode(message.getConsumer().getXRoadInstance());
    SOAPElement memberClass = clientHeader.addChildElement(Constants.NS_ID_ELEM_MEMBER_CLASS, Constants.NS_ID_PREFIX);
    memberClass.addTextNode(message.getConsumer().getMemberClass());
    SOAPElement memberCode = clientHeader.addChildElement(Constants.NS_ID_ELEM_MEMBER_CODE, Constants.NS_ID_PREFIX);
    memberCode.addTextNode(message.getConsumer().getMemberCode());
    if (clientObjectType == ObjectType.SUBSYSTEM) {
        SOAPElement subsystem = clientHeader.addChildElement(Constants.NS_ID_ELEM_SUBSYSTEM_CODE, Constants.NS_ID_PREFIX);
        subsystem.addTextNode(message.getConsumer().getSubsystemCode());
    }
    LOGGER.debug("\"Client\" element was succesfully generated.");
}
项目:openjdk-jdk10    文件:XmlTest.java   
private SOAPMessage createMessage(MessageFactory mf) throws SOAPException, IOException {
    SOAPMessage msg = mf.createMessage();
    SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
    Name name = envelope.createName("hello", "ex", "http://example.com");
    envelope.getBody().addChildElement(name).addTextNode("THERE!");

    String s = "<root><hello>THERE!</hello></root>";

    AttachmentPart ap = msg.createAttachmentPart(
            new StreamSource(new ByteArrayInputStream(s.getBytes())),
            "text/xml"
    );
    msg.addAttachmentPart(ap);
    msg.saveChanges();

    return msg;
}
项目:programacaoweb    文件:UsuarioHandlerMessage.java   
@Override
public boolean handleMessage(SOAPMessageContext context) {
    Boolean request = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    if (!request) {
        try {
            SOAPMessage msg = context.getMessage();
            SOAPEnvelope env = msg.getSOAPPart().getEnvelope();
            SOAPHeader header = env.getHeader();
            if (header == null) {
                header = env.addHeader();
                return false;
            }
            Node node = (Node) header.getElementsByTagName("token").item(0);
            String token = node.getChildNodes().item(0).getNodeValue();
            if (token != null && token.equals("Kalango Lab")) {
                System.out.println("Token válido");
                return true;
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
    return true;
}
项目:scribe    文件:SOAPExecutor.java   
/**
 * Constructs XPath query over the SOAP message
 * 
 * @param query XPath query
 * @param response SOAP message
 * @return XPath query
 * @throws SOAPException in case of SOAP issue
 * @throws JaxenException XPath problem
 */
public final XPath createXPath(final String query, final SOAPMessage response) throws SOAPException, JaxenException {

  /* Uses DOM to XPath mapping */
  final XPath xpath = new DOMXPath(query);

  /* Define a namespaces used in response */
  final SimpleNamespaceContext nsContext = new SimpleNamespaceContext();
  final SOAPPart sp = response.getSOAPPart();
  final SOAPEnvelope env = sp.getEnvelope();
  final SOAPBody bdy = env.getBody();

  /* Add namespaces from SOAP envelope */
  addNamespaces(nsContext, env);

  /* Add namespaces of top body element */
  final Iterator<?> bodyElements = bdy.getChildElements();
  while (bodyElements.hasNext()) {
    SOAPElement element = (SOAPElement) bodyElements.next();
    addNamespaces(nsContext, element);
  }
  xpath.setNamespaceContext(nsContext);
  return xpath;
}
项目:oscm    文件:SoapRequestParserTest.java   
@Test
public void parseApiVersion_ctmg_1_8() throws Exception {
    // given
    SOAPPart part = mock(SOAPPart.class);
    SOAPEnvelope envelope = mock(SOAPEnvelope.class);
    SOAPHeader soapHeader = mock(SOAPHeader.class);
    List<Node> version = new ArrayList<Node>();
    Node node = mock(Node.class);
    doReturn("testVersion").when(node).getValue();
    version.add(node);
    Iterator<?> it = version.iterator();
    doReturn(it).when(soapHeader).extractHeaderElements(
            eq("ctmg.service.version"));
    doReturn(soapHeader).when(envelope).getHeader();
    doReturn(envelope).when(part).getEnvelope();
    doReturn(part).when(message).getSOAPPart();
    // when
    String result = SoapRequestParser.parseApiVersion(context);

    // then
    assertEquals("testVersion", result);
}
项目:xrd4j    文件:ExampleAdapter.java   
@Override
/**
 * Serializes the response data.
 *
 * @param response ServiceResponse holding the application specific
 * response object
 * @param soapResponse SOAPMessage's response object where the response
 * element is added
 * @param envelope SOAPMessage's SOAPEnvelope object
 */
public void serializeResponse(ServiceResponse response, SOAPElement soapResponse, SOAPEnvelope envelope) throws SOAPException {
    // Add "data" element
    SOAPElement data = soapResponse.addChildElement(envelope.createName("data"));
    // Put response data inside the "data" element
    data.addTextNode((String) response.getResponseData());
}
项目:xrd4j    文件:ExampleAdapter.java   
@Override
/**
 * Serializes the response data.
 *
 * @param response ServiceResponse holding the application specific
 * response object
 * @param soapResponse SOAPMessage's response object where the response
 * element is added
 * @param envelope SOAPMessage's SOAPEnvelope object
 */
public void serializeResponse(ServiceResponse response, SOAPElement soapResponse, SOAPEnvelope envelope) throws SOAPException {
    // Add "message" element
    SOAPElement data = soapResponse.addChildElement(envelope.createName("message"));
    // Put response data inside the "message" element
    data.addTextNode((String) response.getResponseData());
}
项目:xrd4j    文件:AbstractServiceResponseSerializer.java   
private void processRequestNode(final SOAPBodyElement body, final ServiceResponse response,
                                final SOAPMessage soapRequest, final SOAPEnvelope envelope) throws SOAPException {
    boolean requestFound = false;
    NodeList list = soapRequest.getSOAPBody().getElementsByTagNameNS("*", response.getProducer().getServiceCode());
    if (list.getLength() == 1) {
        // Copy request from soapRequest
        requestFound = copyRequestNode((Node) list.item(0), body, response);
    }
    // It was not possible to copy the request element, so we must create it
    if (!requestFound) {
        SOAPElement temp = body.addChildElement(envelope.createName("request"));
        if (response.isAddNamespaceToRequest()) {
            LOGGER.debug("Add provider namespace to request element.");
            SOAPHelper.addNamespace(temp, response);
        }
    }
}
项目:xrd4j    文件:AbstractHeaderSerializer.java   
private void serializeService(final SOAPHeader header, final AbstractMessage message, final SOAPEnvelope envelope) throws SOAPException {
    LOGGER.debug("Generate \"Service\" element.");
    ObjectType serviceObjectType = MessageHelper.getObjectType(message.getProducer());
    SOAPElement serviceHeader = header.addChildElement(Constants.NS_XRD_ELEM_SERVICE, Constants.NS_XRD_PREFIX);
    serviceHeader.addAttribute(envelope.createQName(Constants.NS_ID_ATTR_OBJECT_TYPE, Constants.NS_ID_PREFIX), serviceObjectType.toString());
    SOAPElement xRoadInstance = serviceHeader.addChildElement(Constants.NS_ID_ELEM_XROAD_INSTANCE, Constants.NS_ID_PREFIX);
    xRoadInstance.addTextNode(message.getProducer().getXRoadInstance());
    if (serviceObjectType == ObjectType.SERVICE) {
        SOAPElement memberClass = serviceHeader.addChildElement(Constants.NS_ID_ELEM_MEMBER_CLASS, Constants.NS_ID_PREFIX);
        memberClass.addTextNode(message.getProducer().getMemberClass());
        SOAPElement memberCode = serviceHeader.addChildElement(Constants.NS_ID_ELEM_MEMBER_CODE, Constants.NS_ID_PREFIX);
        memberCode.addTextNode(message.getProducer().getMemberCode());
    }
    if (message.getProducer().getSubsystemCode() != null && !message.getProducer().getSubsystemCode().isEmpty()) {
        SOAPElement subsystem = serviceHeader.addChildElement(Constants.NS_ID_ELEM_SUBSYSTEM_CODE, Constants.NS_ID_PREFIX);
        subsystem.addTextNode(message.getProducer().getSubsystemCode());
    }
    SOAPElement serviceCode = serviceHeader.addChildElement(Constants.NS_ID_ELEM_SERVICE_CODE, Constants.NS_ID_PREFIX);
    serviceCode.addTextNode(message.getProducer().getServiceCode());
    if (message.getProducer().getServiceVersion() != null && !message.getProducer().getServiceVersion().isEmpty()) {
        SOAPElement serviceVersion = serviceHeader.addChildElement(Constants.NS_ID_ELEM_SERVICE_VERSION, Constants.NS_ID_PREFIX);
        serviceVersion.addTextNode(message.getProducer().getServiceVersion());
    }
    LOGGER.debug("\"Service\" element was succesfully generated.");
}
项目:openjdk-jdk10    文件:SOAPPartImpl.java   
@Override
public SOAPEnvelope getEnvelope() throws SOAPException {

    // If there is no SOAP envelope already created, then create
    // one from a source if one exists. If there is a newer source
    // then use that source.

    if (sourceWasSet)
          sourceWasSet = false;

    lookForEnvelope();
    if (envelope != null) {
        if (source != null) { // there's a newer source, use it
            document.removeChild(envelope);
            envelope = createEnvelopeFromSource();
        }
    } else if (source != null) {
        envelope = createEnvelopeFromSource();
    } else {
        envelope = createEmptyEnvelope(null);
        document.insertBefore(((EnvelopeImpl) envelope).getDomElement(), null);
    }
    return envelope;
}
项目:openjdk9    文件:XmlTest.java   
private SOAPMessage createMessage(MessageFactory mf) throws SOAPException, IOException {
    SOAPMessage msg = mf.createMessage();
    SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
    Name name = envelope.createName("hello", "ex", "http://example.com");
    envelope.getBody().addChildElement(name).addTextNode("THERE!");

    String s = "<root><hello>THERE!</hello></root>";

    AttachmentPart ap = msg.createAttachmentPart(
            new StreamSource(new ByteArrayInputStream(s.getBytes())),
            "text/xml"
    );
    msg.addAttachmentPart(ap);
    msg.saveChanges();

    return msg;
}
项目:sam-elle    文件:EditTerminalClient.java   
/**
 * Gets the terminal response.
 * 
 * @param message
 * @throws SOAPException
 */
private void writeTerminalResponse(SOAPMessage message) throws SOAPException {
    SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
    Name terminalResponseName = envelope.createName("EditTerminalResponse", PREFIX, NAMESPACE_URI);
    SOAPBodyElement terminalResponseElement = (SOAPBodyElement) message.getSOAPBody().getChildElements(terminalResponseName).next();

    NodeList list = terminalResponseElement.getChildNodes();
    Node n = null;
    for (int i = 0; i < list.getLength(); i++) {
        n = list.item(i);
        if ("status".equalsIgnoreCase(n.getLocalName()))
            break;
    }

    logger.info("status of device = " + n.getNodeValue());

}
项目:sam-elle    文件:GetTerminalsByMsisdnClient.java   
/**
 * This method creates a Terminal Request and sends back the SOAPMessage.
 * MSISDN value is passed into this method
 * 
 * @param msisdn
 * @return
 * @throws SOAPException
 */
private SOAPMessage createTerminalRequest(String msisdn) throws SOAPException {
    SOAPMessage message = messageFactory.createMessage();
    message.getMimeHeaders().addHeader("SOAPAction", "http://api.jasperwireless.com/ws/service/terminal/GetTerminalsByMsisdn");
    SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
    Name terminalRequestName = envelope.createName("GetTerminalsByMsisdnRequest", PREFIX, NAMESPACE_URI);
    SOAPBodyElement terminalRequestElement = message.getSOAPBody().addBodyElement(terminalRequestName);
    Name msgId = envelope.createName("messageId", PREFIX, NAMESPACE_URI);
    SOAPElement msgElement = terminalRequestElement.addChildElement(msgId);
    msgElement.setValue("TCE-100-ABC-34084");
    Name version = envelope.createName("version", PREFIX, NAMESPACE_URI);
    SOAPElement versionElement = terminalRequestElement.addChildElement(version);
    versionElement.setValue("1.0");
    Name license = envelope.createName("licenseKey", PREFIX, NAMESPACE_URI);
    SOAPElement licenseElement = terminalRequestElement.addChildElement(license);
    licenseElement.setValue(apiKey);
    Name msisdns = envelope.createName("msisdns", PREFIX, NAMESPACE_URI);
    SOAPElement msisdnsElement = terminalRequestElement.addChildElement(msisdns);
    Name msisdnName = envelope.createName("msisdn", PREFIX, NAMESPACE_URI);
    SOAPElement msisdnElement = msisdnsElement.addChildElement(msisdnName);
    msisdnElement.setValue(msisdn);
    return message;
}
项目:sam-elle    文件:GetTerminalsByMsisdnClient.java   
/**
 * Gets the terminal response.
 * 
 * @param message
 * @throws SOAPException
 */
private String writeTerminalResponse(SOAPMessage message) throws SOAPException {
    SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
    Name terminalResponseName = envelope.createName("GetTerminalsByMsisdnResponse", PREFIX, NAMESPACE_URI);
    SOAPBodyElement terminalResponseElement = (SOAPBodyElement) message.getSOAPBody().getChildElements(terminalResponseName).next();
    Name terminals = envelope.createName("terminals", PREFIX, NAMESPACE_URI);
    Name terminal = envelope.createName("terminal", PREFIX, NAMESPACE_URI);
    SOAPBodyElement terminalsElement = (SOAPBodyElement) terminalResponseElement.getChildElements(terminals).next();
    SOAPBodyElement terminalElement = (SOAPBodyElement) terminalsElement.getChildElements(terminal).next();
    NodeList list = terminalElement.getChildNodes();
    Node n = null, node = null;
    for (int i = 0; i < list.getLength(); i++) {
        node = list.item(i);
        logger.info(node.getLocalName() + ":" + node.getFirstChild().getNodeValue());
        if ("iccid".equalsIgnoreCase(node.getLocalName())) {
            n = node;
        }
    }

    return n.getFirstChild().getNodeValue();

}
项目:atf-toolbox-java    文件:WebServiceAutomationManager.java   
/**
 * createSOAPRequestMessage - create a SOAP message from an object
 *
 * @param webServiceKey
 *            key to locate the web service
 * @param request
 *            - request body content
 * @param action
 *            - SOAP Action string
 * @return SOAPMessage
 * @throws SOAPException
 *             - if there was an error creating the SOAP Connection
 * @throws JAXBException
 *             - if there was an error marshalling the SOAP Message
 */
private SOAPMessage createSOAPRequestMessage(String webServiceKey, Object request, String action) throws SOAPException, JAXBException {
    WebService service = getWebService(webServiceKey);

    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage message = factory.createMessage();
    SOAPPart soapPart = message.getSOAPPart();

    // SOAP Envelope
    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("example", service.getNamespaceURI());

    if (action != null) {
        MimeHeaders headers = message.getMimeHeaders();
        headers.addHeader("SOAPAction", service.getNamespaceURI() + "VerifyEmail");
    }

    // SOAP Body
    SOAPBody body = message.getSOAPBody();

    marshallObject(webServiceKey, request, body);

    message.saveChanges();
    return message;
}
项目:soap-wrapper-lambda    文件:ExampleSoapMessage.java   
public static SOAPMessage create() throws SOAPException {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage message = messageFactory.createMessage();
    SOAPPart soapPart = message.getSOAPPart();

    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("codecentric", "https://www.codecentric.de");

    SOAPBody envelopeBody = envelope.getBody();
    SOAPElement soapBodyElem = envelopeBody.addChildElement("location", "codecentric");

    SOAPElement place = soapBodyElem.addChildElement("place", "codecentric");
    place.addTextNode("Berlin");

    MimeHeaders headers = message.getMimeHeaders();
    headers.addHeader("SOAPAction", "https://www.codecentric.de/location");

    message.saveChanges();
    return message;
}
项目:rpb    文件:EventDefListAllHandler.java   
@Override
public boolean handleMessage(SOAPMessageContext context) {
    Boolean isRequest = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    if (!isRequest) { // only incoming messages
        try {
            SOAPMessage soapMsg = context.getMessage();
            SOAPEnvelope soapEnv = soapMsg.getSOAPPart().getEnvelope();
            SOAPBody soapBody = soapEnv.getBody();
            if (soapBody != null) {
                // Should have a SOAPBody and a listall response...
                NodeList nodeList = soapBody.getElementsByTagNameNS(EVENTDEF_NS, EVENTDEF_LIST_ALL_RESPONSE);
                if (nodeList.getLength() > 0) { // check for listAllResponse
                                                // tag first!
                    nodeList = soapBody.getElementsByTagNameNS(EVENTDEF_NS, EVENTDEF_ELEMENT);
                    recursiveRenamespace(nodeList); // renamespace...
                    soapMsg.saveChanges();
                }
            }
        } catch (Exception e) {
            catchMessages(e);
        }
    }
    return true;
}
项目:rpb    文件:StudyListAllHandler.java   
@Override
public boolean handleMessage(SOAPMessageContext context) {
    Boolean isRequest = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    if (!isRequest) { // only incoming messages
        try {
            SOAPMessage soapMsg = context.getMessage();
            SOAPEnvelope soapEnv = soapMsg.getSOAPPart().getEnvelope();
            SOAPBody soapBody = soapEnv.getBody();
            if (soapBody != null) {
                // Should have a SOAPBody and a listall response...
                NodeList nodeList = soapBody.getElementsByTagNameNS(STUDIES_NS, STUDY_LIST_ALL_RESPONSE);
                if (nodeList.getLength() > 0) { // check for listAllResponse
                                                // tag first!
                    nodeList = soapBody.getElementsByTagNameNS(STUDIES_NS, STUDIES_ELEMENT);
                    recursiveRenamespace(nodeList); // renamespace...
                    soapMsg.saveChanges();
                }
            }
        } catch (Exception e) {
            catchMessages(e);
        }
    }
    return true;
}
项目:hermes    文件:SOAPResponse.java   
/**
 * Adds a SOAP fault to the SOAP message of this response.
 * 
 * @param code the fault code.
 * @param actor the fault actor.
 * @param desc the fault description.
 * @return the SOAP fault which has been added to the SOAP message. null if
 *         there is no SOAP message in this response or the fault has
 *         already been added.
 * @throws SOAPException a SOAP error occurred when adding the the fault.
 */
public SOAPFault addFault(String code, String actor, String desc)
        throws SOAPException {
    SOAPMessage msg = getMessage();
    if (msg != null) {
        SOAPEnvelope env = msg.getSOAPPart().getEnvelope();
        SOAPBody body = env.getBody();
        if (body != null && !body.hasFault()) {
            SOAPFault fault = body.addFault();
            if (code != null) {
                fault.setFaultCode(env.getElementName().getPrefix() + ":"
                        + code);
            }
            if (actor != null) {
                fault.setFaultActor(actor);
            }
            if (desc != null) {
                fault.setFaultString(desc);
            }
            return fault;
        }
    }
    return null;
}
项目:hermes    文件:StatusRequest.java   
/** 
 * Constructs a <code>StatusRequest</code> object by parsing the given
 * <code>SOAPElement</code>.
 * 
 * @param soapEnvelope      <code>SOAPEnvelope</code>, the header of which
 *                          status request element will be added to.
 * @param soapElement       <code>SOAPElement</code> from which a 
 *                          <code>StatusRequest</code> object is
 *                          constructed.
 * @throws SOAPException 
 */
StatusRequest(SOAPEnvelope soapEnvelope, SOAPElement soapElement)
    throws SOAPException {
    super(soapEnvelope, soapElement);
    final Iterator childElements =
        getChildElements(ELEMENT_REF_TO_MESSAGE_ID);
    if (childElements.hasNext()) {
        refToMessageId = ((SOAPElement) childElements.next()).getValue();
    }
    else {
        throw new SOAPValidationException
            (SOAPValidationException.SOAP_FAULT_CLIENT,
             "Missing <" + NAMESPACE_PREFIX_EB + ":"
             + ELEMENT_REF_TO_MESSAGE_ID + "> in <" + NAMESPACE_PREFIX_EB
             + ":" + STATUS_REQUEST + ">!");
    }
}
项目:hermes    文件:StatusResponse.java   
/** 
 * Constructs a <code>StatusResponse</code> object by parsing the given
 * <code>SOAPElement</code>.
 * 
 * @param soapEnvelope      <code>SOAPEnvelope</code> to which the 
 *                          status response element will be added.
 * @param soapElement       <code>SOAPElement</code> from which a 
 *                          <code>StatusResponse</code> object is
 *                          constructed.
 * @throws SOAPException 
 */
StatusResponse(SOAPEnvelope soapEnvelope, SOAPElement soapElement)
    throws SOAPException {
    super(soapEnvelope, soapElement);
    Iterator childElements = getChildElements(ELEMENT_REF_TO_MESSAGE_ID);
    if (childElements.hasNext()) {
        refToMessageId = ((SOAPElement) childElements.next()).getValue();
    }
    else {
        throw new SOAPValidationException
            (SOAPValidationException.SOAP_FAULT_CLIENT,
             "Missing <" + NAMESPACE_PREFIX_EB + ":" 
             + ELEMENT_REF_TO_MESSAGE_ID + "> in <" + NAMESPACE_PREFIX_EB 
             + ":" + STATUS_RESPONSE + ">!");
    }

    messageStatus = getAttributeValue(ATTRIBUTE_MESSAGE_STATUS);

    childElements = getChildElements(ELEMENT_TIMESTAMP);
    if (childElements.hasNext()) {
        timestamp = ((SOAPElement) childElements.next()).getValue();
    }
    else {
        timestamp = null;
    }
}
项目:hermes    文件:MessageOrder.java   
/** 
 * Constructs a <code>MessageOrder</code> with the given mandatory
 * fields.
 *
 * @param soapEnvelope      <code>SOAPEnvelope</code>, the header container
 *                          of which the <code>MessageOrder</code> is 
 *                          attached to.
 * @param status            Status of the sequence number.
 * @param sequenceNo        The sequence number in the converstaion.
 * @throws SOAPException 
*/
MessageOrder(SOAPEnvelope soapEnvelope, int status, int sequenceNo) 
    throws SOAPException {
    super(soapEnvelope, MESSAGE_ORDER);
    this.sequenceNo = sequenceNo;
    this.status = status;

    String statusName;
    if (status == STATUS_RESET) {
        statusName = VALUE_STATUS_RESET;
    }
    else {
        statusName = VALUE_STATUS_CONTINUE;
    }

    addChildElement(ELEMENT_SEQUENCE_NUMBER, Integer.toString(sequenceNo))
        .addAttribute(ATTRIBUTE_STATUS, statusName);
}
项目:hermes    文件:MessageHeader.java   
/** 
 * Initializes data structures in <code>MessageHeader</code> object 
 * using the given <code>SOAPEnvelope</code>.
 * 
 * @param soapEnvelope      <code>SOAPEnvelope</code> into which the 
 *                          <code>MessageHeader</code> is added.
 * @throws SOAPException 
 */
MessageHeader(SOAPEnvelope soapEnvelope) throws SOAPException {
    super(soapEnvelope, MESSAGE_HEADER);

    this.from = addChildElement(ELEMENT_FROM);
    this.fromPartyIds = new ArrayList();
    this.fromRole = null;

    this.to = addChildElement(ELEMENT_TO);
    this.toPartyIds = new ArrayList();
    this.toRole = null;

    this.service = null;
    this.serviceElement = null;
    this.action = null;

    this.messageData = null;
    this.messageId = null;
    this.timestamp = null;
    this.refToMessageId = null;
    this.timeToLive = null;
    this.duplicateElimination = false;

    descriptions = new ArrayList();
}
项目:hermes    文件:Acknowledgment.java   
/** 
 * Constructs an <code>Acknowledgment</code> with the given mandatory
 * fields.
 *
 * @param soapEnvelope      <code>SOAPEnvelope</code>, the header container
 *                          of which the <code>Acknowledgement</code> is 
 *                          attached to.
 * @param timestamp         The time the message service handler received
 *                          the message to be acknowledged.
 * @param refToMessage      The message this acknowledgement response 
 *                          is referring to.
 * @param fromPartyId       The identifier of the party generating the
 *                          acknowledgement response message.
 * @param fromPartyIdType   PartyId type
 *
 * @throws SOAPException 
*/
Acknowledgment(SOAPEnvelope soapEnvelope, String timestamp,
               EbxmlMessage refToMessage, String fromPartyId,
               String fromPartyIdType) throws SOAPException {
    super(soapEnvelope, ACKNOWLEDGMENT);
    this.timestamp = timestamp;
    this.refToMessageId = refToMessage.getMessageId();
    setActor(ACTOR_TO_PARTY_MSH_URN);
    addChildElement(MessageHeader.ELEMENT_TIMESTAMP, timestamp);
    addChildElement(MessageHeader.ELEMENT_REF_TO_MESSAGE_ID,
                    refToMessageId);
    fromPartyIds = new ArrayList();
    if (fromPartyId != null) {
        from = addChildElement(MessageHeader.ELEMENT_FROM);
        addFromPartyId(fromPartyId, fromPartyIdType);
    }
    else {
        from = null;
    }
    signatureReferences = new ArrayList();
}
项目:jasperreports    文件:JRXmlaQueryExecuter.java   
protected void addParameterList(SOAPEnvelope envelope, SOAPElement eParent, String typeName, String listName, Map<String, String> params) throws SOAPException
{
    Name nPara = envelope.createName(typeName, "", XMLA_URI);
    SOAPElement eType = eParent.addChildElement(nPara);
    nPara = envelope.createName(listName, "", XMLA_URI);
    SOAPElement eList = eType.addChildElement(nPara);
    if (params == null)
    {
        return;
    }
    for (Iterator<Map.Entry<String, String>> entryIt = params.entrySet().iterator(); entryIt.hasNext();)
    {
        Map.Entry<String, String> entry = entryIt.next();
        String tag = entry.getKey();
        String value = entry.getValue();
        nPara = envelope.createName(tag, "", XMLA_URI);
        SOAPElement eTag = eList.addChildElement(nPara);
        eTag.addTextNode(value);
    }
}
项目:Camel    文件:TesterBean.java   
public SOAPMessage processSOAP(Exchange exchange) {
    // Since the Camel-CXF endpoint uses a list to store the parameters
    // and bean component uses the bodyAs expression to get the value
    // we'll need to deal with the parameters ourself
    SOAPMessage soapMessage = (SOAPMessage)exchange.getIn().getBody(List.class).get(0);
    if (soapMessage == null) {
        System.out.println("Incoming null message detected...");
        return createDefaultSoapMessage("Greetings from Apache Camel!!!!", "null");
    }

    try {
        SOAPPart sp = soapMessage.getSOAPPart();
        SOAPEnvelope se = sp.getEnvelope();
        SOAPBody sb = se.getBody();
        String requestText = sb.getFirstChild().getTextContent();
        System.out.println(requestText);
        return createDefaultSoapMessage("Greetings from Apache Camel!!!!", requestText);
    } catch (Exception e) {
        e.printStackTrace();
        return createDefaultSoapMessage("Greetings from Apache Camel!!!!", e.getClass().getName());
    }
}
项目:development    文件:SoapRequestParserTest.java   
@Test
public void parseApiVersion_cm_1_8() throws Exception {
    // given
    SOAPPart part = mock(SOAPPart.class);
    SOAPEnvelope envelope = mock(SOAPEnvelope.class);
    SOAPHeader soapHeader = mock(SOAPHeader.class);
    List<Node> version = new ArrayList<Node>();
    Node node = mock(Node.class);
    doReturn("testVersion").when(node).getValue();
    version.add(node);
    Iterator<?> it = version.iterator();
    doReturn(it).when(soapHeader).extractHeaderElements(
            eq("cm.service.version"));
    doReturn(soapHeader).when(envelope).getHeader();
    doReturn(envelope).when(part).getEnvelope();
    doReturn(part).when(message).getSOAPPart();
    // when
    String result = SoapRequestParser.parseApiVersion(context);

    // then
    assertEquals("testVersion", result);
}
项目:development    文件:SoapRequestParserTest.java   
@Test
public void parseApiVersion_ctmg_1_8() throws Exception {
    // given
    SOAPPart part = mock(SOAPPart.class);
    SOAPEnvelope envelope = mock(SOAPEnvelope.class);
    SOAPHeader soapHeader = mock(SOAPHeader.class);
    List<Node> version = new ArrayList<Node>();
    Node node = mock(Node.class);
    doReturn("testVersion").when(node).getValue();
    version.add(node);
    Iterator<?> it = version.iterator();
    doReturn(it).when(soapHeader).extractHeaderElements(
            eq("ctmg.service.version"));
    doReturn(soapHeader).when(envelope).getHeader();
    doReturn(envelope).when(part).getEnvelope();
    doReturn(part).when(message).getSOAPPart();
    // when
    String result = SoapRequestParser.parseApiVersion(context);

    // then
    assertEquals("testVersion", result);
}
项目:sam-elle    文件:EditTerminalClient.java   
/**
 * Gets the terminal response.
 * 
 * @param message
 * @throws SOAPException
 */
private void writeTerminalResponse(SOAPMessage message) throws SOAPException {
    SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
    Name terminalResponseName = envelope.createName("EditTerminalResponse", PREFIX, NAMESPACE_URI);
    SOAPBodyElement terminalResponseElement = (SOAPBodyElement) message.getSOAPBody().getChildElements(terminalResponseName).next();

    NodeList list = terminalResponseElement.getChildNodes();
    Node n = null;
    for (int i = 0; i < list.getLength(); i++) {
        n = list.item(i);
        if ("status".equalsIgnoreCase(n.getLocalName()))
            break;
    }

    logger.info("status of device = " + n.getNodeValue());

}
项目:sam-elle    文件:GetTerminalsByMsisdnClient.java   
/**
 * This method creates a Terminal Request and sends back the SOAPMessage.
 * MSISDN value is passed into this method
 * 
 * @param msisdn
 * @return
 * @throws SOAPException
 */
private SOAPMessage createTerminalRequest(String msisdn) throws SOAPException {
    SOAPMessage message = messageFactory.createMessage();
    message.getMimeHeaders().addHeader("SOAPAction", "http://api.jasperwireless.com/ws/service/terminal/GetTerminalsByMsisdn");
    SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
    Name terminalRequestName = envelope.createName("GetTerminalsByMsisdnRequest", PREFIX, NAMESPACE_URI);
    SOAPBodyElement terminalRequestElement = message.getSOAPBody().addBodyElement(terminalRequestName);
    Name msgId = envelope.createName("messageId", PREFIX, NAMESPACE_URI);
    SOAPElement msgElement = terminalRequestElement.addChildElement(msgId);
    msgElement.setValue("TCE-100-ABC-34084");
    Name version = envelope.createName("version", PREFIX, NAMESPACE_URI);
    SOAPElement versionElement = terminalRequestElement.addChildElement(version);
    versionElement.setValue("1.0");
    Name license = envelope.createName("licenseKey", PREFIX, NAMESPACE_URI);
    SOAPElement licenseElement = terminalRequestElement.addChildElement(license);
    licenseElement.setValue(apiKey);
    Name msisdns = envelope.createName("msisdns", PREFIX, NAMESPACE_URI);
    SOAPElement msisdnsElement = terminalRequestElement.addChildElement(msisdns);
    Name msisdnName = envelope.createName("msisdn", PREFIX, NAMESPACE_URI);
    SOAPElement msisdnElement = msisdnsElement.addChildElement(msisdnName);
    msisdnElement.setValue(msisdn);
    return message;
}
项目:sam-elle    文件:GetTerminalsByMsisdnClient.java   
/**
 * Gets the terminal response.
 * 
 * @param message
 * @throws SOAPException
 */
private String writeTerminalResponse(SOAPMessage message) throws SOAPException {
    SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
    Name terminalResponseName = envelope.createName("GetTerminalsByMsisdnResponse", PREFIX, NAMESPACE_URI);
    SOAPBodyElement terminalResponseElement = (SOAPBodyElement) message.getSOAPBody().getChildElements(terminalResponseName).next();
    Name terminals = envelope.createName("terminals", PREFIX, NAMESPACE_URI);
    Name terminal = envelope.createName("terminal", PREFIX, NAMESPACE_URI);
    SOAPBodyElement terminalsElement = (SOAPBodyElement) terminalResponseElement.getChildElements(terminals).next();
    SOAPBodyElement terminalElement = (SOAPBodyElement) terminalsElement.getChildElements(terminal).next();
    NodeList list = terminalElement.getChildNodes();
    Node n = null, node = null;
    for (int i = 0; i < list.getLength(); i++) {
        node = list.item(i);
        logger.info(node.getLocalName() + ":" + node.getFirstChild().getNodeValue());
        if ("iccid".equalsIgnoreCase(node.getLocalName())) {
            n = node;
        }
    }

    return n.getFirstChild().getNodeValue();

}
项目:java-ws-discovery    文件:WsDiscoveryS11SOAPMessage.java   
/**
 * Create SOAP message of specified action type containing a JAXB element.
 * 
 * @param action Action type.
 * @param jaxb JAXB element.
 */
public WsDiscoveryS11SOAPMessage(WsDiscoveryActionTypes action, JAXBElement<E> jaxb) throws SOAPOverUDPException {
    super(WsDiscoveryConstants.defaultSoapProtocol, WsDiscoveryConstants.defaultEncoding);

    instanceId = WsDiscoveryConstants.instanceId;
    sequenceId = "urn:uuid:" + WsDiscoveryConstants.sequenceId;
    messageNumber = ++lastMessageNumber;

    try {
        SOAPEnvelope e = soapMessage.getSOAPPart().getEnvelope();
        e.addNamespaceDeclaration("wsd", namespace.getWsDiscoveryNamespace());
        e.addNamespaceDeclaration("wsa", namespace.getWsAddressingNamespace());
    } catch (SOAPException ex) {
        throw new SOAPOverUDPException("Unable to read SOAP envelope");
    }

    this.setAction(action.toURI());
    // Initialize to anonymous recipient
    this.setTo(URI.create("urn:docs-oasis-open-org:ws-dd:ns:discovery:2009:01"));
    this.setJAXBBody(jaxb);
}
项目:java-ws-discovery    文件:WsDiscoveryD2005SOAPMessage.java   
/**
 * Create SOAP message of specified action type containing a JAXB element.
 * 
 * @param action Action type.
 * @param jaxb JAXB element.
 */
public WsDiscoveryD2005SOAPMessage(WsDiscoveryActionTypes action, JAXBElement<E> jaxb) throws SOAPOverUDPException {
    super(WsDiscoveryConstants.defaultSoapProtocol, WsDiscoveryConstants.defaultEncoding);

    instanceId = WsDiscoveryConstants.instanceId;
    sequenceId = "urn:uuid:" + WsDiscoveryConstants.sequenceId;
    messageNumber = ++lastMessageNumber;

    try {
        SOAPEnvelope e = soapMessage.getSOAPPart().getEnvelope();
        e.addNamespaceDeclaration("wsd", namespace.getWsDiscoveryNamespace());
        e.addNamespaceDeclaration("wsa", namespace.getWsAddressingNamespace());
    } catch (SOAPException ex) {
        throw new SOAPOverUDPException("Unable to read SOAP envelope");
    }

    this.setAction(action.toURI());
    // Initialize to anonymous recipient
    this.setTo(URI.create(namespace.getWsAddressingNamespace() + "/role/anonymous"));
    this.setJAXBBody(jaxb);
}
项目:openxds    文件:SoapRequestBean.java   
public SOAPMessage onMessage(SOAPMessage msg){
    //handles the response back from the registry
    PrintStream orig = System.out;

    try {
        SOAPEnvelope env = msg.getSOAPPart().getEnvelope();
        Name response = env.createName("response");
        env.getBody().getChildElements(response);

    } catch (SOAPException ex) {
        ByteArrayOutputStream logarray = new ByteArrayOutputStream();
        ex.printStackTrace(writeErrorlog(logarray));
        logstring = logarray.toString();
        setlogmsg(logstring);  
    }

    return msg;
}
项目:jolie    文件:SoapProtocol.java   
private void groupProcessing(
    Value value,
    XSElementDecl xsDecl,
    SOAPElement element,
    SOAPEnvelope envelope,
    boolean first,
    XSModelGroup modelGroup,
    XSSchemaSet sSet,
    String messageNamespace )
    throws SOAPException
{

    XSParticle[] children = modelGroup.getChildren();
    XSTerm currTerm;
    for( XSParticle child : children ) {
        currTerm = child.getTerm();
        if ( currTerm.isModelGroup() ) {
            groupProcessing( value, xsDecl, element, envelope, first, currTerm.asModelGroup(), sSet, messageNamespace );
        } else {
            termProcessing( value, element, envelope, first, currTerm, child.getMaxOccurs(), sSet, messageNamespace );
        }
    }
}
项目:jolie    文件:SoapProtocol.java   
private void setOutputEncodingStyle( SOAPEnvelope soapEnvelope, String operationName )
    throws IOException, SOAPException
{
    Port port = getWSDLPort();
    if ( port != null ) {
        BindingOperation bindingOperation = port.getBinding().getBindingOperation( operationName, null, null );
        if ( bindingOperation == null ) {
            return;
        }
        BindingOutput output = bindingOperation.getBindingOutput();
        if ( output == null ) {
            return;
        }
        for( ExtensibilityElement element : (List<ExtensibilityElement>) output.getExtensibilityElements() ) {
            if ( element instanceof javax.wsdl.extensions.soap.SOAPBody ) {
                List<String> list = ((javax.wsdl.extensions.soap.SOAPBody) element).getEncodingStyles();
                if ( list != null && list.isEmpty() == false ) {
                    soapEnvelope.setEncodingStyle( list.get( 0 ) );
                    soapEnvelope.addNamespaceDeclaration( "enc", list.get( 0 ) );
                }
            }
        }
    }
}
项目:rpb    文件:EventDefListAllHandler.java   
@Override
public boolean handleMessage(SOAPMessageContext context) {
    Boolean isRequest = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    if (!isRequest) { // only incoming messages
        try {
            SOAPMessage soapMsg = context.getMessage();
            SOAPEnvelope soapEnv = soapMsg.getSOAPPart().getEnvelope();
            SOAPBody soapBody = soapEnv.getBody();
            if (soapBody != null) {
                // Should have a SOAPBody and a listall response...
                NodeList nodeList = soapBody.getElementsByTagNameNS(EVENTDEF_NS, EVENTDEF_LIST_ALL_RESPONSE);
                if (nodeList.getLength() > 0) { // check for listAllResponse
                                                // tag first!
                    nodeList = soapBody.getElementsByTagNameNS(EVENTDEF_NS, EVENTDEF_ELEMENT);
                    recursiveRenamespace(nodeList); // renamespace...
                    soapMsg.saveChanges();
                }
            }
        } catch (Exception e) {
            catchMessages(e);
        }
    }
    return true;
}
项目:rpb    文件:StudyListAllHandler.java   
@Override
public boolean handleMessage(SOAPMessageContext context) {
    Boolean isRequest = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    if (!isRequest) { // only incoming messages
        try {
            SOAPMessage soapMsg = context.getMessage();
            SOAPEnvelope soapEnv = soapMsg.getSOAPPart().getEnvelope();
            SOAPBody soapBody = soapEnv.getBody();
            if (soapBody != null) {
                // Should have a SOAPBody and a listall response...
                NodeList nodeList = soapBody.getElementsByTagNameNS(STUDIES_NS, STUDY_LIST_ALL_RESPONSE);
                if (nodeList.getLength() > 0) { // check for listAllResponse
                                                // tag first!
                    nodeList = soapBody.getElementsByTagNameNS(STUDIES_NS, STUDIES_ELEMENT);
                    recursiveRenamespace(nodeList); // renamespace...
                    soapMsg.saveChanges();
                }
            }
        } catch (Exception e) {
            catchMessages(e);
        }
    }
    return true;
}
项目:x-road-adapter-example    文件:ExampleAdapter.java   
@Override
/**
 * Serializes the response data.
 *
 * @param response ServiceResponse holding the application specific
 * response object
 * @param soapResponse SOAPMessage's response object where the response
 * element is added
 * @param envelope SOAPMessage's SOAPEnvelope object
 */
public void serializeResponse(ServiceResponse response, SOAPElement soapResponse, SOAPEnvelope envelope) throws SOAPException {
    // Add "data" element
    SOAPElement data = soapResponse.addChildElement(envelope.createName("data"));
    // Put response data inside the "data" element
    data.addTextNode((String) response.getResponseData());
}
项目:x-road-adapter-example    文件:ExampleAdapter.java   
@Override
/**
 * Serializes the response data.
 *
 * @param response ServiceResponse holding the application specific
 * response object
 * @param soapResponse SOAPMessage's response object where the response
 * element is added
 * @param envelope SOAPMessage's SOAPEnvelope object
 */
public void serializeResponse(ServiceResponse response, SOAPElement soapResponse, SOAPEnvelope envelope) throws SOAPException {
    // Add "message" element
    SOAPElement data = soapResponse.addChildElement(envelope.createName("message"));
    // Put response data inside the "message" element
    data.addTextNode((String) response.getResponseData());
}