5151 * @author Kenan Klisura
5252 */
5353public class ChromeServiceImpl implements ChromeService {
54+
5455 public static final String ABOUT_BLANK_PAGE = "about:blank" ;
5556
5657 private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper ();
@@ -74,8 +75,8 @@ public class ChromeServiceImpl implements ChromeService {
7475 /**
7576 * Creates a new chrome service given a host, port and web service socket factory.
7677 *
77- * @param host Chrome host.
78- * @param port Chrome debugging port.
78+ * @param host Chrome host.
79+ * @param port Chrome debugging port.
7980 * @param webSocketServiceFactory Web socket service factory.
8081 */
8182 public ChromeServiceImpl (String host , int port , WebSocketServiceFactory webSocketServiceFactory ) {
@@ -106,7 +107,7 @@ public ChromeServiceImpl(int port) {
106107 /**
107108 * Creates new chrome service given a port. Host is assumed to be localhost.
108109 *
109- * @param port Chrome debugging port.
110+ * @param port Chrome debugging port.
110111 * @param webSocketServiceFactory Web socket service factory.
111112 */
112113 public ChromeServiceImpl (int port , WebSocketServiceFactory webSocketServiceFactory ) {
@@ -134,7 +135,7 @@ public ChromeTab createTab() throws ChromeServiceException {
134135
135136 @ Override
136137 public ChromeTab createTab (String tab ) throws ChromeServiceException {
137- return request ( ChromeTab .class , "http://%s:%d/%s?%s" , host , port , CREATE_TAB , tab );
138+ return requestWithMethod ( "PUT" , ChromeTab .class , "http://%s:%d/%s?%s" , host , port , CREATE_TAB , tab );
138139 }
139140
140141 @ Override
@@ -185,8 +186,8 @@ public synchronized ChromeDevToolsService createDevToolsService(
185186 ChromeDevToolsServiceImpl chromeDevToolsService =
186187 ProxyUtils .createProxyFromAbstract (
187188 ChromeDevToolsServiceImpl .class ,
188- new Class [] {WebSocketService .class , ChromeDevToolsServiceConfiguration .class },
189- new Object [] {webSocketService , chromeDevToolsServiceConfiguration },
189+ new Class []{WebSocketService .class , ChromeDevToolsServiceConfiguration .class },
190+ new Object []{webSocketService , chromeDevToolsServiceConfiguration },
190191 (unused , method , args ) ->
191192 commandsCache .computeIfAbsent (
192193 method ,
@@ -255,21 +256,27 @@ private void cacheChromeDevToolsService(
255256 * Sends a request and parses json response as type T.
256257 *
257258 * @param responseType Resulting class type.
258- * @param path Path with optional params similar to String.formats params.
259- * @param params Path params.
260- * @param <T> Type of response type.
259+ * @param path Path with optional params similar to String.formats params.
260+ * @param params Path params.
261+ * @param <T> Type of response type.
261262 * @return Response object.
262263 * @throws ChromeServiceException If sending request fails due to any reason.
263264 */
264265 private static <T > T request (Class <T > responseType , String path , Object ... params )
265266 throws ChromeServiceException {
267+ return requestWithMethod ("GET" , responseType , path , params );
268+ }
269+
270+ private static <T > T requestWithMethod (
271+ String method , Class <T > responseType , String path , Object ... params )
272+ throws ChromeServiceException {
266273 HttpURLConnection connection = null ;
267274 InputStream inputStream = null ;
268275
269276 try {
270277 URL uri = new URL (String .format (path , params ));
271278 connection = (HttpURLConnection ) uri .openConnection ();
272- connection .setRequestMethod ("PUT" );
279+ connection .setRequestMethod (method );
273280
274281 int responseCode = connection .getResponseCode ();
275282 if (HttpURLConnection .HTTP_OK == responseCode ) {
0 commit comments