How to use getPayloadAsSource method of com.consol.citrus.ws.server.WebServiceEndpoint class

Best Citrus code snippet using com.consol.citrus.ws.server.WebServiceEndpoint.getPayloadAsSource

Source:WebServiceEndpoint.java Github

copy

Full Screen

...185 */186 private void addSoapBody(SoapMessage response, Message replyMessage) throws TransformerException {187 if (!(replyMessage.getPayload() instanceof String) || 188 StringUtils.hasText(replyMessage.getPayload(String.class))) {189 Source responseSource = getPayloadAsSource(replyMessage.getPayload());190 191 TransformerFactory transformerFactory = TransformerFactory.newInstance();192 Transformer transformer = transformerFactory.newTransformer();193 194 transformer.transform(responseSource, response.getPayloadResult());195 }196 }197 198 /**199 * Translates message headers to SOAP headers in response.200 * @param response201 * @param replyMessage202 */203 private void addSoapHeaders(SoapMessage response, Message replyMessage) throws TransformerException {204 for (Entry<String, Object> headerEntry : replyMessage.getHeaders().entrySet()) {205 if (MessageHeaderUtils.isSpringInternalHeader(headerEntry.getKey()) ||206 headerEntry.getKey().startsWith(DEFAULT_JMS_HEADER_PREFIX)) {207 continue;208 }209 if (headerEntry.getKey().equalsIgnoreCase(SoapMessageHeaders.SOAP_ACTION)) {210 response.setSoapAction(headerEntry.getValue().toString());211 } else if (!headerEntry.getKey().startsWith(MessageHeaders.PREFIX)) {212 SoapHeaderElement headerElement;213 if (QNameUtils.validateQName(headerEntry.getKey())) {214 QName qname = QNameUtils.parseQNameString(headerEntry.getKey());215 if (StringUtils.hasText(qname.getNamespaceURI())) {216 headerElement = response.getSoapHeader().addHeaderElement(qname);217 } else {218 headerElement = response.getSoapHeader().addHeaderElement(getDefaultQName(headerEntry.getKey()));219 }220 } else {221 throw new SoapHeaderException("Failed to add SOAP header '" + headerEntry.getKey() + "', " +222 "because of invalid QName");223 }224 headerElement.setText(headerEntry.getValue().toString());225 }226 }227 for (String headerData : replyMessage.getHeaderData()) {228 TransformerFactory transformerFactory = TransformerFactory.newInstance();229 Transformer transformer = transformerFactory.newTransformer();230 transformer.transform(new StringSource(headerData),231 response.getSoapHeader().getResult());232 }233 }234 /**235 * Adds a SOAP fault to the SOAP response body. The SOAP fault is declared236 * as QName string in the response message's header (see {@link com.consol.citrus.ws.message.SoapMessageHeaders})237 * 238 * @param response239 * @param replyMessage240 */241 private void addSoapFault(SoapMessage response, SoapFault replyMessage) throws TransformerException {242 SoapBody soapBody = response.getSoapBody();243 org.springframework.ws.soap.SoapFault soapFault;244 245 if (SoapFaultDefinition.SERVER.equals(replyMessage.getFaultCodeQName()) ||246 SoapFaultDefinition.RECEIVER.equals(replyMessage.getFaultCodeQName())) {247 soapFault = soapBody.addServerOrReceiverFault(replyMessage.getFaultString(),248 replyMessage.getLocale());249 } else if (SoapFaultDefinition.CLIENT.equals(replyMessage.getFaultCodeQName()) ||250 SoapFaultDefinition.SENDER.equals(replyMessage.getFaultCodeQName())) {251 soapFault = soapBody.addClientOrSenderFault(replyMessage.getFaultString(),252 replyMessage.getLocale());253 } else if (soapBody instanceof Soap11Body) {254 Soap11Body soap11Body = (Soap11Body) soapBody;255 soapFault = soap11Body.addFault(replyMessage.getFaultCodeQName(),256 replyMessage.getFaultString(),257 replyMessage.getLocale());258 } else if (soapBody instanceof Soap12Body) {259 Soap12Body soap12Body = (Soap12Body) soapBody;260 Soap12Fault soap12Fault = soap12Body.addServerOrReceiverFault(replyMessage.getFaultString(),261 replyMessage.getLocale());262 soap12Fault.addFaultSubcode(replyMessage.getFaultCodeQName());263 264 soapFault = soap12Fault;265 } else {266 throw new CitrusRuntimeException("Found unsupported SOAP implementation. Use SOAP 1.1 or SOAP 1.2.");267 }268 269 if (replyMessage.getFaultActor() != null) {270 soapFault.setFaultActorOrRole(replyMessage.getFaultActor());271 }272 273 List<String> soapFaultDetails = replyMessage.getFaultDetails();274 if (!soapFaultDetails.isEmpty()) {275 TransformerFactory transformerFactory = TransformerFactory.newInstance();276 Transformer transformer = transformerFactory.newTransformer();277 278 transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");279 280 SoapFaultDetail faultDetail = soapFault.addFaultDetail();281 for (int i = 0; i < soapFaultDetails.size(); i++) {282 transformer.transform(new StringSource(soapFaultDetails.get(i)), faultDetail.getResult());283 }284 }285 }286 287 /**288 * Get the message payload object as {@link Source}, supported payload types are289 * {@link Source}, {@link Document} and {@link String}.290 * @param replyPayload payload object291 * @return {@link Source} representation of the payload292 */293 private Source getPayloadAsSource(Object replyPayload) {294 if (replyPayload instanceof Source) {295 return (Source) replyPayload;296 } else if (replyPayload instanceof Document) {297 return new DOMSource((Document) replyPayload);298 } else if (replyPayload instanceof String) {299 return new StringSource((String) replyPayload);300 } else {301 throw new CitrusRuntimeException("Unknown type for reply message payload (" + replyPayload.getClass().getName() + ") " +302 "Supported types are " + "'" + Source.class.getName() + "', " + "'" + Document.class.getName() + "'" + 303 ", or '" + String.class.getName() + "'");304 }305 }306 /**307 * Get the default QName from local part....

Full Screen

Full Screen

getPayloadAsSource

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.dsl.builder.HttpServerResponseActionBuilder2import com.consol.citrus.dsl.builder.HttpServerRequestActionBuilder3import com.consol.citrus.dsl.builder.HttpServerActionBuilder4import com.consol.citrus.dsl.builder.HttpClientActionBuilder5import com.consol.citrus.dsl.runner.TestRunner6import com.consol.citrus.dsl.runner.TestRunner7import com.consol.citrus.dsl.builder.HttpClientRequestActionBuilder8import com.consol.citrus.dsl.builder.HttpClientResponseActionBuilder9import com.consol.citrus.dsl.builder.HttpClientActionBuilder10import com.consol.citrus.dsl.builder.HttpServerActionBuilder11import com.consol.citrus.dsl.builder.HttpServerRequestActionBuilder12import com.consol.citrus.dsl.builder.HttpServerResponseActionBuilder13import com.consol.citrus.dsl.builder.HttpServerActionBuilder14import com.consol.citrus.dsl.builder.HttpServerRequestActionBuilder15import com.consol.citrus.dsl.builder.HttpServerResponseActionBuilder16import com.consol.citrus.dsl.builder.HttpServerActionBuilder17import com.consol.citrus.dsl.builder.HttpServerRequestActionBuilder18import com.consol.citrus.dsl.builder.HttpServerResponseActionBuilder19import com.consol.citrus.dsl.builder.HttpServerActionBuilder20import com.consol.citrus.dsl.builder.HttpServerRequestActionBuilder21import com.consol.citrus.dsl.builder.HttpServerResponseActionBuilder22import com.consol.citrus.dsl.builder.HttpServerActionBuilder23import com.consol.citrus.dsl.builder.HttpServerRequestActionBuilder24import com.consol.citrus.dsl.builder.HttpServerResponseActionBuilder25import com.consol.citrus.dsl.builder.HttpServerActionBuilder26import com.consol.citrus.dsl.builder.HttpServerRequestActionBuilder27import com.consol.citrus.dsl.builder.HttpServerResponseActionBuilder28import com.consol.citrus.dsl.builder.HttpServerActionBuilder29import com.consol.citrus.dsl.builder.HttpServerRequestActionBuilder30import com.consol.citrus.dsl.builder.HttpServerResponseActionBuilder31import com.consol.citrus.dsl.builder.HttpServerActionBuilder32import com.consol.citrus.dsl.builder.HttpServerRequestActionBuilder33import com.consol.cit

Full Screen

Full Screen

getPayloadAsSource

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.dsl.endpoint.CitrusEndpoints;2import com.consol.citrus.dsl.endpoint.CitrusEndpoints.http;3import com.consol.citrus.dsl.runner.TestRunner;4import com.consol.citrus.dsl.runner.TestRunnerSupport;5import com.consol.citrus.http.message.HttpMessage;6import com.consol.citrus.ws.message.SoapMessage;7import com.consol.citrus.ws.server.WebServiceEndpoint;8import org.springframework.beans.factory.annotation.Autowired;9import org.springframework.context.annotation.Bean;10import org.springframework.context.annotation.Configuration;11import org.springframework.ws.soap.SoapMessageFactory;12import org.springframework.ws.soap.SoapVersion;13import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;14import org.springframework.xml.transform.StringSource;15import org.w3c.dom.Document;16import org.w3c.dom.Element;17import org.xml.sax.InputSource;18import javax.xml.parsers.DocumentBuilder;19import javax.xml.parsers.DocumentBuilderFactory;20import javax.xml.transform.Transformer;21import javax.xml.transform.TransformerFactory;22import javax.xml.transform.dom.DOMSource;23import javax.xml.transform.stream.StreamResult;24import java.io.ByteArrayInputStream;25import java.io.ByteArrayOutputStream;26import java.io.StringReader;27import java.io.StringWriter;28import java.util.HashMap;29import java.util.Map;30import static com.consol.citrus.actions.SendMessageAction.Builder.send;31import static com.consol.citrus.container.SequenceBeforeTest.Builder.sequential;32import static com.consol.citrus.dsl.builder.BuilderSupport.variable;33import static com.consol.citrus.dsl.builder.BuilderSupport.xpath;34public class WebServiceEndpointConfig {35 private TestRunnerSupport runner;36 public WebServiceEndpoint webServiceEndpoint() {37 .soap()38 .server()39 .autoStart(true)40 .port(8080)41 .build();42 endpoint.createConsumer()43 .endpoint(endpoint)44 .timeout(5000L)45 .messageProcessor(message -> {46 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();47 factory.setNamespaceAware(true);48 DocumentBuilder builder = factory.newDocumentBuilder();49 Document document = builder.parse(new InputSource

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful