Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions src/main/java/org/jminix/console/resource/OperationResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.StreamSupport;
import java.util.Objects;

import javax.management.InstanceNotFoundException;
import javax.management.IntrospectionException;
Expand Down Expand Up @@ -79,11 +79,7 @@ public Map<String, Object> getModel()
@Post("*:txt|html|json")
public Representation execute(Representation entity) throws ResourceException
{
String[] stringParams = new Form(entity).getValuesArray("param");

if(stringParams != null && isAllNulls(Arrays.asList(stringParams))) {
stringParams = nullToEmpty((String[]) ServletUtils.getRequest(getRequest()).getParameterMap().get("param"));
}
String[] stringParams = getStringParams(entity);

String domain = unescape(getDecodedAttribute("domain"));

Expand Down Expand Up @@ -161,6 +157,16 @@ public Representation execute(Representation entity) throws ResourceException
}
}

private String[] getStringParams(Representation entity) {
String[] stringParams = new Form(entity).getValuesArray("param");

if (stringParams == null || isAllNulls(stringParams)) {
stringParams = ServletUtils.getRequest(getRequest()).getParameterValues("param");
}

return stringParams != null ? stringParams : new String[0];
}

@Override
protected String getTemplateName()
{
Expand Down Expand Up @@ -221,11 +227,8 @@ private MBeanOperationInfo getOperation(MBeanServerConnection server, String dom
}
}

private boolean isAllNulls(Iterable<?> array) {
return StreamSupport.stream(array.spliterator(), true).allMatch(o -> o == null);
}

private String[] nullToEmpty(String[] array) {
return array !=null ? array: new String[0];
private boolean isAllNulls(String[] array) {
return Arrays.stream(array).allMatch(Objects::isNull);
}

}