本文整理匯總了Java中javax.xml.soap.SOAPPart類的典型用法代碼示例。如果您正苦於以下問題:Java SOAPPart類的具體用法?Java SOAPPart怎麽用?Java SOAPPart使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SOAPPart類屬於javax.xml.soap包,在下文中一共展示了SOAPPart類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createXPath
import javax.xml.soap.SOAPPart; //導入依賴的package包/類
/**
* 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;
}
示例2: createSOAPRequestMessage
import javax.xml.soap.SOAPPart; //導入依賴的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;
}
示例3: createSimpleSOAPPart
import javax.xml.soap.SOAPPart; //導入依賴的package包/類
private void createSimpleSOAPPart(SOAPMessage message) throws SOAPException {
SOAPPart sPart = message.getSOAPPart();
SOAPEnvelope env = sPart.getEnvelope();
SOAPBody body = env.getBody();
SOAPHeader header = env.getHeader();
header.addHeaderElement(env.createName("Header1",
"pref",
"http://test.apach.org/test"))
.addTextNode("This is header1");
Name ns = env.createName("echo", "swa2", "http://fakeNamespace2.org");
final SOAPBodyElement bodyElement = body.addBodyElement(ns);
Name ns2 = env.createName("something");
final SOAPElement ele1 = bodyElement.addChildElement(ns2);
ele1.addTextNode("This is some text");
Name ns3 = env.createName("ping", "swa3", "http://fakeNamespace3.org");
final SOAPBodyElement bodyElement2 = body.addBodyElement(ns3);
Name ns4 = env.createName("another");
final SOAPElement ele2 = bodyElement2.addChildElement(ns4);
ele2.addTextNode("This is another text");
}
示例4: parseApiVersion_ctmg_1_8
import javax.xml.soap.SOAPPart; //導入依賴的package包/類
@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);
}
示例5: testSendReceiveMessageWithEmptyNSPrefix
import javax.xml.soap.SOAPPart; //導入依賴的package包/類
@Validated @Test
public void testSendReceiveMessageWithEmptyNSPrefix() throws Exception {
MessageFactory mf = MessageFactory.newInstance();
SOAPMessage request = mf.createMessage();
SOAPPart sPart = request.getSOAPPart();
SOAPEnvelope env = sPart.getEnvelope();
SOAPBody body = env.getBody();
//Namespace prefix is empty
body.addBodyElement(new QName("http://fakeNamespace2.org","echo"))
.addTextNode("This is some text");
SOAPConnection sCon = SOAPConnectionFactory.newInstance().createConnection();
SOAPMessage response = sCon.call(request, getAddress());
assertFalse(response.getAttachments().hasNext());
assertEquals(0, response.countAttachments());
String requestStr = printSOAPMessage(request);
String responseStr = printSOAPMessage(response);
assertTrue(responseStr.indexOf("echo") > -1);
sCon.close();
}
示例6: addSoapHeader
import javax.xml.soap.SOAPPart; //導入依賴的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());
}
}
示例7: create
import javax.xml.soap.SOAPPart; //導入依賴的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;
}
示例8: processSOAP
import javax.xml.soap.SOAPPart; //導入依賴的package包/類
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());
}
}
示例9: parseApiVersion_cm_1_8
import javax.xml.soap.SOAPPart; //導入依賴的package包/類
@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);
}
示例10: testProviderMessageNullResponse
import javax.xml.soap.SOAPPart; //導入依賴的package包/類
@Test
@RunAsClient
public void testProviderMessageNullResponse() throws Exception
{
MessageFactory msgFactory = MessageFactory.newInstance();
SOAPMessage reqMsg = msgFactory.createMessage(null, new ByteArrayInputStream(msgStringForNullResponse.getBytes()));
URL epURL = baseURL;
SOAPConnection con = SOAPConnectionFactory.newInstance().createConnection();
SOAPMessage resMsg = con.call(reqMsg, epURL);
if (resMsg != null)
{
SOAPPart soapPart = resMsg.getSOAPPart();
//verify there's either nothing in the reply or at least the response body is empty
if (soapPart != null && soapPart.getEnvelope() != null && soapPart.getEnvelope().getBody() != null)
{
SOAPBody soapBody = soapPart.getEnvelope().getBody();
assertFalse(soapBody.getChildElements().hasNext());
}
}
}
示例11: getDatasources
import javax.xml.soap.SOAPPart; //導入依賴的package包/類
/**
* Return an array of the datasources in the server, could be null
* @return array of datasources
*/
public DataSourceTreeElement[] getDatasources() {
setRequestType("DISCOVER_DATASOURCES");
SOAPMessage response = executeDiscover(new HashMap<String, String>());
SOAPPart soapPart = response.getSOAPPart();
SOAPEnvelope soapEnvelope;
try {
soapEnvelope = soapPart.getEnvelope();
SOAPElement rowSet = getRowsSet(response, soapEnvelope);
List<DataSourceTreeElement> result = new ArrayList<DataSourceTreeElement>();
Name rowElement = soapEnvelope.createName("row", "", ROW_URI);
Iterator<?> rowValuesElement = rowSet.getChildElements(rowElement);
while (rowValuesElement.hasNext())
{
SOAPElement cellElement = (SOAPElement)rowValuesElement.next();
result.add(new DataSourceElement(this, cellElement));
}
return result.toArray(new DataSourceTreeElement[result.size()]);
} catch (SOAPException e) {
e.printStackTrace();
}
return null;
}
示例12: getCatalogList
import javax.xml.soap.SOAPPart; //導入依賴的package包/類
/**
* Return an array of the catalogs in the server for a specific datasource, could be null
* @param datasourceName the name of the datasource
* @return array of catalogs
*/
public DataSourceTreeElement[] getCatalogList(String datasourceName) {
setRequestType("DBSCHEMA_CATALOGS");
HashMap<String, String> param = new HashMap<String, String>();
param.put("DataSourceInfo", datasourceName);
SOAPMessage response = executeDiscover(param);
SOAPPart soapPart = response.getSOAPPart();
SOAPEnvelope soapEnvelope;
try {
soapEnvelope = soapPart.getEnvelope();
SOAPElement rowSet = getRowsSet(response, soapEnvelope);
List<DataSourceTreeElement> result = new ArrayList<DataSourceTreeElement>();
Name rowElement = soapEnvelope.createName("row", "", ROW_URI);
Iterator<?> rowValuesElement = rowSet.getChildElements(rowElement);
while (rowValuesElement.hasNext())
{
SOAPElement cellElement = (SOAPElement)rowValuesElement.next();
result.add(new CatalogElement(this, cellElement, datasourceName));
}
return result.toArray(new DataSourceTreeElement[result.size()]);
} catch (SOAPException e) {
e.printStackTrace();
}
return null;
}
示例13: getCubeList
import javax.xml.soap.SOAPPart; //導入依賴的package包/類
/**
* Return an array of the cubes in the server for a specific datasource and catalog, could be null
* @param datasourceName the name of the datasource
* @param catalogName the name of the catalog
* @return array of cubes
*/
public DataSourceTreeElement[] getCubeList(String datasourceName, String catalogName) {
setRequestType("MDSCHEMA_CUBES");
HashMap<String, String> param = new HashMap<String, String>();
param.put("DataSourceInfo", datasourceName);
param.put("Catalog", catalogName);
SOAPMessage response = executeDiscover(param);
SOAPPart soapPart = response.getSOAPPart();
SOAPEnvelope soapEnvelope;
try {
soapEnvelope = soapPart.getEnvelope();
SOAPElement rowSet = getRowsSet(response, soapEnvelope);
List<DataSourceTreeElement> result = new ArrayList<DataSourceTreeElement>();
Name rowElement = soapEnvelope.createName("row", "", ROW_URI);
Iterator<?> rowValuesElement = rowSet.getChildElements(rowElement);
while (rowValuesElement.hasNext())
{
SOAPElement cellElement = (SOAPElement)rowValuesElement.next();
result.add(new CubeElement(this, cellElement, datasourceName));
}
return result.toArray(new DataSourceTreeElement[result.size()]);
} catch (SOAPException e) {
e.printStackTrace();
}
return null;
}
示例14: substitute
import javax.xml.soap.SOAPPart; //導入依賴的package包/類
/**
* Substitutes all occurences of some given string inside the given {@link WebServiceMessage} with another value.
*
* @param message message to substitute in
* @param from the value to substitute
* @param to the value to substitute with
* @throws TransformerException
*/
public static void substitute(WebServiceMessage message, String from, String to) throws TransformerException {
SaajSoapMessage saajSoapMessage = (SaajSoapMessage) message;
SOAPPart soapPart = saajSoapMessage.getSaajMessage().getSOAPPart();
Source source = new DOMSource(soapPart);
StringResult stringResult = new StringResult();
TransformerFactory.newInstance().newTransformer().transform(source, stringResult);
String content = stringResult.toString().replaceAll(from, to);
try {
soapPart.setContent(new StringSource(content));
} catch (SOAPException e) {
throw new TransformerException(e);
}
}
示例15: invoke
import javax.xml.soap.SOAPPart; //導入依賴的package包/類
/**
* Very simple operation.
* If there are no attachments, an exception is thrown.
* Otherwise the message is echoed.
*/
public SOAPMessage invoke(SOAPMessage soapMessage) {
System.out.println(">> SoapMessageCheckMTOMProvider: Request received.");
int numAttachments = soapMessage.countAttachments();
if (numAttachments == 0) {
System.out.println(">> SoapMessageCheckMTOMProvider: No Attachments.");
throw new WebServiceException("No Attachments are detected");
}
SOAPMessage response = null;
try {
MessageFactory factory = MessageFactory.newInstance();
response = factory.createMessage();
SOAPPart soapPart = response.getSOAPPart();
SOAPBody soapBody = soapPart.getEnvelope().getBody();
soapBody.addChildElement((SOAPBodyElement)
soapMessage.
getSOAPBody().getChildElements().next());
response.addAttachmentPart((AttachmentPart) soapMessage.getAttachments().next());
} catch (SOAPException e) {
throw new WebServiceException(e);
}
System.out.println(">> SoapMessageCheckMTOMProvider: Returning.");
return response; // echo back the same message
}