本文整理汇总了Java中javax.xml.soap.SOAPMessage.getSOAPPart方法的典型用法代码示例。如果您正苦于以下问题:Java SOAPMessage.getSOAPPart方法的具体用法?Java SOAPMessage.getSOAPPart怎么用?Java SOAPMessage.getSOAPPart使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.soap.SOAPMessage
的用法示例。
在下文中一共展示了SOAPMessage.getSOAPPart方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addSoapHeader
import javax.xml.soap.SOAPMessage; //导入方法依赖的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());
}
}
示例2: parseSoapResponseForUrls
import javax.xml.soap.SOAPMessage; //导入方法依赖的package包/类
private void parseSoapResponseForUrls(byte[] data) {
// System.out.println(new String(data));
try {
MessageFactory factory= MessageFactory.newInstance(WS_DISCOVERY_SOAP_VERSION);
final MimeHeaders headers = new MimeHeaders();
// headers.addHeader("Content-type", WS_DISCOVERY_CONTENT_TYPE);
SOAPMessage message = factory.createMessage(headers, new ByteArrayInputStream(data));
SOAPPart part=message.getSOAPPart();
SOAPEnvelope env=part.getEnvelope();
SOAPBody body=message.getSOAPBody();
NodeList list=body.getElementsByTagNameNS("http://schemas.xmlsoap.org/ws/2005/04/discovery", "XAddrs");
int items=list.getLength();
if(items<1)return;
for (int i = 0; i < items; i++) {
Node n=list.item(i);
String raw=n.getTextContent();
//may contain several
String []addrArray=raw.split(" ");
for (String string : addrArray) {
URL url=new URL(string);
discovered.add(url);
}
}
} catch (Exception e) {
System.out.println("Parse failed");
e.printStackTrace();
}
}
示例3: createProbeXML
import javax.xml.soap.SOAPMessage; //导入方法依赖的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();
}
示例4: readAsSOAPMessageSax2Dom
import javax.xml.soap.SOAPMessage; //导入方法依赖的package包/类
public SOAPMessage readAsSOAPMessageSax2Dom(final SOAPVersion soapVersion, final Message message) throws SOAPException {
SOAPMessage msg = soapVersion.getMessageFactory().createMessage();
SAX2DOMEx s2d = new SAX2DOMEx(msg.getSOAPPart());
try {
message.writeTo(s2d, XmlUtil.DRACONIAN_ERROR_HANDLER);
} catch (SAXException e) {
throw new SOAPException(e);
}
addAttachmentsToSOAPMessage(msg, message);
if (msg.saveRequired())
msg.saveChanges();
return msg;
}
示例5: deserialize
import javax.xml.soap.SOAPMessage; //导入方法依赖的package包/类
/**
* Deserializes the given SOAPMessage object to ServiceResponse object. If
* service producer's namespace URI is given, then it's used for finding the
* response from the SOAP mesagge's body. Value "*" means that the namespace
* is ignored.
*
* @param message SOAP message to be deserialized
* @param producerNamespaceURI service producer's namespace URI
* @param processingWrappers Indicates if "request" and "response" wrappers
* should be processed
* @return ServiceResponse object that represents the given SOAPMessage
* object; if the operation fails, null is returned
*/
@Override
public final ServiceResponse deserialize(final SOAPMessage message, final String producerNamespaceURI, boolean processingWrappers) {
try {
LOGGER.debug("Deserialize SOAP message. Producer namespace URI \"{}\".", producerNamespaceURI);
SOAPPart mySPart = message.getSOAPPart();
SOAPEnvelope envelope = mySPart.getEnvelope();
// Deserialize header
ServiceResponse response = this.deserializeHeader(envelope.getHeader());
response.setSoapMessage(message);
// Setting "request" and "response" wrappers processing
response.setProcessingWrappers(processingWrappers);
try {
// Deserialize body
this.deserializeBody(response, producerNamespaceURI);
} catch (XRd4JMissingMemberException ex) {
LOGGER.warn(ex.getMessage(), ex);
this.deserializeSOAPFault(response);
}
LOGGER.debug("SOAP message was succesfully deserialized.");
return response;
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
}
return null;
}
示例6: deserialize
import javax.xml.soap.SOAPMessage; //导入方法依赖的package包/类
/**
* Deserializes the given SOAPMessage object to ServiceRequest object. Only
* SOAP header is deserialized. An application specific serializer is needed
* for SOAP body.
*
* @param message SOAP message to be deserialized
* @return ServiceRequest object that represents the given SOAPMessage
* object or null if the operation failed
* @throws SOAPException if there's a SOAP error
* @throws XRd4JException if there's a XRd4J error
*/
@Override
public final ServiceRequest deserialize(final SOAPMessage message) throws XRd4JException, SOAPException {
LOGGER.debug("Deserialize SOAP message.");
SOAPPart mySPart = message.getSOAPPart();
SOAPEnvelope envelope = mySPart.getEnvelope();
// Desearialize header
ServiceRequest request = this.deserializeHeader(envelope.getHeader());
request.setSoapMessage(message);
LOGGER.debug("SOAP message header was succesfully deserialized.");
return request;
}
示例7: testEnvelope
import javax.xml.soap.SOAPMessage; //导入方法依赖的package包/类
public void testEnvelope(String[] args) throws Exception {
String xmlString =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" +
" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n" +
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
" <soapenv:Header>\n" +
" <shw:Hello xmlns:shw=\"http://localhost:8080/axis/services/MessageService\">\n" +
" <shw:Myname>Tony</shw:Myname>\n" +
" </shw:Hello>\n" +
" </soapenv:Header>\n" +
" <soapenv:Body>\n" +
" <shw:process xmlns:shw=\"http://message.samples\">\n" +
" <shw:City>GENT</shw:City>\n" +
" </shw:process>\n" +
" </soapenv:Body>\n" +
"</soapenv:Envelope>";
MessageFactory mf = MessageFactory.newInstance();
SOAPMessage smsg =
mf.createMessage(new MimeHeaders(), new ByteArrayInputStream(xmlString.getBytes()));
SOAPPart sp = smsg.getSOAPPart();
SOAPEnvelope se = (SOAPEnvelope)sp.getEnvelope();
SOAPConnection conn = SOAPConnectionFactory.newInstance().createConnection();
SOAPMessage response = conn.call(smsg, "http://localhost:8080/axis/services/MessageService2");
}
示例8: getStockQuote
import javax.xml.soap.SOAPMessage; //导入方法依赖的package包/类
public String getStockQuote(String tickerSymbol) throws Exception {
SOAPConnectionFactory scFactory = SOAPConnectionFactory.newInstance();
SOAPConnection con = scFactory.createConnection();
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage();
SOAPPart soapPart = message.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPHeader header = envelope.getHeader();
SOAPBody body = envelope.getBody();
header.detachNode();
Name bodyName = envelope.createName("getQuote", "n", "urn:xmethods-delayed-quotes");
SOAPBodyElement gltp = body.addBodyElement(bodyName);
Name name = envelope.createName("symbol");
SOAPElement symbol = gltp.addChildElement(name);
symbol.addTextNode(tickerSymbol);
URLEndpoint endpoint = new URLEndpoint("http://64.124.140.30/soap");
SOAPMessage response = con.call(message, endpoint);
con.close();
SOAPPart sp = response.getSOAPPart();
SOAPEnvelope se = sp.getEnvelope();
SOAPBody sb = se.getBody();
Iterator it = sb.getChildElements();
while (it.hasNext()) {
SOAPBodyElement bodyElement = (SOAPBodyElement) it.next();
Iterator it2 = bodyElement.getChildElements();
while (it2.hasNext()) {
SOAPElement element2 = (SOAPElement) it2.next();
return element2.getValue();
}
}
return null;
}
示例9: echoUsingSAAJ
import javax.xml.soap.SOAPMessage; //导入方法依赖的package包/类
/**
* This method sends a file as an attachment then
* receives it as a return. The returned file is
* compared to the source. Uses SAAJ API.
* @param The filename that is the source to send.
* @return True if sent and compared.
*/
public boolean echoUsingSAAJ(String filename) throws Exception {
String endPointURLString = "http://localhost:" +opts.getPort() + "/axis/services/urn:EchoAttachmentsService";
SOAPConnectionFactory soapConnectionFactory =
javax.xml.soap.SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection =
soapConnectionFactory.createConnection();
MessageFactory messageFactory =
MessageFactory.newInstance();
SOAPMessage soapMessage =
messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope requestEnvelope =
soapPart.getEnvelope();
SOAPBody body = requestEnvelope.getBody();
SOAPBodyElement operation = body.addBodyElement
(requestEnvelope.createName("echo"));
Vector dataHandlersToAdd = new Vector();
dataHandlersToAdd.add(new DataHandler(new FileDataSource(new
File(filename))));
if (dataHandlersToAdd != null) {
ListIterator dataHandlerIterator =
dataHandlersToAdd.listIterator();
while (dataHandlerIterator.hasNext()) {
DataHandler dataHandler = (DataHandler)
dataHandlerIterator.next();
javax.xml.soap.SOAPElement element =
operation.addChildElement(requestEnvelope.createName("source"));
javax.xml.soap.AttachmentPart attachment =
soapMessage.createAttachmentPart(dataHandler);
soapMessage.addAttachmentPart(attachment);
element.addAttribute(requestEnvelope.createName
("href"), "cid:" + attachment.getContentId());
}
}
javax.xml.soap.SOAPMessage returnedSOAPMessage =
soapConnection.call(soapMessage, endPointURLString);
Iterator iterator = returnedSOAPMessage.getAttachments();
if (!iterator.hasNext()) {
//The wrong type of object that what was expected.
System.out.println("Received problem response from server");
throw new AxisFault("", "Received problem response from server", null, null);
}
//Still here, so far so good.
//Now lets brute force compare the source attachment
// to the one we received.
DataHandler rdh = (DataHandler) ((AttachmentPart)iterator.next()).getDataHandler();
//From here we'll just treat the data resource as file.
String receivedfileName = rdh.getName();//Get the filename.
if (receivedfileName == null) {
System.err.println("Could not get the file name.");
throw new AxisFault("", "Could not get the file name.", null, null);
}
System.out.println("Going to compare the files..");
boolean retv = compareFiles(filename, receivedfileName);
java.io.File receivedFile = new java.io.File(receivedfileName);
receivedFile.delete();
return retv;
}
示例10: handleMTOMUploads
import javax.xml.soap.SOAPMessage; //导入方法依赖的package包/类
private void handleMTOMUploads(String sessionID, SOAPMessage requestMessage) throws SOAPException, FileNotFoundException, IOException {
SOAPPart sp = requestMessage.getSOAPPart();
SOAPEnvelope se = sp.getEnvelope();
SOAPBody sb = se.getBody();
handleMTOMUploads(sessionID, sb.getChildElements());
}
示例11: buildOutputData
import javax.xml.soap.SOAPMessage; //导入方法依赖的package包/类
public Object buildOutputData(Context context, Object convertigoResponse) throws Exception {
Engine.logBeans.debug("[WebServiceTranslator] Encoding the SOAP response...");
SOAPMessage responseMessage = null;
String sResponseMessage = "";
String encodingCharSet = "UTF-8";
if (context.requestedObject != null)
encodingCharSet = context.requestedObject.getEncodingCharSet();
if (convertigoResponse instanceof Document) {
Engine.logBeans.debug("[WebServiceTranslator] The Convertigo response is a XML document.");
Document document = Engine.theApp.schemaManager.makeResponse((Document) convertigoResponse);
//MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
MessageFactory messageFactory = MessageFactory.newInstance();
responseMessage = messageFactory.createMessage();
responseMessage.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, encodingCharSet);
SOAPPart sp = responseMessage.getSOAPPart();
SOAPEnvelope se = sp.getEnvelope();
SOAPBody sb = se.getBody();
sb.setEncodingStyle("http://schemas.xmlsoap.org/soap/encoding/");
//se.addNamespaceDeclaration(prefix, targetNameSpace);
se.addNamespaceDeclaration("soapenc", "http://schemas.xmlsoap.org/soap/encoding/");
se.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance");
se.addNamespaceDeclaration("xsd", "http://www.w3.org/2001/XMLSchema");
// Remove header as it not used. Seems that empty headers causes the WS client of Flex 4 to fail
se.getHeader().detachNode();
addSoapElement(context, se, sb, document.getDocumentElement());
sResponseMessage = SOAPUtils.toString(responseMessage, encodingCharSet);
// Correct missing "xmlns" (Bug AXA POC client .NET)
//sResponseMessage = sResponseMessage.replaceAll("<soapenv:Envelope", "<soapenv:Envelope xmlns=\""+targetNameSpace+"\"");
}
else {
Engine.logBeans.debug("[WebServiceTranslator] The Convertigo response is not a XML document.");
sResponseMessage = convertigoResponse.toString();
}
if (Engine.logBeans.isDebugEnabled()) {
Engine.logBeans.debug("[WebServiceTranslator] SOAP response:\n" + sResponseMessage);
}
return responseMessage == null ? sResponseMessage.getBytes(encodingCharSet) : responseMessage;
}