本文整理汇总了Java中javax.xml.soap.SOAPMessage类的典型用法代码示例。如果您正苦于以下问题:Java SOAPMessage类的具体用法?Java SOAPMessage怎么用?Java SOAPMessage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SOAPMessage类属于javax.xml.soap包,在下文中一共展示了SOAPMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendSoapMessage
import javax.xml.soap.SOAPMessage; //导入依赖的package包/类
private void sendSoapMessage(String filePath) throws SOAPException, NoSuchAlgorithmException, KeyManagementException, IOException, TransformerException {
Map<Object, Object> currentSession = Thucydides.getCurrentSession();
String webServicesEndpointUrl = (String) currentSession.get(WEB_SERVICE_ENDPOINT_URL_KEY);
String webServiceSoapAction = (String) currentSession.get(WEB_SERVICE_SOAP_ACTION_KEY);
SOAPMessage soapRequest = createSOAPMessageFromFile(filePath, webServiceSoapAction);
SOAPMessage rawSoapResponse = callWebServiceMethod(soapRequest, webServicesEndpointUrl);
LOGGER.debug(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>START SOAP REQUEST>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
LOGGER.debug(convertToString(soapRequest));
LOGGER.debug("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<END SOAP REQUEST<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
LOGGER.debug(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>START SOAP RESPONSE>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
LOGGER.debug(convertToString(rawSoapResponse));
LOGGER.debug("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<END SOAP RESPONSE<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
Thucydides.getCurrentSession().put(RESPONSE, rawSoapResponse);
requestResponseDetails(String.format(TABLE_2_COLUMNS, "Actual SOAP Request", "Actual SOAP Response",
convertToString(soapRequest), convertToString(rawSoapResponse)));
}
示例2: createDispatch
import javax.xml.soap.SOAPMessage; //导入依赖的package包/类
/**
* Creates a new {@link Dispatch} stub that connects to the given pipe.
*
* @param portName
* see {@link Service#createDispatch(QName, Class, Service.Mode)}.
* @param owner
* see <a href="#param">common parameters</a>
* @param binding
* see <a href="#param">common parameters</a>
* @param clazz
* Type of the {@link Dispatch} to be created.
* See {@link Service#createDispatch(QName, Class, Service.Mode)}.
* @param mode
* The mode of the dispatch.
* See {@link Service#createDispatch(QName, Class, Service.Mode)}.
* @param next
* see <a href="#param">common parameters</a>
* @param epr
* see <a href="#param">common parameters</a>
* TODO: are these parameters making sense?
*/
@SuppressWarnings("unchecked")
public static <T> Dispatch<T> createDispatch(QName portName,
WSService owner,
WSBinding binding,
Class<T> clazz, Service.Mode mode, Tube next,
@Nullable WSEndpointReference epr) {
if (clazz == SOAPMessage.class) {
return (Dispatch<T>) createSAAJDispatch(portName, owner, binding, mode, next, epr);
} else if (clazz == Source.class) {
return (Dispatch<T>) createSourceDispatch(portName, owner, binding, mode, next, epr);
} else if (clazz == DataSource.class) {
return (Dispatch<T>) createDataSourceDispatch(portName, owner, binding, mode, next, epr);
} else if (clazz == Message.class) {
if(mode==Mode.MESSAGE)
return (Dispatch<T>) createMessageDispatch(portName, owner, binding, next, epr);
else
throw new WebServiceException(mode+" not supported with Dispatch<Message>");
} else if (clazz == Packet.class) {
return (Dispatch<T>) createPacketDispatch(portName, owner, binding, next, epr);
} else
throw new WebServiceException("Unknown class type " + clazz.getName());
}
示例3: test19WithWrappers
import javax.xml.soap.SOAPMessage; //导入依赖的package包/类
/**
* Subsystem level service call. No NS on request. NS prefix on response.
* @throws XRd4JException
* @throws SOAPException
*/
public void test19WithWrappers() 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:securityServer id:objectType=\"SERVER\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode><id:serverCode>server1</id:serverCode></xrd:securityServer><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:securityServer id:objectType=\"SERVER\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode><id:serverCode>server1</id:serverCode></xrd:securityServer><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><xxprod:data>Response data</xxprod:data></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");
SecurityServer securityServer = new SecurityServer("FI", "GOV", "MEMBER1", "server1");
ServiceRequest<String> request = new ServiceRequest<String>(consumer, producer, "1234567890");
request.setSecurityServer(securityServer);
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, String> response = new ServiceResponse<String, String>(request.getConsumer(), request.getProducer(), request.getId());
response.setResponseData("Response data");
request.setProcessingWrappers(true);
ServiceResponseSerializer serializer = new ServiceResponseSerializerImpl();
SOAPMessage msg = serializer.serialize(response, request);
assertEquals(correctResponse, SOAPHelper.toString(msg));
}
示例4: test1
import javax.xml.soap.SOAPMessage; //导入依赖的package包/类
/**
* allowedMethos : member - member level service call.
*
* @throws XRd4JException
* @throws SOAPException
*/
public void test1() throws XRd4JException, SOAPException {
String id = MessageHelper.generateId();
String correctRequest = "<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=\"MEMBER\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode></xrd:client><xrd:service id:objectType=\"SERVICE\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>COM</id:memberClass><id:memberCode>MEMBER2</id:memberCode><id:serviceCode>allowedMethods</id:serviceCode></xrd:service><xrd:userId>user</xrd:userId><xrd:id>" + id + "</xrd:id><xrd:protocolVersion>4.0</xrd:protocolVersion></SOAP-ENV:Header><SOAP-ENV:Body><xrd:allowedMethods/></SOAP-ENV:Body></SOAP-ENV:Envelope>";
ConsumerMember consumer = new ConsumerMember("FI", "GOV", "MEMBER1");
ProducerMember producer = new ProducerMember("FI", "COM", "MEMBER2", "subsystem", Constants.META_SERVICE_ALLOWED_METHODS);
producer.setSubsystemCode(null);
producer.setNamespacePrefix(Constants.NS_XRD_PREFIX);
producer.setNamespaceUrl(Constants.NS_XRD_URL);
ServiceRequest<String> request = new ServiceRequest<String>(consumer, producer, id);
request.setUserId("user");
ServiceRequestSerializer serializer = new DefaultServiceRequestSerializer();
SOAPMessage msg = serializer.serialize(request);
assertEquals(correctRequest, SOAPHelper.toString(msg));
}
示例5: 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());
}
}
示例6: test8
import javax.xml.soap.SOAPMessage; //导入依赖的package包/类
/**
* Member level service call.
*
* @throws XRd4JException
* @throws SOAPException
*/
public void test8() throws XRd4JException, SOAPException {
String correctRequest = "<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=\"MEMBER\"><id:xRoadInstance>FI</id:xRoadInstance><id:memberClass>GOV</id:memberClass><id:memberCode>MEMBER1</id:memberCode></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></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\"><ns1:request><ns1:data>1234567890</ns1:data></ns1:request></ns1:getRandom></SOAP-ENV:Body></SOAP-ENV:Envelope>";
ConsumerMember consumer = new ConsumerMember("FI", "GOV", "MEMBER1");
ProducerMember producer = new ProducerMember("FI", "COM", "MEMBER2", "subsystem", "getRandom");
producer.setNamespacePrefix("ns1");
producer.setNamespaceUrl("http://consumer.x-road.ee");
ServiceRequest<String> request = new ServiceRequest<String>(consumer, producer, "1234567890");
request.setUserId("EE1234567890");
request.setRequestData("1234567890");
ServiceRequestSerializer serializer = new TestRequestSerializer1();
SOAPMessage msg = serializer.serialize(request);
assertEquals(correctRequest, SOAPHelper.toString(msg));
}
示例7: writeResponse
import javax.xml.soap.SOAPMessage; //导入依赖的package包/类
/**
* Writes the given SOAP response to output stream. Sets the necessary HTTP
* headers according to the content of the response.
*
* @param soapResponse SOAP response
* @param response servlet response
*/
private void writeResponse(SOAPMessage soapResponse, HttpServletResponse response) {
PrintWriter out = null;
try {
LOGGER.debug("Send response.");
// SOAPMessage to String
String responseStr = SOAPHelper.toString(soapResponse);
// Set response headers
if (responseStr != null && soapResponse != null && soapResponse.getAttachments().hasNext()) {
// Get MIME boundary from SOAP message
String boundary = AdapterUtils.getMIMEBoundary(responseStr);
response.setContentType(Constants.MULTIPART_RELATED + "; type=\"text/xml\"; boundary=\"" + boundary + "\"; charset=UTF-8");
} else {
response.setContentType(Constants.TEXT_XML + "; charset=UTF-8");
}
LOGGER.debug("Response content type : \"{}\".", response.getContentType());
// Get writer
out = response.getWriter();
// Send response
if (responseStr != null) {
out.println(responseStr);
LOGGER.trace("SOAP response : \"{}\"", responseStr);
} else {
out.println(this.errInternalServerErrStr);
LOGGER.warn("Internal serveri error. Message processing failed.");
LOGGER.trace("SOAP response : \"{}\"", this.errInternalServerErrStr);
}
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
if (out != null) {
out.println(this.errInternalServerErrStr);
}
} finally {
if (out != null) {
out.close();
}
LOGGER.debug("Request was succesfully processed.");
}
}
示例8: writeTo
import javax.xml.soap.SOAPMessage; //导入依赖的package包/类
public void writeTo(SOAPMessage saaj) throws SOAPException {
try {
// TODO what about in-scope namespaces
// Not very efficient consider implementing a stream buffer
// processor that produces a DOM node from the buffer.
TransformerFactory tf = XmlUtil.newTransformerFactory();
Transformer t = tf.newTransformer();
XMLStreamBufferSource source = new XMLStreamBufferSource(_mark);
DOMResult result = new DOMResult();
t.transform(source, result);
Node d = result.getNode();
if(d.getNodeType() == Node.DOCUMENT_NODE)
d = d.getFirstChild();
SOAPHeader header = saaj.getSOAPHeader();
if(header == null)
header = saaj.getSOAPPart().getEnvelope().addHeader();
Node node = header.getOwnerDocument().importNode(d, true);
header.appendChild(node);
} catch (Exception e) {
throw new SOAPException(e);
}
}
示例9: testSOAPNonTechErr2
import javax.xml.soap.SOAPMessage; //导入依赖的package包/类
/**
* Non-technical SOAP error with empty values.
* @throws XRd4JException
* @throws SOAPException
*/
public void testSOAPNonTechErr2() 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>6.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>6.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><faultcode/><faultstring/></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.setProtocolVersion("6.0");
request.setRequestData("Request data");
request.setSoapMessage(SOAPHelper.toSOAP(requestStr));
request.getProducer().setNamespacePrefix("xxprod");
request.getProducer().setNamespaceUrl("http://foobar.x-road.ee/producer");
ServiceResponse<String, String> response = new ServiceResponse<String, String>(request.getConsumer(), request.getProducer(), request.getId());
response.setResponseData("Response data");
ErrorMessage errorMsg = new ErrorMessage("", "");
response.setErrorMessage(errorMsg);
ServiceResponseSerializer serializer = new ServiceResponseSerializerImpl();
SOAPMessage msg = serializer.serialize(response, request);
assertEquals(correctResponse, SOAPHelper.toString(msg));
}
示例10: test5
import javax.xml.soap.SOAPMessage; //导入依赖的package包/类
/**
* Subsystem level service call. Response data in a Map. NS on request.
* NS prefix on response.
* @throws XRd4JException
* @throws SOAPException
*/
public void test5() 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></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\"><ns1:request><ns1:data>Request data</ns1:data></ns1: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></xrd:service><xrd:userId>EE1234567890</xrd:userId><xrd:id>1234567890</xrd:id><xrd:protocolVersion>4.0</xrd:protocolVersion></SOAP-ENV:Header><SOAP-ENV:Body><prod:getRandomResponse xmlns:prod=\"http://foobar.x-road.ee/producer\"><prod:request><prod:data>Request data</prod:data></prod:request><prod:response><prod:field1>Field1</prod:field1><prod:field2>Field2</prod:field2><prod:field3>Field3</prod:field3></prod:response></prod:getRandomResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>";
ConsumerMember consumer = new ConsumerMember("FI", "GOV", "MEMBER1", "subsystem");
ProducerMember producer = new ProducerMember("FI", "COM", "MEMBER2", "subsystem", "getRandom");
ServiceRequest<String> request = new ServiceRequest<String>(consumer, producer, "1234567890");
request.setUserId("EE1234567890");
request.setRequestData("Request data");
request.setSoapMessage(SOAPHelper.toSOAP(requestStr));
request.getProducer().setNamespacePrefix("prod");
request.getProducer().setNamespaceUrl("http://foobar.x-road.ee/producer");
ServiceResponse<String, Map> response = new ServiceResponse<String, Map>(request.getConsumer(), request.getProducer(), request.getId());
Map<String, String> map = new LinkedHashMap<String, String>();
map.put("field1", "Field1");
map.put("field2", "Field2");
map.put("field3", "Field3");
response.setResponseData(map);
ServiceResponseSerializer serializer = new ServiceResponseSerializerImpl1();
SOAPMessage msg = serializer.serialize(response, request);
assertEquals(correctResponse, SOAPHelper.toString(msg));
}
示例11: testSOAPFault3
import javax.xml.soap.SOAPMessage; //导入依赖的package包/类
/**
* SOAP Fault with detail null.
* @throws XRd4JException
* @throws SOAPException
*/
public void testSOAPFault3() 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/\"><SOAP-ENV:Header/><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>Fault code</faultcode><faultstring>Fault string</faultstring><faultactor>Fault actor</faultactor></SOAP-ENV:Fault></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, String> response = new ServiceResponse<String, String>();
response.setResponseData("Response data");
ErrorMessage errorMsg = new ErrorMessage("Fault code", "Fault string", "Fault actor", null);
response.setErrorMessage(errorMsg);
ServiceResponseSerializer serializer = new ServiceResponseSerializerImpl();
SOAPMessage msg = serializer.serialize(response, request);
assertEquals(correctResponse, SOAPHelper.toString(msg));
}
示例12: processRequestNode
import javax.xml.soap.SOAPMessage; //导入依赖的package包/类
private void processRequestNode(final SOAPBodyElement body, final ServiceResponse response,
final SOAPMessage soapRequest, final SOAPEnvelope envelope) throws SOAPException {
boolean requestFound = false;
NodeList list = soapRequest.getSOAPBody().getElementsByTagNameNS("*", response.getProducer().getServiceCode());
if (list.getLength() == 1) {
// Copy request from soapRequest
requestFound = copyRequestNode((Node) list.item(0), body, response);
}
// It was not possible to copy the request element, so we must create it
if (!requestFound) {
SOAPElement temp = body.addChildElement(envelope.createName("request"));
if (response.isAddNamespaceToRequest()) {
LOGGER.debug("Add provider namespace to request element.");
SOAPHelper.addNamespace(temp, response);
}
}
}
示例13: testAddElementToNullNs
import javax.xml.soap.SOAPMessage; //导入依赖的package包/类
@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());
}
示例14: test14
import javax.xml.soap.SOAPMessage; //导入依赖的package包/类
/**
* 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));
}
示例15: test1WithoutWrappers
import javax.xml.soap.SOAPMessage; //导入依赖的package包/类
/**
* Subsystem level service call. No NS on request. NS prefix on response.
* @throws XRd4JException
* @throws SOAPException
*/
public void test1WithoutWrappers() 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\"><data>Request data</data></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:data>Response data</xxprod:data></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, String> response = new ServiceResponse<String, String>(request.getConsumer(), request.getProducer(), request.getId());
response.setResponseData("Response data");
request.setProcessingWrappers(false);
ServiceResponseSerializer serializer = new ServiceResponseSerializerImpl();
SOAPMessage msg = serializer.serialize(response, request);
assertEquals(correctResponse, SOAPHelper.toString(msg));
}