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

项目:openjdk-jdk10    文件:Fault1_2Impl.java   
@Override
public void appendFaultSubcode(QName subcode) throws SOAPException {
    if (subcode == null) {
        return;
    }
    if (subcode.getNamespaceURI() == null ||
        "".equals(subcode.getNamespaceURI())) {

        log.severe("SAAJ0432.ver1_2.subcode.not.ns.qualified");
        throw new SOAPExceptionImpl("A Subcode must be namespace-qualified");
    }
    if (innermostSubCodeElement == null) {
        if (faultCodeElement == null)
            findFaultCodeElement();
        innermostSubCodeElement = faultCodeElement;
    }
    String prefix = null;
    if (subcode.getPrefix() == null || "".equals(subcode.getPrefix())) {
        prefix =
            ((ElementImpl) innermostSubCodeElement).getNamespacePrefix(
                subcode.getNamespaceURI());
    } else
        prefix = subcode.getPrefix();
    if (prefix == null || "".equals(prefix)) {
        prefix = "ns1";
    }
    innermostSubCodeElement =
        innermostSubCodeElement.addChildElement(subcodeName);
    SOAPElement subcodeValueElement =
        innermostSubCodeElement.addChildElement(valueName);
    ((ElementImpl) subcodeValueElement).ensureNamespaceIsDeclared(
        prefix,
        subcode.getNamespaceURI());
    subcodeValueElement.addTextNode(prefix + ":" + subcode.getLocalPart());
}
项目: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.");
}
项目:incubator-netbeans    文件:PartnerUtils.java   
public static String getUniqueID(SOAPElement itinerary) {
    String uniqueID = "";

    NodeList nodeList = itinerary.getChildNodes();
    try {
        for(int index1=0; index1<nodeList.getLength() ; index1++) {
            Node node1 = nodeList.item(index1);
            if(node1.getNodeName().endsWith("ItineraryRef")) {
                for (int index2=0 ; index2<node1.getChildNodes().getLength() ; index2++) {
                    Node node2 = node1.getChildNodes().item(index2);
                    if(node2.getNodeName().endsWith("UniqueID")) {
                        uniqueID = node2.getTextContent();
                        break;
                    }
                }
            }
        }
    } catch (Exception ex) {
    }
    return uniqueID;

}
项目:openjdk-jdk10    文件:Fault1_2Impl.java   
@Override
public SOAPElement addChildElement(SOAPElement element)
    throws SOAPException {
    String localName = element.getLocalName();
    if ("Detail".equalsIgnoreCase(localName)) {
        if (hasDetail()) {
            log.severe("SAAJ0436.ver1_2.detail.exists.error");
            throw new SOAPExceptionImpl("Cannot add Detail, Detail already exists");
        }
        String uri = element.getElementQName().getNamespaceURI();
        if (!uri.equals(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE)) {
            log.severe("SAAJ0437.ver1_2.version.mismatch.error");
            throw new SOAPExceptionImpl("Cannot add Detail, Incorrect SOAP version specified for Detail element");
        }
    }
    if (element instanceof Detail1_2Impl) {
        Element importedElement = importElement(element);
        addNode(importedElement);
        return convertToSoapElement(importedElement);
    } else
        return super.addChildElement(element);
}
项目:openjdk-jdk10    文件:Fault1_2Impl.java   
private SOAPElement getFaultReasonTextElement(Locale locale)
    throws SOAPException {

    // Fault Reason has similar semantics as faultstring
    Iterator eachTextElement =
        this.faultStringElement.getChildElements(textName);
    while (eachTextElement.hasNext()) {
        SOAPElement textElement = (SOAPElement) eachTextElement.next();
        Locale thisLocale = getLocale(textElement);
        if (thisLocale == null) {
            log.severe("SAAJ0431.ver1_2.xml.lang.missing");
            throw new SOAPExceptionImpl("\"xml:lang\" attribute is not present on the Text element");
        }
        if (thisLocale.equals(locale)) {
            return textElement;
        }
    }
    return null;
}
项目: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    文件:ServiceResponseSerializerTest.java   
/**
 * Subsystem level service call. No NS on request. Multiple NSs prefix on
 * response.
 * @throws XRd4JException
 * @throws SOAPException
 */
public void test14() throws XRd4JException, SOAPException {
    String requestStr = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:xrd=\"http://x-road.eu/xsd/xroad.xsd\"><SOAP-ENV:Header><xrd:client id:objectType=\"SUBSYSTEM\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode></xrd:client><xrd:service id:objectType=\"SERVICE\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode><id:serviceCode>getRandom</id:serviceCode><id:serviceVersion>v1</id:serviceVersion></xrd:service><xrd:userId>EE1234567890</xrd:userId><xrd:id>1234567890</xrd:id><xrd:protocolVersion>4.0</xrd:protocolVersion></SOAP-ENV:Header><SOAP-ENV:Body><ns1:getRandom xmlns:ns1=\"http://consumer.x-road.ee\"><request><data>Request data</data></request></ns1:getRandom></SOAP-ENV:Body></SOAP-ENV:Envelope>";
    String correctResponse = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:id=\"http://x-road.eu/xsd/identifiers\" xmlns:xrd=\"http://x-road.eu/xsd/xroad.xsd\"><SOAP-ENV:Header><xrd:client id:objectType=\"SUBSYSTEM\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode></xrd:client><xrd:service id:objectType=\"SERVICE\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:subsystemCode>subsystem</id:subsystemCode><id:serviceCode>getRandom</id:serviceCode><id:serviceVersion>v1</id:serviceVersion></xrd:service><xrd:userId>EE1234567890</xrd:userId><xrd:id>1234567890</xrd:id><xrd:protocolVersion>4.0</xrd:protocolVersion></SOAP-ENV:Header><SOAP-ENV:Body><xxprod:getRandomResponse xmlns:xxprod=\"http://foobar.x-road.ee/producer\"><xxprod:request><xxprod:data>Request data</xxprod:data></xxprod:request><xxprod:response><ns1:responseData xmlns:ns1=\"http://ns1.com\" xmlns:ns2=\"http://ns2.com\"><ns1:data>Response data</ns1:data><ns2:data2>Response data 2</ns2:data2></ns1:responseData></xxprod:response></xxprod:getRandomResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>";
    ConsumerMember consumer = new ConsumerMember("FI", "GOV", "MEMBER1", "subsystem");
    ProducerMember producer = new ProducerMember("FI", "COM", "MEMBER2", "subsystem", "getRandom", "v1");
    ServiceRequest<String> request = new ServiceRequest<String>(consumer, producer, "1234567890");
    request.setUserId("EE1234567890");
    request.setRequestData("Request data");
    request.setSoapMessage(SOAPHelper.toSOAP(requestStr));

    request.getProducer().setNamespacePrefix("xxprod");
    request.getProducer().setNamespaceUrl("http://foobar.x-road.ee/producer");

    ServiceResponse<String, SOAPElement> response = new ServiceResponse<String, SOAPElement>(request.getConsumer(), request.getProducer(), request.getId());
    response.setResponseData(SOAPHelper.xmlStrToSOAPElement(
            "<ns1:responseData xmlns:ns1=\"http://ns1.com\" xmlns:ns2=\"http://ns2.com\"><ns1:data>Response data</ns1:data><ns2:data2>Response data 2</ns2:data2></ns1:responseData>"));
    response.setForceNamespaceToResponseChildren(false);

    ServiceResponseSerializer serializer = new XMLServiceResponseSerializer();
    SOAPMessage msg = serializer.serialize(response, request);

    assertEquals(correctResponse, SOAPHelper.toString(msg));
}
项目:openjdk-jdk10    文件:Fault1_2Impl.java   
@Override
public void setFaultNode(String uri) throws SOAPException {
    SOAPElement faultNode = findAndConvertChildElement(getFaultNodeName());
    if (faultNode != null) {
        faultNode.detachNode();
    }
    faultNode = createSOAPFaultElement(getFaultNodeName());
    faultNode = faultNode.addTextNode(uri);
    if (getFaultRole() != null) {
        insertBefore(faultNode, this.faultActorElement);
        return;
    }
    if (hasDetail()) {
        insertBefore(faultNode, this.detail);
        return;
    }
    addNode(faultNode);
}
项目: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.");
}
项目:xrd4j    文件:SOAPHelperTest.java   
/**
 * Multiple parameters with the same name.
 */
public void testNodesToMap1() {
    String xml = "<request><param1>value1</param1><param1>value2</param1><param1>value3</param1><param2>value1</param2><param2>value2</param2><param3></param3><param4>\n</param4></request>";
    SOAPElement soap = SOAPHelper.xmlStrToSOAPElement(xml);
    Map<String, String> nodes = SOAPHelper.nodesToMap(soap.getChildNodes());
    if (nodes.keySet().size() != 3) {
        fail("Too many keys found: " + nodes.keySet().size() + ". The right key count is 3.");
    }
    if (!nodes.get("param1").equals("value3")) {
        fail("\"param1\" invalid value: " + nodes.get("param1"));
    }
    if (!nodes.get("param2").equals("value2")) {
        fail("\"param2\" invalid value: " + nodes.get("param2"));
    }
    if (!nodes.get("param3").equals("")) {
        fail("\"param3\" invalid value: " + nodes.get("param3"));
    }
}
项目:xrd4j    文件:SOAPHelperTest.java   
/**
 * Unique parameter names with tabs and line breaks.
 */
public void testNodesToMap2() {
    String xml = "<test:request xmlns:test=\"http://test.com\">\n<test:param1>\tvalue1\n</test:param1><test:param2>value2</test:param2>\r\n<test:param3>value3</test:param3></test:request>";
    SOAPElement soap = SOAPHelper.xmlStrToSOAPElement(xml);
    Map<String, String> nodes = SOAPHelper.nodesToMap(soap.getChildNodes());
    if (nodes.keySet().size() != 3) {
        fail("Too many keys found: " + nodes.keySet().size() + ". The right key count is 3.");
    }
    if (!nodes.get("param1").equals("value1")) {
        fail("\"param1\" invalid value: " + nodes.get("param1"));
    }
    if (!nodes.get("param2").equals("value2")) {
        fail("\"param2\" invalid value: " + nodes.get("param2"));
    }
    if (!nodes.get("param3").equals("value3")) {
        fail("\"param3\" invalid value: " + nodes.get("param3"));
    }
}
项目:xrd4j    文件:SOAPHelperTest.java   
/**
 * Multiple parameters with the same name inside en extra wrapper element.
 */
public void testNodesToMap3() {
    String xml = "<request><wrapper><param1>value1</param1><param2>value2</param2><param3>value3</param3></wrapper></request>";
    SOAPElement soap = SOAPHelper.xmlStrToSOAPElement(xml);
    Map<String, String> nodes = SOAPHelper.nodesToMap(soap.getChildNodes());
    if (nodes.keySet().size() != 3) {
        fail("Too many keys found: " + nodes.keySet().size() + ". The right key count is 3.");
    }
    if (!nodes.get("param1").equals("value1")) {
        fail("\"param1\" invalid value: " + nodes.get("param1"));
    }
    if (!nodes.get("param2").equals("value2")) {
        fail("\"param2\" invalid value: " + nodes.get("param2"));
    }
    if (!nodes.get("param3").equals("value3")) {
        fail("\"param3\" invalid value: " + nodes.get("param3"));
    }
}
项目:xrd4j    文件:SOAPHelperTest.java   
/**
 * Multiple parameters with the same name inside two extra wrapper elements
 * with tabs and line breaks.
 */
public void testNodesToMap4() {
    String xml = "<request><wrapperext>\n<wrapper>\n\t<param1>value1</param1>\r\n<param2>value2</param2><param3>value3</param3></wrapper></wrapperext></request>";
    SOAPElement soap = SOAPHelper.xmlStrToSOAPElement(xml);
    Map<String, String> nodes = SOAPHelper.nodesToMap(soap.getChildNodes());
    if (nodes.keySet().size() != 3) {
        fail("Too many keys found: " + nodes.keySet().size() + ". The right key count is 3.");
    }
    if (!nodes.get("param1").equals("value1")) {
        fail("\"param1\" invalid value: " + nodes.get("param1"));
    }
    if (!nodes.get("param2").equals("value2")) {
        fail("\"param2\" invalid value: " + nodes.get("param2"));
    }
    if (!nodes.get("param3").equals("value3")) {
        fail("\"param3\" invalid value: " + nodes.get("param3"));
    }
}
项目:jdk8u-jdk    文件:SaajEmptyNamespaceTest.java   
@Test
public void testAddElementToGlobalNs() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement("global-child", "", "");
    childGlobalNS.addNamespaceDeclaration("", "");
    SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
    Assert.assertEquals(childDefaultNS.getNamespaceURI(), TEST_NS);
}
项目:openjdk-jdk10    文件:Fault1_2Impl.java   
@Override
public Iterator<Locale> getFaultReasonLocales() throws SOAPException {
    // Fault Reason has similar semantics as faultstring
    if (this.faultStringElement == null)
        findReasonElement();
    Iterator eachTextElement =
        this.faultStringElement.getChildElements(textName);
    List<Locale> localeSet = new ArrayList<>();
    while (eachTextElement.hasNext()) {
        SOAPElement textElement = (SOAPElement) eachTextElement.next();
        Locale thisLocale = getLocale(textElement);
        if (thisLocale == null) {
            log.severe("SAAJ0431.ver1_2.xml.lang.missing");
            throw new SOAPExceptionImpl("\"xml:lang\" attribute is not present on the Text element");
        }
        localeSet.add(thisLocale);
    }
    if (localeSet.isEmpty()) {
        log.severe("SAAJ0434.ver1_2.text.element.not.present");
        throw new SOAPExceptionImpl("env:Text elements with mandatory xml:lang attributes must be present inside env:Reason");
    }
    return localeSet.iterator();
}
项目:jdk8u-jdk    文件:SaajEmptyNamespaceTest.java   
@Test
public void testAddElementToGlobalNsQName() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement(new QName("", "global-child"));
    childGlobalNS.addNamespaceDeclaration("", "");
    SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
    Assert.assertEquals(childDefaultNS.getNamespaceURI(),TEST_NS);
}
项目:openjdk-jdk10    文件:SaajEmptyNamespaceTest.java   
@Test
public void testAddElementToNullNsQName() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement(new QName(null, "global-child"));
    childGlobalNS.addNamespaceDeclaration("", "");
    SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
    Assert.assertEquals(childDefaultNS.getNamespaceURI(), TEST_NS);
}
项目:openjdk-jdk10    文件:SaajEmptyNamespaceTest.java   
@Test
public void testAddElementToGlobalNs() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement("global-child", "", "");
    childGlobalNS.addNamespaceDeclaration("", "");
    SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
    Assert.assertEquals(childDefaultNS.getNamespaceURI(), TEST_NS);
}
项目:openjdk-jdk10    文件:SaajEmptyNamespaceTest.java   
@Test
public void testAddElementToNullNs() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement("global-child", "", null);
    childGlobalNS.addNamespaceDeclaration("", null);
    SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
    Assert.assertEquals(TEST_NS, childDefaultNS.getNamespaceURI());
}
项目:openjdk-jdk10    文件:Fault1_2Impl.java   
@Override
public Iterator<String> getFaultReasonTexts() throws SOAPException {
    // Fault Reason has similar semantics as faultstring
    if (this.faultStringElement == null)
        findReasonElement();
    Iterator eachTextElement =
        this.faultStringElement.getChildElements(textName);
    List<String> texts = new ArrayList<>();
    while (eachTextElement.hasNext()) {
        SOAPElement textElement = (SOAPElement) eachTextElement.next();
        Locale thisLocale = getLocale(textElement);
        if (thisLocale == null) {
            log.severe("SAAJ0431.ver1_2.xml.lang.missing");
            throw new SOAPExceptionImpl("\"xml:lang\" attribute is not present on the Text element");
        }
        texts.add(textElement.getValue());
    }
    if (texts.isEmpty()) {
        log.severe("SAAJ0434.ver1_2.text.element.not.present");
        throw new SOAPExceptionImpl("env:Text must be present inside env:Reason");
    }
    return texts.iterator();
}
项目:openjdk-jdk10    文件:ElementImpl.java   
protected SOAPElement replaceElementWithSOAPElement(
    Element element,
    ElementImpl copy) {

    Iterator<Name> eachAttribute = getAllAttributesFrom(element);
    while (eachAttribute.hasNext()) {
        Name name = eachAttribute.next();
        copy.addAttributeBare(name, getAttributeValueFrom(element, name));
    }

    Iterator<Node> eachChild = getChildElementsFromDOM(element);
    while (eachChild.hasNext()) {
        Node nextChild = eachChild.next();
        copy.insertBefore(nextChild, null);
    }

    Node parent = soapDocument.find(element.getParentNode());
    if (parent != null) {
        parent.replaceChild(copy, element);
    } // XXX else throw an exception?

    return copy;
}
项目:openjdk-jdk10    文件:HeaderImpl.java   
@Override
protected SOAPElement convertToSoapElement(Element element) {
    final org.w3c.dom.Node soapNode = getSoapDocument().findIfPresent(element);
    if (soapNode instanceof SOAPHeaderElement) {
        return (SOAPElement) soapNode;
    } else {
        SOAPHeaderElement headerElement;
        try {
            headerElement =
                createHeaderElement(NameImpl.copyElementName(element));
        } catch (SOAPException e) {
            throw new ClassCastException("Could not convert Element to SOAPHeaderElement: " + e.getMessage());
        }
        return replaceElementWithSOAPElement(
            element,
            (ElementImpl) headerElement);
    }
}
项目:coteafs-services    文件:SoapRequestParser.java   
/**
 * @author wasiq.bhamla
 * @since Aug 26, 2017 4:10:56 PM
 * @param parent
 * @param element
 * @throws SOAPException
 */
private static <T extends SOAPElement> void addNamespaces (final T parent, final RequestElement element)
        throws SOAPException {
    if (!element.namespaces ()
        .isEmpty ()) {
        for (final String prefix : element.namespaces ()
            .keySet ()) {
            final String uri = element.namespaces ()
                .get (prefix);
            parent.addNamespaceDeclaration (prefix, uri);
        }
    }
}
项目:oscm    文件:SOAPSecurityHandler.java   
@Override
public boolean handleMessage(final SOAPMessageContext msgCtx) {

    // Indicator telling us which direction this message is going in
    final Boolean outInd = (Boolean) msgCtx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

    // Handler must only add security headers to outbound messages
    if (outInd.booleanValue()) {
        try {
            // Get the SOAP Envelope
            final SOAPEnvelope envelope = msgCtx.getMessage().getSOAPPart().getEnvelope();

            // Header may or may not exist yet
            SOAPHeader header = envelope.getHeader();
            if (header == null)
                header = envelope.addHeader();

            // Add WSS Usertoken Element Tree 
            final SOAPElement security = header.addChildElement("Security", "wsse",
                    "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
            final SOAPElement userToken = security.addChildElement("UsernameToken", "wsse");
            userToken.addChildElement("Username", "wsse").addTextNode(userId);
            userToken.addChildElement("Password", "wsse").addAttribute(new QName("Type"), "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText").addTextNode(password);

        } catch (final Exception e) {
            e.printStackTrace();
            return false;
        }
    }
    return true;
}
项目:openjdk-jdk10    文件:BodyImpl.java   
@Override
public void setParentElement(SOAPElement element) throws SOAPException {

    if (!(element instanceof SOAPEnvelope)) {
        log.severe("SAAJ0111.impl.body.parent.must.be.envelope");
        throw new SOAPException("Parent of SOAPBody has to be a SOAPEnvelope");
    }
    super.setParentElement(element);
}
项目:openjdk-jdk10    文件:Fault1_2Impl.java   
@Override
public String getFaultNode() {
    SOAPElement faultNode = findAndConvertChildElement(getFaultNodeName());
    if (faultNode == null) {
        return null;
    }
    return faultNode.getValue();
}
项目:openjdk-jdk10    文件:ElementImpl.java   
@Override
public SOAPElement addAttribute(QName qname, String value)
    throws SOAPException {
    addAttributeBare(qname, value);
    if (!"".equals(qname.getNamespaceURI())) {
        ensureNamespaceIsDeclared(qname.getPrefix(), qname.getNamespaceURI());
    }
    return this;
}
项目:onvifjava    文件:CameraDiscovery.java   
private byte[] createProbeXML() throws SOAPException, IOException {
    MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
    SOAPMessage message = messageFactory.createMessage();
    SOAPPart part = message.getSOAPPart();
    SOAPEnvelope envelope = part.getEnvelope();
    envelope.addNamespaceDeclaration("wsa", "http://schemas.xmlsoap.org/ws/2004/08/addressing");
    envelope.addNamespaceDeclaration("tns", "http://schemas.xmlsoap.org/ws/2005/04/discovery");
    envelope.addNamespaceDeclaration("nns", "http://www.onvif.org/ver10/network/wsdl");
    QName action = envelope.createQName("Action", "wsa");
    QName mid = envelope.createQName("MessageID", "wsa");
    QName to = envelope.createQName("To", "wsa");
    QName probe = envelope.createQName("Probe", "tns");
    QName types = envelope.createQName("Types", "tns");
    QName tramsmitter=envelope.createQName("NetworkVideoTransmitter", "nns");
    SOAPHeader header = envelope.getHeader();
    SOAPElement actionEl = header.addChildElement(action);
    actionEl.setTextContent("http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe");
    SOAPElement messIsEl = header.addChildElement(mid);
    messIsEl.setTextContent("urn:uuid:" + UUID.randomUUID().toString());
    SOAPElement toEl = header.addChildElement(to);
    toEl.setTextContent("urn:schemas-xmlsoap-org:ws:2005:04:discovery");
    SOAPBody body = envelope.getBody();
    SOAPElement probeEl = body.addChildElement(probe);
    SOAPElement typesEl=probeEl.addChildElement(types);
    typesEl.setTextContent("nns:NetworkVideoTransmitter");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    message.writeTo(out);
    return out.toByteArray();
}
项目:openjdk-jdk10    文件:FaultElement1_2Impl.java   
@Override
public SOAPElement addAttribute(QName name, String value)
    throws SOAPException {
    if (name.getLocalPart().equals("encodingStyle")
        && name.getNamespaceURI().equals(NameImpl.SOAP12_NAMESPACE)) {
        setEncodingStyle(value);
    }
    return super.addAttribute(name, value);
}
项目:OpenJSharp    文件:Fault1_1Impl.java   
public SOAPElement addChildElement(SOAPElement element)
    throws SOAPException {
    String localName = element.getLocalName();
    if ("Detail".equalsIgnoreCase(localName)) {
        if (hasDetail()) {
            log.severe("SAAJ0305.ver1_2.detail.exists.error");
            throw new SOAPExceptionImpl("Cannot add Detail, Detail already exists");
        }
    }
    return super.addChildElement(element);
}
项目:OpenJSharp    文件:FaultElement1_1Impl.java   
public SOAPElement setElementQName(QName newName) throws SOAPException {
    if (!isStandardFaultElement()) {
        FaultElement1_1Impl copy =
            new FaultElement1_1Impl((SOAPDocumentImpl) getOwnerDocument(), newName);
        return replaceElementWithSOAPElement(this,copy);
    } else {
        return super.setElementQName(newName);
    }
}
项目:OpenJSharp    文件:CDATAImpl.java   
public void setParentElement(SOAPElement parent) throws SOAPException {
    if (parent == null) {
        log.severe("SAAJ0145.impl.no.null.to.parent.elem");
        throw new SOAPException("Cannot pass NULL to setParentElement");
    }
    ((ElementImpl) parent).addNode(this);
}
项目:OpenJSharp    文件:TextImpl.java   
public void setParentElement(SOAPElement parent) throws SOAPException {
    if (parent == null) {
        log.severe("SAAJ0126.impl.cannot.locate.ns");
        throw new SOAPException("Cannot pass NULL to setParentElement");
    }
    ((ElementImpl) parent).addNode(this);
}
项目:OpenJSharp    文件:FaultElementImpl.java   
public SOAPElement setElementQName(QName newName) throws SOAPException {
        log.log(Level.SEVERE,
                "SAAJ0146.impl.invalid.name.change.requested",
                new Object[] {elementQName.getLocalPart(),
                              newName.getLocalPart()});
        throw new SOAPException("Cannot change name for "
                                + elementQName.getLocalPart() + " to "
                                + newName.getLocalPart());
}
项目:OpenJSharp    文件:FaultElement1_2Impl.java   
public SOAPElement setElementQName(QName newName) throws SOAPException {
    if (!isStandardFaultElement()) {
        FaultElement1_2Impl copy =
            new FaultElement1_2Impl((SOAPDocumentImpl) getOwnerDocument(), newName);
        return replaceElementWithSOAPElement(this,copy);
    } else {
        return super.setElementQName(newName);
    }
}
项目:xrd4j    文件:AbstractServiceRequestSerializer.java   
/**
 * Generates SOAP body, including the request element.
 *
 * @param request ServiceRequest to be serialized
 * @throws SOAPException if there's a SOAP error
 * @throws XRd4JException if there's a XRd4J error
 */
private void serializeBody(final ServiceRequest request) throws SOAPException, XRd4JException {
    LOGGER.debug("Generate SOAP body.");
    LOGGER.debug("Use producer namespace \"{}\".", request.getProducer().getNamespaceUrl());
    // Body - Start
    SOAPEnvelope envelope = request.getSoapMessage().getSOAPPart().getEnvelope();
    SOAPBody body = request.getSoapMessage().getSOAPBody();
    Name bodyName;
    boolean hasNamespace = false;

    // Is namespace defined?
    if (request.getProducer().getNamespaceUrl() != null && !request.getProducer().getNamespaceUrl().isEmpty()) {
        bodyName = envelope.createName(request.getProducer().getServiceCode(),
            request.getProducer().getNamespacePrefix(), request.getProducer().getNamespaceUrl());
        hasNamespace = true;
    } else {
        bodyName = envelope.createName(request.getProducer().getServiceCode());
    }

    SOAPBodyElement gltp = body.addBodyElement(bodyName);
    if (request.getRequestData() != null) {
        SOAPElement soapRequest;
        // Check if it is needed to process "request" and "response" wrappers
        if (request.isProcessingWrappers()) {
            LOGGER.debug("Adding \"request\" wrapper to request message.");
            soapRequest = gltp.addChildElement(envelope.createName("request"));
        } else {
            LOGGER.debug("Skipping addition of \"request\" wrapper to request message.");
            soapRequest = gltp;
        }
        LOGGER.trace("Passing processing to subclass implementing \"serializeRequest\" method.");
        // Generate request
        this.serializeRequest(request, soapRequest, envelope);
        // Is namespace defined and should it be added to the request?
        if (hasNamespace && request.isAddNamespaceToRequest()) {
            SOAPHelper.addNamespace(soapRequest, request);
        }
    }
    LOGGER.debug("SOAP body was generated succesfully.");
}
项目:openjdk-jdk10    文件:FaultElement1_2Impl.java   
@Override
public SOAPElement addAttribute(Name name, String value)
    throws SOAPException {
    if (name.getLocalName().equals("encodingStyle")
        && name.getURI().equals(NameImpl.SOAP12_NAMESPACE)) {
        setEncodingStyle(value);
    }
    return super.addAttribute(name, value);
}
项目:xrd4j    文件:AbstractServiceResponseSerializer.java   
/**
 * Generates SOAP body, including the request and response elements.
 *
 * @param response ServiceResponse to be serialized
 * @param soapRequest request's SOAP message object that's used for copying
 * the request element
 * @throws SOAPException if there's a SOAP error
 */
private void serializeBody(final ServiceResponse response, final SOAPMessage soapRequest) throws SOAPException, XRd4JException {
    LOGGER.debug("Generate SOAP body.");
    if (response.isAddNamespaceToServiceResponse() || response.isAddNamespaceToRequest() || response.isAddNamespaceToResponse()) {
        if (response.getProducer().getNamespaceUrl() == null || response.getProducer().getNamespaceUrl().isEmpty()) {
            throw new XRd4JException("Producer namespace URI can't be null or empty.");
        }
        LOGGER.debug("Producer namespace \"{}\".", response.getProducer().getNamespaceUrl());
    }

    // Body - Start
    SOAPEnvelope envelope = response.getSoapMessage().getSOAPPart().getEnvelope();
    SOAPBody body = envelope.getBody();
    Name bodyName;
    if (response.isAddNamespaceToServiceResponse()) {
        LOGGER.debug("Create service response with namespace.");
        bodyName = envelope.createName(response.getProducer().getServiceCode() + "Response",
            response.getProducer().getNamespacePrefix(), response.getProducer().getNamespaceUrl());
    } else {
        LOGGER.debug("Create service response without namespace.");
        bodyName = envelope.createName(response.getProducer().getServiceCode() + "Response");
    }
    SOAPBodyElement gltp = body.addBodyElement(bodyName);
    // Process SOAP body
    SOAPElement soapResponse = processBody(gltp, response, soapRequest, envelope);
    // Process the actual payload
    processBodyContent(soapResponse, response, envelope);
    LOGGER.debug("SOAP body was generated succesfully.");
}
项目:xrd4j    文件:AbstractServiceResponseSerializer.java   
private SOAPElement processBody(final SOAPBodyElement body, final ServiceResponse response,
                                final SOAPMessage soapRequest, final SOAPEnvelope envelope) throws SOAPException {
    SOAPElement soapResponse;
    if (response.isProcessingWrappers()) {
        LOGGER.debug("Adding \"request\" and \"response\" wrappers to response message.");
        // Add request element
        processRequestNode(body, response, soapRequest, envelope);
        // Create response element
        soapResponse = body.addChildElement(envelope.createName("response"));
    } else {
        LOGGER.debug("Skipping addition of \"request\" and \"response\" wrappers to response message.");
        soapResponse = body;
    }
    return soapResponse;
}