How to use locale method of com.consol.citrus.ws.message.SoapFault class

Best Citrus code snippet using com.consol.citrus.ws.message.SoapFault.locale

Source:WebServiceEndpoint.java Github

copy

Full Screen

1/*2 * Copyright 2006-2010 the original author or authors.3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package com.consol.citrus.ws.server;17import com.consol.citrus.endpoint.EndpointAdapter;18import com.consol.citrus.endpoint.adapter.EmptyResponseEndpointAdapter;19import com.consol.citrus.exceptions.CitrusRuntimeException;20import com.consol.citrus.message.*;21import com.consol.citrus.ws.client.WebServiceEndpointConfiguration;22import com.consol.citrus.ws.message.*;23import com.consol.citrus.ws.message.SoapFault;24import org.slf4j.Logger;25import org.slf4j.LoggerFactory;26import org.springframework.util.*;27import org.springframework.ws.context.MessageContext;28import org.springframework.ws.mime.MimeMessage;29import org.springframework.ws.server.endpoint.MessageEndpoint;30import org.springframework.ws.soap.*;31import org.springframework.ws.soap.SoapMessage;32import org.springframework.ws.soap.axiom.AxiomSoapMessage;33import org.springframework.ws.soap.saaj.SaajSoapMessage;34import org.springframework.ws.soap.server.endpoint.SoapFaultDefinition;35import org.springframework.ws.soap.soap11.Soap11Body;36import org.springframework.ws.soap.soap12.Soap12Body;37import org.springframework.ws.soap.soap12.Soap12Fault;38import org.springframework.ws.transport.WebServiceConnection;39import org.springframework.ws.transport.context.TransportContextHolder;40import org.springframework.ws.transport.http.HttpServletConnection;41import org.springframework.xml.namespace.QNameUtils;42import org.springframework.xml.transform.StringSource;43import org.w3c.dom.Document;44import javax.xml.namespace.QName;45import javax.xml.soap.MimeHeaders;46import javax.xml.transform.*;47import javax.xml.transform.dom.DOMSource;48import java.io.IOException;49import java.util.List;50import java.util.Map.Entry;51/**52 * SpringWS {@link MessageEndpoint} implementation. Endpoint will delegate message processing to 53 * a {@link EndpointAdapter} implementation.54 * 55 * @author Christoph Deppisch56 */57public class WebServiceEndpoint implements MessageEndpoint {58 /** EndpointAdapter handling incoming requests and providing proper responses */59 private EndpointAdapter endpointAdapter = new EmptyResponseEndpointAdapter();60 61 /** Default namespace for all SOAP header entries */62 private String defaultNamespaceUri;63 64 /** Default prefix for all SOAP header entries */65 private String defaultPrefix = "";66 /** Endpoint configuration */67 private WebServiceEndpointConfiguration endpointConfiguration = new WebServiceEndpointConfiguration();68 /** Logger */69 private static Logger log = LoggerFactory.getLogger(WebServiceEndpoint.class);70 71 /** JMS headers begin with this prefix */72 private static final String DEFAULT_JMS_HEADER_PREFIX = "JMS";73 /**74 * @see org.springframework.ws.server.endpoint.MessageEndpoint#invoke(org.springframework.ws.context.MessageContext)75 * @throws CitrusRuntimeException76 */77 public void invoke(final MessageContext messageContext) throws Exception {78 Assert.notNull(messageContext.getRequest(), "Request must not be null - unable to send message");79 80 Message requestMessage = endpointConfiguration.getMessageConverter().convertInbound(messageContext.getRequest(), messageContext, endpointConfiguration);81 if (log.isDebugEnabled()) {82 log.debug("Received SOAP request:\n" + requestMessage.toString());83 }84 85 //delegate request processing to endpoint adapter86 Message replyMessage = endpointAdapter.handleMessage(requestMessage);87 88 if (simulateHttpStatusCode(replyMessage)) {89 return;90 }91 92 if (replyMessage != null && replyMessage.getPayload() != null) {93 if (log.isDebugEnabled()) {94 log.debug("Sending SOAP response:\n" + replyMessage.toString());95 }96 97 SoapMessage response = (SoapMessage) messageContext.getResponse();98 99 //add soap fault or normal soap body to response100 if (replyMessage instanceof SoapFault) {101 addSoapFault(response, (SoapFault) replyMessage);102 } else {103 addSoapBody(response, replyMessage);104 }105 addSoapAttachments(response, replyMessage);106 addSoapHeaders(response, replyMessage);107 addMimeHeaders(response, replyMessage);108 } else {109 if (log.isDebugEnabled()) {110 log.debug("No reply message from endpoint adapter '" + endpointAdapter + "'");111 }112 log.warn("No SOAP response for calling client");113 }114 }115 private void addSoapAttachments(MimeMessage response, Message replyMessage) {116 if (replyMessage instanceof com.consol.citrus.ws.message.SoapMessage) {117 List<SoapAttachment> soapAttachments = ((com.consol.citrus.ws.message.SoapMessage) replyMessage).getAttachments();118 soapAttachments.stream()119 .filter(soapAttachment -> !soapAttachment.isMtomInline())120 .forEach(soapAttachment -> {121 String contentId = soapAttachment.getContentId();122 if (!contentId.startsWith("<")) {123 contentId = "<" + contentId + ">";124 }125 response.addAttachment(contentId, soapAttachment.getDataHandler());126 });127 }128 }129 /**130 * If Http status code is set on reply message headers simulate Http error with status code.131 * No SOAP response is sent back in this case.132 * @param replyMessage133 * @return134 * @throws IOException 135 */136 private boolean simulateHttpStatusCode(Message replyMessage) throws IOException {137 if (replyMessage == null || CollectionUtils.isEmpty(replyMessage.getHeaders())) {138 return false;139 }140 141 for (Entry<String, Object> headerEntry : replyMessage.getHeaders().entrySet()) {142 if (headerEntry.getKey().equalsIgnoreCase(SoapMessageHeaders.HTTP_STATUS_CODE)) {143 WebServiceConnection connection = TransportContextHolder.getTransportContext().getConnection();144 145 int statusCode = Integer.valueOf(headerEntry.getValue().toString());146 if (connection instanceof HttpServletConnection) {147 ((HttpServletConnection)connection).setFault(false);148 ((HttpServletConnection)connection).getHttpServletResponse().setStatus(statusCode);149 return true;150 } else {151 log.warn("Unable to set custom Http status code on connection other than HttpServletConnection (" + connection.getClass().getName() + ")");152 }153 }154 }155 156 return false;157 }158 /**159 * Adds mime headers outside of SOAP envelope. Header entries that go to this header section 160 * must have internal http header prefix defined in {@link com.consol.citrus.ws.message.SoapMessageHeaders}.161 * @param response the soap response message.162 * @param replyMessage the internal reply message.163 */164 private void addMimeHeaders(SoapMessage response, Message replyMessage) {165 for (Entry<String, Object> headerEntry : replyMessage.getHeaders().entrySet()) {166 if (headerEntry.getKey().toLowerCase().startsWith(SoapMessageHeaders.HTTP_PREFIX)) {167 String headerName = headerEntry.getKey().substring(SoapMessageHeaders.HTTP_PREFIX.length());168 169 if (response instanceof SaajSoapMessage) {170 SaajSoapMessage saajSoapMessage = (SaajSoapMessage) response;171 MimeHeaders headers = saajSoapMessage.getSaajMessage().getMimeHeaders();172 headers.setHeader(headerName, headerEntry.getValue().toString());173 } else if (response instanceof AxiomSoapMessage) {174 log.warn("Unable to set mime message header '" + headerName + "' on AxiomSoapMessage - unsupported");175 } else {176 log.warn("Unsupported SOAP message implementation - unable to set mime message header '" + headerName + "'");177 }178 }179 }180 }181 /**182 * Add message payload as SOAP body element to the SOAP response.183 * @param response184 * @param replyMessage185 */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.308 * @param localPart309 * @return310 */311 private QName getDefaultQName(String localPart) {312 if (StringUtils.hasText(defaultNamespaceUri)) {313 return new QName(defaultNamespaceUri, localPart, defaultPrefix);314 } else {315 throw new SoapHeaderException("Failed to add SOAP header '" + localPart + "', " +316 "because neither valid QName nor default namespace-uri is set!");317 }318 }319 /**320 * Gets the endpoint adapter.321 * @return322 */323 public EndpointAdapter getEndpointAdapter() {324 return endpointAdapter;325 }326 /**327 * Set the endpoint adapter.328 * @param endpointAdapter the endpointAdapter to set329 */330 public void setEndpointAdapter(EndpointAdapter endpointAdapter) {331 this.endpointAdapter = endpointAdapter;332 }333 /**334 * Gets the default header namespace uri.335 * @return336 */337 public String getDefaultNamespaceUri() {338 return defaultNamespaceUri;339 }340 /**341 * Set the default namespace used in SOAP response headers.342 * @param defaultNamespaceUri the defaultNamespaceUri to set343 */344 public void setDefaultNamespaceUri(String defaultNamespaceUri) {345 this.defaultNamespaceUri = defaultNamespaceUri;346 }347 /**348 * Gets the default header prefix.349 * @return350 */351 public String getDefaultPrefix() {352 return defaultPrefix;353 }354 /**355 * Set the default namespace prefix used in SOAP response headers.356 * @param defaultPrefix the defaultPrefix to set357 */358 public void setDefaultPrefix(String defaultPrefix) {359 this.defaultPrefix = defaultPrefix;360 }361 /**362 * Gets the endpoint configuration.363 * @return364 */365 public WebServiceEndpointConfiguration getEndpointConfiguration() {366 return endpointConfiguration;367 }368 /**369 * Sets the endpoint configuration.370 * @param endpointConfiguration371 */372 public void setEndpointConfiguration(WebServiceEndpointConfiguration endpointConfiguration) {373 this.endpointConfiguration = endpointConfiguration;374 }375}...

Full Screen

Full Screen

Source:SendSoapFaultActionTest.java Github

copy

Full Screen

1/*2 * Copyright 2006-2010 the original author or authors.3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package com.consol.citrus.ws.actions;17import com.consol.citrus.context.TestContext;18import com.consol.citrus.endpoint.Endpoint;19import com.consol.citrus.endpoint.EndpointConfiguration;20import com.consol.citrus.exceptions.CitrusRuntimeException;21import com.consol.citrus.message.Message;22import com.consol.citrus.messaging.Producer;23import com.consol.citrus.testng.AbstractTestNGUnitTest;24import com.consol.citrus.ws.message.SoapFault;25import org.mockito.Mockito;26import org.mockito.invocation.InvocationOnMock;27import org.mockito.stubbing.Answer;28import org.testng.Assert;29import org.testng.annotations.Test;30import java.util.Locale;31import static org.mockito.Mockito.*;32/**33 * @author Christoph Deppisch34 */35public class SendSoapFaultActionTest extends AbstractTestNGUnitTest {36 private Endpoint endpoint = Mockito.mock(Endpoint.class);37 private Producer producer = Mockito.mock(Producer.class);38 private EndpointConfiguration endpointConfiguration = Mockito.mock(EndpointConfiguration.class);39 @Test40 @SuppressWarnings("rawtypes")41 public void testSendSoapFault() {42 SendSoapFaultAction sendSoapFaultAction = new SendSoapFaultAction();43 sendSoapFaultAction.setEndpoint(endpoint);44 45 sendSoapFaultAction.setFaultCode("{http://citrusframework.org}ws:TEC-1000");46 sendSoapFaultAction.setFaultString("Internal server error");47 48 reset(endpoint, producer, endpointConfiguration);49 when(endpoint.createProducer()).thenReturn(producer);50 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);51 when(endpointConfiguration.getTimeout()).thenReturn(5000L);52 doAnswer(new Answer() {53 @Override54 public Object answer(InvocationOnMock invocation) throws Throwable {55 Message sentMessage = (Message)invocation.getArguments()[0];56 Assert.assertTrue(sentMessage instanceof SoapFault);57 SoapFault soapFault = (SoapFault) sentMessage;58 Assert.assertEquals(soapFault.getFaultCode(), "{http://citrusframework.org}ws:TEC-1000");59 Assert.assertEquals(soapFault.getFaultString(), "Internal server error");60 Assert.assertEquals(soapFault.getLocale(), Locale.ENGLISH);61 return null;62 }63 }).when(producer).send(any(Message.class), any(TestContext.class));64 when(endpoint.getActor()).thenReturn(null);65 66 sendSoapFaultAction.execute(context);67 }68 69 @Test70 @SuppressWarnings("rawtypes")71 public void testSendSoapFaultWithActor() {72 SendSoapFaultAction sendSoapFaultAction = new SendSoapFaultAction();73 sendSoapFaultAction.setEndpoint(endpoint);74 75 sendSoapFaultAction.setFaultCode("{http://citrusframework.org}ws:TEC-1000");76 sendSoapFaultAction.setFaultString("Internal server error");77 sendSoapFaultAction.setFaultActor("SERVER");78 79 reset(endpoint, producer, endpointConfiguration);80 when(endpoint.createProducer()).thenReturn(producer);81 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);82 when(endpointConfiguration.getTimeout()).thenReturn(5000L);83 doAnswer(new Answer() {84 @Override85 public Object answer(InvocationOnMock invocation) throws Throwable {86 Message sentMessage = (Message)invocation.getArguments()[0];87 Assert.assertTrue(sentMessage instanceof SoapFault);88 SoapFault soapFault = (SoapFault) sentMessage;89 Assert.assertEquals(soapFault.getFaultCode(), "{http://citrusframework.org}ws:TEC-1000");90 Assert.assertEquals(soapFault.getFaultString(), "Internal server error");91 Assert.assertEquals(soapFault.getLocale(), Locale.ENGLISH);92 Assert.assertEquals(soapFault.getFaultActor(), "SERVER");93 return null;94 }95 }).when(producer).send(any(Message.class), any(TestContext.class));96 when(endpoint.getActor()).thenReturn(null);97 98 sendSoapFaultAction.execute(context);99 }100 101 @Test102 @SuppressWarnings("rawtypes")103 public void testSendSoapFaultMissingFaultString() {104 SendSoapFaultAction sendSoapFaultAction = new SendSoapFaultAction();105 sendSoapFaultAction.setEndpoint(endpoint);106 107 sendSoapFaultAction.setFaultCode("{http://citrusframework.org}ws:TEC-1000");108 109 reset(endpoint, producer, endpointConfiguration);110 when(endpoint.createProducer()).thenReturn(producer);111 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);112 when(endpointConfiguration.getTimeout()).thenReturn(5000L);113 doAnswer(new Answer() {114 @Override115 public Object answer(InvocationOnMock invocation) throws Throwable {116 Message sentMessage = (Message)invocation.getArguments()[0];117 Assert.assertTrue(sentMessage instanceof SoapFault);118 SoapFault soapFault = (SoapFault) sentMessage;119 Assert.assertEquals(soapFault.getFaultCode(), "{http://citrusframework.org}ws:TEC-1000");120 Assert.assertNull(soapFault.getFaultString());121 Assert.assertEquals(soapFault.getLocale(), Locale.ENGLISH);122 return null;123 }124 }).when(producer).send(any(Message.class), any(TestContext.class));125 when(endpoint.getActor()).thenReturn(null);126 127 sendSoapFaultAction.execute(context);128 }129 130 @Test131 @SuppressWarnings("rawtypes")132 public void testSendSoapFaultWithVariableSupport() {133 SendSoapFaultAction sendSoapFaultAction = new SendSoapFaultAction();134 sendSoapFaultAction.setEndpoint(endpoint);135 136 sendSoapFaultAction.setFaultCode("citrus:concat('{http://citrusframework.org}ws:', ${faultCode})");137 sendSoapFaultAction.setFaultString("${faultString}");138 139 context.setVariable("faultCode", "TEC-1000");140 context.setVariable("faultString", "Internal server error");141 reset(endpoint, producer, endpointConfiguration);142 when(endpoint.createProducer()).thenReturn(producer);143 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);144 when(endpointConfiguration.getTimeout()).thenReturn(5000L);145 doAnswer(new Answer() {146 @Override147 public Object answer(InvocationOnMock invocation) throws Throwable {148 Message sentMessage = (Message)invocation.getArguments()[0];149 Assert.assertTrue(sentMessage instanceof SoapFault);150 SoapFault soapFault = (SoapFault) sentMessage;151 Assert.assertEquals(soapFault.getFaultCode(), "{http://citrusframework.org}ws:TEC-1000");152 Assert.assertEquals(soapFault.getFaultString(), "Internal server error");153 Assert.assertEquals(soapFault.getLocale(), Locale.ENGLISH);154 return null;155 }156 }).when(producer).send(any(Message.class), any(TestContext.class));157 when(endpoint.getActor()).thenReturn(null);158 159 sendSoapFaultAction.execute(context);160 }161 162 @Test163 public void testSendSoapFaultMissingFaultCode() {164 SendSoapFaultAction sendSoapFaultAction = new SendSoapFaultAction();165 sendSoapFaultAction.setEndpoint(endpoint);166 167 reset(endpoint, producer, endpointConfiguration);168 when(endpoint.createProducer()).thenReturn(producer);169 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);170 when(endpointConfiguration.getTimeout()).thenReturn(5000L);171 when(endpoint.getActor()).thenReturn(null);172 173 try {174 sendSoapFaultAction.execute(context);175 } catch(CitrusRuntimeException e) {176 Assert.assertEquals(e.getLocalizedMessage(), "Missing fault code definition for SOAP fault generation. Please specify a proper SOAP fault code!");177 return;178 }179 180 Assert.fail("Missing " + CitrusRuntimeException.class + " because of missing SOAP fault code");181 }182}...

Full Screen

Full Screen

locale

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.dsl.junit.JUnit4CitrusTestDesigner;4import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;5import com.consol.citrus.message.MessageType;6import org.springframework.http.HttpStatus;7import org.testng.annotations.Test;8import java.util.Locale;9import static com.consol.citrus.actions.EchoAction.Builder.echo;10public class SoapFaultLocaleTest extends TestNGCitrusTestDesigner {11 public void soapFaultLocaleTest() {12 variable("locale", "fr");13 soap()14 .client("soapClient")15 .send()16 .soapFault()17 .faultString("Test error")18 .faultActor("citrus:concat('Citrus:', citrus:randomNumber(3))")19 .locale("${locale}");20 soap()21 .client("soapClient")22 .receive()23 .fault()24 .faultString("Test error")25 .faultActor("citrus:concat('Citrus:', citrus:randomNumber(3))")26 .locale("${locale}");27 }28}29package com.consol.citrus.samples;30import com.consol.citrus.annotations.CitrusTest;31import com.consol.citrus.dsl.junit.JUnit4CitrusTestDesigner;32import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;33import com.consol.citrus.message.MessageType;34import org.springframework.http.HttpStatus;35import org.testng.annotations.Test;36import java.util.Locale;37import static com.consol.citrus.actions.EchoAction.Builder.echo;38public class SoapFaultLocaleTest extends JUnit4CitrusTestDesigner {39 public void soapFaultLocaleTest() {40 variable("locale", "fr");41 soap()42 .client("soapClient")43 .send()44 .soapFault()45 .faultString("Test

Full Screen

Full Screen

locale

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import com.consol.citrus.dsl.endpoint.CitrusEndpoints;3import com.consol.citrus.dsl.runner.TestRunner;4import com.consol.citrus.dsl.runner.TestRunnerSupport;5import com.consol.citrus.http.client.HttpClient;6import com.consol.citrus.message.MessageType;7import com.consol.citrus.ws.message.SoapFault;8import org.testng.annotations.Test;9import java.util.Locale;10public class TestRunnerSample_3 extends TestRunnerSupport {11 .http()12 .client()13 .build();14 public void testSoapFault() {15 run(new TestRunner() {16 public void execute() {17 soap(soapClient)18 .send()19 .soapAction("getQuote")20 "<tickerSymbol>citrus:randomNumber(4)</tickerSymbol>" +21 "</GetQuote>");22 soap(soapClient)23 .receive()24 .fault(SoapFault.clientFault("Client.Error", "Unknown symbol"))25 .locale(Locale.ENGLISH);26 }27 });28 }29}30package com.consol.citrus.samples;31import com.consol.citrus.dsl.endpoint.CitrusEndpoints;32import com.consol.citrus.dsl.runner.TestRunner;33import com.consol.citrus.dsl.runner.TestRunnerSupport;34import com.consol.citrus.http.client.HttpClient;35import com.consol.citrus.message.MessageType;36import com.consol.citrus.ws.message.SoapFault;37import org.testng.annotations.Test;38import java.util.Locale;39public class TestRunnerSample_4 extends TestRunnerSupport {40 .http()41 .client()42 .build();43 public void testSoapFault() {44 run(new TestRunner() {45 public void execute() {46 soap(soapClient)47 .send()48 .soapAction("getQuote")

Full Screen

Full Screen

locale

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.dsl.junit.JUnit4CitrusTestDesigner;4import com.consol.citrus.ws.client.WebServiceClient;5import com.consol.citrus.ws.message.SoapFault;6import org.springframework.beans.factory.annotation.Autowired;7import org.springframework.core.io.ClassPathResource;8import org.springframework.http.HttpStatus;9import org.springframework.ws.soap.SoapFaultDetail;10import org.springframework.ws.soap.SoapFaultDetailElement;11import org.springframework.ws.soap.SoapFaultDetailElementName;12import org.springframework.ws.soap.SoapFaultDetailException;13import org.springframework.ws.soap.SoapFaultDetailSource;14import org.springframework.ws.soap.SoapFaultException;15import org.springframework.ws.soap.SoapFaultReason;16import org.springframework.ws.soap.SoapFaultSubcode;17import org.springframework.ws.soap.SoapVersion;18import org.springframework.ws.soap.client.SoapFaultClientException;19import org.springframework.ws.soap.client.SoapFaultClientExceptionTranslator;20import org.springframework.ws.soap.client.SoapFaultClientExceptionTranslatorFactory;21import org.springframework.ws.soap.client.SoapFaultClientExceptionUtils;22import org.springframework.ws.soap.client.SoapFaultClientExceptionUtils.SoapFaultClientExceptionTranslatorFactoryImpl;23import org.springframework.ws.soap.client.SoapFaultClientExceptionUtils.SoapFaultClientExceptionTranslatorImpl;24import org.springframework.ws.soap.client.SoapFaultClientExceptionUtils.SoapFaultClientExceptionTranslatorImpl.SoapFaultClientExceptionTranslatorFactoryImpl;25import org.springframework.ws.soap.client.SoapFaultClientExceptionUtils.SoapFaultClientExceptionTranslatorImpl.SoapFaultClientExceptionTranslatorFactoryImpl.SoapFaultClientExceptionTranslatorImpl;26import org.springframework.ws.soap.client.SoapFaultClientExceptionUtils.SoapFaultClientExceptionTranslatorImpl.SoapFaultClientExceptionTranslatorFactoryImpl.SoapFaultClientExceptionTranslatorImpl.SoapFaultClientExceptionTranslatorImpl;27import org.springframework.ws.soap.client.SoapFaultClientExceptionUtils.SoapFaultClientExceptionTranslatorImpl.SoapFaultClientExceptionTranslatorFactoryImpl.SoapFaultClientExceptionTranslatorImpl.SoapFaultClientExceptionTranslatorImpl.SoapFaultClientExceptionTranslatorImpl;28import org.springframework.ws.soap.client.SoapFaultClientExceptionUtils.SoapFaultClientExceptionTranslatorImpl.SoapFaultClientExceptionTranslatorFactoryImpl.SoapFaultClientExceptionTranslatorImpl.SoapFaultClientExceptionTranslatorImpl.SoapFaultClientExceptionTranslatorImpl.So

Full Screen

Full Screen

locale

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ws.message;2import org.springframework.ws.soap.SoapBody;3import org.springframework.ws.soap.SoapFault;4import org.springframework.ws.soap.SoapMessage;5import org.springframework.ws.soap.SoapVersion;6import org.springframework.ws.soap.client.SoapFaultClientException;7import org.springframework.ws.soap.saaj.SaajSoapMessage;8import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;9import javax.xml.namespace.QName;10import javax.xml.soap.MessageFactory;11import javax.xml.soap.SOAPBody;12import javax.xml.soap.SOAPElement;13import javax.xml.soap.SOAPException;14import javax.xml.soap.SOAPFactory;15import javax.xml.soap.SOAPFault;16import java.util.Locale;17public class SoapFaultTest {18 public static void main(String[] args) throws Exception {19 MessageFactory messageFactory = MessageFactory.newInstance();20 SOAPFault fault = messageFactory.createMessage().getSOAPBody().addFault();21 fault.setFaultString("Hello world!", Locale.ENGLISH);22 fault.setFaultString("Hallo Welt!", Locale.GERMAN);23 fault.setFaultString("Bonjour le monde!", Locale.FRENCH);24 SOAPFactory soapFactory = SOAPFactory.newInstance();25 SOAPElement detailElement = fault.addDetail();26 errorElement.addTextNode("This is an error message!");27 SoapFault soapFault = new SoapFault(fault);28 System.out.println("Fault code: " + soapFault.getFaultCode());29 System.out.println("Fault string: " + soapFault.getFaultString());30 System.out.println("Fault detail: " + soapFault.getFaultDetail());31 SaajSoapMessageFactory messageFactory2 = new SaajSoapMessageFactory();32 messageFactory2.afterPropertiesSet();33 SaajSoapMessage soapMessage = (SaajSoapMessage) messageFactory2.createWebServiceMessage();34 SoapBody soapBody = soapMessage.getSoapBody();35 soapBody.addFault(soapFault.getFaultCode(), soapFault.getFaultString(), soapFault.getFaultDetail());

Full Screen

Full Screen

locale

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus;2import com.consol.citrus.context.TestContext;3import com.consol.citrus.dsl.design.TestDesigner;4import com.consol.citrus.dsl.design.TestDesignerBeforeTestSupport;5import com.consol.citrus.ws.client.WebServiceClient;6import com.consol.citrus.ws.message.SoapFault;7import org.springframework.beans.factory.annotation.Autowired;8import org.springframework.context.annotation.Bean;9import org.springframework.context.annotation.Configuration;10import org.springframework.ws.soap.SoapFaultDetail;11import org.springframework.ws.soap.SoapFaultDetailElement;12import javax.xml.namespace.QName;13public class Sample3 {14 public static class Config {15 public WebServiceClient webServiceClient() {16 return new WebServiceClient();17 }18 }19 private WebServiceClient webServiceClient;20 private TestContext context;21 private TestDesignerBeforeTestSupport designer;22 public void test() {23 designer.echo("This is a test");24 designer.send(webServiceClient)25 .header("Operation", "sayHello")26 .header("citrus_soap_action", "sayHello")27 .header("citrus_http_method", "POST")28 .header("citrus_message_id", "1234567890")29 .header("citrus_http_version", "HTTP/1.1")30 .header("citrus_http_request_path", "/services/helloWorld")31 .header("citrus_http_query_params", "param1=value1&

Full Screen

Full Screen

locale

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;3import org.testng.annotations.Test;4public class 3 extends TestNGCitrusTestDesigner {5 public void 3() {6 echo("This is a sample test");7 soap().client(soapClient)8 .send()9 .header("Content-Type", "text/xml;charset=UTF-8")10 soap().client(soapClient)11 .receive()12 .header("Content-Type", "text/xml;charset=UTF-8");13 soap().client(soapClient)14 .send()

Full Screen

Full Screen

locale

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ws.message;2import org.testng.Assert;3import org.testng.annotations.Test;4import com.consol.citrus.exceptions.CitrusRuntimeException;5import com.consol.citrus.message.DefaultMessage;6import com.consol.citrus.testng.AbstractTestNGUnitTest;7import com.consol.citrus.ws.message.SoapFault;8public class SoapFaultTest extends AbstractTestNGUnitTest {9 public void testSoapFault() {10 SoapFault soapFault = new SoapFault("faultCode", "faultString", "faultActor", "faultDetail");11 Assert.assertEquals(soapFault.getFaultCode(), "faultCode");12 Assert.assertEquals(soapFault.getFaultString(), "faultString");13 Assert.assertEquals(soapFault.getFaultActor(), "faultActor");14 Assert.assertEquals(soapFault.getFaultDetail(), "faultDetail");15 }16 public void testSoapFaultWithFaultDetail() {17 SoapFault soapFault = new SoapFault("faultCode", "faultString", "faultActor", new DefaultMessage("faultDetail"));18 Assert.assertEquals(soapFault.getFaultCode(), "faultCode");19 Assert.assertEquals(soapFault.getFaultString(), "faultString");20 Assert.assertEquals(soapFault.getFaultActor(), "faultActor");21 Assert.assertEquals(soapFault.getFaultDetail(), "faultDetail");22 }23 public void testSoapFaultWithMessage() {24 Assert.assertEquals(soapFault.getFaultCode(), "soap:Server");25 Assert.assertEquals(soapFault.getFaultString(), "Internal Server Error");26 Assert.assertEquals(soapFault.getFaultDetail(),

Full Screen

Full Screen

locale

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import com.consol.citrus.dsl.design.TestDesigner;3import com.consol.citrus.dsl.design.TestDesignerBefore;4import org.springframework.context.annotation.Bean;5import org.springframework.context.annotation.Configuration;6public class 3 implements TestDesignerBefore {7 public TestDesigner 3(TestDesigner designer) {8 designer.soap()9 .client("soapClient")10 .send()11 .fault()12 .faultString("faultString")13 .faultActor("faultActor")14 .detailEntry("detail1", "value1")15 .detailEntry("detail2", "value2");16 designer.soap()17 .client("soapClient")18 .receive()19 .fault()20 .faultString("faultString")21 .faultActor("faultActor")22 .detailEntry("detail1", "value1")23 .detailEntry("detail2", "value2");24 return designer;25 }26}27package com.consol.citrus.samples;28import com.consol.citrus.dsl.design.TestDesigner;29import com.consol.citrus.dsl.design.TestDesignerBefore;30import org.springframework.context.annotation.Bean;31import org.springframework.context.annotation.Configuration;32public class 4 implements TestDesignerBefore {33 public TestDesigner 4(TestDesigner designer) {34 designer.soap()35 .client("soapClient")36 .send()37 .fault()38 .faultString("faultString")39 .faultActor("faultActor")40 .detailEntry("detail1", "value1")41 .detailEntry("detail2", "value2");42 designer.soap()43 .client("soapClient")44 .receive()45 .fault()46 .faultString("faultString")47 .faultActor("faultActor")48 .detailEntry("detail1", "value1")

Full Screen

Full Screen

locale

Using AI Code Generation

copy

Full Screen

1public void sample() {2 SoapFault soapFault = new SoapFault();3 soapFault.setFaultString("faultString");4 soapFault.setFaultCode("faultCode");5 soapFault.setFaultActor("faultActor");6 soapFault.setLocale(Locale.US);7 soapFault.addFaultDetail("faultDetail", "faultDetailValue");8 soapFault.addFaultDetail("faultDetail2", "faultDetailValue2");9 soapFault.addFaultDetail("faultDetail3", "faultDetailValue3");10 soapFault.addFaultDetail("faultDetail4", "faultDetailValue4");11 soapFault.addFaultDetail("faultDetail5", "faultDetailValue5");12 soapFault.addFaultDetail("faultDetail6", "faultDetailValue6");13 soapFault.addFaultDetail("faultDetail7", "faultDetailValue7");14 soapFault.addFaultDetail("faultDetail8", "faultDetailValue8");15 soapFault.addFaultDetail("faultDetail9", "faultDetailValue9");16 soapFault.addFaultDetail("faultDetail10", "faultDetailValue10");17 soapFault.addFaultDetail("faultDetail11", "faultDetailValue11");18 soapFault.addFaultDetail("faultDetail12", "faultDetailValue12");19 soapFault.addFaultDetail("faultDetail13", "faultDetailValue13");20 soapFault.addFaultDetail("faultDetail14", "faultDetailValue14");21 soapFault.addFaultDetail("faultDetail15", "faultDetailValue15");22 soapFault.addFaultDetail("faultDetail16", "faultDetailValue16");23 soapFault.addFaultDetail("faultDetail17", "faultDetailValue17");24 soapFault.addFaultDetail("faultDetail18", "faultDetailValue18");25 soapFault.addFaultDetail("faultDetail19", "faultDetailValue19");26 soapFault.addFaultDetail("faultDetail20", "faultDetailValue20");27 soapFault.addFaultDetail("faultDetail21", "faultDetailValue21");28 soapFault.addFaultDetail("faultDetail22", "faultDetailValue22");29 soapFault.addFaultDetail("faultDetail23", "faultDetailValue23");30 soapFault.addFaultDetail("faultDetail24", "faultDetailValue24");31 soapFault.addFaultDetail("faultDetail25", "faultDetailValue25");32 soapFault.addFaultDetail("faultDetail26", "faultDetailValue26");

Full Screen

Full Screen

locale

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import org.testng.annotations.Test;3import com.consol.citrus.annotations.CitrusTest;4import com.consol.citrus.testng.CitrusParameters;5import com.consol.citrus.ws.message.SoapFault;6public class CitrusLocaleMethodTest extends AbstractTestNGCitrusTest {7 @CitrusParameters("runner")8 public void CitrusLocaleMethodTest(ITestContext context) {9 description("This is a test to use locale method of SoapFault class");10 variable("locale", "en");11 variable("faultCode", "soap:Client");12 variable("faultString", "Client Error");13 soap().client(soapClient)14 .send()15 .fault()16 .locale("${locale}")17 .faultCode("${faultCode}")18 .faultString("${faultString}");19 soap().client(soapClient)20 .receive()21 .fault()22 .locale("${locale}")23 .faultCode("${faultCode}")24 .faultString("${faultString}");25 }26}27package com.consol.citrus.samples;28import org.testng.annotations.Test;29import com.consol.citrus.annotations.CitrusTest;30import com.consol.citrus.testng.CitrusParameters;31import com.consol.citrus.ws.message.SoapFault;32public class CitrusLocaleMethodTest extends AbstractTestNGCitrusTest {33 @CitrusParameters("runner")34 public void CitrusLocaleMethodTest(ITestContext context) {35 description("This is a test to use locale method of SoapFault class");36 variable("locale", "en");37 variable("faultCode", "soap:Client");38 variable("faultString", "Client Error");39 soap().client(soapClient)40 .send()41 .fault()42 .locale("${

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.

Run Citrus automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful