Polished previous commit
- added author - removed lombok - upgraded to s-c-build 2.1.4 and fixed http/https issues Resolves #1608
This commit is contained in:
5
pom.xml
5
pom.xml
@@ -9,7 +9,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-build</artifactId>
|
||||
<version>2.1.4.BUILD-SNAPSHOT</version>
|
||||
<version>2.1.4.RELEASE</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
<scm>
|
||||
@@ -28,8 +28,7 @@
|
||||
<reactor.version>Californium-SR5</reactor.version>
|
||||
<kryo-shaded.version>3.0.3</kryo-shaded.version>
|
||||
<objenesis.version>2.1</objenesis.version>
|
||||
<spring-cloud-function.version>2.1.0.M1
|
||||
</spring-cloud-function.version>
|
||||
<spring-cloud-function.version>2.1.0.RC1</spring-cloud-function.version>
|
||||
|
||||
<maven-checkstyle-plugin.failsOnError>true</maven-checkstyle-plugin.failsOnError>
|
||||
<maven-checkstyle-plugin.failsOnViolation>true</maven-checkstyle-plugin.failsOnViolation>
|
||||
|
||||
@@ -39,10 +39,6 @@
|
||||
<version>${avro.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-stream-test-support</artifactId>
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.springframework.util.MimeType;
|
||||
* @author Marius Bogoevici
|
||||
* @author Vinicius Carvalho
|
||||
* @author Sercan Karaoglu
|
||||
* @author Ish Mahajan
|
||||
*/
|
||||
public abstract class AbstractAvroMessageConverter extends AbstractMessageConverter {
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.springframework.util.ReflectionUtils;
|
||||
* @author Marius Bogoevici
|
||||
* @author Vinicius Carvalho
|
||||
* @author Sercan Karaoglu
|
||||
* @author Ish Mahajan
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(name = "org.apache.avro.Schema")
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.springframework.util.MimeType;
|
||||
* to {@link org.apache.avro.generic.GenericRecord} targets, a schema must be set.s
|
||||
*
|
||||
* @author Marius Bogoevici
|
||||
* @author Ish Mahajan
|
||||
*/
|
||||
|
||||
public class AvroSchemaMessageConverter extends AbstractAvroMessageConverter {
|
||||
|
||||
@@ -73,6 +73,7 @@ import org.springframework.util.ObjectUtils;
|
||||
* @author Vinicius Carvalho
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Sercan Karaoglu
|
||||
* @author Ish Mahajan
|
||||
*/
|
||||
public class AvroSchemaRegistryClientMessageConverter extends AbstractAvroMessageConverter
|
||||
implements InitializingBean {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -31,7 +31,7 @@ import org.apache.avro.io.DatumWriter;
|
||||
* Provide a custom bean definition of {@link AvroSchemaServiceManager} and mark
|
||||
* it as @Primary to override the default implementation
|
||||
*
|
||||
* @author 5aab
|
||||
* @author Ish Mahajan
|
||||
*
|
||||
*/
|
||||
public interface AvroSchemaServiceManager {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -47,7 +47,7 @@ import org.springframework.stereotype.Component;
|
||||
* Provide a custom bean definition of {@link AvroSchemaServiceManager} and mark
|
||||
* it as @Primary to override this default implementation
|
||||
*
|
||||
* @author 5aab
|
||||
* @author Ish Mahajan
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.schema.avro;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -25,7 +26,6 @@ import com.fasterxml.jackson.dataformat.avro.AvroFactory;
|
||||
import com.fasterxml.jackson.dataformat.avro.AvroMapper;
|
||||
import com.fasterxml.jackson.dataformat.avro.AvroSchema;
|
||||
import com.fasterxml.jackson.dataformat.avro.schema.AvroSchemaGenerator;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.avro.Schema;
|
||||
import org.apache.avro.SchemaParseException;
|
||||
import org.apache.avro.file.DataFileReader;
|
||||
@@ -33,7 +33,6 @@ import org.apache.avro.file.DataFileWriter;
|
||||
import org.apache.avro.io.DatumReader;
|
||||
import org.apache.avro.io.DatumWriter;
|
||||
import org.assertj.core.util.Lists;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.cloud.schema.avro.domain.FoodOrder;
|
||||
@@ -43,26 +42,30 @@ import org.springframework.cloud.stream.schema.avro.AvroSchemaServiceManagerImpl
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.util.MimeType;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
/**
|
||||
* @author 5aab
|
||||
* @author Ish Mahajan
|
||||
*/
|
||||
@Slf4j
|
||||
public class AvroSchemaServiceManagerTests {
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked", "resource" })
|
||||
@Test(expected = DataFileWriter.AppendWriteException.class)
|
||||
public void testWithDefaultImplementation() throws IOException {
|
||||
AvroSchemaServiceManager defaultServiceManager = new AvroSchemaServiceManagerImpl();
|
||||
Schema schema = defaultServiceManager.getSchema(FoodOrder.class);
|
||||
FoodOrder foodOrder = FoodOrder.builder().restaurant("Spring Kitchen")
|
||||
.orderDescription("avro makhani").customerAddress("world wide web").build();
|
||||
FoodOrder foodOrder = new FoodOrder();
|
||||
foodOrder.setRestaurant("Spring Kitchen");
|
||||
foodOrder.setOrderDescription("avro makhani");
|
||||
foodOrder.setCustomerAddress("world wide web");
|
||||
File file = new File("foodorder.avro");
|
||||
|
||||
DatumWriter datumWriter = defaultServiceManager.getDatumWriter(foodOrder.getClass(), schema);
|
||||
DataFileWriter<FoodOrder> dataFileWriter = new DataFileWriter<FoodOrder>(datumWriter);
|
||||
dataFileWriter.create(schema, file);
|
||||
dataFileWriter.append(foodOrder);
|
||||
|
||||
FoodOrder foodOrder2 = FoodOrder.builder().restaurant(null)
|
||||
.orderDescription(null).customerAddress(null).build();
|
||||
FoodOrder foodOrder2 = new FoodOrder();
|
||||
dataFileWriter.append(foodOrder2);
|
||||
dataFileWriter.close();
|
||||
|
||||
@@ -89,7 +92,7 @@ public class AvroSchemaServiceManagerTests {
|
||||
mapper.acceptJsonFormatVisitor(FoodOrder.class, gen);
|
||||
}
|
||||
catch (JsonMappingException e) {
|
||||
log.error("Error while setting acceptJsonFormatVisitor {}", e);
|
||||
fail("Error while setting acceptJsonFormatVisitor {}", e);
|
||||
}
|
||||
AvroSchema schemaWrapper = gen.getGeneratedSchema();
|
||||
return schemaWrapper.getAvroSchema();
|
||||
@@ -114,7 +117,7 @@ public class AvroSchemaServiceManagerTests {
|
||||
mapper.acceptJsonFormatVisitor(targetClass, gen);
|
||||
}
|
||||
catch (JsonMappingException e) {
|
||||
log.error("Error while setting acceptJsonFormatVisitor {}", e);
|
||||
fail("Error while setting acceptJsonFormatVisitor {}", e);
|
||||
}
|
||||
return mapper.readerFor(targetClass)
|
||||
.with(new AvroSchema(readerSchema))
|
||||
@@ -122,43 +125,46 @@ public class AvroSchemaServiceManagerTests {
|
||||
}
|
||||
};
|
||||
|
||||
FoodOrder foodOrder1 = FoodOrder.builder().restaurant("Spring Kitchen")
|
||||
.orderDescription("avro makhani").customerAddress("world wide web").build();
|
||||
FoodOrder foodOrder2 = FoodOrder.builder().restaurant("Spring Kitchen")
|
||||
.orderDescription(null).customerAddress(null).build();
|
||||
FoodOrder foodOrder1 = new FoodOrder();
|
||||
foodOrder1.setRestaurant("Spring Kitchen");
|
||||
foodOrder1.setOrderDescription("avro makhani");
|
||||
foodOrder1.setCustomerAddress("world wide web");
|
||||
FoodOrder foodOrder2 = new FoodOrder();
|
||||
foodOrder2.setRestaurant("Spring Kitchen");
|
||||
|
||||
Schema schema = manager.getSchema(FoodOrder.class);
|
||||
AvroMapper mapper = new AvroMapper();
|
||||
byte[] payload1 = mapper.writer(new AvroSchema(schema)).writeValueAsBytes(foodOrder1);
|
||||
byte[] payload2 = mapper.writer(new AvroSchema(schema)).writeValueAsBytes(foodOrder2);
|
||||
foodOrder1 = (FoodOrder) manager.readData(foodOrder1.getClass(), payload1, schema, schema);
|
||||
foodOrder2 = (FoodOrder) manager.readData(foodOrder1.getClass(), payload2, schema, schema);
|
||||
Assert.assertNull(foodOrder2.getOrderDescription());
|
||||
Assert.assertNull(foodOrder2.getCustomerAddress());
|
||||
assertThat(foodOrder2.getOrderDescription()).isNull();
|
||||
assertThat(foodOrder2.getCustomerAddress()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAvroSchemaMessageConverter() {
|
||||
AvroSchemaMessageConverter converter = new AvroSchemaMessageConverter();
|
||||
MimeType mimeType = new MimeType("application", "avro");
|
||||
Assert.assertEquals(converter.getSupportedMimeTypes().get(0), mimeType);
|
||||
assertThat(mimeType).isEqualTo(converter.getSupportedMimeTypes().get(0));
|
||||
|
||||
AvroSchemaMessageConverter converter2 = new AvroSchemaMessageConverter(mimeType);
|
||||
Assert.assertEquals(converter2.getSupportedMimeTypes().get(0), mimeType);
|
||||
assertThat(mimeType).isEqualTo(converter2.getSupportedMimeTypes().get(0));
|
||||
|
||||
AvroSchemaMessageConverter converter3 =
|
||||
new AvroSchemaMessageConverter(Lists.newArrayList(mimeType));
|
||||
Assert.assertEquals(converter3.getSupportedMimeTypes().get(0), mimeType);
|
||||
assertThat(mimeType).isEqualTo(converter3.getSupportedMimeTypes().get(0));
|
||||
|
||||
AvroSchemaServiceManager manager = new AvroSchemaServiceManagerImpl();
|
||||
AvroSchemaMessageConverter converter4 = new AvroSchemaMessageConverter(manager);
|
||||
Assert.assertEquals(converter4.getSupportedMimeTypes().get(0), mimeType);
|
||||
assertThat(mimeType).isEqualTo(converter4.getSupportedMimeTypes().get(0));
|
||||
|
||||
AvroSchemaMessageConverter converter5 =
|
||||
new AvroSchemaMessageConverter(Lists.newArrayList(mimeType), manager);
|
||||
Schema schema = manager.getSchema(FoodOrder.class);
|
||||
converter5.setSchema(schema);
|
||||
Assert.assertEquals(converter5.getSupportedMimeTypes().get(0), mimeType);
|
||||
Assert.assertEquals(converter5.getSchema(), schema);
|
||||
assertThat(mimeType).isEqualTo(converter5.getSupportedMimeTypes().get(0));
|
||||
assertThat(schema).isEqualTo(converter5.getSchema());
|
||||
}
|
||||
|
||||
@Test(expected = SchemaParseException.class)
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -16,25 +16,29 @@
|
||||
|
||||
package org.springframework.cloud.schema.avro.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
|
||||
/**
|
||||
* @author 5aab
|
||||
* @author Ish Mahajan
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
@ToString
|
||||
public class FoodOrder {
|
||||
private String restaurant;
|
||||
private String customerAddress;
|
||||
private String orderDescription;
|
||||
public String getRestaurant() {
|
||||
return restaurant;
|
||||
}
|
||||
public void setRestaurant(String restaurant) {
|
||||
this.restaurant = restaurant;
|
||||
}
|
||||
public String getCustomerAddress() {
|
||||
return customerAddress;
|
||||
}
|
||||
public void setCustomerAddress(String customerAddress) {
|
||||
this.customerAddress = customerAddress;
|
||||
}
|
||||
public String getOrderDescription() {
|
||||
return orderDescription;
|
||||
}
|
||||
public void setOrderDescription(String orderDescription) {
|
||||
this.orderDescription = orderDescription;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user