本文整理匯總了Java中javax.xml.soap.SOAPEnvelope.addNamespaceDeclaration方法的典型用法代碼示例。如果您正苦於以下問題:Java SOAPEnvelope.addNamespaceDeclaration方法的具體用法?Java SOAPEnvelope.addNamespaceDeclaration怎麽用?Java SOAPEnvelope.addNamespaceDeclaration使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.xml.soap.SOAPEnvelope
的用法示例。
在下文中一共展示了SOAPEnvelope.addNamespaceDeclaration方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createSOAPRequestMessage
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
/**
* 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;
}
示例2: addSoapHeader
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
protected void addSoapHeader(SOAPMessage soapMessage) throws SOAPException, NoSuchAlgorithmException {
onvifDevice.createNonce();
String encrypedPassword = onvifDevice.getEncryptedPassword();
if (encrypedPassword != null && onvifDevice.getUsername() != null) {
SOAPPart sp = soapMessage.getSOAPPart();
SOAPEnvelope se = sp.getEnvelope();
SOAPHeader header = soapMessage.getSOAPHeader();
se.addNamespaceDeclaration("wsse",
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
se.addNamespaceDeclaration("wsu",
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
SOAPElement securityElem = header.addChildElement("Security", "wsse");
// securityElem.setAttribute("SOAP-ENV:mustUnderstand", "1");
SOAPElement usernameTokenElem = securityElem.addChildElement("UsernameToken", "wsse");
SOAPElement usernameElem = usernameTokenElem.addChildElement("Username", "wsse");
usernameElem.setTextContent(onvifDevice.getUsername());
SOAPElement passwordElem = usernameTokenElem.addChildElement("Password", "wsse");
passwordElem.setAttribute("Type",
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest");
passwordElem.setTextContent(encrypedPassword);
SOAPElement nonceElem = usernameTokenElem.addChildElement("Nonce", "wsse");
nonceElem.setAttribute("EncodingType",
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary");
nonceElem.setTextContent(onvifDevice.getEncryptedNonce());
SOAPElement createdElem = usernameTokenElem.addChildElement("Created", "wsu");
createdElem.setTextContent(onvifDevice.getLastUTCTime());
}
}
示例3: create
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
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;
}
示例4: WsDiscoveryS11SOAPMessage
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
/**
* 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);
}
示例5: WsDiscoveryD2005SOAPMessage
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
/**
* 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);
}
示例6: setOutputEncodingStyle
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
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 ) );
}
}
}
}
}
示例7: doWithMessage
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {
callback.doWithMessage(message);
try {
SaajSoapMessage saajMessage = (SaajSoapMessage) message;
SOAPMessage soapmess = saajMessage.getSaajMessage();
SOAPEnvelope env = soapmess.getSOAPPart().getEnvelope();
env.addNamespaceDeclaration("xro", "http://x-road.ee/xsd/x-road.xsd");
Iterator headers = env.getHeader().getChildElements();
while (headers.hasNext()) {
SOAPElement header = (SOAPElement) headers.next();
if (header.getNamespaceURI().equalsIgnoreCase("http://x-rd.net/xsd/xroad.xsd")) {
String localHeaderName = header.getLocalName();
QName qName = new QName("http://x-road.ee/xsd/x-road.xsd", localHeaderName, "xro");
header.setElementQName(qName);
}
}
} catch (SOAPException e) {
throw new RuntimeException(e);
}
}
示例8: testAddDetailsTwice
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
@Validated @Test
public void testAddDetailsTwice() throws Exception {
MessageFactory fac = MessageFactory.newInstance();
//Create the response to the message
SOAPMessage soapMessage = fac.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("cwmp", "http://cwmp.com");
SOAPBody body = envelope.getBody();
body.addFault().addDetail();
try {
body.getFault().addDetail();
fail("Expected Exception did not occur");
} catch (SOAPException e) {
assertTrue(true);
}
}
示例9: testAppendSubCode
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
@Validated @Test
public void testAppendSubCode() throws Exception {
MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPMessage soapMessage = fac.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("cwmp", "http://cwmp.com");
SOAPBody body = envelope.getBody();
SOAPFault soapFault = body.addFault();
QName qname = new QName("http://example.com", "myfault1", "flt1");
soapFault.appendFaultSubcode(qname);
QName qname2 = new QName("http://example2.com", "myfault2", "flt2");
soapFault.appendFaultSubcode(qname2);
QName qname3 = new QName("http://example3.com", "myfault3", "flt3");
soapFault.appendFaultSubcode(qname3);
soapMessage.saveChanges();
Iterator faultSubCodes = soapFault.getFaultSubcodes();
assertNotNull(faultSubCodes);
}
示例10: _testGetFaultReasonTexts
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
public void _testGetFaultReasonTexts() throws Exception {
MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPMessage soapMessage = fac.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("cwmp", "http://cwmp.com");
SOAPBody body = envelope.getBody();
SOAPFault soapFault = body.addFault();
soapFault.addFaultReasonText("myReason", new Locale("en"));
soapFault.addFaultReasonText("de-myReason", new Locale("de"));
soapFault.addFaultReasonText("si-myReason", new Locale("si"));
soapMessage.saveChanges();
Iterator reasonTexts = soapFault.getFaultReasonTexts();
while (reasonTexts.hasNext()) {
String reasonText = (String)reasonTexts.next();
assertNotNull(reasonText);
}
}
示例11: _testGetFaultReasonText
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
public void _testGetFaultReasonText() throws Exception {
MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPMessage soapMessage = fac.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("cwmp", "http://cwmp.com");
SOAPBody body = envelope.getBody();
SOAPFault soapFault = body.addFault();
soapFault.addFaultReasonText("myReason", new Locale("en"));
soapFault.addFaultReasonText("de-myReason", new Locale("de"));
soapFault.addFaultReasonText("si-myReason", new Locale("si"));
soapMessage.saveChanges();
String faultReasonText = soapFault.getFaultReasonText(new Locale("si"));
assertNotNull(faultReasonText);
faultReasonText = soapFault.getFaultReasonText(new Locale("ja"));
assertNull(faultReasonText);
}
示例12: _testGetFaultCodeAsQName
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
public void _testGetFaultCodeAsQName() throws Exception {
//MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
MessageFactory fac = MessageFactory.newInstance();
SOAPMessage soapMessage = fac.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("cwmp", "http://cwmp.com");
SOAPBody body = envelope.getBody();
SOAPFault soapFault = body.addFault();
soapFault.addFaultReasonText("myReason", new Locale("en"));
soapFault.setFaultCode("mycode");
soapMessage.saveChanges();
QName qname = soapFault.getFaultCodeAsQName();
assertNotNull(qname);
}
示例13: createProbeXML
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
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();
}
示例14: createVerifyEmailSOAPRequest
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
/**
* createVerifyEmailSOAPRequest
*
* @param emailToVerify
* email input
* @param licenseKey
* licenseKey input
* @return the SOAP Request message
* @throws Exception
*
* <SOAP-ENV:Envelope xmlns:SOAP-ENV=
* "http://schemas.xmlsoap.org/soap/envelope/" xmlns:example=
* "http://ws.cdyne.com/"> <SOAP-ENV:Header/> <SOAP-ENV:Body>
* <example:VerifyEmail> <example:email>?</example:email>
* <example:LicenseKey>?</example:LicenseKey>
* </example:VerifyEmail> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
*/
private SOAPMessage createVerifyEmailSOAPRequest(String emailToVerify, String licenseKey) throws Exception {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("example", getNamespaceURI());
// SOAP Body
SOAPBody soapBody = envelope.getBody();
SOAPElement soapBodyElem = soapBody.addChildElement("VerifyEmail", "example");
SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("email", "example");
soapBodyElem1.addTextNode(emailToVerify);
SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("LicenseKey", "example");
soapBodyElem2.addTextNode(licenseKey);
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("SOAPAction", getNamespaceURI() + "VerifyEmail");
soapMessage.saveChanges();
ATFHandler.getInstance().getWebServiceAutomation().logSOAPMessage(soapMessage, "Request");
return soapMessage;
}
示例15: create
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
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");
SOAPElement position = soapBodyElem.addChildElement("position", "codecentric");
SOAPElement latitude = position.addChildElement("latitude", "codecentric");
latitude.addTextNode("52.510818");
SOAPElement longitude = position.addChildElement("longitude", "codecentric");
longitude.addTextNode("13.372008");
MimeHeaders headers = message.getMimeHeaders();
headers.addHeader("SOAPAction", "https://www.codecentric.de/receive");
message.saveChanges();
return message;
}