List of usage examples for javax.xml.soap SOAPElement addNamespaceDeclaration
public SOAPElement addNamespaceDeclaration(String prefix, String uri) throws SOAPException;
From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java
@Validated @Test/* www . java2 s. com*/ public void testAddChildElementFromLocalNameAndPrefix() throws Exception { SOAPElement element = saajUtil.createSOAPElement(null, "test", null); element.addNamespaceDeclaration("p", "urn:test"); SOAPElement child = element.addChildElement("child", "p"); assertEquals("urn:test", child.getNamespaceURI()); assertEquals("p", child.getPrefix()); assertEquals("child", child.getLocalName()); }
From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java
@Validated @Test//from ww w .j a v a 2s . c o m public void testGetNamespaceURIForPrefixDeclaredOnParent() throws Exception { SOAPElement parent = saajUtil.createSOAPElement("urn:ns", "test", "p"); parent.addNamespaceDeclaration("p", "urn:ns"); SOAPElement child = parent.addChildElement(new QName("child")); assertEquals("urn:ns", child.getNamespaceURI("p")); }
From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java
/** * Test that a call do {@link SOAPElement#addNamespaceDeclaration(String, String)} for a prefix * that is already declared on the same element will replace the existing namespace declaration. * /*from w w w .j a v a 2 s . c o m*/ * @throws SOAPException */ @Validated @Test public void testAddNamespaceDeclarationForExistingPrefix() throws SOAPException { SOAPElement element = saajUtil.createSOAPElement(null, "test", null); element.addNamespaceDeclaration("p", "urn:ns1"); element.addNamespaceDeclaration("p", "urn:ns2"); assertEquals("urn:ns2", element.lookupNamespaceURI("p")); assertNull(element.lookupPrefix("urn:ns1")); assertEquals("p", element.lookupPrefix("urn:ns2")); }
From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java
@Validated @Test/*from w ww .j a v a2s. c om*/ public void testGetNamespaceURIDefault() throws Exception { SOAPElement element = saajUtil.createSOAPElement("urn:ns", "test", null); element.addNamespaceDeclaration("", "urn:ns"); assertEquals("urn:ns", element.getNamespaceURI("")); }
From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java
@Validated @Test/*from w w w . j av a 2 s. c o m*/ public void testAddNamespaceDeclarationDefaultNamespace() throws SOAPException { SOAPElement element = saajUtil.createSOAPElement("urn:test", "test", "p"); element.addNamespaceDeclaration("", "urn:ns"); assertEquals("urn:ns", element.getAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns")); }
From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java
/** * Test that a namespace declaration added using * {@link SOAPElement#addNamespaceDeclaration(String, String)} can be retrieved using * {@link Element#getAttributeNS(String, String)}. * /* ww w .j a va 2 s . co m*/ * @throws SOAPException */ @Validated @Test public void testAddNamespaceDeclarationNonDefaultNamespace() throws SOAPException { SOAPElement element = saajUtil.createSOAPElement("urn:test", "test", "p"); element.addNamespaceDeclaration("ns", "urn:ns"); assertEquals("urn:ns", element.getAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "ns")); }
From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java
@Validated @Test/*from ww w . jav a2 s. c o m*/ public void testCreateQNameWithAddNamespaceDeclaration() throws Exception { SOAPElement element = saajUtil.createSOAPElement("urn:ns", "test", null); element.addNamespaceDeclaration("p", "urn:test"); QName qname = element.createQName("local", "p"); assertEquals("p", qname.getPrefix()); assertEquals("local", qname.getLocalPart()); assertEquals("urn:test", qname.getNamespaceURI()); }
From source file:com.maxl.java.aips2sqlite.AllDown.java
public void downSwissindexXml(String language, String file_refdata_pharma_xml) { boolean disp = false; ProgressBar pb = new ProgressBar(); try {//from www. j av a2 s . com // Start timer long startTime = System.currentTimeMillis(); if (disp) System.out.print("- Downloading Swissindex (" + language + ") file... "); else { pb.init("- Downloading Swissindex (" + language + ") file... "); pb.start(); } SOAPMessage soapRequest = MessageFactory.newInstance().createMessage(); // Setting SOAPAction header line MimeHeaders headers = soapRequest.getMimeHeaders(); headers.addHeader("SOAPAction", "http://swissindex.e-mediat.net/SwissindexPharma_out_V101/DownloadAll"); SOAPPart soapPart = soapRequest.getSOAPPart(); SOAPEnvelope envelope = soapPart.getEnvelope(); SOAPBody soapBody = envelope.getBody(); // Construct SOAP request message SOAPElement soapBodyElement1 = soapBody.addChildElement("pharmacode"); soapBodyElement1.addNamespaceDeclaration("", "http://swissindex.e-mediat.net/SwissindexPharma_out_V101"); soapBodyElement1.addTextNode("DownloadAll"); SOAPElement soapBodyElement2 = soapBody.addChildElement("lang"); soapBodyElement2.addNamespaceDeclaration("", "http://swissindex.e-mediat.net/SwissindexPharma_out_V101"); if (language.equals("DE")) soapBodyElement2.addTextNode("DE"); else if (language.equals("FR")) soapBodyElement2.addTextNode("FR"); else { System.err.println("down_swissindex_xml: wrong language!"); return; } soapRequest.saveChanges(); SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection connection = soapConnectionFactory.createConnection(); String wsURL = "https://swissindex.refdata.ch/Swissindex/Pharma/ws_Pharma_V101.asmx?WSDL"; SOAPMessage soapResponse = connection.call(soapRequest, wsURL); Document doc = soapResponse.getSOAPBody().extractContentAsDocument(); String strBody = getStringFromDoc(doc); String xmlBody = prettyFormat(strBody); // Note: parsing the Document tree and using the removeAttribute function is hopeless! xmlBody = xmlBody.replaceAll("xmlns.*?\".*?\" ", ""); long len = writeToFile(xmlBody, file_refdata_pharma_xml); if (!disp) pb.stopp(); long stopTime = System.currentTimeMillis(); System.out.println("\r- Downloading Swissindex (" + language + ") file... " + len / 1024 + " kB in " + (stopTime - startTime) / 1000.0f + " sec"); connection.close(); } catch (Exception e) { if (!disp) pb.stopp(); System.err.println(" Exception: in 'downSwissindexXml'"); e.printStackTrace(); } }
From source file:com.maxl.java.aips2sqlite.AllDown.java
public void downRefdataPharmaXml(String file_refdata_pharma_xml) { boolean disp = false; ProgressBar pb = new ProgressBar(); try {//from www . j a va 2s.c o m // Start timer long startTime = System.currentTimeMillis(); if (disp) System.out.print("- Downloading Refdatabase pharma file... "); else { pb.init("- Downloading Refdatabase pharma file... "); pb.start(); } // Create soaprequest SOAPMessage soapRequest = MessageFactory.newInstance().createMessage(); // Set SOAPAction header line MimeHeaders headers = soapRequest.getMimeHeaders(); headers.addHeader("SOAPAction", "http://refdatabase.refdata.ch/Pharma/Download"); // Set SOAP main request part SOAPPart soapPart = soapRequest.getSOAPPart(); SOAPEnvelope envelope = soapPart.getEnvelope(); SOAPBody soapBody = envelope.getBody(); // Construct SOAP request message SOAPElement soapBodyElement1 = soapBody.addChildElement("DownloadArticleInput"); soapBodyElement1.addNamespaceDeclaration("", "http://refdatabase.refdata.ch/"); SOAPElement soapBodyElement2 = soapBodyElement1.addChildElement("ATYPE"); soapBodyElement2.addNamespaceDeclaration("", "http://refdatabase.refdata.ch/Article_in"); soapBodyElement2.addTextNode("ALL"); soapRequest.saveChanges(); // If needed print out soapRequest in a pretty format // System.out.println(prettyFormatSoapXml(soapRequest)); // Create connection to SOAP server SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection connection = soapConnectionFactory.createConnection(); // wsURL contains service end point String wsURL = "http://refdatabase.refdata.ch/Service/Article.asmx?WSDL"; SOAPMessage soapResponse = connection.call(soapRequest, wsURL); // Extract response Document doc = soapResponse.getSOAPBody().extractContentAsDocument(); String strBody = getStringFromDoc(doc); String xmlBody = prettyFormat(strBody); // Note: parsing the Document tree and using the removeAttribute function is hopeless! xmlBody = xmlBody.replaceAll("xmlns.*?\".*?\" ", ""); long len = writeToFile(xmlBody, file_refdata_pharma_xml); if (!disp) pb.stopp(); long stopTime = System.currentTimeMillis(); System.out.println("\r- Downloading Refdata pharma file... " + len / 1024 + " kB in " + (stopTime - startTime) / 1000.0f + " sec"); connection.close(); } catch (Exception e) { if (!disp) pb.stopp(); System.err.println(" Exception: in 'downRefdataPharmaXml'"); e.printStackTrace(); } }
From source file:com.maxl.java.aips2sqlite.AllDown.java
public void downRefdataPartnerXml(String file_refdata_partner_xml) { boolean disp = false; ProgressBar pb = new ProgressBar(); try {//from w w w . java 2 s .com // Start timer long startTime = System.currentTimeMillis(); if (disp) System.out.print("- Downloading Refdata partner file... "); else { pb.init("- Downloading Refdata partner file... "); pb.start(); } // Create soaprequest SOAPMessage soapRequest = MessageFactory.newInstance().createMessage(); // Set SOAPAction header line MimeHeaders headers = soapRequest.getMimeHeaders(); headers.addHeader("SOAPAction", "http://refdatabase.refdata.ch/Download"); // Set SOAP main request part SOAPPart soapPart = soapRequest.getSOAPPart(); SOAPEnvelope envelope = soapPart.getEnvelope(); SOAPBody soapBody = envelope.getBody(); // Construct SOAP request message SOAPElement soapBodyElement1 = soapBody.addChildElement("DownloadPartnerInput"); soapBodyElement1.addNamespaceDeclaration("", "http://refdatabase.refdata.ch/"); SOAPElement soapBodyElement2 = soapBodyElement1.addChildElement("PTYPE"); soapBodyElement2.addNamespaceDeclaration("", "http://refdatabase.refdata.ch/Partner_in"); soapBodyElement2.addTextNode("ALL"); soapRequest.saveChanges(); // If needed print out soapRequest in a pretty format // System.out.println(prettyFormatSoapXml(soapRequest)); // Create connection to SOAP server SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection connection = soapConnectionFactory.createConnection(); // wsURL contains service end point String wsURL = "http://refdatabase.refdata.ch/Service/Partner.asmx?WSDL"; SOAPMessage soapResponse = connection.call(soapRequest, wsURL); // Extract response Document doc = soapResponse.getSOAPBody().extractContentAsDocument(); String strBody = getStringFromDoc(doc); String xmlBody = prettyFormat(strBody); // Note: parsing the Document tree and using the removeAttribute function is hopeless! xmlBody = xmlBody.replaceAll("xmlns.*?\".*?\" ", ""); long len = writeToFile(xmlBody, file_refdata_partner_xml); if (!disp) pb.stopp(); long stopTime = System.currentTimeMillis(); System.out.println("\r- Downloading Refdata partner file... " + len / 1024 + " kB in " + (stopTime - startTime) / 1000.0f + " sec"); connection.close(); } catch (Exception e) { if (!disp) pb.stopp(); System.err.println(" Exception: in 'downRefdataPartnerXml'"); e.printStackTrace(); } }