Skip to content

Commit

Permalink
Moving from Gson to internal Json converter in DisplayHelpServlet
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Feb 28, 2018
1 parent f88d011 commit 9537053
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public Method getWriteMethod() {
return writeMethod;
}

public static SimplePropertyDescriptor[] getPropertyDescriptors(Class<? extends Object> clazz) {
public static SimplePropertyDescriptor[] getPropertyDescriptors(Class<?> clazz) {
HashMap<String, SimplePropertyDescriptor> properties = new HashMap<>();
for (Method m : clazz.getMethods()) {
String methodName = m.getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,18 @@
package org.openqa.grid.web.servlet;

import com.google.common.io.ByteStreams;
import com.google.gson.GsonBuilder;

import org.openqa.grid.common.GridRole;
import org.openqa.grid.web.servlet.console.ConsoleServlet;
import org.openqa.selenium.internal.BuildInfo;
import org.openqa.selenium.json.Json;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.stream.Collectors;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Expand All @@ -52,19 +51,31 @@ private final class DisplayHelpServletConfig {
String version;
String type;
String consoleLink;

public String getVersion() {
return version;
}

public String getType() {
return type;
}

public String getConsoleLink() {
return consoleLink;
}
}

private final DisplayHelpServletConfig servletConfig = new DisplayHelpServletConfig();

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
throws IOException {
process(request, response);
}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
throws IOException {
process(request, response);
}

Expand Down Expand Up @@ -93,7 +104,7 @@ protected void process(HttpServletRequest request, HttpServletResponse response)
if (in == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
} else {
final String json = new GsonBuilder().serializeNulls().create().toJson(servletConfig);
final String json = new Json().toJson(servletConfig);
final String jsonUtf8 = new String(json.getBytes(), "UTF-8");
final String htmlTemplate =
new BufferedReader(new InputStreamReader(in, "UTF-8")).lines().collect(Collectors.joining("\n"));
Expand Down Expand Up @@ -156,8 +167,7 @@ private String getInitParameter(String param, String defaultValue) {
return value;
}

private InputStream getResourceInputStream(String resource)
throws IOException {
private InputStream getResourceInputStream(String resource) {
InputStream in = Thread.currentThread().getContextClassLoader()
.getResourceAsStream(HELPER_SERVLET_RESOURCE_PATH + resource);
if (in == null) {
Expand Down
15 changes: 7 additions & 8 deletions java/server/test/org/openqa/testing/FakeHttpServletResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.openqa.testing;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Collection;
Expand Down Expand Up @@ -81,15 +80,15 @@ public String encodeRedirectUrl(String s) {
throw new UnsupportedOperationException();
}

public void sendError(int i, String s) throws IOException {
public void sendError(int i, String s) {
throw new UnsupportedOperationException();
}

public void sendError(int i) throws IOException {
public void sendError(int i) {
throw new UnsupportedOperationException();
}

public void sendRedirect(String s) throws IOException {
public void sendRedirect(String s) {
setStatus(SC_SEE_OTHER);
setHeader("Location", s);
}
Expand All @@ -110,11 +109,11 @@ public String getContentType() {
return getHeader("Content-Type");
}

public ServletOutputStream getOutputStream() throws IOException {
public ServletOutputStream getOutputStream() {
return servletOutputStream;
}

public PrintWriter getWriter() throws IOException {
public PrintWriter getWriter() {
return printWriter;
}

Expand Down Expand Up @@ -144,7 +143,7 @@ public int getBufferSize() {
throw new UnsupportedOperationException();
}

public void flushBuffer() throws IOException {
public void flushBuffer() {
// no-op
}

Expand Down Expand Up @@ -177,7 +176,7 @@ private StringServletOutputStream(StringWriter stringWriter) {
}

@Override
public void write(int i) throws IOException {
public void write(int i) {
printWriter.write(i);
}

Expand Down

0 comments on commit 9537053

Please sign in to comment.