@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ViewGroup mView = (ViewGroup) inflater.inflate(R.layout.fragment_main, container, false); btnFetch = (Button) mView.findViewById(R.id.btnSearch); txtSearch = (EditText) mView.findViewById(R.id.txtSearch); btnFetch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { JsonHandler handler = new JsonHandler(); handler.fetchImages(txtSearch.getText().toString()); } }); return mView; }
@Override public HandlerResponse<String> call() { return jsonHandler.apply(jsonRequest); } });
@Override public void setServerRpcMetadata(RpcMetadataResponse metadata) { // Set the metadata for the normal service calls service.setRpcMetadata(metadata); // Also add it to the handler to include with exceptions jsonHandler.setRpcMetadata(metadata); }
@Test public void testExecuteRequestWithNumberParameter() { final List<TypedValue> expectedParameterValues = new ArrayList<>(); final Service service = new ParameterValuesCheckingService(expectedParameterValues); final JsonService jsonService = new LocalJsonService(service); final JsonHandler jsonHandler = new JsonHandler(jsonService, NoopMetricsSystem.getInstance()); final List<TypedValue> parameterValues = Arrays.asList( TypedValue.create("NUMBER", new BigDecimal("123")), TypedValue.create("STRING", "calcite")); jsonHandler.apply( "{'request':'execute'," + "'parameterValues':[{'type':'NUMBER','value':123}," + "{'type':'STRING','value':'calcite'}]}"); assertThat(expectedParameterValues.size(), is(2)); assertThat(expectedParameterValues.get(0), is(parameterValues.get(0))); assertThat(expectedParameterValues.get(1), is(parameterValues.get(1))); } }
jsonResponse = jsonHandler.apply(jsonRequest); jsonResponse = jsonHandler.unauthenticatedErrorResponse(e); } catch (RemoteUserDisallowedException e) { LOG.debug("Remote user is not authorized", e); jsonResponse = jsonHandler.unauthorizedErrorResponse(e); } catch (Exception e) { LOG.debug("Error invoking request from {}", baseRequest.getRemoteAddr(), e); jsonResponse = jsonHandler.convertToErrorResponse(e);
public AvaticaJsonHandler(Service service, MetricsSystem metrics, AvaticaServerConfiguration serverConfig) { this.service = Objects.requireNonNull(service); this.metrics = Objects.requireNonNull(metrics); // Avatica doesn't have a Guava dependency this.jsonHandler = new JsonHandler(service, this.metrics); // Metrics this.requestTimer = this.metrics.getTimer( concat(AvaticaJsonHandler.class, MetricsAwareAvaticaHandler.REQUEST_TIMER_NAME)); this.threadLocalBuffer = new ThreadLocal<UnsynchronizedBuffer>() { @Override public UnsynchronizedBuffer initialValue() { return new UnsynchronizedBuffer(); } }; this.serverConfig = serverConfig; }
@Test public void testExecuteRequestWithNumberParameter() { final List<TypedValue> expectedParameterValues = new ArrayList<>(); final Service service = new ParameterValuesCheckingService(expectedParameterValues); final JsonService jsonService = new LocalJsonService(service); final JsonHandler jsonHandler = new JsonHandler(jsonService, NoopMetricsSystem.getInstance()); final List<TypedValue> parameterValues = Arrays.asList( TypedValue.create("NUMBER", new BigDecimal("123")), TypedValue.create("STRING", "calcite")); jsonHandler.apply( "{'request':'execute'," + "'parameterValues':[{'type':'NUMBER','value':123}," + "{'type':'STRING','value':'calcite'}]}"); assertThat(expectedParameterValues.size(), is(2)); assertThat(expectedParameterValues.get(0), is(parameterValues.get(0))); assertThat(expectedParameterValues.get(1), is(parameterValues.get(1))); } }
jsonResponse = jsonHandler.apply(jsonRequest); jsonResponse = jsonHandler.unauthenticatedErrorResponse(e); } catch (RemoteUserDisallowedException e) { LOG.debug("Remote user is not authorized", e); jsonResponse = jsonHandler.unauthorizedErrorResponse(e); } catch (Exception e) { LOG.debug("Error invoking request from {}", baseRequest.getRemoteAddr(), e); jsonResponse = jsonHandler.convertToErrorResponse(e);
public AvaticaJsonHandler(Service service, MetricsSystem metrics, AvaticaServerConfiguration serverConfig) { this.service = Objects.requireNonNull(service); this.metrics = Objects.requireNonNull(metrics); // Avatica doesn't have a Guava dependency this.jsonHandler = new JsonHandler(service, this.metrics); // Metrics this.requestTimer = this.metrics.getTimer( concat(AvaticaJsonHandler.class, MetricsAwareAvaticaHandler.REQUEST_TIMER_NAME)); this.threadLocalBuffer = new ThreadLocal<UnsynchronizedBuffer>() { @Override public UnsynchronizedBuffer initialValue() { return new UnsynchronizedBuffer(); } }; this.serverConfig = serverConfig; }
@Test public void testExecuteRequestWithNumberParameter() { final List<TypedValue> expectedParameterValues = new ArrayList<>(); final Service service = new ParameterValuesCheckingService(expectedParameterValues); final JsonService jsonService = new LocalJsonService(service); final JsonHandler jsonHandler = new JsonHandler(jsonService); final List<TypedValue> parameterValues = Arrays.asList( TypedValue.create("NUMBER", new BigDecimal("123")), TypedValue.create("STRING", "calcite")); jsonHandler.apply( "{'request':'execute'," + "'parameterValues':[{'type':'NUMBER','value':123}," + "{'type':'STRING','value':'calcite'}]}"); assertThat(expectedParameterValues.size(), is(2)); assertThat(expectedParameterValues.get(0), is(parameterValues.get(0))); assertThat(expectedParameterValues.get(1), is(parameterValues.get(1))); } }
@Override public HandlerResponse<String> call() { return jsonHandler.apply(jsonRequest); } });
@Override public void setServerRpcMetadata(RpcMetadataResponse metadata) { // Set the metadata for the normal service calls service.setRpcMetadata(metadata); // Also add it to the handler to include with exceptions jsonHandler.setRpcMetadata(metadata); }