How to use getMarshaller method of com.consol.citrus.jdbc.server.JdbcEndpointConfiguration class

Best Citrus code snippet using com.consol.citrus.jdbc.server.JdbcEndpointConfiguration.getMarshaller

Source:JdbcEndpointAdapterController.java Github

copy

Full Screen

...82 @Override83 public Message handleMessage(Message request) {84 if (request.getPayload() instanceof Operation) {85 StringResult result = new StringResult();86 endpointConfiguration.getMarshaller().marshal(request.getPayload(Operation.class), result);87 request.setPayload(result.toString());88 }89 if (log.isDebugEnabled()) {90 log.debug(String.format("Received request on server: '%s':%n%s",91 endpointConfiguration.getServerConfiguration().getDatabaseName(),92 request.getPayload(String.class)));93 }94 if (request.getPayload(Operation.class) != null) {95 String sqlQuery = Optional.ofNullable(request.getPayload(Operation.class).getExecute())96 .map(Execute::getStatement)97 .map(Execute.Statement::getSql)98 .orElse("");99 if (autoHandleQueryPattern.matcher(sqlQuery).find()) {100 log.debug(String.format("Auto handle query '%s' with positive response", sqlQuery));101 JdbcMessage defaultResponse = JdbcMessage.success().rowsUpdated(0);102 defaultResponse.setHeader(MessageHeaders.MESSAGE_TYPE, MessageType.XML.name());103 return defaultResponse;104 }105 }106 return Optional.ofNullable(delegate.handleMessage(request))107 .orElse(JdbcMessage.success());108 }109 /**110 * Opens the connection with the given properties111 * @param properties The properties to open the connection with112 * @throws JdbcServerException In case that the maximum connections have been reached113 */114 @Override115 public void openConnection(Map<String, String> properties) throws JdbcServerException {116 if (!endpointConfiguration.isAutoConnect()) {117 List<OpenConnection.Property> propertyList = convertToPropertyList(properties);118 handleMessageAndCheckResponse(JdbcMessage.openConnection(propertyList));119 }120 if (connections.get() == endpointConfiguration.getServerConfiguration().getMaxConnections()) {121 throw new JdbcServerException(String.format("Maximum number of connections (%s) reached",122 endpointConfiguration.getServerConfiguration().getMaxConnections()));123 }124 connections.incrementAndGet();125 }126 /**127 * Closes the connection128 * @throws JdbcServerException In case that the connection could not be closed129 */130 @Override131 public void closeConnection() throws JdbcServerException {132 if (!endpointConfiguration.isAutoConnect()) {133 handleMessageAndCheckResponse(JdbcMessage.closeConnection());134 }135 if (connections.decrementAndGet() < 0) {136 connections.set(0);137 }138 }139 /**140 * Creates a prepared statement141 * @param stmt The statement to create142 * @throws JdbcServerException In case that the statement was not successful143 */144 @Override145 public void createPreparedStatement(String stmt) throws JdbcServerException {146 if (!endpointConfiguration.isAutoCreateStatement()) {147 handleMessageAndCheckResponse(JdbcMessage.createPreparedStatement(stmt));148 }149 }150 /**151 * Creates a statement152 * @throws JdbcServerException In case that the statement was not successfully created153 */154 @Override155 public void createStatement() throws JdbcServerException {156 if (!endpointConfiguration.isAutoCreateStatement()) {157 handleMessageAndCheckResponse(JdbcMessage.createStatement());158 }159 }160 /**161 * Executes a given query and returns the mapped result162 * @param query The query to execute163 * @return The DataSet containing the query result164 * @throws JdbcServerException In case that the query was not successful165 */166 @Override167 public DataSet executeQuery(String query) throws JdbcServerException {168 log.info("Received execute query request: " + query);169 Message response = handleMessageAndCheckResponse(JdbcMessage.execute(query));170 return dataSetCreator.createDataSet(response, getMessageType(response));171 }172 /**173 * Executes the given statement174 * @param stmt The statement to be executed175 * @throws JdbcServerException In case that the execution was not successful176 */177 @Override178 public DataSet executeStatement(String stmt) throws JdbcServerException {179 log.info("Received execute statement request: " + stmt);180 Message response = handleMessageAndCheckResponse(JdbcMessage.execute(stmt));181 return dataSetCreator.createDataSet(response, getMessageType(response));182 }183 /**184 * Executes the given update185 * @param updateSql The update statement to be executed186 * @throws JdbcServerException In case that the execution was not successful187 */188 @Override189 public int executeUpdate(String updateSql) throws JdbcServerException {190 log.info("Received execute update request: " + updateSql);191 Message response = handleMessageAndCheckResponse(JdbcMessage.execute(updateSql));192 return Optional.ofNullable(193 response.getHeader(JdbcMessageHeaders.JDBC_ROWS_UPDATED))194 .map(Object::toString).map(Integer::valueOf)195 .orElse(0);196 }197 /**198 * Closes the connection199 * @throws JdbcServerException In case that the connection could not be closed200 */201 @Override202 public void closeStatement() throws JdbcServerException {203 if (!endpointConfiguration.isAutoCreateStatement()) {204 handleMessageAndCheckResponse(JdbcMessage.closeStatement());205 }206 }207 /**208 * Sets the transaction state of the database connection209 * @param transactionState The boolean value whether the server is in transaction state.210 */211 @Override212 public void setTransactionState(boolean transactionState) {213 if (log.isDebugEnabled()) {214 log.debug(String.format("Received transaction state change: '%s':%n%s",215 endpointConfiguration.getServerConfiguration().getDatabaseName(),216 String.valueOf(transactionState)));217 }218 this.transactionState = transactionState;219 if(!endpointConfiguration.isAutoTransactionHandling() && transactionState){220 handleMessageAndCheckResponse(JdbcMessage.startTransaction());221 }222 }223 /**224 * Returns the transaction state225 * @return The transaction state of the connection226 */227 @Override228 public boolean getTransactionState() {229 return this.transactionState;230 }231 /**232 * Commits the transaction statements233 */234 @Override235 public void commitStatements() {236 if (log.isDebugEnabled()) {237 log.debug(String.format("Received transaction commit: '%s':%n",238 endpointConfiguration.getServerConfiguration().getDatabaseName()));239 }240 if(!endpointConfiguration.isAutoTransactionHandling()){241 handleMessageAndCheckResponse(JdbcMessage.commitTransaction());242 }243 }244 /**245 * Performs a rollback on the current transaction246 */247 @Override248 public void rollbackStatements() {249 if (log.isDebugEnabled()) {250 log.debug(String.format("Received transaction rollback: '%s':%n",251 endpointConfiguration.getServerConfiguration().getDatabaseName()));252 }253 if(!endpointConfiguration.isAutoTransactionHandling()){254 handleMessageAndCheckResponse(JdbcMessage.rollbackTransaction());255 }256 }257 /**258 * Creates a callable statement259 */260 @Override261 public void createCallableStatement(String sql) {262 if (!endpointConfiguration.isAutoCreateStatement()) {263 handleMessageAndCheckResponse(JdbcMessage.createCallableStatement(sql));264 }265 }266 /**267 * Determines the MessageType of the given response268 * @param response The response to get the message type from269 * @return The MessageType of the response270 */271 private MessageType getMessageType(Message response) {272 String messageTypeString = (String) response.getHeader(MessageHeaders.MESSAGE_TYPE);273 if (MessageType.knows(messageTypeString)){274 return MessageType.valueOf(messageTypeString.toUpperCase());275 }276 return null;277 }278 /**279 * Converts a property map propertyKey -> propertyValue to a list of OpenConnection.Properties280 * @param properties The map to convert281 * @return A list of Properties282 */283 private List<OpenConnection.Property> convertToPropertyList(Map<String, String> properties) {284 return properties.entrySet()285 .stream()286 .map(this::convertToProperty)287 .sorted(Comparator.comparingInt(OpenConnection.Property::hashCode))288 .collect(Collectors.toList());289 }290 /**291 * Converts a Map entry into a OpenConnection.Property292 * @param entry The entry to convert293 * @return the OpenConnection.Property representation294 */295 private OpenConnection.Property convertToProperty(Map.Entry<String, String> entry) {296 OpenConnection.Property property = new OpenConnection.Property();297 property.setName(entry.getKey());298 property.setValue(entry.getValue());299 return property;300 }301 /**302 * Handle request message and check response is successful.303 * @param request The request message to handle304 * @return The response Message305 * @throws JdbcServerException Thrown when the response has some exception header.306 */307 private Message handleMessageAndCheckResponse(Message request) throws JdbcServerException {308 Message response = handleMessage(request);309 checkSuccess(response);310 return response;311 }312 /**313 * Check that response is not having an exception message.314 * @param response The response message to check315 * @throws JdbcServerException In case the message contains a error.316 */317 private void checkSuccess(Message response) throws JdbcServerException {318 OperationResult operationResult = null;319 if (response instanceof JdbcMessage || response.getPayload() instanceof OperationResult) {320 operationResult = response.getPayload(OperationResult.class);321 } else if (response.getPayload() != null && StringUtils.hasText(response.getPayload(String.class))) {322 operationResult = (OperationResult) endpointConfiguration.getMarshaller().unmarshal(new StringSource(response.getPayload(String.class)));323 }324 if (!success(response, operationResult)) {325 throw new JdbcServerException(getExceptionMessage(response, operationResult));326 }327 }328 private String getExceptionMessage(Message response, OperationResult operationResult) {329 return Optional.ofNullable(response.getHeader(JdbcMessageHeaders.JDBC_SERVER_EXCEPTION))330 .map(Object::toString)331 .orElse(Optional.ofNullable(operationResult).map(OperationResult::getException).orElse(""));332 }333 private boolean success(Message response, OperationResult result) {334 return Optional.ofNullable(response.getHeader(JdbcMessageHeaders.JDBC_SERVER_SUCCESS))335 .map(Object::toString)336 .map(Boolean::valueOf)...

Full Screen

Full Screen

Source:JdbcEndpointConfiguration.java Github

copy

Full Screen

...112 * Gets the marshaller.113 *114 * @return115 */116 public JdbcMarshaller getMarshaller() {117 return marshaller;118 }119 /**120 * Sets the marshaller.121 *122 * @param marshaller123 */124 public void setMarshaller(JdbcMarshaller marshaller) {125 this.marshaller = marshaller;126 }127 /**128 * Gets the serverConfiguration.129 *130 * @return...

Full Screen

Full Screen

getMarshaller

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus;2import com.consol.citrus.context.TestContext;3import com.consol.citrus.db.driver.JdbcResultSet;4import com.consol.citrus.db.driver.JdbcStatement;5import com.consol.citrus.db.server.JdbcEndpointConfiguration;6import com.consol.citrus.db.server.JdbcServer;7import com.consol.citrus.db.server.handler.JdbcStatementHandler;8import com.consol.citrus.db.server.handler.StatementHandler;9import com.consol.citrus.db.server.handler.StatementHandlerProvider;10import com.consol.citrus.db.server.handler.StatementResult;11import com.consol.citrus.db.server.handler.StatementResultHandler;12import com.consol.citrus.db.server.handler.StatementResultH

Full Screen

Full Screen

getMarshaller

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.jdbc.server;2import com.consol.citrus.exceptions.CitrusRuntimeException;3import com.consol.citrus.message.MessageType;4import com.consol.citrus.message.builder.ObjectMappingPayloadBuilder;5import com.consol.citrus.message.builder.PayloadTemplateMessageBuilder;6import com.consol.citrus.message.builder.ScriptTemplateMessageBuilder;7import com.consol.citrus.message.builder.StaticMessageContentBuilder;8import com.consol.citrus.message.builder.TemplateMessageBuilder;9import com.consol.citrus.message.builder.XmlPayloadBuilder;10import com.consol.citrus.message.builder.XpathPayloadBuilder;11import com.consol.citrus.message.builder.XpathPayloadVariableExtractor;12import com.consol.citrus.message.selector.MessageSelectorBuilder;13import com.consol.citrus.message.selector.XPathMessageSelectorBuilder;14import com.consol.citrus.message.selector.XPathMessageSelectorBuilder.XPathMessageSelectorBuilderSupport;15import com.consol.citrus.server.AbstractServerBuilder;16import com.consol.citrus.server.Server;17import com.consol.citrus.spi.ReferenceResolver;18import com.consol.citrus.spi.ReferenceResolverAware;19import com.consol.citrus.spi.ReferenceResolverAwareTrait;20import com.consol.citrus.spi.ReferenceResolverFactory;21import com.consol.citrus.spi.ReferenceResolverFactoryAware;22import com.consol.citrus.spi.ReferenceResolverFactoryAwareTrait;23import com.consol.citrus.validation.builder.PayloadTemplateMessageBuilderSupport;24import com.consol.citrus.validation.builder.StaticMessageContentBuilderSupport;25import com.consol.citrus.validation.builder.XpathPayloadBuilderSupport;26import com.consol.citrus.validation.script.GroovyScriptMessageBuilder;27import com.consol.citrus.validation.script.GroovyScriptMessageBuilder.GroovyScriptMessageBuilderSupport;28import com.consol.citrus.validation.script.ScriptTemplateMessageBuilderSupport;29import com.consol.citrus.validation.xml.XmlMessageValidationContext;30import com.consol.citrus.variable.GlobalVariables;31import com.consol.citrus.variable.dictionary.DataDictionary;32import com.consol.citrus.variable.dictionary.xml.NodeMappingDataDictionary;33import com.consol.citrus.variable.dictionary.xml.NodeMappingDataDictionary.NodeMappingDataDictionaryBuilderSupport;34import com.consol.citrus.variable.dictionary.xml.XpathMappingDataDictionary;35import com.consol.citrus.variable.dictionary.xml.XpathMappingDataDictionary.XpathMappingDataDictionaryBuilderSupport

Full Screen

Full Screen

getMarshaller

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.jdbc.server;2import java.util.HashMap;3import java.util.Map;4import org.springframework.beans.factory.annotation.Autowired;5import org.springframework.context.annotation.Bean;6import org.springframework.context.annotation.Configuration;7import org.springframework.context.annotation.Import;8import org.springframework.oxm.Marshaller;9import org.springframework.oxm.jaxb.Jaxb2Marshaller;10import com.consol.citrus.Citrus;11import com.consol.citrus.CitrusSpringConfig;12import com.consol.citrus.TestAction;13import com.consol.citrus.actions.ExecutePLSQLAction;14import com.consol.citrus.actions.ReceiveMessageAction;15import com.consol.citrus.actions.SendMessageAction;16import com.consol.citrus.container.SequenceBeforeTest;17import com.consol.citrus.dsl.builder.BuilderSupport;18import com.consol.citrus.dsl.builder.ReceiveMessageBuilder;19import com.consol.citrus.dsl.builder.SendMessageBuilder;20import com.consol.citrus.dsl.design.TestDesigner;21import com.consol.citrus.dsl.design.TestDesignerBeforeTestSupport;22import com.consol.citrus.dsl.runner.TestRunner;23import com.consol.citrus.dsl.runner.TestRunnerBeforeTestSupport;24import com.consol.citrus.endpoint.Endpoint;25import com.consol.citrus.endpoint.EndpointAdapter;26import com.consol.citrus.endpoint.EndpointConfiguration;27import com.consol.citrus.endpoint.EndpointQualifier;28import com.consol.citrus.endpoint.adapter.StaticEndpointAdapter;29import com.consol.citrus.endpoint.direct.DirectEndpoint;30import com.consol.citrus.endpoint.direct.DirectEndpointConfiguration;31import com.consol.citrus.endpoint.direct.annotation.DirectEndpointConfig;32import com.consol.citrus.endpoint.direct.annotation.DirectEndpointConfigurators;33import com.consol.citrus.endpoint.direct.annotation.DirectEndpointComponentScan;34import com.consol.citrus.endpoint.direct.annotation.DirectEndpointComponentScans;35import com.consol.citrus.endpoint.direct.annotation.DirectEndpointComponentScan.AnnotationConfig;36import com.consol.citrus.endpoint.direct.annotation.DirectEndpointComponentScan.PackageScan;37import com.consol.citrus.endpoint.direct.annotation.DirectEndpointComponentScan.PackageScans;38import com.consol.citrus.endpoint.direct.annotation.DirectEndpointInject;39import com.consol.citrus.endpoint.direct.annotation.DirectEndpointInjects;40import com.consol.citrus.endpoint.direct.annotation.DirectEndpointMessageConverter;41import com.consol.c

Full Screen

Full Screen

getMarshaller

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.jdbc.server;2import java.util.*;3import org.springframework.jdbc.core.JdbcTemplate;4import org.springframework.jdbc.datasource.DriverManagerDataSource;5import org.springframework.oxm.Marshaller;6import org.springframework.oxm.castor.CastorMarshaller;7import org.springframework.oxm.jaxb.Jaxb2Marshaller;8import org.springframework.oxm.xstream.XStreamMarshaller;9import org.springframework.xml.transform.StringResult;10import org.springframework.xml.transform.StringSource;11import com.consol.citrus.exceptions.CitrusRuntimeException;12import com.consol.citrus.jdbc.model.JdbcMessage;13import com.consol.citrus.message.Message;14import com.consol.citrus.message.MessageType;15import com.consol.citrus.server.AbstractServer;16import com.consol.citrus.util.FileUtils;17import com.consol.citrus.xml.XsdSchemaRepository;18public class JdbcServer extends AbstractServer {19 private JdbcEndpointConfiguration configuration = new JdbcEndpointConfiguration();20 private JdbcTemplate jdbcTemplate;21 private DriverManagerDataSource dataSource;22 private Marshaller marshaller;23 private XsdSchemaRepository schemaRepository = new XsdSchemaRepository();24 public JdbcServer() {25 super("jdbc-server");26 }27 public JdbcServer(String name) {28 super(name);29 }30 public void run() {31 log.info("Starting JDBC server on port: '" + configuration.getPort() + "'");32 while (isRunning()) {33 try {34 Message request = receive(configuration.getRequestTimeout());35 if (request == null) {36 log.warn("Did not receive any message within " + configuration.getRequestTimeout() + "ms");37 continue;38 }39 log.info("Received JDBC request message: " + request);40 String sqlStatement = request.getPayload(String.class);41 List<Map<String, Object>> rows = jdbcTemplate.queryForList(sqlStatement);42 JdbcMessage response = new JdbcMessage();43 response.setRows(rows);44 if (configuration.isMarshalling()) {45 StringResult result = new StringResult();46 marshaller.marshal(response, result);47 send(response("

Full Screen

Full Screen

getMarshaller

Using AI Code Generation

copy

Full Screen

1package org.apache.cxf.jaxrs.tests;2import java.io.IOException;3import java.io.InputStream;4import java.io.OutputStream;5import java.lang.annotation.Annotation;6import java.lang.reflect.Type;7import javax.ws.rs.Consumes;8import javax.ws.rs.Produces;9import javax.ws.rs.WebApplicationException;10import javax.ws.rs.core.MediaType;11import javax.ws.rs.core.MultivaluedMap;12import javax.ws.rs.ext.MessageBodyReader;13import javax.ws.rs.ext.MessageBodyWriter;14import javax.ws.rs.ext.Provider;15@Consumes("application/json")16@Produces("application/json")17public class JsonMessageBodyHandler implements MessageBodyReader<Object>, MessageBodyWriter<Object> {18 public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {19 return true;20 }21 public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType,22 throws IOException, WebApplicationException {23 return null;24 }25 public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {26 return true;27 }28 public long getSize(Object t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {29 return 0;30 }31 public void writeTo(Object t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,32 throws IOException, WebApplicationException {33 }34}

Full Screen

Full Screen

getMarshaller

Using AI Code Generation

copy

Full Screen

1public void test() {2 JdbcEndpointConfiguration jdbcEndpointConfiguration = new JdbcEndpointConfiguration();3 try {4 JdbcMarshaller jdbcMarshaller = jdbcEndpointConfiguration.getMarshaller();5 } catch (Exception e) {6 e.printStackTrace();7 }8}9I just checked the code and it seems to work fine. I have added a unit test for the getMarshaller() method which runs fine. The exception you get is probably related to the fact that you are using a custom marshaller implementation. Can you check if the marshaller class is available in the classpath?10JdbcEndpointConfiguration jdbcEndpointConfiguration = new JdbcEndpointConfiguration();11JdbcMarshaller jdbcMarshaller = jdbcEndpointConfiguration.getMarshaller();12 at com.consol.citrus.jdbc.server.JdbcEndpointConfiguration.getMarshaller(JdbcEndpointConfiguration.java:105)13 at com.consol.citrus.jdbc.server.JdbcEndpointConfigurationTest.test(JdbcEndpointConfigurationTest.java:19)14 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)15 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)16 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)17 at java.lang.reflect.Method.invoke(Method.java:498)18 at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)19 at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)20 at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)21 at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

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