commit
47779df896
|
@ -13,6 +13,7 @@ dependencies {
|
|||
optional("io.rsocket:rsocket-transport-netty")
|
||||
optional("com.fasterxml.jackson.core:jackson-databind")
|
||||
optional("javax.xml.bind:jaxb-api")
|
||||
optional("com.google.protobuf:protobuf-java-util")
|
||||
optional("org.jetbrains.kotlinx:kotlinx-coroutines-core")
|
||||
optional("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
|
||||
testCompile("javax.inject:javax.inject-tck")
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -17,6 +17,7 @@
|
|||
package org.springframework.messaging.converter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
@ -47,7 +48,7 @@ public abstract class AbstractMessageConverter implements SmartMessageConverter
|
|||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private final List<MimeType> supportedMimeTypes;
|
||||
private final List<MimeType> supportedMimeTypes = new ArrayList<>(4);
|
||||
|
||||
@Nullable
|
||||
private ContentTypeResolver contentTypeResolver = new DefaultContentTypeResolver();
|
||||
|
@ -58,21 +59,28 @@ public abstract class AbstractMessageConverter implements SmartMessageConverter
|
|||
|
||||
|
||||
/**
|
||||
* Construct an {@code AbstractMessageConverter} supporting a single MIME type.
|
||||
* Constructor with a single MIME type.
|
||||
* @param supportedMimeType the supported MIME type
|
||||
*/
|
||||
protected AbstractMessageConverter(MimeType supportedMimeType) {
|
||||
Assert.notNull(supportedMimeType, "supportedMimeType is required");
|
||||
this.supportedMimeTypes = Collections.<MimeType>singletonList(supportedMimeType);
|
||||
this(Collections.singletonList(supportedMimeType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an {@code AbstractMessageConverter} supporting multiple MIME types.
|
||||
* Constructor with one or more MIME types via vararg.
|
||||
* @param supportedMimeTypes the supported MIME types
|
||||
* @since 5.2.2
|
||||
*/
|
||||
protected AbstractMessageConverter(MimeType... supportedMimeTypes) {
|
||||
this(Arrays.asList(supportedMimeTypes));
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with a Collection of MIME types.
|
||||
* @param supportedMimeTypes the supported MIME types
|
||||
*/
|
||||
protected AbstractMessageConverter(Collection<MimeType> supportedMimeTypes) {
|
||||
Assert.notNull(supportedMimeTypes, "supportedMimeTypes must not be null");
|
||||
this.supportedMimeTypes = new ArrayList<>(supportedMimeTypes);
|
||||
this.supportedMimeTypes.addAll(supportedMimeTypes);
|
||||
}
|
||||
|
||||
|
||||
|
@ -83,6 +91,14 @@ public abstract class AbstractMessageConverter implements SmartMessageConverter
|
|||
return Collections.unmodifiableList(this.supportedMimeTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows sub-classes to add more supported mime types.
|
||||
* @since 5.2.2
|
||||
*/
|
||||
protected void addSupportedMimeTypes(MimeType... supportedMimeTypes) {
|
||||
this.supportedMimeTypes.addAll(Arrays.asList(supportedMimeTypes));
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the {@link ContentTypeResolver} to use to resolve the content
|
||||
* type of an input message.
|
||||
|
|
|
@ -22,7 +22,6 @@ import java.io.StringWriter;
|
|||
import java.io.Writer;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
|
@ -84,7 +83,7 @@ public class MappingJackson2MessageConverter extends AbstractMessageConverter {
|
|||
* @since 4.1.5
|
||||
*/
|
||||
public MappingJackson2MessageConverter(MimeType... supportedMimeTypes) {
|
||||
super(Arrays.asList(supportedMimeTypes));
|
||||
super(supportedMimeTypes);
|
||||
this.objectMapper = initObjectMapper();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -21,7 +21,6 @@ import java.io.ByteArrayOutputStream;
|
|||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.Source;
|
||||
|
@ -70,7 +69,7 @@ public class MarshallingMessageConverter extends AbstractMessageConverter {
|
|||
* @param supportedMimeTypes the MIME types
|
||||
*/
|
||||
public MarshallingMessageConverter(MimeType... supportedMimeTypes) {
|
||||
super(Arrays.asList(supportedMimeTypes));
|
||||
super(supportedMimeTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* 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,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.messaging.converter;
|
||||
|
||||
import com.google.protobuf.ExtensionRegistry;
|
||||
import com.google.protobuf.util.JsonFormat;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Subclass of {@link ProtobufMessageConverter} for use with the official
|
||||
* {@code "com.google.protobuf:protobuf-java-util"} library for JSON support.
|
||||
*
|
||||
* <p>Most importantly, this class allows for custom JSON parser and printer
|
||||
* configurations through the {@link JsonFormat} utility. If no special parser
|
||||
* or printer configuration is given, default variants will be used instead.
|
||||
*
|
||||
* <p>Requires Protobuf 3.x and {@code "com.google.protobuf:protobuf-java-util"} 3.x,
|
||||
* with 3.3 or higher recommended.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 5.2.2
|
||||
*/
|
||||
public class ProtobufJsonFormatMessageConverter extends ProtobufMessageConverter {
|
||||
|
||||
/**
|
||||
* Constructor with default instances of {@link JsonFormat.Parser},
|
||||
* {@link JsonFormat.Printer}, and {@link ExtensionRegistry}.
|
||||
*/
|
||||
public ProtobufJsonFormatMessageConverter(@Nullable ExtensionRegistry extensionRegistry) {
|
||||
this(null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with given instances of {@link JsonFormat.Parser},
|
||||
* {@link JsonFormat.Printer}, and a default instance of {@link ExtensionRegistry}.
|
||||
*/
|
||||
public ProtobufJsonFormatMessageConverter(
|
||||
@Nullable JsonFormat.Parser parser, @Nullable JsonFormat.Printer printer) {
|
||||
|
||||
this(parser, printer, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with given instances of {@link JsonFormat.Parser},
|
||||
* {@link JsonFormat.Printer}, and {@link ExtensionRegistry}.
|
||||
*/
|
||||
public ProtobufJsonFormatMessageConverter(@Nullable JsonFormat.Parser parser,
|
||||
@Nullable JsonFormat.Printer printer, @Nullable ExtensionRegistry extensionRegistry) {
|
||||
|
||||
super(new ProtobufJavaUtilSupport(parser, printer), extensionRegistry);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,289 @@
|
|||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* 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,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.messaging.converter;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.protobuf.ExtensionRegistry;
|
||||
import com.google.protobuf.Message;
|
||||
import com.google.protobuf.util.JsonFormat;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ConcurrentReferenceHashMap;
|
||||
import org.springframework.util.MimeType;
|
||||
|
||||
import static org.springframework.util.MimeTypeUtils.APPLICATION_JSON;
|
||||
import static org.springframework.util.MimeTypeUtils.TEXT_PLAIN;
|
||||
|
||||
/**
|
||||
* An {@code MessageConverter} that reads and writes
|
||||
* {@link com.google.protobuf.Message com.google.protobuf.Messages} using
|
||||
* <a href="https://developers.google.com/protocol-buffers/">Google Protocol Buffers</a>.
|
||||
*
|
||||
* <p>To generate {@code Message} Java classes, you need to install the {@code protoc} binary.
|
||||
*
|
||||
* <p>This converter supports by default {@code "application/x-protobuf"} with the official
|
||||
* {@code "com.google.protobuf:protobuf-java"} library.
|
||||
*
|
||||
* <p>{@code "application/json"} can be supported with the official {@code "com.google.protobuf:protobuf-java-util"} 3.x
|
||||
* with 3.3 or higher recommended
|
||||
*
|
||||
* @author Parviz Rozikov
|
||||
* @since 5.2.2
|
||||
*/
|
||||
public class ProtobufMessageConverter extends AbstractMessageConverter {
|
||||
|
||||
|
||||
/**
|
||||
* The default charset used by the converter.
|
||||
*/
|
||||
public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
|
||||
|
||||
/**
|
||||
* The mime-type for protobuf {@code application/x-protobuf}.
|
||||
*/
|
||||
public static final MimeType PROTOBUF = new MimeType("application", "x-protobuf", DEFAULT_CHARSET);
|
||||
|
||||
|
||||
private static final Map<Class<?>, Method> methodCache = new ConcurrentReferenceHashMap<>();
|
||||
|
||||
final ExtensionRegistry extensionRegistry;
|
||||
|
||||
@Nullable
|
||||
private final ProtobufFormatSupport protobufFormatSupport;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor with a default instance of {@link ExtensionRegistry}.
|
||||
*/
|
||||
public ProtobufMessageConverter() {
|
||||
this(null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with a given {@code ExtensionRegistry}.
|
||||
*/
|
||||
public ProtobufMessageConverter(ExtensionRegistry extensionRegistry) {
|
||||
this(null, extensionRegistry);
|
||||
}
|
||||
|
||||
ProtobufMessageConverter(@Nullable ProtobufFormatSupport formatSupport,
|
||||
@Nullable ExtensionRegistry extensionRegistry) {
|
||||
|
||||
super(PROTOBUF, TEXT_PLAIN);
|
||||
|
||||
if (formatSupport != null) {
|
||||
this.protobufFormatSupport = formatSupport;
|
||||
}
|
||||
else if (ClassUtils.isPresent("com.google.protobuf.util.JsonFormat", getClass().getClassLoader())) {
|
||||
this.protobufFormatSupport = new ProtobufJavaUtilSupport(null, null);
|
||||
}
|
||||
else {
|
||||
this.protobufFormatSupport = null;
|
||||
}
|
||||
|
||||
if (this.protobufFormatSupport != null) {
|
||||
addSupportedMimeTypes(this.protobufFormatSupport.supportedMediaTypes());
|
||||
}
|
||||
|
||||
this.extensionRegistry = (extensionRegistry == null ? ExtensionRegistry.newInstance() : extensionRegistry);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean supports(Class<?> clazz) {
|
||||
return Message.class.isAssignableFrom(clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canConvertTo(Object payload, @Nullable MessageHeaders headers) {
|
||||
MimeType mimeType = getMimeType(headers);
|
||||
return (super.canConvertTo(payload, headers) ||
|
||||
this.protobufFormatSupport != null && this.protobufFormatSupport.supportsWriteOnly(mimeType));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object convertFromInternal(org.springframework.messaging.Message<?> message,
|
||||
Class<?> targetClass, @Nullable Object conversionHint) {
|
||||
|
||||
MimeType contentType = getMimeType(message.getHeaders());
|
||||
final Object payload = message.getPayload();
|
||||
|
||||
if (contentType == null) {
|
||||
contentType = PROTOBUF;
|
||||
}
|
||||
|
||||
Charset charset = contentType.getCharset();
|
||||
if (charset == null) {
|
||||
charset = DEFAULT_CHARSET;
|
||||
}
|
||||
|
||||
Message.Builder builder = getMessageBuilder(targetClass);
|
||||
try {
|
||||
if (PROTOBUF.isCompatibleWith(contentType)) {
|
||||
builder.mergeFrom((byte[]) payload, this.extensionRegistry);
|
||||
}
|
||||
else if (this.protobufFormatSupport != null) {
|
||||
this.protobufFormatSupport.merge(message, charset, contentType, this.extensionRegistry, builder);
|
||||
}
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new MessageConversionException(message, "Could not read proto message" + ex.getMessage(), ex);
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Object convertToInternal(
|
||||
Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint) {
|
||||
|
||||
final Message message = (Message) payload;
|
||||
|
||||
MimeType contentType = getMimeType(headers);
|
||||
if (contentType == null) {
|
||||
contentType = PROTOBUF;
|
||||
}
|
||||
|
||||
Charset charset = contentType.getCharset();
|
||||
if (charset == null) {
|
||||
charset = DEFAULT_CHARSET;
|
||||
}
|
||||
|
||||
try {
|
||||
if (PROTOBUF.isCompatibleWith(contentType)) {
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
message.writeTo(byteArrayOutputStream);
|
||||
payload = byteArrayOutputStream.toByteArray();
|
||||
}
|
||||
else if (this.protobufFormatSupport != null) {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
this.protobufFormatSupport.print(message, outputStream, contentType, charset);
|
||||
payload = new String(outputStream.toByteArray(), charset);
|
||||
}
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new MessageConversionException("Could not write proto message" + ex.getMessage(), ex);
|
||||
|
||||
}
|
||||
return payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@code Message.Builder} instance for the given class.
|
||||
* <p>This method uses a ConcurrentReferenceHashMap for caching method lookups.
|
||||
*/
|
||||
private Message.Builder getMessageBuilder(Class<?> clazz) {
|
||||
try {
|
||||
Method method = methodCache.get(clazz);
|
||||
if (method == null) {
|
||||
method = clazz.getMethod("newBuilder");
|
||||
methodCache.put(clazz, method);
|
||||
}
|
||||
return (Message.Builder) method.invoke(clazz);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new MessageConversionException(
|
||||
"Invalid Protobuf Message type: no invocable newBuilder() method on " + clazz, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Protobuf format support.
|
||||
*/
|
||||
interface ProtobufFormatSupport {
|
||||
|
||||
MimeType[] supportedMediaTypes();
|
||||
|
||||
boolean supportsWriteOnly(@Nullable MimeType mediaType);
|
||||
|
||||
void merge(org.springframework.messaging.Message<?> message,
|
||||
Charset charset, MimeType contentType, ExtensionRegistry extensionRegistry,
|
||||
Message.Builder builder) throws IOException, MessageConversionException;
|
||||
|
||||
void print(Message message, OutputStream output, MimeType contentType, Charset charset)
|
||||
throws IOException, MessageConversionException;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@link ProtobufFormatSupport} implementation used when
|
||||
* {@code com.google.protobuf.util.JsonFormat} is available.
|
||||
*/
|
||||
static class ProtobufJavaUtilSupport implements ProtobufFormatSupport {
|
||||
|
||||
private final JsonFormat.Parser parser;
|
||||
|
||||
private final JsonFormat.Printer printer;
|
||||
|
||||
public ProtobufJavaUtilSupport(@Nullable JsonFormat.Parser parser, @Nullable JsonFormat.Printer printer) {
|
||||
this.parser = (parser != null ? parser : JsonFormat.parser());
|
||||
this.printer = (printer != null ? printer : JsonFormat.printer());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MimeType[] supportedMediaTypes() {
|
||||
return new MimeType[]{APPLICATION_JSON};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsWriteOnly(@Nullable MimeType mimeType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void merge(org.springframework.messaging.Message<?> message, Charset charset,
|
||||
MimeType contentType, ExtensionRegistry extensionRegistry, Message.Builder builder)
|
||||
throws IOException, MessageConversionException {
|
||||
|
||||
if (contentType.isCompatibleWith(APPLICATION_JSON)) {
|
||||
this.parser.merge(message.getPayload().toString(), builder);
|
||||
}
|
||||
else {
|
||||
throw new MessageConversionException(
|
||||
"protobuf-java-util does not support parsing " + contentType);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(Message message, OutputStream output, MimeType contentType, Charset charset)
|
||||
throws IOException, MessageConversionException {
|
||||
|
||||
if (contentType.isCompatibleWith(APPLICATION_JSON)) {
|
||||
OutputStreamWriter writer = new OutputStreamWriter(output, charset);
|
||||
this.printer.appendTo(message, writer);
|
||||
writer.flush();
|
||||
}
|
||||
else {
|
||||
throw new MessageConversionException(
|
||||
"protobuf-java-util does not support printing " + contentType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -16,9 +16,6 @@
|
|||
|
||||
package org.springframework.messaging.converter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -81,14 +78,14 @@ public class MessageConverterTests {
|
|||
public void supportsMimeTypeNoneConfigured() {
|
||||
Message<String> message = MessageBuilder.withPayload(
|
||||
"ABC").setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON).build();
|
||||
this.converter = new TestMessageConverter(Collections.<MimeType>emptyList());
|
||||
this.converter = new TestMessageConverter(new MimeType[0]);
|
||||
|
||||
assertThat(this.converter.fromMessage(message, String.class)).isEqualTo("success-from");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canConvertFromStrictContentTypeMatch() {
|
||||
this.converter = new TestMessageConverter(Arrays.asList(MimeTypeUtils.TEXT_PLAIN));
|
||||
this.converter = new TestMessageConverter(MimeTypeUtils.TEXT_PLAIN);
|
||||
this.converter.setStrictContentTypeMatch(true);
|
||||
|
||||
Message<String> message = MessageBuilder.withPayload("ABC").build();
|
||||
|
@ -102,9 +99,8 @@ public class MessageConverterTests {
|
|||
|
||||
@Test
|
||||
public void setStrictContentTypeMatchWithNoSupportedMimeTypes() {
|
||||
this.converter = new TestMessageConverter(Collections.<MimeType>emptyList());
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
this.converter.setStrictContentTypeMatch(true));
|
||||
this.converter = new TestMessageConverter(new MimeType[0]);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> this.converter.setStrictContentTypeMatch(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -149,7 +145,7 @@ public class MessageConverterTests {
|
|||
super(MimeTypeUtils.TEXT_PLAIN);
|
||||
}
|
||||
|
||||
public TestMessageConverter(Collection<MimeType> supportedMimeTypes) {
|
||||
public TestMessageConverter(MimeType... supportedMimeTypes) {
|
||||
super(supportedMimeTypes);
|
||||
}
|
||||
|
||||
|
@ -159,15 +155,15 @@ public class MessageConverterTests {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Object convertFromInternal(Message<?> message, Class<?> targetClass,
|
||||
@Nullable Object conversionHint) {
|
||||
protected Object convertFromInternal(
|
||||
Message<?> message, Class<?> targetClass, @Nullable Object conversionHint) {
|
||||
|
||||
return "success-from";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object convertToInternal(Object payload, @Nullable MessageHeaders headers,
|
||||
@Nullable Object conversionHint) {
|
||||
protected Object convertToInternal(
|
||||
Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint) {
|
||||
|
||||
return "success-to";
|
||||
}
|
||||
|
|
|
@ -0,0 +1,147 @@
|
|||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* 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,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.messaging.converter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.protobuf.ExtensionRegistry;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.messaging.protobuf.Msg;
|
||||
import org.springframework.messaging.protobuf.SecondMsg;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.springframework.messaging.MessageHeaders.CONTENT_TYPE;
|
||||
import static org.springframework.util.MimeTypeUtils.APPLICATION_JSON;
|
||||
|
||||
/**
|
||||
* Test suite for {@link ProtobufMessageConverter}.
|
||||
*
|
||||
* @author Parviz Rozikov
|
||||
*/
|
||||
public class ProtobufMessageConverterTests {
|
||||
|
||||
private ProtobufMessageConverter converter;
|
||||
|
||||
private ExtensionRegistry extensionRegistry;
|
||||
|
||||
private Msg testMsg;
|
||||
|
||||
private Message<byte[]> message;
|
||||
|
||||
private Message<byte[]> messageWithoutContentType;
|
||||
|
||||
private Message<String> messageJson;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
this.extensionRegistry = mock(ExtensionRegistry.class);
|
||||
this.converter = new ProtobufMessageConverter();
|
||||
this.testMsg = Msg.newBuilder().setFoo("Foo").setBlah(SecondMsg.newBuilder().setBlah(123).build()).build();
|
||||
this.message = MessageBuilder.withPayload(this.testMsg.toByteArray())
|
||||
.setHeader(CONTENT_TYPE, ProtobufMessageConverter.PROTOBUF).build();
|
||||
this.messageWithoutContentType = MessageBuilder.withPayload(this.testMsg.toByteArray()).build();
|
||||
this.messageJson = MessageBuilder.withPayload(
|
||||
"{\n" +
|
||||
" \"foo\": \"Foo\",\n" +
|
||||
" \"blah\": {\n" +
|
||||
" \"blah\": 123\n" +
|
||||
" }\n" +
|
||||
"}")
|
||||
.setHeader(CONTENT_TYPE, APPLICATION_JSON)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void extensionRegistryNull() {
|
||||
ProtobufMessageConverter converter = new ProtobufMessageConverter(null);
|
||||
assertThat(converter.extensionRegistry).isNotNull();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void canConvertFrom() {
|
||||
assertThat(converter.canConvertFrom(message, Msg.class)).isTrue();
|
||||
assertThat(converter.canConvertFrom(messageWithoutContentType, Msg.class)).isTrue();
|
||||
assertThat(converter.canConvertFrom(messageJson, Msg.class)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canConvertTo() {
|
||||
assertThat(converter.canConvertTo(testMsg, message.getHeaders())).isTrue();
|
||||
assertThat(converter.canConvertTo(testMsg, messageWithoutContentType.getHeaders())).isTrue();
|
||||
assertThat(converter.canConvertTo(testMsg, messageJson.getHeaders())).isTrue();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void convertFrom() {
|
||||
final Msg msg = (Msg) converter.fromMessage(message, Msg.class);
|
||||
assertThat(msg).isEqualTo(testMsg);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertTo() {
|
||||
final Message<?> message = converter.toMessage(this.testMsg, this.message.getHeaders());
|
||||
assertThat(message).isNotNull();
|
||||
assertThat(message.getPayload()).isEqualTo(this.message.getPayload());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void convertFromNoContentType(){
|
||||
Msg result = (Msg) converter.fromMessage(messageWithoutContentType, Msg.class);
|
||||
assertThat(result).isEqualTo(testMsg);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void defaultContentType() {
|
||||
assertThat(converter.getDefaultContentType(testMsg)).isEqualTo(ProtobufMessageConverter.PROTOBUF);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJsonWithGoogleProtobuf() {
|
||||
this.converter = new ProtobufMessageConverter(
|
||||
new ProtobufMessageConverter.ProtobufJavaUtilSupport(null, null),
|
||||
extensionRegistry);
|
||||
|
||||
final Map<String, Object> headers = new HashMap<>();
|
||||
headers.put(CONTENT_TYPE, APPLICATION_JSON);
|
||||
|
||||
//convertTo
|
||||
final Message<?> message = this.converter.toMessage(this.testMsg, new MessageHeaders(headers));
|
||||
assertThat(message).isNotNull();
|
||||
assertThat(message.getHeaders().get(CONTENT_TYPE)).isEqualTo(APPLICATION_JSON);
|
||||
assertThat(((String) message.getPayload()).length() > 0).isTrue();
|
||||
assertThat(((String) message.getPayload()).isEmpty()).as("Body is empty").isFalse();
|
||||
assertThat(((String) message.getPayload())).isEqualTo(this.messageJson.getPayload());
|
||||
|
||||
//convertFrom
|
||||
final Msg msg = (Msg) converter.fromMessage(message, Msg.class);
|
||||
assertThat(msg).isEqualTo(this.testMsg);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,654 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* 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,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: sample.proto
|
||||
|
||||
package org.springframework.messaging.protobuf;
|
||||
|
||||
/**
|
||||
* Protobuf type {@code Msg}
|
||||
*/
|
||||
public final class Msg extends
|
||||
com.google.protobuf.GeneratedMessage
|
||||
implements MsgOrBuilder {
|
||||
// Use Msg.newBuilder() to construct.
|
||||
private Msg(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
|
||||
super(builder);
|
||||
this.unknownFields = builder.getUnknownFields();
|
||||
}
|
||||
private Msg(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }
|
||||
|
||||
private static final Msg defaultInstance;
|
||||
public static Msg getDefaultInstance() {
|
||||
return defaultInstance;
|
||||
}
|
||||
|
||||
public Msg getDefaultInstanceForType() {
|
||||
return defaultInstance;
|
||||
}
|
||||
|
||||
private final com.google.protobuf.UnknownFieldSet unknownFields;
|
||||
@java.lang.Override
|
||||
public final com.google.protobuf.UnknownFieldSet
|
||||
getUnknownFields() {
|
||||
return this.unknownFields;
|
||||
}
|
||||
private Msg(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
initFields();
|
||||
@SuppressWarnings("unused")
|
||||
int mutable_bitField0_ = 0;
|
||||
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
|
||||
com.google.protobuf.UnknownFieldSet.newBuilder();
|
||||
try {
|
||||
boolean done = false;
|
||||
while (!done) {
|
||||
int tag = input.readTag();
|
||||
switch (tag) {
|
||||
case 0:
|
||||
done = true;
|
||||
break;
|
||||
default: {
|
||||
if (!parseUnknownField(input, unknownFields,
|
||||
extensionRegistry, tag)) {
|
||||
done = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 10: {
|
||||
bitField0_ |= 0x00000001;
|
||||
foo_ = input.readBytes();
|
||||
break;
|
||||
}
|
||||
case 18: {
|
||||
SecondMsg.Builder subBuilder = null;
|
||||
if (((bitField0_ & 0x00000002) == 0x00000002)) {
|
||||
subBuilder = blah_.toBuilder();
|
||||
}
|
||||
blah_ = input.readMessage(SecondMsg.PARSER, extensionRegistry);
|
||||
if (subBuilder != null) {
|
||||
subBuilder.mergeFrom(blah_);
|
||||
blah_ = subBuilder.buildPartial();
|
||||
}
|
||||
bitField0_ |= 0x00000002;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
|
||||
throw e.setUnfinishedMessage(this);
|
||||
} catch (java.io.IOException e) {
|
||||
throw new com.google.protobuf.InvalidProtocolBufferException(
|
||||
e.getMessage()).setUnfinishedMessage(this);
|
||||
} finally {
|
||||
this.unknownFields = unknownFields.build();
|
||||
makeExtensionsImmutable();
|
||||
}
|
||||
}
|
||||
public static final com.google.protobuf.Descriptors.Descriptor
|
||||
getDescriptor() {
|
||||
return OuterSample.internal_static_Msg_descriptor;
|
||||
}
|
||||
|
||||
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
|
||||
internalGetFieldAccessorTable() {
|
||||
return OuterSample.internal_static_Msg_fieldAccessorTable
|
||||
.ensureFieldAccessorsInitialized(
|
||||
Msg.class, Msg.Builder.class);
|
||||
}
|
||||
|
||||
public static com.google.protobuf.Parser<Msg> PARSER =
|
||||
new com.google.protobuf.AbstractParser<Msg>() {
|
||||
public Msg parsePartialFrom(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return new Msg(input, extensionRegistry);
|
||||
}
|
||||
};
|
||||
|
||||
@java.lang.Override
|
||||
public com.google.protobuf.Parser<Msg> getParserForType() {
|
||||
return PARSER;
|
||||
}
|
||||
|
||||
private int bitField0_;
|
||||
// optional string foo = 1;
|
||||
public static final int FOO_FIELD_NUMBER = 1;
|
||||
private java.lang.Object foo_;
|
||||
/**
|
||||
* <code>optional string foo = 1;</code>
|
||||
*/
|
||||
public boolean hasFoo() {
|
||||
return ((bitField0_ & 0x00000001) == 0x00000001);
|
||||
}
|
||||
/**
|
||||
* <code>optional string foo = 1;</code>
|
||||
*/
|
||||
public java.lang.String getFoo() {
|
||||
java.lang.Object ref = foo_;
|
||||
if (ref instanceof java.lang.String) {
|
||||
return (java.lang.String) ref;
|
||||
} else {
|
||||
com.google.protobuf.ByteString bs =
|
||||
(com.google.protobuf.ByteString) ref;
|
||||
java.lang.String s = bs.toStringUtf8();
|
||||
if (bs.isValidUtf8()) {
|
||||
foo_ = s;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <code>optional string foo = 1;</code>
|
||||
*/
|
||||
public com.google.protobuf.ByteString
|
||||
getFooBytes() {
|
||||
java.lang.Object ref = foo_;
|
||||
if (ref instanceof java.lang.String) {
|
||||
com.google.protobuf.ByteString b =
|
||||
com.google.protobuf.ByteString.copyFromUtf8(
|
||||
(java.lang.String) ref);
|
||||
foo_ = b;
|
||||
return b;
|
||||
} else {
|
||||
return (com.google.protobuf.ByteString) ref;
|
||||
}
|
||||
}
|
||||
|
||||
// optional .SecondMsg blah = 2;
|
||||
public static final int BLAH_FIELD_NUMBER = 2;
|
||||
private SecondMsg blah_;
|
||||
/**
|
||||
* <code>optional .SecondMsg blah = 2;</code>
|
||||
*/
|
||||
public boolean hasBlah() {
|
||||
return ((bitField0_ & 0x00000002) == 0x00000002);
|
||||
}
|
||||
/**
|
||||
* <code>optional .SecondMsg blah = 2;</code>
|
||||
*/
|
||||
public SecondMsg getBlah() {
|
||||
return blah_;
|
||||
}
|
||||
/**
|
||||
* <code>optional .SecondMsg blah = 2;</code>
|
||||
*/
|
||||
public SecondMsgOrBuilder getBlahOrBuilder() {
|
||||
return blah_;
|
||||
}
|
||||
|
||||
private void initFields() {
|
||||
foo_ = "";
|
||||
blah_ = SecondMsg.getDefaultInstance();
|
||||
}
|
||||
private byte memoizedIsInitialized = -1;
|
||||
public final boolean isInitialized() {
|
||||
byte isInitialized = memoizedIsInitialized;
|
||||
if (isInitialized != -1) return isInitialized == 1;
|
||||
|
||||
memoizedIsInitialized = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void writeTo(com.google.protobuf.CodedOutputStream output)
|
||||
throws java.io.IOException {
|
||||
getSerializedSize();
|
||||
if (((bitField0_ & 0x00000001) == 0x00000001)) {
|
||||
output.writeBytes(1, getFooBytes());
|
||||
}
|
||||
if (((bitField0_ & 0x00000002) == 0x00000002)) {
|
||||
output.writeMessage(2, blah_);
|
||||
}
|
||||
getUnknownFields().writeTo(output);
|
||||
}
|
||||
|
||||
private int memoizedSerializedSize = -1;
|
||||
public int getSerializedSize() {
|
||||
int size = memoizedSerializedSize;
|
||||
if (size != -1) return size;
|
||||
|
||||
size = 0;
|
||||
if (((bitField0_ & 0x00000001) == 0x00000001)) {
|
||||
size += com.google.protobuf.CodedOutputStream
|
||||
.computeBytesSize(1, getFooBytes());
|
||||
}
|
||||
if (((bitField0_ & 0x00000002) == 0x00000002)) {
|
||||
size += com.google.protobuf.CodedOutputStream
|
||||
.computeMessageSize(2, blah_);
|
||||
}
|
||||
size += getUnknownFields().getSerializedSize();
|
||||
memoizedSerializedSize = size;
|
||||
return size;
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 0L;
|
||||
@java.lang.Override
|
||||
protected java.lang.Object writeReplace()
|
||||
throws java.io.ObjectStreamException {
|
||||
return super.writeReplace();
|
||||
}
|
||||
|
||||
public static Msg parseFrom(
|
||||
com.google.protobuf.ByteString data)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data);
|
||||
}
|
||||
public static Msg parseFrom(
|
||||
com.google.protobuf.ByteString data,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
public static Msg parseFrom(byte[] data)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data);
|
||||
}
|
||||
public static Msg parseFrom(
|
||||
byte[] data,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
public static Msg parseFrom(java.io.InputStream input)
|
||||
throws java.io.IOException {
|
||||
return PARSER.parseFrom(input);
|
||||
}
|
||||
public static Msg parseFrom(
|
||||
java.io.InputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return PARSER.parseFrom(input, extensionRegistry);
|
||||
}
|
||||
public static Msg parseDelimitedFrom(java.io.InputStream input)
|
||||
throws java.io.IOException {
|
||||
return PARSER.parseDelimitedFrom(input);
|
||||
}
|
||||
public static Msg parseDelimitedFrom(
|
||||
java.io.InputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return PARSER.parseDelimitedFrom(input, extensionRegistry);
|
||||
}
|
||||
public static Msg parseFrom(
|
||||
com.google.protobuf.CodedInputStream input)
|
||||
throws java.io.IOException {
|
||||
return PARSER.parseFrom(input);
|
||||
}
|
||||
public static Msg parseFrom(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return PARSER.parseFrom(input, extensionRegistry);
|
||||
}
|
||||
|
||||
public static Builder newBuilder() { return Builder.create(); }
|
||||
public Builder newBuilderForType() { return newBuilder(); }
|
||||
public static Builder newBuilder(Msg prototype) {
|
||||
return newBuilder().mergeFrom(prototype);
|
||||
}
|
||||
public Builder toBuilder() { return newBuilder(this); }
|
||||
|
||||
@java.lang.Override
|
||||
protected Builder newBuilderForType(
|
||||
com.google.protobuf.GeneratedMessage.BuilderParent parent) {
|
||||
Builder builder = new Builder(parent);
|
||||
return builder;
|
||||
}
|
||||
/**
|
||||
* Protobuf type {@code Msg}
|
||||
*/
|
||||
public static final class Builder extends
|
||||
com.google.protobuf.GeneratedMessage.Builder<Builder>
|
||||
implements MsgOrBuilder {
|
||||
public static final com.google.protobuf.Descriptors.Descriptor
|
||||
getDescriptor() {
|
||||
return OuterSample.internal_static_Msg_descriptor;
|
||||
}
|
||||
|
||||
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
|
||||
internalGetFieldAccessorTable() {
|
||||
return OuterSample.internal_static_Msg_fieldAccessorTable
|
||||
.ensureFieldAccessorsInitialized(
|
||||
Msg.class, Msg.Builder.class);
|
||||
}
|
||||
|
||||
// Construct using org.springframework.messaging.protobuf.Msg.newBuilder()
|
||||
private Builder() {
|
||||
maybeForceBuilderInitialization();
|
||||
}
|
||||
|
||||
private Builder(
|
||||
com.google.protobuf.GeneratedMessage.BuilderParent parent) {
|
||||
super(parent);
|
||||
maybeForceBuilderInitialization();
|
||||
}
|
||||
private void maybeForceBuilderInitialization() {
|
||||
if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
|
||||
getBlahFieldBuilder();
|
||||
}
|
||||
}
|
||||
private static Builder create() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder clear() {
|
||||
super.clear();
|
||||
foo_ = "";
|
||||
bitField0_ = (bitField0_ & ~0x00000001);
|
||||
if (blahBuilder_ == null) {
|
||||
blah_ = SecondMsg.getDefaultInstance();
|
||||
} else {
|
||||
blahBuilder_.clear();
|
||||
}
|
||||
bitField0_ = (bitField0_ & ~0x00000002);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder clone() {
|
||||
return create().mergeFrom(buildPartial());
|
||||
}
|
||||
|
||||
public com.google.protobuf.Descriptors.Descriptor
|
||||
getDescriptorForType() {
|
||||
return OuterSample.internal_static_Msg_descriptor;
|
||||
}
|
||||
|
||||
public Msg getDefaultInstanceForType() {
|
||||
return Msg.getDefaultInstance();
|
||||
}
|
||||
|
||||
public Msg build() {
|
||||
Msg result = buildPartial();
|
||||
if (!result.isInitialized()) {
|
||||
throw newUninitializedMessageException(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Msg buildPartial() {
|
||||
Msg result = new Msg(this);
|
||||
int from_bitField0_ = bitField0_;
|
||||
int to_bitField0_ = 0;
|
||||
if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
|
||||
to_bitField0_ |= 0x00000001;
|
||||
}
|
||||
result.foo_ = foo_;
|
||||
if (((from_bitField0_ & 0x00000002) == 0x00000002)) {
|
||||
to_bitField0_ |= 0x00000002;
|
||||
}
|
||||
if (blahBuilder_ == null) {
|
||||
result.blah_ = blah_;
|
||||
} else {
|
||||
result.blah_ = blahBuilder_.build();
|
||||
}
|
||||
result.bitField0_ = to_bitField0_;
|
||||
onBuilt();
|
||||
return result;
|
||||
}
|
||||
|
||||
public Builder mergeFrom(com.google.protobuf.Message other) {
|
||||
if (other instanceof Msg) {
|
||||
return mergeFrom((Msg)other);
|
||||
} else {
|
||||
super.mergeFrom(other);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public Builder mergeFrom(Msg other) {
|
||||
if (other == Msg.getDefaultInstance()) return this;
|
||||
if (other.hasFoo()) {
|
||||
bitField0_ |= 0x00000001;
|
||||
foo_ = other.foo_;
|
||||
onChanged();
|
||||
}
|
||||
if (other.hasBlah()) {
|
||||
mergeBlah(other.getBlah());
|
||||
}
|
||||
this.mergeUnknownFields(other.getUnknownFields());
|
||||
return this;
|
||||
}
|
||||
|
||||
public final boolean isInitialized() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Builder mergeFrom(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
Msg parsedMessage = null;
|
||||
try {
|
||||
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
|
||||
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
|
||||
parsedMessage = (Msg) e.getUnfinishedMessage();
|
||||
throw e;
|
||||
} finally {
|
||||
if (parsedMessage != null) {
|
||||
mergeFrom(parsedMessage);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
private int bitField0_;
|
||||
|
||||
// optional string foo = 1;
|
||||
private java.lang.Object foo_ = "";
|
||||
/**
|
||||
* <code>optional string foo = 1;</code>
|
||||
*/
|
||||
public boolean hasFoo() {
|
||||
return ((bitField0_ & 0x00000001) == 0x00000001);
|
||||
}
|
||||
/**
|
||||
* <code>optional string foo = 1;</code>
|
||||
*/
|
||||
public java.lang.String getFoo() {
|
||||
java.lang.Object ref = foo_;
|
||||
if (!(ref instanceof java.lang.String)) {
|
||||
java.lang.String s = ((com.google.protobuf.ByteString) ref)
|
||||
.toStringUtf8();
|
||||
foo_ = s;
|
||||
return s;
|
||||
} else {
|
||||
return (java.lang.String) ref;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <code>optional string foo = 1;</code>
|
||||
*/
|
||||
public com.google.protobuf.ByteString
|
||||
getFooBytes() {
|
||||
java.lang.Object ref = foo_;
|
||||
if (ref instanceof String) {
|
||||
com.google.protobuf.ByteString b =
|
||||
com.google.protobuf.ByteString.copyFromUtf8(
|
||||
(java.lang.String) ref);
|
||||
foo_ = b;
|
||||
return b;
|
||||
} else {
|
||||
return (com.google.protobuf.ByteString) ref;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <code>optional string foo = 1;</code>
|
||||
*/
|
||||
public Builder setFoo(
|
||||
java.lang.String value) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
bitField0_ |= 0x00000001;
|
||||
foo_ = value;
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>optional string foo = 1;</code>
|
||||
*/
|
||||
public Builder clearFoo() {
|
||||
bitField0_ = (bitField0_ & ~0x00000001);
|
||||
foo_ = getDefaultInstance().getFoo();
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>optional string foo = 1;</code>
|
||||
*/
|
||||
public Builder setFooBytes(
|
||||
com.google.protobuf.ByteString value) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
bitField0_ |= 0x00000001;
|
||||
foo_ = value;
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
// optional .SecondMsg blah = 2;
|
||||
private SecondMsg blah_ = SecondMsg.getDefaultInstance();
|
||||
private com.google.protobuf.SingleFieldBuilder<
|
||||
SecondMsg, SecondMsg.Builder,
|
||||
SecondMsgOrBuilder> blahBuilder_;
|
||||
/**
|
||||
* <code>optional .SecondMsg blah = 2;</code>
|
||||
*/
|
||||
public boolean hasBlah() {
|
||||
return ((bitField0_ & 0x00000002) == 0x00000002);
|
||||
}
|
||||
/**
|
||||
* <code>optional .SecondMsg blah = 2;</code>
|
||||
*/
|
||||
public SecondMsg getBlah() {
|
||||
if (blahBuilder_ == null) {
|
||||
return blah_;
|
||||
} else {
|
||||
return blahBuilder_.getMessage();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <code>optional .SecondMsg blah = 2;</code>
|
||||
*/
|
||||
public Builder setBlah(SecondMsg value) {
|
||||
if (blahBuilder_ == null) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
blah_ = value;
|
||||
onChanged();
|
||||
} else {
|
||||
blahBuilder_.setMessage(value);
|
||||
}
|
||||
bitField0_ |= 0x00000002;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>optional .SecondMsg blah = 2;</code>
|
||||
*/
|
||||
public Builder setBlah(
|
||||
SecondMsg.Builder builderForValue) {
|
||||
if (blahBuilder_ == null) {
|
||||
blah_ = builderForValue.build();
|
||||
onChanged();
|
||||
} else {
|
||||
blahBuilder_.setMessage(builderForValue.build());
|
||||
}
|
||||
bitField0_ |= 0x00000002;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>optional .SecondMsg blah = 2;</code>
|
||||
*/
|
||||
public Builder mergeBlah(SecondMsg value) {
|
||||
if (blahBuilder_ == null) {
|
||||
if (((bitField0_ & 0x00000002) == 0x00000002) &&
|
||||
blah_ != SecondMsg.getDefaultInstance()) {
|
||||
blah_ =
|
||||
SecondMsg.newBuilder(blah_).mergeFrom(value).buildPartial();
|
||||
} else {
|
||||
blah_ = value;
|
||||
}
|
||||
onChanged();
|
||||
} else {
|
||||
blahBuilder_.mergeFrom(value);
|
||||
}
|
||||
bitField0_ |= 0x00000002;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>optional .SecondMsg blah = 2;</code>
|
||||
*/
|
||||
public Builder clearBlah() {
|
||||
if (blahBuilder_ == null) {
|
||||
blah_ = SecondMsg.getDefaultInstance();
|
||||
onChanged();
|
||||
} else {
|
||||
blahBuilder_.clear();
|
||||
}
|
||||
bitField0_ = (bitField0_ & ~0x00000002);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>optional .SecondMsg blah = 2;</code>
|
||||
*/
|
||||
public SecondMsg.Builder getBlahBuilder() {
|
||||
bitField0_ |= 0x00000002;
|
||||
onChanged();
|
||||
return getBlahFieldBuilder().getBuilder();
|
||||
}
|
||||
/**
|
||||
* <code>optional .SecondMsg blah = 2;</code>
|
||||
*/
|
||||
public SecondMsgOrBuilder getBlahOrBuilder() {
|
||||
if (blahBuilder_ != null) {
|
||||
return blahBuilder_.getMessageOrBuilder();
|
||||
} else {
|
||||
return blah_;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <code>optional .SecondMsg blah = 2;</code>
|
||||
*/
|
||||
private com.google.protobuf.SingleFieldBuilder<
|
||||
SecondMsg, SecondMsg.Builder,
|
||||
SecondMsgOrBuilder>
|
||||
getBlahFieldBuilder() {
|
||||
if (blahBuilder_ == null) {
|
||||
blahBuilder_ = new com.google.protobuf.SingleFieldBuilder<>(
|
||||
blah_,
|
||||
getParentForChildren(),
|
||||
isClean());
|
||||
blah_ = null;
|
||||
}
|
||||
return blahBuilder_;
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(builder_scope:Msg)
|
||||
}
|
||||
|
||||
static {
|
||||
defaultInstance = new Msg(true);
|
||||
defaultInstance.initFields();
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(class_scope:Msg)
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: sample.proto
|
||||
|
||||
package org.springframework.messaging.protobuf;
|
||||
|
||||
public interface MsgOrBuilder
|
||||
extends com.google.protobuf.MessageOrBuilder {
|
||||
|
||||
// optional string foo = 1;
|
||||
/**
|
||||
* <code>optional string foo = 1;</code>
|
||||
*/
|
||||
boolean hasFoo();
|
||||
/**
|
||||
* <code>optional string foo = 1;</code>
|
||||
*/
|
||||
java.lang.String getFoo();
|
||||
/**
|
||||
* <code>optional string foo = 1;</code>
|
||||
*/
|
||||
com.google.protobuf.ByteString
|
||||
getFooBytes();
|
||||
|
||||
// optional .SecondMsg blah = 2;
|
||||
/**
|
||||
* <code>optional .SecondMsg blah = 2;</code>
|
||||
*/
|
||||
boolean hasBlah();
|
||||
/**
|
||||
* <code>optional .SecondMsg blah = 2;</code>
|
||||
*/
|
||||
SecondMsg getBlah();
|
||||
/**
|
||||
* <code>optional .SecondMsg blah = 2;</code>
|
||||
*/
|
||||
SecondMsgOrBuilder getBlahOrBuilder();
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: sample.proto
|
||||
|
||||
package org.springframework.messaging.protobuf;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class OuterSample {
|
||||
private OuterSample() {}
|
||||
public static void registerAllExtensions(
|
||||
com.google.protobuf.ExtensionRegistry registry) {
|
||||
}
|
||||
static com.google.protobuf.Descriptors.Descriptor
|
||||
internal_static_Msg_descriptor;
|
||||
static
|
||||
com.google.protobuf.GeneratedMessage.FieldAccessorTable
|
||||
internal_static_Msg_fieldAccessorTable;
|
||||
static com.google.protobuf.Descriptors.Descriptor
|
||||
internal_static_SecondMsg_descriptor;
|
||||
static
|
||||
com.google.protobuf.GeneratedMessage.FieldAccessorTable
|
||||
internal_static_SecondMsg_fieldAccessorTable;
|
||||
|
||||
public static com.google.protobuf.Descriptors.FileDescriptor
|
||||
getDescriptor() {
|
||||
return descriptor;
|
||||
}
|
||||
private static com.google.protobuf.Descriptors.FileDescriptor
|
||||
descriptor;
|
||||
static {
|
||||
java.lang.String[] descriptorData = {
|
||||
"\n\014sample.proto\",\n\003Msg\022\013\n\003foo\030\001 \001(\t\022\030\n\004bl" +
|
||||
"ah\030\002 \001(\0132\n.SecondMsg\"\031\n\tSecondMsg\022\014\n\004bla" +
|
||||
"h\030\001 \001(\005B-\n\034org.springframework.protobufB" +
|
||||
"\013OuterSampleP\001"
|
||||
};
|
||||
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
|
||||
new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
|
||||
public com.google.protobuf.ExtensionRegistry assignDescriptors(
|
||||
com.google.protobuf.Descriptors.FileDescriptor root) {
|
||||
descriptor = root;
|
||||
internal_static_Msg_descriptor =
|
||||
getDescriptor().getMessageTypes().get(0);
|
||||
internal_static_Msg_fieldAccessorTable = new
|
||||
com.google.protobuf.GeneratedMessage.FieldAccessorTable(
|
||||
internal_static_Msg_descriptor,
|
||||
new java.lang.String[] { "Foo", "Blah", });
|
||||
internal_static_SecondMsg_descriptor =
|
||||
getDescriptor().getMessageTypes().get(1);
|
||||
internal_static_SecondMsg_fieldAccessorTable = new
|
||||
com.google.protobuf.GeneratedMessage.FieldAccessorTable(
|
||||
internal_static_SecondMsg_descriptor,
|
||||
new java.lang.String[] { "Blah", });
|
||||
return null;
|
||||
}
|
||||
};
|
||||
com.google.protobuf.Descriptors.FileDescriptor
|
||||
.internalBuildGeneratedFileFrom(descriptorData,
|
||||
new com.google.protobuf.Descriptors.FileDescriptor[] {
|
||||
}, assigner);
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(outer_class_scope)
|
||||
}
|
|
@ -0,0 +1,389 @@
|
|||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: sample.proto
|
||||
|
||||
package org.springframework.messaging.protobuf;
|
||||
|
||||
/**
|
||||
* Protobuf type {@code SecondMsg}
|
||||
*/
|
||||
public final class SecondMsg extends
|
||||
com.google.protobuf.GeneratedMessage
|
||||
implements SecondMsgOrBuilder {
|
||||
// Use SecondMsg.newBuilder() to construct.
|
||||
private SecondMsg(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
|
||||
super(builder);
|
||||
this.unknownFields = builder.getUnknownFields();
|
||||
}
|
||||
private SecondMsg(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }
|
||||
|
||||
private static final SecondMsg defaultInstance;
|
||||
public static SecondMsg getDefaultInstance() {
|
||||
return defaultInstance;
|
||||
}
|
||||
|
||||
public SecondMsg getDefaultInstanceForType() {
|
||||
return defaultInstance;
|
||||
}
|
||||
|
||||
private final com.google.protobuf.UnknownFieldSet unknownFields;
|
||||
@java.lang.Override
|
||||
public final com.google.protobuf.UnknownFieldSet
|
||||
getUnknownFields() {
|
||||
return this.unknownFields;
|
||||
}
|
||||
private SecondMsg(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
initFields();
|
||||
@SuppressWarnings("unused")
|
||||
int mutable_bitField0_ = 0;
|
||||
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
|
||||
com.google.protobuf.UnknownFieldSet.newBuilder();
|
||||
try {
|
||||
boolean done = false;
|
||||
while (!done) {
|
||||
int tag = input.readTag();
|
||||
switch (tag) {
|
||||
case 0:
|
||||
done = true;
|
||||
break;
|
||||
default: {
|
||||
if (!parseUnknownField(input, unknownFields,
|
||||
extensionRegistry, tag)) {
|
||||
done = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 8: {
|
||||
bitField0_ |= 0x00000001;
|
||||
blah_ = input.readInt32();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
|
||||
throw e.setUnfinishedMessage(this);
|
||||
} catch (java.io.IOException e) {
|
||||
throw new com.google.protobuf.InvalidProtocolBufferException(
|
||||
e.getMessage()).setUnfinishedMessage(this);
|
||||
} finally {
|
||||
this.unknownFields = unknownFields.build();
|
||||
makeExtensionsImmutable();
|
||||
}
|
||||
}
|
||||
public static final com.google.protobuf.Descriptors.Descriptor
|
||||
getDescriptor() {
|
||||
return OuterSample.internal_static_SecondMsg_descriptor;
|
||||
}
|
||||
|
||||
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
|
||||
internalGetFieldAccessorTable() {
|
||||
return OuterSample.internal_static_SecondMsg_fieldAccessorTable
|
||||
.ensureFieldAccessorsInitialized(
|
||||
SecondMsg.class, SecondMsg.Builder.class);
|
||||
}
|
||||
|
||||
public static com.google.protobuf.Parser<SecondMsg> PARSER =
|
||||
new com.google.protobuf.AbstractParser<SecondMsg>() {
|
||||
public SecondMsg parsePartialFrom(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return new SecondMsg(input, extensionRegistry);
|
||||
}
|
||||
};
|
||||
|
||||
@java.lang.Override
|
||||
public com.google.protobuf.Parser<SecondMsg> getParserForType() {
|
||||
return PARSER;
|
||||
}
|
||||
|
||||
private int bitField0_;
|
||||
// optional int32 blah = 1;
|
||||
public static final int BLAH_FIELD_NUMBER = 1;
|
||||
private int blah_;
|
||||
/**
|
||||
* <code>optional int32 blah = 1;</code>
|
||||
*/
|
||||
public boolean hasBlah() {
|
||||
return ((bitField0_ & 0x00000001) == 0x00000001);
|
||||
}
|
||||
/**
|
||||
* <code>optional int32 blah = 1;</code>
|
||||
*/
|
||||
public int getBlah() {
|
||||
return blah_;
|
||||
}
|
||||
|
||||
private void initFields() {
|
||||
blah_ = 0;
|
||||
}
|
||||
private byte memoizedIsInitialized = -1;
|
||||
public final boolean isInitialized() {
|
||||
byte isInitialized = memoizedIsInitialized;
|
||||
if (isInitialized != -1) return isInitialized == 1;
|
||||
|
||||
memoizedIsInitialized = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void writeTo(com.google.protobuf.CodedOutputStream output)
|
||||
throws java.io.IOException {
|
||||
getSerializedSize();
|
||||
if (((bitField0_ & 0x00000001) == 0x00000001)) {
|
||||
output.writeInt32(1, blah_);
|
||||
}
|
||||
getUnknownFields().writeTo(output);
|
||||
}
|
||||
|
||||
private int memoizedSerializedSize = -1;
|
||||
public int getSerializedSize() {
|
||||
int size = memoizedSerializedSize;
|
||||
if (size != -1) return size;
|
||||
|
||||
size = 0;
|
||||
if (((bitField0_ & 0x00000001) == 0x00000001)) {
|
||||
size += com.google.protobuf.CodedOutputStream
|
||||
.computeInt32Size(1, blah_);
|
||||
}
|
||||
size += getUnknownFields().getSerializedSize();
|
||||
memoizedSerializedSize = size;
|
||||
return size;
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 0L;
|
||||
@java.lang.Override
|
||||
protected java.lang.Object writeReplace()
|
||||
throws java.io.ObjectStreamException {
|
||||
return super.writeReplace();
|
||||
}
|
||||
|
||||
public static SecondMsg parseFrom(
|
||||
com.google.protobuf.ByteString data)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data);
|
||||
}
|
||||
public static SecondMsg parseFrom(
|
||||
com.google.protobuf.ByteString data,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
public static SecondMsg parseFrom(byte[] data)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data);
|
||||
}
|
||||
public static SecondMsg parseFrom(
|
||||
byte[] data,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
public static SecondMsg parseFrom(java.io.InputStream input)
|
||||
throws java.io.IOException {
|
||||
return PARSER.parseFrom(input);
|
||||
}
|
||||
public static SecondMsg parseFrom(
|
||||
java.io.InputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return PARSER.parseFrom(input, extensionRegistry);
|
||||
}
|
||||
public static SecondMsg parseDelimitedFrom(java.io.InputStream input)
|
||||
throws java.io.IOException {
|
||||
return PARSER.parseDelimitedFrom(input);
|
||||
}
|
||||
public static SecondMsg parseDelimitedFrom(
|
||||
java.io.InputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return PARSER.parseDelimitedFrom(input, extensionRegistry);
|
||||
}
|
||||
public static SecondMsg parseFrom(
|
||||
com.google.protobuf.CodedInputStream input)
|
||||
throws java.io.IOException {
|
||||
return PARSER.parseFrom(input);
|
||||
}
|
||||
public static SecondMsg parseFrom(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return PARSER.parseFrom(input, extensionRegistry);
|
||||
}
|
||||
|
||||
public static Builder newBuilder() { return Builder.create(); }
|
||||
public Builder newBuilderForType() { return newBuilder(); }
|
||||
public static Builder newBuilder(SecondMsg prototype) {
|
||||
return newBuilder().mergeFrom(prototype);
|
||||
}
|
||||
public Builder toBuilder() { return newBuilder(this); }
|
||||
|
||||
@java.lang.Override
|
||||
protected Builder newBuilderForType(
|
||||
com.google.protobuf.GeneratedMessage.BuilderParent parent) {
|
||||
Builder builder = new Builder(parent);
|
||||
return builder;
|
||||
}
|
||||
/**
|
||||
* Protobuf type {@code SecondMsg}
|
||||
*/
|
||||
public static final class Builder extends
|
||||
com.google.protobuf.GeneratedMessage.Builder<Builder>
|
||||
implements SecondMsgOrBuilder {
|
||||
public static final com.google.protobuf.Descriptors.Descriptor
|
||||
getDescriptor() {
|
||||
return OuterSample.internal_static_SecondMsg_descriptor;
|
||||
}
|
||||
|
||||
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
|
||||
internalGetFieldAccessorTable() {
|
||||
return OuterSample.internal_static_SecondMsg_fieldAccessorTable
|
||||
.ensureFieldAccessorsInitialized(
|
||||
SecondMsg.class, SecondMsg.Builder.class);
|
||||
}
|
||||
|
||||
// Construct using org.springframework.messaging.protobuf.SecondMsg.newBuilder()
|
||||
private Builder() {
|
||||
maybeForceBuilderInitialization();
|
||||
}
|
||||
|
||||
private Builder(
|
||||
com.google.protobuf.GeneratedMessage.BuilderParent parent) {
|
||||
super(parent);
|
||||
maybeForceBuilderInitialization();
|
||||
}
|
||||
private void maybeForceBuilderInitialization() {
|
||||
if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
|
||||
}
|
||||
}
|
||||
private static Builder create() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder clear() {
|
||||
super.clear();
|
||||
blah_ = 0;
|
||||
bitField0_ = (bitField0_ & ~0x00000001);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder clone() {
|
||||
return create().mergeFrom(buildPartial());
|
||||
}
|
||||
|
||||
public com.google.protobuf.Descriptors.Descriptor
|
||||
getDescriptorForType() {
|
||||
return OuterSample.internal_static_SecondMsg_descriptor;
|
||||
}
|
||||
|
||||
public SecondMsg getDefaultInstanceForType() {
|
||||
return SecondMsg.getDefaultInstance();
|
||||
}
|
||||
|
||||
public SecondMsg build() {
|
||||
SecondMsg result = buildPartial();
|
||||
if (!result.isInitialized()) {
|
||||
throw newUninitializedMessageException(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public SecondMsg buildPartial() {
|
||||
SecondMsg result = new SecondMsg(this);
|
||||
int from_bitField0_ = bitField0_;
|
||||
int to_bitField0_ = 0;
|
||||
if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
|
||||
to_bitField0_ |= 0x00000001;
|
||||
}
|
||||
result.blah_ = blah_;
|
||||
result.bitField0_ = to_bitField0_;
|
||||
onBuilt();
|
||||
return result;
|
||||
}
|
||||
|
||||
public Builder mergeFrom(com.google.protobuf.Message other) {
|
||||
if (other instanceof SecondMsg) {
|
||||
return mergeFrom((SecondMsg)other);
|
||||
} else {
|
||||
super.mergeFrom(other);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public Builder mergeFrom(SecondMsg other) {
|
||||
if (other == SecondMsg.getDefaultInstance()) return this;
|
||||
if (other.hasBlah()) {
|
||||
setBlah(other.getBlah());
|
||||
}
|
||||
this.mergeUnknownFields(other.getUnknownFields());
|
||||
return this;
|
||||
}
|
||||
|
||||
public final boolean isInitialized() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Builder mergeFrom(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
SecondMsg parsedMessage = null;
|
||||
try {
|
||||
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
|
||||
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
|
||||
parsedMessage = (SecondMsg) e.getUnfinishedMessage();
|
||||
throw e;
|
||||
} finally {
|
||||
if (parsedMessage != null) {
|
||||
mergeFrom(parsedMessage);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
private int bitField0_;
|
||||
|
||||
// optional int32 blah = 1;
|
||||
private int blah_ ;
|
||||
/**
|
||||
* <code>optional int32 blah = 1;</code>
|
||||
*/
|
||||
public boolean hasBlah() {
|
||||
return ((bitField0_ & 0x00000001) == 0x00000001);
|
||||
}
|
||||
/**
|
||||
* <code>optional int32 blah = 1;</code>
|
||||
*/
|
||||
public int getBlah() {
|
||||
return blah_;
|
||||
}
|
||||
/**
|
||||
* <code>optional int32 blah = 1;</code>
|
||||
*/
|
||||
public Builder setBlah(int value) {
|
||||
bitField0_ |= 0x00000001;
|
||||
blah_ = value;
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>optional int32 blah = 1;</code>
|
||||
*/
|
||||
public Builder clearBlah() {
|
||||
bitField0_ = (bitField0_ & ~0x00000001);
|
||||
blah_ = 0;
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(builder_scope:SecondMsg)
|
||||
}
|
||||
|
||||
static {
|
||||
defaultInstance = new SecondMsg(true);
|
||||
defaultInstance.initFields();
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(class_scope:SecondMsg)
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: sample.proto
|
||||
|
||||
package org.springframework.messaging.protobuf;
|
||||
|
||||
public interface SecondMsgOrBuilder
|
||||
extends com.google.protobuf.MessageOrBuilder {
|
||||
|
||||
// optional int32 blah = 1;
|
||||
/**
|
||||
* <code>optional int32 blah = 1;</code>
|
||||
*/
|
||||
boolean hasBlah();
|
||||
/**
|
||||
* <code>optional int32 blah = 1;</code>
|
||||
*/
|
||||
int getBlah();
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
option java_package = "org.springframework.protobuf.messaging";
|
||||
option java_outer_classname = "OuterSample";
|
||||
option java_multiple_files = true;
|
||||
|
||||
message Msg {
|
||||
optional string foo = 1;
|
||||
optional SecondMsg blah = 2;
|
||||
}
|
||||
|
||||
message SecondMsg {
|
||||
optional int32 blah = 1;
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -42,18 +42,16 @@ import org.springframework.lang.Nullable;
|
|||
public class ProtobufJsonFormatHttpMessageConverter extends ProtobufHttpMessageConverter {
|
||||
|
||||
/**
|
||||
* Construct a new {@code ProtobufJsonFormatHttpMessageConverter} with default
|
||||
* {@code JsonFormat.Parser} and {@code JsonFormat.Printer} configuration.
|
||||
* Constructor with default instances of {@link JsonFormat.Parser},
|
||||
* {@link JsonFormat.Printer}, and {@link ExtensionRegistry}.
|
||||
*/
|
||||
public ProtobufJsonFormatHttpMessageConverter() {
|
||||
this(null, null, (ExtensionRegistry)null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new {@code ProtobufJsonFormatHttpMessageConverter} with the given
|
||||
* {@code JsonFormat.Parser} and {@code JsonFormat.Printer} configuration.
|
||||
* @param parser the JSON parser configuration
|
||||
* @param printer the JSON printer configuration
|
||||
* Constructor with given instances of {@link JsonFormat.Parser},
|
||||
* {@link JsonFormat.Printer}, and a default instance of {@link ExtensionRegistry}.
|
||||
*/
|
||||
public ProtobufJsonFormatHttpMessageConverter(
|
||||
@Nullable JsonFormat.Parser parser, @Nullable JsonFormat.Printer printer) {
|
||||
|
@ -62,13 +60,8 @@ public class ProtobufJsonFormatHttpMessageConverter extends ProtobufHttpMessageC
|
|||
}
|
||||
|
||||
/**
|
||||
* Construct a new {@code ProtobufJsonFormatHttpMessageConverter} with the given
|
||||
* {@code JsonFormat.Parser} and {@code JsonFormat.Printer} configuration, also
|
||||
* accepting a registry that specifies protocol message extensions.
|
||||
* @param parser the JSON parser configuration
|
||||
* @param printer the JSON printer configuration
|
||||
* @param extensionRegistry the registry to populate
|
||||
* @since 5.1
|
||||
* Constructor with given instances of {@link JsonFormat.Parser},
|
||||
* {@link JsonFormat.Printer}, and {@link ExtensionRegistry}.
|
||||
*/
|
||||
public ProtobufJsonFormatHttpMessageConverter(@Nullable JsonFormat.Parser parser,
|
||||
@Nullable JsonFormat.Printer printer, @Nullable ExtensionRegistry extensionRegistry) {
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
<suppress files="StompHeaderAccessor" checks="JavadocVariable" />
|
||||
<suppress files="StompHeaders" checks="JavadocVariable" />
|
||||
<suppress files="org[\\/]springframework[\\/]messaging[\\/]handler[\\/]annotation[\\/]ValueConstants" checks="InterfaceIsType" />
|
||||
<suppress files="src[\\/]test[\\/]java[\\/]org[\\/]springframework[\\/]messaging[\\/]protobuf[\\/].*" checks=".*" />
|
||||
|
||||
<!-- spring-orm -->
|
||||
<suppress files="jpa[\\/]vendor[\\/]Database" checks="JavadocVariable|JavadocStyle"/>
|
||||
|
|
Loading…
Reference in New Issue