Skip to content

Commit

Permalink
Merge pull request #1943 from Cousjava/PAYARA-1030-remove-jettison
Browse files Browse the repository at this point in the history
PAYARA-1030 Remove Jettison from Payara
  • Loading branch information
Cousjava authored Sep 12, 2017
2 parents 09044c9 + bd210b9 commit f5581c4
Show file tree
Hide file tree
Showing 92 changed files with 1,619 additions and 981 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@
</properties>

<dependencies>
<dependency>
<groupId>org.codehaus.jettison</groupId>
<artifactId>jettison</artifactId>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@

<dependencies>
<dependency>
<groupId>org.codehaus.jettison</groupId>
<artifactId>jettison</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<groupId>javax.json</groupId>
<artifactId>javax.json-api</artifactId>
<type>jar</type>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@
import fish.payara.monitoring.rest.app.processor.ProcessorFactory;
import fish.payara.monitoring.rest.app.processor.TypeProcessor;
import javax.inject.Singleton;
import javax.json.Json;
import javax.json.JsonException;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;
import javax.json.JsonValue;
import javax.management.AttributeNotFoundException;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanException;
import javax.management.MalformedObjectNameException;
import javax.management.ReflectionException;
import javax.ws.rs.core.Response;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;

/**
*
Expand All @@ -78,23 +81,23 @@ public MBeanAttributeReadHandler(@Singleton MBeanServerDelegate delegate,
}

@Override
public JSONObject getRequestObject() {
JSONObject requestObject = new JSONObject();
public JsonObject getRequestObject() {
JsonObjectBuilder objectBuilder = Json.createObjectBuilder();
try {
requestObject.put(RestMonitoringAppResponseToken.getMbeanNameKey(),
objectBuilder.add(RestMonitoringAppResponseToken.getMbeanNameKey(),
mbeanname);
requestObject.put(RestMonitoringAppResponseToken.getAttributeNameKey(),
objectBuilder.add(RestMonitoringAppResponseToken.getAttributeNameKey(),
attributename);
requestObject.put(RestMonitoringAppResponseToken.getRequestTypeKey(),
objectBuilder.add(RestMonitoringAppResponseToken.getRequestTypeKey(),
requesttype);
} catch (JSONException ex) {
} catch (JsonException ex) {
super.setStatus(Response.Status.INTERNAL_SERVER_ERROR);
}
return requestObject;
return objectBuilder.build();
}

@Override
public Object getValueObject() throws JSONException {
public JsonValue getValueObject() throws JsonException {
try {
Object attribute = delegate
.getMBeanAttribute(mbeanname, attributename);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,23 @@

import fish.payara.monitoring.rest.app.RestMonitoringAppResponseToken;
import fish.payara.monitoring.rest.app.MBeanServerDelegate;
import java.math.BigDecimal;
import javax.inject.Singleton;
import javax.json.Json;
import javax.json.JsonException;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;
import javax.json.JsonValue;
import javax.management.InstanceNotFoundException;
import javax.management.IntrospectionException;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanInfo;
import javax.management.MalformedObjectNameException;
import javax.management.ReflectionException;
import javax.ws.rs.core.Response;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;

/**
*
* @since 4.1.2.173
* @author Fraser Savage
*/
public class MBeanReadHandler extends ReadHandler {
Expand All @@ -74,21 +78,21 @@ public MBeanReadHandler(@Singleton MBeanServerDelegate delegate,
}

@Override
public JSONObject getRequestObject() {
JSONObject requestObject = new JSONObject();
public JsonObject getRequestObject() {
JsonObjectBuilder objectBuilder = Json.createObjectBuilder();
try {
requestObject.put(RestMonitoringAppResponseToken.getMbeanNameKey(),
mbeanname);
requestObject.put(RestMonitoringAppResponseToken.getRequestTypeKey(),

objectBuilder.add(RestMonitoringAppResponseToken.getMbeanNameKey(), mbeanname);
objectBuilder.add(RestMonitoringAppResponseToken.getRequestTypeKey(),
requesttype);
} catch (JSONException ex) {
} catch (JsonException ex) {
super.setStatus(Response.Status.INTERNAL_SERVER_ERROR);
}
return requestObject;
return objectBuilder.build();
}

@Override
public Object getValueObject() throws JSONException {
public JsonValue getValueObject() throws JsonException {
try {
MBeanInfo mbeanInfo = delegate.getMBean(mbeanname);
return buildAttributes(mbeanInfo);
Expand All @@ -98,19 +102,19 @@ public Object getValueObject() throws JSONException {
}
}

private JSONObject buildAttributes(MBeanInfo mbean) throws JSONException {
JSONObject attributesObject = new JSONObject();
private JsonObject buildAttributes(MBeanInfo mbean) throws JsonException {
JsonObjectBuilder objectBuilder = Json.createObjectBuilder();
MBeanAttributeInfo[] attributes = mbean.getAttributes();

for (MBeanAttributeInfo attribute : attributes) {
String attributeName = attribute.getName();
MBeanAttributeReadHandler attributeHandler =
new MBeanAttributeReadHandler(delegate, mbeanname,
attributeName);
attributesObject.put(attributeName,
objectBuilder.add(attributeName,
attributeHandler.getValueObject());
}

return attributesObject;
return objectBuilder.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@
import java.io.StringWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.json.Json;
import javax.json.JsonException;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;
import javax.json.JsonValue;
import javax.ws.rs.core.Response;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;

/**
*
Expand All @@ -68,52 +71,53 @@ public ResourceHandler(MBeanServerDelegate delegate) {
}

/**
* Returns a {@link JSONObject} containing the response to the request given
* Returns a {@link JsonObject} containing the response to the request given
* to the implementing class.
* The response is made up of a request object and a value object.
* In some cases the value object is removed in the case of an exception and
* replaced with an error object.
*
* @return The {@link JSONObject} containing the response to the request.
* @return The {@link JsonObject} containing the response to the request.
*/
public JSONObject getResource() {
JSONObject resourceResponse = new JSONObject();
public JsonObject getResource() {
JsonObject resourceResponse = Json.createObjectBuilder().build();
JsonObjectBuilder objectBuilder = Json.createObjectBuilder();
try {
JSONObject requestObject = getRequestObject();
resourceResponse.put(RestMonitoringAppResponseToken.getRequestKey(),
JsonObject requestObject = getRequestObject();
objectBuilder.add(RestMonitoringAppResponseToken.getRequestKey(),
requestObject);

Object valueObject = getValueObject();
resourceResponse.put(RestMonitoringAppResponseToken.getValueKey(),
JsonValue valueObject = getValueObject();
objectBuilder.add(RestMonitoringAppResponseToken.getValueKey(),
valueObject);

setStatus(Response.Status.OK);

if (errorThrown(status)) {
JSONObject traceObject = (JSONObject) resourceResponse
JsonObject traceObject = (JsonObject) resourceResponse
.get(RestMonitoringAppResponseToken.getValueKey());

resourceResponse.put(RestMonitoringAppResponseToken.getStacktraceKey(),
objectBuilder.add(RestMonitoringAppResponseToken.getStacktraceKey(),
traceObject.get(RestMonitoringAppResponseToken.getStacktraceKey()));
resourceResponse.put(RestMonitoringAppResponseToken.getErrorTypeKey(),
objectBuilder.add(RestMonitoringAppResponseToken.getErrorTypeKey(),
traceObject.get(RestMonitoringAppResponseToken.getErrorTypeKey()));
resourceResponse.put(RestMonitoringAppResponseToken.getErrorKey(),
objectBuilder.add(RestMonitoringAppResponseToken.getErrorKey(),
traceObject.get(RestMonitoringAppResponseToken.getErrorKey()));

resourceResponse.remove(RestMonitoringAppResponseToken.getValueKey());
} else {
Long millis = System.currentTimeMillis();
resourceResponse.put(RestMonitoringAppResponseToken.getTimestampKey(),
objectBuilder.add(RestMonitoringAppResponseToken.getTimestampKey(),
millis);
}

int statusCode = status.getStatusCode();
resourceResponse.put(RestMonitoringAppResponseToken.getHttpStatusKey(),
objectBuilder.add(RestMonitoringAppResponseToken.getHttpStatusKey(),
statusCode);
} catch (JSONException ex) {
// @TODO - FANG-6: Properly handle any JSONException caught in the ResourceHandler class.
} catch (JsonException ex) {
// @TODO - FANG-6: Properly handle any JsonException caught in the ResourceHandler class.
// Is this the best way to handle it? Return the response built so far and log the issue.
// Don't exactly want to return a JSON error in the response.
// Don't exactly want to return a Json error in the response.
//
// Options:
// 1. Place each put in it's own try-catch block so that what can be
Expand All @@ -124,56 +128,60 @@ public JSONObject getResource() {
// internal error or something?
Logger.getLogger(ResourceHandler.class.getName()).log(Level.SEVERE, null, ex);
}
return resourceResponse;
return objectBuilder.build();
}

/**
* Returns a {@link JSONObject} that contains values relating to the request.
* Returns a {@link JsonObject} that contains values relating to the request.
*
* @return A {@link JSONObject} containing the value(s) relating to the request..
* @throws JSONException {@inheritDoc}
* @return A {@link JsonObject} containing the value(s) relating to the request..
* @throws JsonException {@inheritDoc}
*/
abstract JSONObject getRequestObject() throws JSONException;
abstract JsonObject getRequestObject() throws JsonException;

/**
* Returns an {@link Object} that contains values relating to the target of
* Returns an {@link JsonValue} that contains values relating to the target of
* the request.
* Typically this is a primitive type or a JSONObject.
* Typically this is a primitive type or a JsonObject.
*
* @return An {@link Object} containing the value(s) relating to the request target.
* @throws JSONException {@inheritDoc}
* @return An {@link JsonValue} containing the value(s) relating to the request target.
* @throws JsonException {@inheritDoc}
*/
abstract Object getValueObject() throws JSONException;
abstract JsonValue getValueObject() throws JsonException;

// If the response status isn't set then will set it
/* If the response status isn't set then will set it
*/
protected void setStatus(Response.Status status) {
if (this.status == null) {
this.status = status;
}
}

// Gets the JSONObject containing information about the exception passed
protected JSONObject getTraceObject(Exception exception) throws JSONException {
JSONObject traceObject = new JSONObject();
/**
* Gets the JsonObject containing information about the exception passed
*/
protected JsonObject getTraceObject(Exception exception) throws JsonException {
JsonObjectBuilder objectBuilder = Json.createObjectBuilder();

StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
exception.printStackTrace(printWriter);

traceObject.put(RestMonitoringAppResponseToken.getStacktraceKey(),
objectBuilder.add(RestMonitoringAppResponseToken.getStacktraceKey(),
stringWriter.toString());

traceObject.put(RestMonitoringAppResponseToken.getErrorTypeKey(),
objectBuilder.add(RestMonitoringAppResponseToken.getErrorTypeKey(),
exception.getClass().getCanonicalName());

traceObject.put(RestMonitoringAppResponseToken.getErrorKey(),
objectBuilder.add(RestMonitoringAppResponseToken.getErrorKey(),
exception.getClass().getCanonicalName() + " : "
+ exception.getMessage());

return traceObject;
return objectBuilder.build();
}

// Returns true if one of the checked response codes is passed to it
/* Returns true if one of the checked response codes is passed to it
*/
private boolean errorThrown(Response.Status status) {
switch (status) {
case NOT_FOUND:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@
import fish.payara.monitoring.rest.app.RestMonitoringAppState;
import fish.payara.monitoring.rest.app.MBeanServerDelegate;
import javax.inject.Singleton;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import javax.json.Json;
import javax.json.JsonException;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;

/**
*
Expand All @@ -58,30 +60,30 @@ public RestMonitoringAppStateHandler(@Singleton MBeanServerDelegate delegate) {
}

@Override
JSONObject getRequestObject() {
JSONObject requestObject = new JSONObject();
JsonObject getRequestObject() {
JsonObjectBuilder objectBuilder = Json.createObjectBuilder();
try {
requestObject.put(RestMonitoringAppResponseToken.getRequestTypeKey(),
objectBuilder.add(RestMonitoringAppResponseToken.getRequestTypeKey(),
RestMonitoringAppResponseToken.getVersionRequestToken());
return requestObject;
} catch (JSONException ex) {
return requestObject;
return objectBuilder.build();
} catch (JsonException ex) {
return objectBuilder.build();
}
}

@Override
JSONObject getValueObject() {
JSONObject valueObject = new JSONObject();
JsonObject getValueObject() {
JsonObjectBuilder objectBuilder = Json.createObjectBuilder();
try {
valueObject.put(RestMonitoringAppState.getAgentNameKey(),
objectBuilder.add(RestMonitoringAppState.getAgentNameKey(),
RestMonitoringAppState.getAgentName());
valueObject.put(RestMonitoringAppState.getAgentVersionKey(),
objectBuilder.add(RestMonitoringAppState.getAgentVersionKey(),
RestMonitoringAppState.getAgentVersion());
valueObject.put(RestMonitoringAppState.getAgentTypeKey(),
objectBuilder.add(RestMonitoringAppState.getAgentTypeKey(),
RestMonitoringAppState.getAgentType());
return valueObject;
} catch (JSONException ex) {
return valueObject;
return objectBuilder.build();
} catch (JsonException ex) {
return objectBuilder.build();
}
}

Expand Down
Loading

0 comments on commit f5581c4

Please sign in to comment.