Skip to content

Commit

Permalink
fix Management API
Browse files Browse the repository at this point in the history
* do not expose HornetQ internal resources through the management API
  • Loading branch information
jmesnil committed Mar 31, 2010
1 parent 476c4d9 commit 731239c
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 59 deletions.
154 changes: 154 additions & 0 deletions src/main/org/hornetq/api/core/management/AddressSettingsInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/*
* Copyright 2010 Red Hat, Inc.
* Red Hat 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.hornetq.api.core.management;

import org.hornetq.utils.json.JSONObject;

/**
* A AddressSettingsInfo
*
* @author jmesnil
*
*
*/
public class AddressSettingsInfo
{

// Constants -----------------------------------------------------

// Attributes ----------------------------------------------------

private String addressFullMessagePolicy;

private long maxSizeBytes;

private int pageSizeBytes;

private int maxDeliveryAttempts;

private long redeliveryDelay;

private String deadLetterAddress;

private String expiryAddress;

private boolean lastValueQueue;

private long redistributionDelay;

private boolean sendToDLAOnNoRoute;

// Static --------------------------------------------------------

public static final AddressSettingsInfo from(final String jsonString) throws Exception
{
JSONObject object = new JSONObject(jsonString);
return new AddressSettingsInfo(object.getString("addressFullMessagePolicy"),
object.getLong("maxSizeBytes"),
object.getInt("pageSizeBytes"),
object.getInt("maxDeliveryAttempts"),
object.getLong("redeliveryDelay"),
object.getString("DLA"),
object.getString("expiryAddress"),
object.getBoolean("lastValueQueue"),
object.getLong("redistributionDelay"),
object.getBoolean("sendToDLAOnNoRoute"));
}

// Constructors --------------------------------------------------

public AddressSettingsInfo(String addressFullMessagePolicy,
long maxSizeBytes,
int pageSizeBytes,
int maxDeliveryAttempts,
long redeliveryDelay,
String deadLetterAddress,
String expiryAddress,
boolean lastValueQueue,
long redistributionDelay,
boolean sendToDLAOnNoRoute)
{
this.addressFullMessagePolicy = addressFullMessagePolicy;
this.maxSizeBytes = maxSizeBytes;
this.pageSizeBytes = pageSizeBytes;
this.maxDeliveryAttempts = maxDeliveryAttempts;
this.redeliveryDelay = redeliveryDelay;
this.deadLetterAddress = deadLetterAddress;
this.expiryAddress = expiryAddress;
this.lastValueQueue = lastValueQueue;
this.redistributionDelay = redistributionDelay;
this.sendToDLAOnNoRoute = sendToDLAOnNoRoute;
}

// Public --------------------------------------------------------

public String getAddressFullMessagePolicy()
{
return addressFullMessagePolicy;
}

public long getMaxSizeBytes()
{
return maxSizeBytes;
}

public int getPageSizeBytes()
{
return pageSizeBytes;
}

public int getMaxDeliveryAttempts()
{
return maxDeliveryAttempts;
}

public long getRedeliveryDelay()
{
return redeliveryDelay;
}

public String getDeadLetterAddress()
{
return deadLetterAddress;
}

public String getExpiryAddress()
{
return expiryAddress;
}

public boolean isLastValueQueue()
{
return lastValueQueue;
}

public long getRedistributionDelay()
{
return redistributionDelay;
}

public boolean isSendToDLAOnNoRoute()
{
return sendToDLAOnNoRoute;
}

// Package protected ---------------------------------------------

// Protected -----------------------------------------------------

// Private -------------------------------------------------------

// Inner classes -------------------------------------------------

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.hornetq.api.core.HornetQException;
import org.hornetq.api.core.Interceptor;
import org.hornetq.core.security.Role;
import org.hornetq.core.settings.impl.AddressSettings;

/**
* A HornetQServerControl is used to manage HornetQ servers.
Expand Down Expand Up @@ -495,8 +494,6 @@ void addSecuritySettings(
@Operation(desc = "Remove security settings for an address", impact = MBeanOperationInfo.ACTION)
void removeSecuritySettings(@Parameter(desc = "an address match", name = "addressMatch") String addressMatch) throws Exception;

Set<Role> getSecuritySettings(String addressMatch) throws Exception;

@Operation(desc = "get roles for a specific address match", impact = MBeanOperationInfo.INFO)
Object[] getRoles(@Parameter(desc = "an address match", name = "addressMatch") String addressMatch) throws Exception;

Expand All @@ -519,8 +516,6 @@ void addAddressSettings(@Parameter(desc="an address match", name="addressMatch")
@Parameter(desc="do we send to the DLA when there is no where to route the message", name="sendToDLAOnNoRoute") boolean sendToDLAOnNoRoute,
@Parameter(desc="the ploicy to use when the address is full", name="addressFullMessagePolicy") String addressFullMessagePolicy) throws Exception;

AddressSettings getAddressSettings(String address) throws Exception;

void removeAddressSettings(String addressMatch) throws Exception;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1227,21 +1227,6 @@ public void removeSecuritySettings(String addressMatch) throws Exception
}
}

public Set<Role> getSecuritySettings(String addressMatch) throws Exception
{
checkStarted();

clearIO();
try
{
return server.getSecurityRepository().getMatch(addressMatch);
}
finally
{
blockOnIO();
}
}

public Object[] getRoles(String addressMatch) throws Exception
{
checkStarted();
Expand Down Expand Up @@ -1372,13 +1357,6 @@ else if (addressFullMessagePolicy.equalsIgnoreCase("BLOCK"))
storageManager.storeAddressSetting(new PersistedAddressSetting(new SimpleString(address), addressSettings));
}

public AddressSettings getAddressSettings(final String address)
{
checkStarted();

return server.getAddressSettingsRepository().getMatch(address);
}

public void removeAddressSettings(String addressMatch) throws Exception
{
checkStarted();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

import org.hornetq.api.core.SimpleString;
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.core.management.AddressSettingsInfo;
import org.hornetq.api.core.management.HornetQServerControl;
import org.hornetq.api.core.management.ObjectNameBuilder;
import org.hornetq.api.core.management.Parameter;
import org.hornetq.api.core.management.QueueControl;
import org.hornetq.api.core.management.RoleInfo;
import org.hornetq.core.config.Configuration;
Expand All @@ -31,7 +31,6 @@
import org.hornetq.core.remoting.impl.invm.InVMConnectorFactory;
import org.hornetq.core.server.HornetQServer;
import org.hornetq.core.server.HornetQServers;
import org.hornetq.core.settings.impl.AddressSettings;
import org.hornetq.tests.util.RandomUtil;
import org.hornetq.utils.json.JSONArray;
import org.hornetq.utils.json.JSONObject;
Expand Down Expand Up @@ -481,18 +480,19 @@ public void testAddressSettings() throws Exception
//restartServer();
serverControl = createManagementControl();

AddressSettings settings = serverControl.getAddressSettings(exactAddress);

assertEquals(DLA, settings.getDeadLetterAddress().toString());
assertEquals(expiryAddress, settings.getExpiryAddress().toString());
assertEquals(lastValueQueue, settings.isLastValueQueue());
assertEquals(deliveryAttempts, settings.getMaxDeliveryAttempts());
assertEquals(maxSizeBytes, settings.getMaxSizeBytes());
assertEquals(pageSizeBytes, settings.getPageSizeBytes());
assertEquals(redeliveryDelay, settings.getRedeliveryDelay());
assertEquals(redistributionDelay, settings.getRedistributionDelay());
assertEquals(sendToDLAOnNoRoute, settings.isSendToDLAOnNoRoute());
assertEquals(addressFullMessagePolicy, settings.getAddressFullMessagePolicy().toString());
String jsonString = serverControl.getAddressSettingsAsJSON(exactAddress);
AddressSettingsInfo info = AddressSettingsInfo.from(jsonString);

assertEquals(DLA, info.getDeadLetterAddress());
assertEquals(expiryAddress, info.getExpiryAddress());
assertEquals(lastValueQueue, info.isLastValueQueue());
assertEquals(deliveryAttempts, info.getMaxDeliveryAttempts());
assertEquals(maxSizeBytes, info.getMaxSizeBytes());
assertEquals(pageSizeBytes, info.getPageSizeBytes());
assertEquals(redeliveryDelay, info.getRedeliveryDelay());
assertEquals(redistributionDelay, info.getRedistributionDelay());
assertEquals(sendToDLAOnNoRoute, info.isSendToDLAOnNoRoute());
assertEquals(addressFullMessagePolicy, info.getAddressFullMessagePolicy());
}

// Package protected ---------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,24 +517,6 @@ public void addAddressSettings(@Parameter(desc = "an address match", name = "add
proxy.invokeOperation("addAddressSettings", addressMatch, DLA, expiryAddress, lastValueQueue, deliveryAttempts, maxSizeBytes, pageSizeBytes, redeliveryDelay, redistributionDelay, sendToDLAOnNoRoute, addressFullMessagePolicy);
}

public AddressSettings getAddressSettings(String address) throws Exception
{
String res = (String)proxy.invokeOperation("getAddressSettingsAsJSON", address);
JSONObject object = new JSONObject(res);
AddressSettings settings = new AddressSettings();
settings.setDeadLetterAddress(SimpleString.toSimpleString(object.getString("DLA")));
settings.setExpiryAddress(SimpleString.toSimpleString(object.getString("expiryAddress")));
settings.setLastValueQueue(object.getBoolean("lastValueQueue"));
settings.setMaxDeliveryAttempts(object.getInt("maxDeliveryAttempts"));
settings.setMaxSizeBytes(object.getLong("maxSizeBytes"));
settings.setPageSizeBytes(object.getInt("pageSizeBytes"));
settings.setRedeliveryDelay(object.getLong("redeliveryDelay"));
settings.setRedistributionDelay(object.getLong("redistributionDelay"));
settings.setSendToDLAOnNoRoute(object.getBoolean("sendToDLAOnNoRoute"));
settings.setAddressFullMessagePolicy(AddressFullMessagePolicy.valueOf(object.getString("addressFullMessagePolicy")));
return settings;
}

public void removeAddressSettings(String addressMatch) throws Exception
{
proxy.invokeOperation("removeAddressSettings", addressMatch);
Expand Down

0 comments on commit 731239c

Please sign in to comment.