public static void fromObjectToReponse( HttpServletResponse response, Object clazz) { response.setStatus( HttpServletResponse.SC_ACCEPTED ); response.setContentType( "application/json" ); PrintWriter jsonResponse; try { jsonResponse = response.getWriter(); jsonResponse.print( toJson( clazz ) ); jsonResponse.flush(); } catch ( IOException e ) { e.printStackTrace(); } } }
@Override public RecaptchaResponse verifyRecaptcha( String key, String remoteIp ) throws IOException { MultiValueMap<String, String> params = new LinkedMultiValueMap<>(); params.add( "secret", (String) systemSettingManager.getSystemSetting( SettingKey.RECAPTCHA_SECRET ) ); params.add( "response", key ); params.add( "remoteip", remoteIp ); String result = restTemplate.postForObject( RECAPTCHA_VERIFY_URL, params, String.class ); log.info( "Recaptcha result: " + result ); return JacksonUtils.fromJson( result, RecaptchaResponse.class ); }
@Override public <T> void addValue( String namespace, String key, T object ) { String value = JacksonUtils.toJson( object ); KeyJsonValue keyJsonValue = new KeyJsonValue( namespace, key, value, false ); keyJsonValueStore.save( keyJsonValue ); }
@Override public <T> T getValue( String namespace, String key, Class<T> clazz ) { KeyJsonValue value = getKeyJsonValue( namespace, key ); if ( value == null || value.getJbPlainValue() == null ) { return null; } return JacksonUtils.fromJson( value.getJbPlainValue(), clazz ); }
@Override public <T> void updateValue( String namespace, String key, T object ) { KeyJsonValue keyJsonValue = getKeyJsonValue( namespace, key ); if ( keyJsonValue == null ) { throw new IllegalStateException( String.format( "No object found for namespace '%s' and key '%s'", namespace, key ) ); } String value = JacksonUtils.toJson( object ); keyJsonValue.setValue( value ); keyJsonValueStore.update( keyJsonValue ); } }