mirror of https://github.com/apache/activemq.git
Making new values in ActiveMQObjectMessage transient which fixes HTTP serialization
This commit is contained in:
parent
09cbfa9477
commit
b9dcb010f7
|
@ -27,6 +27,7 @@ import java.io.Serializable;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.zip.DeflaterOutputStream;
|
||||
import java.util.zip.InflaterInputStream;
|
||||
|
||||
|
@ -66,15 +67,16 @@ import org.apache.activemq.wireformat.WireFormat;
|
|||
* @see javax.jms.StreamMessage
|
||||
* @see javax.jms.TextMessage
|
||||
*/
|
||||
public class ActiveMQObjectMessage extends ActiveMQMessage implements ObjectMessage {
|
||||
public class ActiveMQObjectMessage extends ActiveMQMessage implements ObjectMessage, TransientInitializer {
|
||||
|
||||
public static final byte DATA_STRUCTURE_TYPE = CommandTypes.ACTIVEMQ_OBJECT_MESSAGE;
|
||||
|
||||
private List<String> trustedPackages = Arrays.asList(ClassLoadingAwareObjectInputStream.serializablePackages);
|
||||
private boolean trustAllPackages = false;
|
||||
private transient List<String> trustedPackages = Arrays.asList(ClassLoadingAwareObjectInputStream.serializablePackages);
|
||||
private transient boolean trustAllPackages = false;
|
||||
|
||||
protected transient Serializable object;
|
||||
|
||||
@Override
|
||||
public Message copy() {
|
||||
ActiveMQObjectMessage copy = new ActiveMQObjectMessage();
|
||||
copy(copy);
|
||||
|
@ -126,10 +128,12 @@ public class ActiveMQObjectMessage extends ActiveMQMessage implements ObjectMess
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getDataStructureType() {
|
||||
return DATA_STRUCTURE_TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getJMSXMimeType() {
|
||||
return "jms/object-message";
|
||||
}
|
||||
|
@ -146,6 +150,7 @@ public class ActiveMQObjectMessage extends ActiveMQMessage implements ObjectMess
|
|||
* due to some internal error.
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void clearBody() throws JMSException {
|
||||
super.clearBody();
|
||||
this.object = null;
|
||||
|
@ -166,6 +171,7 @@ public class ActiveMQObjectMessage extends ActiveMQMessage implements ObjectMess
|
|||
* read-only mode.
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void setObject(Serializable newObject) throws JMSException {
|
||||
checkReadOnlyBody();
|
||||
this.object = newObject;
|
||||
|
@ -183,6 +189,7 @@ public class ActiveMQObjectMessage extends ActiveMQMessage implements ObjectMess
|
|||
* @return the serializable object containing this message's data
|
||||
* @throws JMSException
|
||||
*/
|
||||
@Override
|
||||
public Serializable getObject() throws JMSException {
|
||||
if (object == null && getContent() != null) {
|
||||
try {
|
||||
|
@ -216,11 +223,13 @@ public class ActiveMQObjectMessage extends ActiveMQMessage implements ObjectMess
|
|||
storeContent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearMarshalledState() throws JMSException {
|
||||
super.clearMarshalledState();
|
||||
this.object = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageRolledBack() {
|
||||
super.onMessageRolledBack();
|
||||
|
||||
|
@ -235,6 +244,7 @@ public class ActiveMQObjectMessage extends ActiveMQMessage implements ObjectMess
|
|||
super.compress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
try {
|
||||
getObject();
|
||||
|
@ -258,4 +268,10 @@ public class ActiveMQObjectMessage extends ActiveMQMessage implements ObjectMess
|
|||
public void setTrustAllPackages(boolean trustAllPackages) {
|
||||
this.trustAllPackages = trustAllPackages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initTransients() {
|
||||
trustedPackages = Arrays.asList(ClassLoadingAwareObjectInputStream.serializablePackages);
|
||||
trustAllPackages = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package org.apache.activemq.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
@ -30,7 +29,7 @@ import org.apache.activemq.state.CommandVisitor;
|
|||
* @openwire:marshaller code="5"
|
||||
*
|
||||
*/
|
||||
public class ConsumerInfo extends BaseCommand {
|
||||
public class ConsumerInfo extends BaseCommand implements TransientInitializer {
|
||||
|
||||
public static final byte DATA_STRUCTURE_TYPE = CommandTypes.CONSUMER_INFO;
|
||||
|
||||
|
@ -527,6 +526,7 @@ public class ConsumerInfo extends BaseCommand {
|
|||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initTransients() {
|
||||
assignedGroupCount = new ConcurrentHashMap<>();
|
||||
lastDeliveredSequenceId = RemoveInfo.LAST_DELIVERED_UNSET;
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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
|
||||
*
|
||||
* http://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.apache.activemq.command;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public interface TransientInitializer {
|
||||
|
||||
public void initTransients();
|
||||
}
|
|
@ -24,9 +24,11 @@ import com.thoughtworks.xstream.converters.MarshallingContext;
|
|||
import com.thoughtworks.xstream.converters.UnmarshallingContext;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
|
||||
|
||||
import org.apache.activemq.command.ConsumerInfo;
|
||||
import org.apache.activemq.command.MarshallAware;
|
||||
import org.apache.activemq.command.MessageDispatch;
|
||||
import org.apache.activemq.command.TransientInitializer;
|
||||
import org.apache.activemq.transport.stomp.XStreamSupport;
|
||||
import org.apache.activemq.transport.util.TextWireFormat;
|
||||
import org.apache.activemq.util.ByteSequence;
|
||||
|
@ -67,8 +69,8 @@ public class XStreamWireFormat extends TextWireFormat {
|
|||
@Override
|
||||
public Object unmarshalText(Reader reader) {
|
||||
Object val = getXStream().fromXML(reader);
|
||||
if (val instanceof ConsumerInfo) {
|
||||
((ConsumerInfo)val).initTransients();
|
||||
if (val instanceof TransientInitializer) {
|
||||
((TransientInitializer)val).initTransients();
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue