I’m trying to connect to a Spring RESTful service on the same server where my webapp is running.
I’d like to use a «relative» path because it could be installed on several environments (localhost, test, production) but I get the error message: URI is not absolute
.
How can I call a service running on another webapp on the same server?
My code is like following:
final RestTemplate restTemplate = new RestTemplate();
URI uri;
try {
String url = "app2/myservice?par=1";
uri = new URI(url);
String result = restTemplate.getForObject(uri, String.class);
System.out.println(result);
} catch (URISyntaxException e) {
logger.error(e.getMessage());
}
Thanks.
Update:
I solved it by getting the host, port, etc… from the request
, could it be a right and elegant solution? This’s my actual simplified code:
String scheme = request.getScheme();
String userInfo = request.getRemoteUser();
String host = request.getLocalAddr();
int port = request.getLocalPort();
String path = "/app2/myservice";
String query = "par=1";
URI uri = new URI(scheme, userInfo, host, port, path, query, null);
boolean isOK = restTemplate.getForObject(uri, Boolean.class);
if (isOK) {
System.out.println("Is OK");
}
java.lang. IllegalArgumentException: URI is not absolute occurs when a relative url is used to identify the resource. In the spring boot RestTemplate, the complete url will be used to invoke the rest call. If the relative url is used in the restful call, the java exception java.lang. IllegalArgumentException: URI is not absolute would be thrown.
A resource can be invoked in java using a complete url. If the relative url is used, the relative url can not be converted to an absolute url. Therefore, the resource can’t be identified. The exception URI is not absolute will be thrown.
Exception
The exception java.lang. IllegalArgumentException: URI is not absolute stack trace will be shown as below in the spring boot. The root cause will be thrown from the java.
2020-10-06 17:15:08.417 ERROR 20534 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalArgumentException: URI is not absolute] with root cause
java.lang.IllegalArgumentException: URI is not absolute
at java.net.URI.toURL(URI.java:1088) ~[na:1.8.0_101]
at org.springframework.http.client.SimpleClientHttpRequestFactory.createRequest(SimpleClientHttpRequestFactory.java:145) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.http.client.support.HttpAccessor.createRequest(HttpAccessor.java:124) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:735) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
How to recreate this exception
If a relative url is sent to a rest call in the RestTemplate, a relative url can not be converted to an absolute url. This is why the exception “java.lang.IllegalArgumentException: URI is not absolute” would be thrown. In the “/getstudent” rest call invokes another rest call using the relative url “/student”.
package com.yawintutor;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
@RestController
public class TestController {
@GetMapping(value = "/student")
public Student getStudent() {
return new Student(1, "name1");
}
@GetMapping(value = "/getstudent")
private Student getStudentObject(HttpServletRequest request)
{
String uri = "/student";
RestTemplate restTemplate = new RestTemplate();
Student result = restTemplate.getForObject(uri, Student.class);
return result;
}
}
Solution 1
If a relative url is sent to a rest call in the RestTemplate, the relative url has to be changed to an absolute url. The RestTemplate will use the absolute url to identify the resource. In the example below, the complete url “http:/localhost:8080/student” is used to invoke a rest call using RestTemplate.
package com.yawintutor;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
@RestController
public class TestController {
@GetMapping(value = "/student")
public Student getStudent() {
return new Student(1, "name1");
}
@GetMapping(value = "/getstudent")
private Student getStudentObject(HttpServletRequest request)
{
String uri = "http://localhost:8080/student";
RestTemplate restTemplate = new RestTemplate();
Student result = restTemplate.getForObject(uri, Student.class);
return result;
}
}
Solution 2
If you are using a relative url in a rest call that refers to the same tomcat server, use the HTTPRequest object to construct a complete url before submitting it to the rest template. The example below demonstrates how to create a complete url from the relative url to the same server.
package com.yawintutor;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
@RestController
public class TestController {
@GetMapping(value = "/student")
public Student getStudent() {
return new Student(1, "name1");
}
@GetMapping(value = "/getstudent")
private Student getStudentObject(HttpServletRequest request)
{
String requestURL = request.getRequestURL().substring(0, request.getRequestURL().indexOf(request.getRequestURI()));
String uri = requestURL + "/student";
RestTemplate restTemplate = new RestTemplate();
Student result = restTemplate.getForObject(uri, Student.class);
return result;
}
}
Solution 3
If the relative url is used in RestTemplete that must be referred to an external host server, the external host server url can be externalized in the application.properties files. The properties can be added to the relative url as shown in the example below.
application.properties
external.server.url=http://www.yawintutor.com
TestController.java
package com.yawintutor;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
@RestController
public class TestController {
@Value("${external.server.url}")
String externalServerURL;
@GetMapping(value = "/student")
public Student getStudent() {
return new Student(1, "name1");
}
@GetMapping(value = "/getstudent")
private Student getStudentObject()
{
String uri = externalServerURL + "/student";
RestTemplate restTemplate = new RestTemplate();
Student result = restTemplate.getForObject(uri, Student.class);
return result;
}
}
When working with Java, you might encounter the `java.lang.IllegalArgumentException: URI is not absolute` error. This error occurs when you are trying to create a `URI` object with a string that doesn't represent an absolute URI. This comprehensive guide will help you understand the causes of this error and provide step-by-step solutions to fix it.
## Table of Contents
1. [Understanding URIs](#understanding-uris)
2. [Causes of the Error](#causes-of-the-error)
3. [Solutions](#solutions)
1. [Using Absolute URIs](#using-absolute-uris)
2. [Handling Relative URIs](#handling-relative-uris)
4. [FAQ](#faq)
5. [Related Links](#related-links)
## Understanding URIs
A Uniform Resource Identifier (URI) is a string of characters that identifies a name or a resource on the internet. URIs can be of two types:
1. Absolute URI: Contains a scheme (such as `http`, `https`, `file`, etc.) followed by a colon and a hierarchical part.
Example: `https://example.com/test`
2. Relative URI: Doesn't contain a scheme and is usually relative to a base URI.
Example: `/test`
Learn more about URIs in the [official Java URI documentation](https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java.base/java/net/URI.html).
## Causes of the Error
The `java.lang.IllegalArgumentException: URI is not absolute` error occurs when you try to create a `URI` object with a string that doesn't represent an absolute URI.
For example, the following code will throw an error:
```java
import java.net.URI;
public class Main {
public static void main(String[] args) {
String uriString = "/test";
URI uri = URI.create(uriString);
}
}
Solutions
Using Absolute URIs
Ensure that you are using an absolute URI when creating a URI
object. An absolute URI contains the scheme and the hierarchical part.
Example:
import java.net.URI;
public class Main {
public static void main(String[] args) {
String uriString = "https://example.com/test";
URI uri = URI.create(uriString);
}
}
Handling Relative URIs
If you need to work with relative URIs, you can use the java.net.URL
class to handle them. The URL
class allows you to specify a base URL to resolve the relative URI against.
Example:
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL baseUrl = new URL("https://example.com");
URL relativeUrl = new URL(baseUrl, "/test");
} catch (Exception e) {
System.err.println(e);
}
}
}
FAQ
Q1: Can I use the java.net.URI
class to handle relative URIs?
No, the java.net.URI
class doesn’t support handling relative URIs. You need to use the java.net.URL
class to handle relative URIs.
Q2: How can I check if a URI is absolute in Java?
You can use the isAbsolute()
method of the java.net.URI
class to check if a URI is absolute.
Example:
URI uri = new URI("https://example.com/test");
System.out.println(uri.isAbsolute()); // Output: true
Q3: How can I convert a relative URI to an absolute URI in Java?
You can use the java.net.URL
class to convert a relative URI to an absolute URI.
Example:
URL baseUrl = new URL("https://example.com");
URL relativeUrl = new URL(baseUrl, "/test");
URI absoluteUri = relativeUrl.toURI();
Q4: How can I resolve a relative URI against a base URI in Java?
You can use the resolve()
method of the java.net.URI
class to resolve a relative URI against a base URI.
Example:
URI baseUri = new URI("https://example.com");
URI relativeUri = new URI("/test");
URI resolvedUri = baseUri.resolve(relativeUri);
Q5: Can I create a java.net.URI
object from a java.net.URL
object?
Yes, you can create a java.net.URI
object from a java.net.URL
object using the toURI()
method.
Example:
URL url = new URL("https://example.com/test");
URI uri = url.toURI();
- Java URI Documentation
- Java URL Documentation
- URI Syntax
«`
* Trim extraneous whitespace from base64-encoded aia The base64 utility on macOS writes a carriage return at the end of the base64 encoded string. When App Inventor attempts to read a project template with this extra whitespace, it causes an exception to be thrown since the server's decode() implementation expects a string with a length multiple of 4. This change switches to using decodeLines(), which ignores whitespace. Change-Id: I34f6c7b1ef1fcd12b82eab67c98ffb422bbf5894 * Stop propagation of mouse events on warning toggle button In Firefox, Blockly seems to handle mouse events differently than in Chrome. This generally isn't a problem, but it affects the warning indicator toggle button. Blockly starts a drag at the mousedown but then we never will see a mouseup or click event. This change registers a mouse down listener on the toggle to stop propagation to Blockly so that the warning indicator can receive the click event. We also update to include support for touch events on the toggle button to support App Inventor on tablets. Change-Id: Iba4e1e274dd3eac86939bb122a1c7f15cc7d41f9 * Changes for Java 8 and the Buildservers We properly close the HttpURLConnection between App Engine (the App Inventor server) and the buildserver infrastructure. If we don’t App Engine sends RST packets which causes issues for some buildserver infrastructures. Also limit project size to 10MB up-front (rather then after an IOException is thrown). Add reporting to the buildserver status page to report the number of Java threads. Change-Id: I934df537dfe9419f5f8effafe80f0a2460091cdd * Fix GeoJSON Source processing in MockFeatureCollection (mit-cml#1248) If there were multiple features of the same type in a GeoJSON file and the file did not include names for the components, one would receive multiple components with the same name (e.g., LineString1). LineString processing was also broken, resulting in a coordinate string without values. Setting the Source to None... would remove the components but not clear the features off the map. This commit addresses three changes: 1. Refactors how naming of map features is handled during the loading of GeoJSON into a MockFeatureCollection so that each component has a unique name. 2. It corrects handling of LineString coordinates when the line string is not part of a MultiLineString construct. 3. It cleans up how features are removed when a feature collection is cleared. Change-Id: Iccbcab65989169ab730239b8915b62ca6b6f636c * Fix clearing of MockFeatureCollection when Source is None Change-Id: Icf74d804689dcaa323bac3b4d1f0400631b74a5e * Remove BOM from GeoJSON files While GeoJSON files should not have a BOM per the spec, sometimes systems will include the UTF byte order marker (BOM). This breaks the JSON parsing on both in the web client and app. This change will check for and strip out the BOM before passing the JSON string along for further processing. Change-Id: I9452871e19b3985f9beea48b30cf49b60e4835cb * Bugfix to AARLibrary Some aar files do not have an explicit directory entry for every object. Make sure we create the needed directories. Change-Id: Ic79d8852b6cc48f2399794c4087507e8f9c3bbaf * Reset min size of button with images (mit-cml#1398) * Reset min size of button with images If someone sets an image on a button in a non-Classic theme, the minimum width/height settings in the theme will force the button to sometimes resize the image arbitrarily to fit the minimum constraints rather than allowing the button to assume the shape of the image like it would in the Classic theme. This fix sets the minimum size of a button to 0x0 so that it can take on the image size regardless of what the platform's default dimensions for a button. Change-Id: I590eb1bec860cda221e821c663c03c5cd81a65fe * Replace use of isRenderingOn with Blockly event management When the 2017 Blockly update was done, it used isRenderingOn to determine when to position and render the blocks. This was to optimize the interaction between the load/upgrade process and workspace resizes. However, in rare instances it seems to result in blocks not being placed correctly. This change removes the special handling of upgrading. Instead, it disables and enables the Blockly event system during a load/upgrade operation. At the end of the upgrade process (if needed), it will also force a save of the blocks workspace. Fixes mit-cml#1071 Change-Id: I6bec41dd67bc6371e794e93850ea1455b9acf8c7 * Force MockCircle default position to (0, 0) Fixes mit-cml#1379 Change-Id: I2682c4b12806e13a78524fce2d47293d46123f93 * Make annotation processors target Java 7 Change-Id: Ie2ae31c90304d6278541f22513adfcf731f999a0 * Restore button ripple effect for material theme phones Fixes mit-cml#1318 * Enable debug panel logging only when admin Projects with many components may cause a large number calls to OdeLog.log, which appends messages by converting the debugger panel's content to HTML and back. This change enables logging only if the user is an Admin, since only Admins have access to the debugger panel to begin with. This reduces the number of cycles spent on logging for the vast majority of App Inventor users. We also optimize how the log is constructed so that users with Admin rights have reasonable performance on complicated projects. Change-Id: I62cc2af0e421d3f5fda668f72de62c1895414092 * Numerous Changes in order to target Android API 26 Set target api to 26 which corresponds to Android verison 8.0 (Oreo). Numerous changes where required in order to target api 26 while still having minSdk set to 7. As a trade-off, some “theme” selections will not be available on older devices, but the apps packaged with this code will operate on API 7 (Android 2.1). Author: Evan W. Patton <ewpatton@mit.edu> Author: Jeffrey I. Schiller <jis@mit.edu> Change-Id: Ia307c080072c76d4699550892c99a07b65d3465e * Communicate with the Companion with WebRTC Add support for using WebRTC to communicate between the browser and the Companion. While using WebRTC assets (images, sounds, etc.) are downloaded directly to the Companion from the MIT App Inventor server without being redirected through the user’s browser. By supporting WebRTC we pave the way for offering MIT App Inventor over https. The current HTTP based communications system used today (without WebRTC) prohibits us from using https for MIT App Inventor itself. This version of code supports both the new WebRTC approach as well as the pre-WebRTC approach both within the MIT App Inventor client (browser) and the Companion. The new Companion will use WebRTC by default, but can be told to use the HTTP based system (called a “Legacy Connection”) by checking a box on the Companion home screen. We will have to remove HTTP (Legacy) support prior to serving MIT App Inventor over https. Change-Id: Ib7b2db4261f2c852a7593b7a7b32b7356ff8cb6c * Update Companion Version to 2.48 Change-Id: Ic1a9060e2664a9709267e6dc3a36116f79ecca49 * Fix null pointer when logging before user info available Change-Id: Ie39c3a9e0e35c58a97a9307db8cd31a086e602b5 * Fix GeoJSON parsing in MockFeatureCollection Change-Id: Ifd5cd24c006bac1acc996fcb7d3763c58c54dd84 * Make Backpack open in Firefox Change-Id: If360e42e1fc497b7cdd5ffdc0756513ade51af14 * Ensure connections added to ConnectionDB on load Change-Id: Ia29c8c4ed94486098c069b33298b1c66f59d6dde * Fix connection DB bug when workspace contains blocks with errors Change-Id: I47f76f80ac48b37f2fb9bc82c174021fb918da0f * Stop resetting list of connections when errors occur Change-Id: I0377e3c1958885587d1a2a6336ec9c9b30e7c7cb * Fix processing of // in File and add unit tests Fixes mit-cml#1457 Change-Id: I73ff292d87e8ba22a5900eac774d8ae576f05ef2 * Fix handling of Map.ZoomLevel when animating changes Change-Id: If652e6759e95e47884a1324f8dfd203d8b15e65a * Fix PlayApp build on Windows due to wrong slash Change-Id: Idbd09280429ee9a786a4c476224fcae0e69f7e6c * Fix permissions handling on older Android versions Change-Id: If93a3e452908781c35e577c5d72df88eb028ade8 * Fix backpack icon state with multiple screens Change-Id: Ib55f66b4b15aea0ca2889916d8bb76dda9f3fa70 * Implement versionName and dateBuilt annotation fields This change adds two new fields toe @DesignerComponent. The first is a versionName field so that extensions can display custom version names rather than the version number. This can be used to mark an extension build as beta or a release candidate, for example. The second change is a dateBuilt field that is populated by ComponentProcessor at compile time. This is useful for knowing when an extension is compiled. Both pieces of information appear in the component help widget, and version name is preferred over version if provided. Change-Id: I12c97c9c0a3b18abd64a539f1c5072b975d47d14 * Update Companion Version to 2.49 Change-Id: I882136070e9d651a5acdffd26fdf8c2d4cb310d1 * Patch Blockly core to fix extension blocks in Backpack Change-Id: I6d4299fc43c8d3e4ea17053af950b36906f4ef39 * Chunk large Messages to the Companion WebRTC can only safely send messages of 16K. So we will only send up to 8K characters (ok, a margin of safety). Most projects do not need to send YAIL forms larger then this, but a few do. To “chunk” the code into smaller pieces would normally require changes both on the browser side and the Companion side. However we wish to avoid changing the Companion at this time. So instead, we break the large YAIL forms into smaller YAIL forms that can each be evaled on the device correctly. Change-Id: I865e39cad3c55ea35b2a56582d50136f8303e90e * Added context menu items to show and hide all comments This commit adds two new options to the block editor's context menu to show and hide all the comments on the workspace. Resolves mit-cml#1422 * Add two css styles to textarea * Align labeled text boxes in the middle * Add bitwise operator blocks Added bitwise-and. bitwise-or, and bitwise-xor Math blocks. * Implement scale bar for Map Change-Id: I8824cde5d7481a6349e7604dd97a372b67abc7dc * Add ScaleUnits property to control scale unit system Change-Id: I8638eca2fe11daf4ad353b8e7fad4e25ee7ca496 * Bump YOUNG_ANDROID_VERSION Change-Id: I58c4b564491185a15fd8900989866309775838aa * Make removeDupes run in linear time In the previous version, removeDupes used Array.splice, which ends up moving the end of the array up in O(n) time, and makes the loop effectively O(n^2). This version uses a dictionary for bookkeeping so that duplicates can be removed in linear time. Change-Id: I78e23b97e9cc932ee653823674fcc19eb90be342 * Implement upgrader for Map version 5 Change-Id: I65db61ca7fa1f9652e84c814208f333f331f5831 * Update testing R classes to include SDK 26 resources Change-Id: I62cf1eb54cb627620f7164263ff206fa2adda38e * Extract SDK 26 resources for testing Change-Id: I849f9fefe7db94e106d0ee2e2883112aa055754e * Fix default background color on SDKs prior to 14 Change-Id: I46562b4a2668303862940456bec490fe6c757bdc * Updates HELPURL links so that all HELP context menu options should work. (mit-cml#1501) * Updates HELPURL links so that all HELP context menu options should work. * Add HELPURLs for Maps components Also made whitespace in METHODS_HELPURLS match the rest of the document Change-Id: I5044ceb07befa2db74590bd00de2b4f1cba70b9c * Allow for Any Marker, LineString, and Polygon with Maps When one dynamically loads map content from the web, one might want to manipulate that content. To do that today, you must add one of each of the relevant types to a Map and make them invisible so that the "Any ..." tree items are shown. This change makes it so that as long as the Map exists it will add the any component options for Marker (Point), LineString, and Polygon components. Change-Id: Ifb6837be89231c7f713a140318858da366113c21 * Update Companion Version to 2.50 Change-Id: I627e10b911c013482e2dfa153f4aedf341733942 * Fix HELPURL for Screen component selector block * Added instructions for combining DatePicker and TimePicker Instants Also changed related anchor links to relative links Change-Id: I6433975f0055a29a86843a1ba32e6c0f6a9513e8 * Provide Deprecation Warning for FusiontablesControl Google will be turning off Fusion Tables on December 3, 2019. This change provides a warning when a FusiontablesControl is dragged into a project. Change-Id: I275ab12eeb664252a312602598afab94ef5c52c3 * Documentation Updates * Make help for neg block match the actual neg block Issue #mit-cml#1368 * Refine TinyDB documentation * Fix link for tinywebdb server * Add TinyDB namespace documentation Change-Id: I7c844ce85ada92ab63f46d747ac1d7782506bfa1 * Fix error 1101 on Android versions before Nougat (mit-cml#1526) Installing a package via the QR code scanner fails on Android versions before SDK 24. The issue is that we switched to using content: URIs, which is required on SDK 24+, but this fails to resolve the package installer activity on SDK < 24. This commit adds a helper method for constructing the correct URI based on the device's SDK version. Change-Id: Ieaec37b79d6189f75535b5a9be4d0f38b756e63a * Simplify javadoc classpath (mit-cml#1495) Change-Id: I09c53561646b6172fd85746e54b08db612bbbe95 * Update README.md for update from Java 7 to Java 8 Change-Id: I98cb72ed416705d43228525b7196a86f889fe970 * Fix for WebRTC on Safari Use the “urls” property of ICEServer instead of the deprecated “url” property. Change-Id: I391f06eaffd26261a7a106e9fb35eedf2e0d84ee * Ensure Polygon Points and HolePoints invalidate map view Change-Id: I35b143a3dbe3aecdc6c57352468c73e9baf40b72 * Create a Connection Progress Bar (mit-cml#1534) WebRTC Connections can take a while to negotiate. This change gives the user some feedback while negotiation is taking place. We remove the ProgressBarDialog functionality from AssetManager and place it in a new module which is called from AssetManager and from replmgr.js. This permits us to put up the progress dialog at connection attempt time instead of at asset download time. Change-Id: I28772eb92a49b8ed2aa9af9ab84b1ea10d915bcc * Fix mapview invalidation when Marker visibility changed Change-Id: Iea7872a0896e39c30353cd89d950c6d3779370bf * Implement conditional permissions for Texting and PhoneCall (mit-cml#1506) * Implement conditional permissions for Texting and PhoneCall Change-Id: Id4b526eb0ebd83d9b811c137f6628e503333db84 * Implement default event handlers for GotFeatures and LoadError Until now, app developers needed to define event handlers for GotFeatures and LoadError to process map features being loaded dynamically onto a map. This is not intuitive for beginners. This change makes it so that if an event handler isn't defined, we will do basic handling of these events. App developers may still override the default behavior by defining their own event handling. Change-Id: Iaeb972e28aee51abc5957c84e8d499710b343b41 * Generalize support classpath (mit-cml#1539) Change-Id: Id03a84c068f1fbf698f968dc0b7f1b48c5e1888a * Correctly convert bignums to strings in YailList (mit-cml#1546) Change-Id: Ia3b29e30091e88e1db0fb5ec02c6b0d270c17f15 * Update Companion Version to 2.51 Change-Id: Ib22f2b97c0bdec3a8f24f9c60b3f5cfcc8287d7c * Limit Certain Permissions Google has defined a set of permissions that they consider “dangerous” and can only be used in an application under certain specific circumstances and then only with special permission from Google. This is enforced when an application is submitted to the Google Play Store, not on a device. This change causes these permissions to not be included in the MIT AI2 Companion. However it is controlled by the “limitPermissions()” flag in the AppInventor features module. Change the return value to “false” to give the Companion these permissions. Change-Id: I0fa3b2e928e7aa53c70cd339f50ed11008fe1876 * Update WebViewer docs to include StringChange event * Add drop down menu for designer preview size Resolves mit-cml#1428 * Address Power User identified issues Fixes mit-cml#1449 Screen1 Documentation Fixes mit-cml#1450 Screen Development Guidance Fixes mit-cml#1452 Procedure Blocks Change-Id: I572cc17f088ae443a45c6126298f3fdcb46ba46a * Hold number for Augmented Reality Error Messages * Refactor of App Inventor messages to standardize naming and facilitate internationalization Change-Id: Ib180d8e18b6056e9f75e882c4bd9b8faf49f5548 * Made blocks return to original position if trash is canceled Change-Id: I07d684643df2f5ceaa63be8c2f45c39c8a3c0099 * Move "Empty Backpack" menu item to Backpack menu * Add password dialog option to Notifier (mit-cml#1550) Closes mit-cml#1431 * Improve Blockly controls Fixed Issue mit-cml#1352: 1. Cursor changes to pointer when hovering over the backpack and zoom elements on the right side of screen. 2. Zoom elements and trashcan are now black to increase their visibility on the screen, especially when the grey sidebar is extended over them. 3. Shifted the positioning of the zoom control images from the sprites.png image so that no more ugly lines display around the controls. * Cycle through warning and error blocks Change-Id: I7d3f5864bd65c3607a0f7083e8df44aef79c8cb9 * Make preview size listbox invisible when Sizing = Fixed * Fixed getVersionName translations (mit-cml#1564) * Fix buggy ask for write permissions when not in REPL (mit-cml#1579) Change-Id: I4a4b0af5365581cf4663f66181991ca3c747146e * Use per-app User-Agent for OpenStreetMap (mit-cml#1582) Change-Id: I9409f6f3f503d467b6014461d51c6f213dcb76ff * Attempt HTTPS version of URL if HTTP redirect fails due to lack of CORS Change-Id: I32f1bba6e7f1db17321665612a8ff2c2236446fb * Add Clock MakeDate, MakeTime, MakeInstantFromParts methods Change-Id: Ibe249c4de10d8d8213c009728771062eabba9630 * Implement list reverse block This commit introduces a new block to list operations that reverses the order of input list and outputs the result as new list. Change-Id: If22a6641a2586ecc6586ead9ea046cc119a2a9fc * Move shared constants from Compiler and ComponentListGenerator into ComponentDescriptorConstants * Move copy before paste in workspace menu * Add Stop method to VideoPlayer Change-Id: I09bec5aca529b51746d3b56a5f2c4c9a4bcf5eea * Implement join-with-separator block Change-Id: I6d7899a36e7e2ee4dd748948a98ce6693af18650 * Add generic events for component Change-Id: I1925eb15feb0e5f6b51e409538491fb0b5257928 * Implement menu option to make component blocks generic Change-Id: I62ae3fed73342a5f6cb7652903a09e4dd9c6d620 * Allow component blocks and property getters in global declarations It is often the case that people will want to construct a list of components or store some information about a copmonent so that it can be restored later. this currently requires putting all of the initialization into the Screen's Initialize event handler. However, many people intuitively expect that they can construct a list of components as part of the global declaration. This changes allows for component blocks and property getters to be used in a blocks tree with a global declaration root node. Change-Id: I69d26716ebf4bfcdd52465f15eaf75af1c4170cf * Update LocationSensor documentation Change-Id: I00d6063b297aa17da1e30cd140cf0403b0d3642c * Fix build system dependency relationships (mit-cml#1605) PR mit-cml#1569 moved some constants into the shared ComponentConstants.jar file. Building the full system works with this change, but only due to implicit relationships in the order of how targets are executed. Unfortunately, these implicit relationships are not present when running either `ant extensions` or `ant RunLocalBuildServer`, which results in a broken build. This changes does two things: 1. Add an explicit dependency to CopyToRunLibDir in buildserver on the target to build ComponentConstants.jar 2. Breaks a cyclic dependency of the components module on the buildserver module on the components module due to the extensions mechanism wanting to build the buildserver to aggregate the dependencies of the AndroidRuntime into a single directory. This is accomplished by breaking the move into two parts, one which moves the files into the public build directory, which is now populated by the components build.xml, and the second which copies them into the buildserver in its build.xml. This allows the extensions mechanism to use the public directory so it no longer needs to reference the buildserver. Change-Id: I8df1a373dbb4e98a53e9a41817a15b1dfd4856c6 * Fix ill-encoding of UriBuilder class (mit-cml#1598) This method misses URLEncode.encode() encapsulation, which leaves the danger of URL injection. * First Step and Using the Website CSS for documentation (mit-cml#1601) * First Step and Using the Website CSS for documentation * Change “Create Apps!” to “Go Back” in header * Fix dead links * Fix palette not showing when removing screen from blocks editor * Add menu option to hide workspace controls * App Inventor Hungarian translation (mit-cml#1622) Hungarian translation by Faragó Csaba and Zsolt Kolbay * Remove bad image file from webassets (mit-cml#1624) * Fix logic bug when property value is the empty string (mit-cml#1618) The conditional properties change added the ability to use a default value when a property isn't specified. However, there is a logic bug due to the fact that the empty string is falsey in JavaScript. This fix also checks specifically for the empty string as well so that the default value will be sent. * Simplify AndroidRuntime classpath further (mit-cml#1617) PR mit-cml#1605 made components manage parts of the classpath instead of the buildserver. This move means that all of AndroidRuntime's dependencies are managed within components/build.xml, and so we can further simplify the classpath for all of the targets within the components module. This change introduces an AndroidRuntime.path reference that is constructed from the dependencies set created by the aforementioned PR. It becomes a single point to introduce dependencies targetting the Android platform, including extension writing, and is used both for compilation and unit test evaluation. * Make FormPropertiesAnalyzer handle Windows line endings (mit-cml#1556) Change-Id: Id58ad71b23a4132db983e8a2c9d8dce6919c4433 * WidthPercent, HeightPercent, Width & Height Tooltips, Documentation (mit-cml#1595) * Use built-in (rejection algorithm) random sampling The original method, uniform integer modulo 100000, is biased in distribution. Now it's replaced by built-in sampling method. Java 7 API has comments on random.nextInt(int n): https://docs.oracle.com/javase/7/docs/api/java/util/Random.html#nextInt(int) * De-Bounce the “Connect with Code” Button De-Bounce the “Connect with Code” Button in the MIT AI2 Companion The Companion's design is to setup communications with the user's browser and get to work. Once this process starts, enough things are in motion that it is best to quit the Companion and start a fresh copy if a different code is needed. If the same code is entered more then once, we just ignore the second attempt. This often happens when someone scans a QR Code and then presses the "Connect" Button because they do not know that they don't have to do that. Effectively we are "de-bouncing" Change-Id: I06b20c5d9cdb07999a380d9f877edd111e0357c5 * Rename image joinwithseparator.png Changed the extension from PNG to png (because case matters!) Fixes mit-cml#1620 Change-Id: I6a334cfb18caa5b2a50ac4ea34109a6325a3586f * Add DrawShape & DrawArc into Canvas component Allow drawing shapes (made up with lines) and arcs (or sectors) * Implement toggle switch control This is a toggle switch component. Functionally, it behaves the same as a checkbox: the ON state is equivalent to checked. Since iOS does not have a checkbox and only offers toggle switches, this component paves the way for an on/off component that is shared by both Android and iOS. The toggle switch is a 2-color control, which means that there are 4 configurable colors, 2 for on and 2 for off. * Simplify the WebRTC Poller Eliminate the single threaded executor because it is not needed. Instead use Timer.scheduleAtFixedRate() to trigger the Poller once per second. This approach is more correct and simpler. Also, ignore an empty response from the Rendezvous server (which means that it hasn’t received any ICE Candidates from the browser yet). Previously we attempted to JSON parse it and threw an exception (which was logged and ignored). Change-Id: If0bc95c754a3fd052ac32cfa966fcbcfe658f55d * Add field to specify maximum permission request code The value of this variable can be changed if any class other than Activity is used as base class for Form. * Fix handling of percent lengths when changing width/height in blocks Change-Id: Ic56482d73262b9a1ddab955e8560f975f42d87a0 * Have Companion Create a unique ID Have the Companion create a unique “InstallationId” which it reports to the Rendezvous Server. This will help us keep track of how many Companions are out there and what version of Android (and the Companion) they are running on. Note: The id is generated by the ACRA Library and is persistent across upgrades of the Companion. However it will be re-created if the Companion is uninstalled and then re-installed. It is not related in any way to any Android provided identifier, which minimizes the privacy impact of this identifier. Change-Id: I7b85afe1451f4d44b4e0d412b3f37904425e3112 * Fix MockSwitch sizing and positioning interactions with FontSize * Handle transitive nature of disabled blocks in conditional permissions Null value shouldn't add to map, and blocks under a disabled block should be ignored. * Pass query string parameters through the TOS (mit-cml#1634) * Fix logic bug in MakePhoneCallDirect (mit-cml#1633) * Do not show 'no project dialog' in gallery view (mit-cml#1638) Change-Id: I103da79effba61d8255d6189b6e0bcef55b8875d * Fix theme issue due to property/component initialization (mit-cml#1632) The change to make component reference blocks usable in globals changed the ordering of initialization in such a way that components that rely on the theme applied to Screen1 end up getting the wrong theme. This corrects the order of initialization so that Screen1's properties are set immediately before any other components are created. * Update Closure Library to fix typeblocking autocomplete Change-Id: Ia732cb6a35725ef49bb5605f1ab0bc6a808fe33b * Fix bug in closure-library use of alias in goog.scope * Unified file provider source (mit-cml#1563) * Unified file provider source * Clean up old blocks editor code Change-Id: I44ce7d4cda5623b482283c30ebb63aea9053da83 * Save and restore user preferred locale For non-English users of App Inventor, if they go to the main page or click a link without a locale specified, for example, a repo link, then they will be presented App Inventor in English. This is bad from a UX perspective as the user then has to change the language and wait for the site to reload. It also interrupts whatever workflow they were currently doing (e.g., when opening a template project). This change stores the last locale from the query string as the user's preferred locale. When a locale isn't specified in the URL, we will check the locale and if it is set, redirect to that page automatically. To also save on performing actions that would be canceled by the redirect, we also reorder some initialization of Ode so that it only occurs if the redirect won't happen. Change-Id: I1b9ffa756aa08f05495832768b242341e4a30c38 * Add missing GWT DTD for validation Change-Id: I2502bb3bce93db98575655bfb0e0cf8dd92f1119 * Hide Progress Dialog on Companion Update When the “OK” button on the Companion Update dialog is pressed, properly hide the ConnectProgressBar as we are now no longer connecting. Change-Id: I4c5f24a5e8979757d6e7066c734ba40078e4a8ce * Fix blocks PNG export in Webkit (mit-cml#1646) Change-Id: I25a6e14773fb75a43a556bee57d49e8aa292d036 * Fix issues with HolePointsFromString in Polygon (mit-cml#1654) Change-Id: I9b23ee39bb46e63d56e4bd7b6cc24b8d32cdade3 * Fix failing PolygonTests Change-Id: I0548b10a840678e25baa2636e2891838a5c6775b * Updated Texting documents for Google Voice no receiving issue mit-cml#1015 (mit-cml#1648) * Updated Texting documents for Google Voice no receiving issue * Update macOS binaries to 64-bit for Mojave Change-Id: I6b527f899b08e488a191b39bcfc37976e5fe5af6 * Correct testShowScale() method Javadoc in the MapTest.java * Replace JarSigner with ApkSigner (mit-cml#1417) Replace JarSigner with ApkSigner * Fix performance issue in project list (mit-cml#1663) The onProjectAdded method of ProjectList will sort and refresh the table, which is an `O(n log n)` operation. However, when we load the list of projects initially, this will get called `O(n)` times, resulting in `O(n^2 log n)` performance. For many users, the number of projects might be small and this load time may appear negligible. However, for more prolific users with hunders of projects, this may result in multiple seconds wait time while the list is first loaded. This fix defers sorting the list until all projects have been added. Change-Id: I50332dd8f2993883428c79e8dafbebbe32e2c1fa * Use DomHelper to show Do It error dialog (mit-cml#1664) * Use DomHelper to show Do It error dialog * Disable Do It when companion not connected * 1439 german translation for ai (mit-cml#1671) German translation with multiple authors: Author: Marina de Queiroz Tavares <dqtm@zhaw.ch> Author: Matthias Müller <matthias.mueller.2@uni-jena.de> Author: Lyndsey Bonelli <lyn.bonelli@gmail.com> * Add support for a “secondary” Rendezvous Server The primary rendezvous server is used for the initial rendezvous, whether using WebRTC or not (Legacy Mode). This change provides the location for a secondary rendezvous server to use for the WebRTC negotiation. This is only done if the Companion indicates that it supports this feature (sets “r2” to true in the JSON object it posts). Any information provided by the Companion can be used by the primary rendezvous server to determine which secondary server to use. Change-Id: I8706c4f0fe66a0e902595689896003feff9cdff7 * Remove calls to the Package Installer Remove calls to the Package Installer in order to be compliant with Google Play Store rules. Change-Id: Iab89c09e815af14728f08682d02e4447077aed55 * Implement additional companion build targets We now need to build three different companions for every release. This change makes it so that we can build all three with a single run of ant rather than having to configure multiple different companions and performing three separate builds of App Inventor for a components release. Change-Id: Ia0ed7e85513081e1fbaff606223f7d88b4dbc638 * Fix German Translation Fix issues related to the merge of the translation into master Change-Id: If23bfb96f811467ee609ea92aa9ef53f518f4b92 * Update Companion Version to 2.52 Change-Id: Ia306d6a821dd00695d9721ead97bc81845ef7231 * Another minor fix to the German translation Change-Id: I31b6218b4e851822c701cc65eb7812d76895a83b * Make Image.Picture ask for read permissions if needed Change-Id: I98a2aa0ccb8b231634b4122044e7a82ee9e801bd * Fix translations of event params when switching languages Change-Id: I11fcadeac62427a9f03a5ef1173c3ca3a2523b06 * Make 'global' keyword internationalizable Change-Id: I326f2f64f03fcc43a85c6f498e22b36da407815c * Make English the blocks editor base language Change-Id: I44526bf5fce726673f615e8d61d1fe21e57d4deb * Fix NPE when only using Google login Change-Id: I588d0b4e6f8c4dcf896f88cdee67a79b883cd006 * Refactor GeoJSON processing in mock map features Change-Id: I89f5cd0b2ab49c08ea263323ce2d8a058b6cc8fb * Fallback to application/octet-stream for unknown file types Change-Id: I2dcc304bbca68827c0b92dd5b1ef012d21de1db1 * Apply AnchorHorizontal and AnchorVertical values to Marker Change-Id: I7720bb0df1e312769dfed12819a56ebb45e44e65 * Initialize polygons loaded at runtime Change-Id: I708b6f4f2d602ed227a1a6343461ee60273b40f8 * Improve WebRTC Stability Improve the stability of the WebRTC IceCandidate negotiation when the round trip time to the Rendezvous server is large (> 400ms) which can be the case when the Rendezvous server is on the other side of the planet! Change-Id: I7a8883d30696ada2ea13393fde82f1d8f49bbc0c * Mitigate WebRTC Issue The previous commit updates the Companion to better handle the case where the Rendezvous server is far away from the user (long round trip time). This commit does a mitigation, at the cost of 5 seconds, in replmgr.js that results in older Companions being more likely to connect with a long round trip time. Change-Id: Ice6b86b11a3c21beedf2c066ac46593659651713 * Update README This commit specifies installation of 32-bit libraries needed in 64-bit Linux Systems * Fix warning counter going to -1 Change-Id: If0ed5ffc8c8fbb4cc4306f6de2949ca733e0f482 * Add Build Fingerprint Add the source fingerprint, which is the git commit hash, to crash reports in the log. Change-Id: Icba88d8a26655fe3ee0917736888bcf973b7af85 * Handle compiled app installation via browser Change-Id: Ia72226088534933b61021100a990fc74979c1d5e * Remove charset declaration from Android MIME type Android apps are binary blobs, not UTF-8. It's possible that the archive includes byte sequences that are invalid UTF-8 and we can't expect clients to do the right thing when they encounter such data. Change-Id: Iad16c06f7e977c44e2c71ab3f7952036a03fb22e * Remove vestigial XML blocks generator Change-Id: I886416cefa1a0eb34311e656847fb5dc4c433bf0 * Add missing entry for German in languages.json Change-Id: I4edeb1edf44fefe5b5ada27b528ac76cefb81746 * Enable import/export block code as PNGs (mit-cml#1706) * Enable import/export block code as PNGs This commit adds a feature to download individual blocks as PNG files. In the PNG file there will be a code chunk that stores the Blockly XML representation for the block. Dragging and dropping one of these images into the blocks editor will import that block. This can be useful for writing tutorials because the images of the blocks will also contain the code, so one can drag the block image into the workspace from another page. In order for the cross-site drag to work, the server serving the document must allow CORS from the App Inventor server. Change-Id: I524bbfbef739554884caa31a8b677ce1bcc893d1 * More WebRTC fixes This set of changes appears to cause WebRTC to negotiate ICE Candidates in just about all reasonable cases. Change-Id: Iff20c75c4ca2611e4dce2a8f8f11badafe002253 * Re-Enable the “Update Companion” Menu Item Re-Enable the “Update Companion” Menu Item, but limit its use to the Emulator. Change-Id: I86e530b65fd7845de42cdccecb5550af6215db3c * Add Switch style for Classic theme Change-Id: If82b8a5bdb43b686680a27cdc473fd118a42edb5 * Update Companion Version to 2.53 Change-Id: I13f194f1d0030757fbff37b36c312cfcbf1619dc * Fix backpack remove Fixes mit-cml#1467 * Reconcile block deletion confirmation Change-Id: I110d180f67feef0a0cd34b12902dbc182cbf5e43 * Handle unbound variables and prompt user for input Change-Id: I19869c5f2fa32f384b3dbbd7d07c4cadd821ecd5 * Fix export projects in oneProject mode Change the scope of the “selectedProjects” variable so we do not call “getProjectList()” when we are not on the PROJECTS tab. This fixes an issue with “oneproject” mode (which isn’t in this source tree). Change-Id: I515a9c25fad12339810712b1f5b995c3a8a3855b * Implement component search filter Change-Id: Ia27c0510d7a19b3715dd21040320676d06b9b281 * Implement a StopListening method for SpeechRecognizer The major changes in this commit involve implementing IntentBasedSpeechRecognizer and ServiceBasedSpeechRecognizer. UseLegacy property has also been added. Resolves mit-cml#1013 Change-Id: I56f94cdadda486576d6462f798dbf78c29ea905b * Add phone skin to designer * Fix exception when deleting extension with hidden components Change-Id: Id3df87c907e20a3cc1241337a64594ca48c6ad29 * Fix unbound variable dialog button Fixes mit-cml#1735 * Make App Inventor target Android SDK 28 (Pie 9.0) Change-Id: Id830f9bad0ff873a8df6ddc29c58e24e98fae452 * Blocks Toolkit (mit-cml#1728) Feature adapted from Lynda Tang's graduate work. Adds project-level property "BlocksToolkit" (internally also called SubsetJSON), which is a JSON string describing UI components and code blocks to be displayed in the Designer and Blocks Editor. This allows projects to limit the options in the GUI to fit the curriculum and not overwhelm students. Change-Id: Ie37ecbaa31398fcfcc57320a01dd1f67d1b13522 * Update Companion Version to 2.54 Change-Id: I4c1447b782279a6c461ba89d2393df05d74d0a3f * Fixed empty dropdown * Fix screen names with underscore (mit-cml#1755) Logic that finds the screen name by taking the form name and removing everything up to the first _ character broke when the screen name contains an underscore. Change-Id: I5503b302477df77eaab5cdf5804e33acd35cc941 * Optimise code (mit-cml#1758) * Don’t require WiFi for the Emulator Change-Id: I5376ce35f0b858b11563c903a32c820e25f1aa2d * Move component creator README to the right place (mit-cml#1738) * Fix blocks missing from editor after Blocks Toolkit enhancement Change-Id: Id1365f151e87f28c15e130e81e19885694158a0f * Clean up toolkit code, restore old code that worked better. Change-Id: Id33564e88afac4a331296e4af4af48b769e6120a * Add internationalization to component block tooltips in Blocks Editor Change-Id: I4a399d8a3defb239f7cd74384a3ba4b465710234 * Move CloudDB from Experimental to Storage Category Fixes mit-cml#1747 Change-Id: I03fdbcc0ba553fb43e0ffc401a0b462bc89ddb01 * Update README This commit specifies installation using commands based on Google Cloud SDK instead of App Engine SDK. * Remove Obsolete Docs from Service The knownIssues and ReleaseNotes pages here are ancient. These pages are now served from our website (and have been for the last 7 years!), so it is time to flush them from here! Change-Id: If109b83c02b6454ec1ae7c55ec7e96efd83f9547 * Make ScaledFrameLayout only save matrix Previous versions of ScaledFrameLayout saved the entire layer. This isn't great for performance reasons, but it also had the side effect on Android > 8.0 of messing with how WebView draws to the screen since it is drawing to a back buffer. This change switches to only calling save(), which saves the various transformations without creating a secondary buffer. This seems to make the WebView happy again. Change-Id: I9188e68d943fdc56bca7a57a24d0d17b2f9b49e7 * Korean translation update (mit-cml#1726) * Fix REPL bug when switching to freshly opened projects Change-Id: If71bbaee9000dc6332d1452cb02be63a1c3402e2 * Create built-in repo for YR Media templates Change-Id: I331cfcebc9e9053dec399d5b724495f8ef7a51f0 * Polish translation (mit-cml#1729) Translation Credit to: Krzysztof Kucner Change-Id: I29298525dd017abdf4880e9d2f80a23aa4936a82 * Make PhoneCall request READ_PHONE_STATE dangerous permission also Change-Id: Ibacdc5f81f57ab6e49dc906daec47ae593fc94bc * Make template wizard dialog fit smaller screens Change-Id: I558443f2afbe08ee192d06f468bcd173f31997d0 * Remove horizontal scroll from template wizard dialog * Add missing android.arch.lifecycle dependency Change-Id: I3f616e1a4c42416b8e33b40fb3183e65cc862e58 * Fix project download bug reported by @barreeeiroo Change-Id: Ibe01541a106b37bffbde21f05ea7f1b2c134070a * Update Companion Version to 2.55 Change-Id: I6ffef0b3bc66d55adea643bccf34ed4dae2d6d57 * Add missing extension to emulator build to allow package installation Change-Id: I004e2beda3cd26a1f25e19f38370cca4f2f1fbf5 * Fix author info problem * Add direct link to download in Barcode link dialog * Remove unused code * Add legacy connection information to README.md * Fix missing tooltips in extension blocks (mit-cml#1804) * Fix missing tooltips in extension blocks * Add regression testing for component blocks translation Change-Id: I524b4639234b51d55b82f84a02abdca0db40a4a7 * Add not-equal to text compare block * Remove debug logging * Make blocks collapse/expand on double click (mit-cml#1809) Change-Id: Ia4964537d457316824325bdf351a26820a51144a * Add Javadoc extraction for property descriptions (mit-cml#1811) Change-Id: I7fdc2d77430473420ed2d0e17d798a485ea16325 * Fix landscape navigationbar orientation in designer * Implement substring search on components palette (mit-cml#1814) * Implement substring search on components palette * Add "Target Android SDK" information to Help > About menu * Add media preview Change-Id: I6702e49a89777c1aa65c6a9fb766e0980d0fc380 * Add %type% as a token in component descriptions App Inventor doesn't present a type hierarchy even though internally it makes sense for objects to have shared methods defined in super classes. However, the documentation for the properties, methods, and events of an App Inventor component shared in this way must typically be written generic enough so that they make sense when shown on concrete classes. This can lead to either awkward/generic sounding documentation or requires that the component author override all of the relevant features on the component to provide component-specific descriptions. This change makes it so that descriptions of components, properties, methods, and events can contain one or more %type% tokens that can be substituted with the name of the concrete representation shown to the App Inventor user. This allows for documentation to be shared at the super class level while still making it sound specific to the individual component type. Change-Id: Ida4eb22bec12b2e33ac73de2bb5706d1683b227a * Update Sort By Category Function Change-Id: If1fe3358fb87be47a90dd90a79c794a751ab7288 * Register YaFormEditor and YaBlocksEditor earlier Prior to this change, YaFormEditor and YaBlocksEditor are registered in loadDesigner, which is called from onShow. This is problematic because if the screen hasn't been opened in the current session and the user deletes an extension, the unopened screens are not notified of the change. When the project is reloaded, it will fail to load because the unopened screens still referenced the deleted extension. This change moves the registration of YaFormEditor and YaBlocksEditor as FormChangeListeners to the onFileLoaded method so that they are made aware of project-level changes (like removing an extension) even if they are never viewed in a session. Change-Id: I8306ede85f5fb3576d810c9bd213e5e00df938ff * Redesign the dialog box that appears when a user has no projects Change-Id: I9802f22cbe9fba8ed768de995d40b315ec3483ed * Add OpenDyslexic font as alternative user setting * Use border box sizing for MockTextBox (mit-cml#1721) Change-Id: Ic374dbabd9fad57c06b1b070ab3d84a63ba0b4e6 * Update AssetList.java * Give deprecation warning for FusiontablesControl Give a warning when a project that uses the FusiontablesControl is loaded. Google will be shutting down the Fusiontables service on December 3rd, 2019. Change-Id: I6a56853ea8a56790495b4462b1c59d5c3059eaef * Support disabling events in the REPL (mit-cml#1849) * Cancel focusing on TreeItems in Tree widgets (mit-cml#1848) Change-Id: Ib3e663aae8135694ddf423611ebcf7a7caffbd39 * Add GitHub templates (mit-cml#1850) * Add GitHub templates * Update AIStarter to Python 3 Also supports Windows, Linux & Mac OS all in one file Co-authored-by: Evan W. Patton <ewpatton@mit.edu> * Associate marker asset with Map for runtime markers (mit-cml#1868) Change-Id: I9338893e68d64d67207c107b039dc4d7cfbfb556 * Make AWT run in headless mode in buildserver On macOS, the application icon preparation step causes Java AWT to create an app window. This window gains focus, even though the buildserver is a background process. This really only affects developers working with the sources on OS X. This change sets a flag to inform AWT to run in headless mode, which prevents it from creating the app window. Change-Id: Ida725b80e67c55777437cdd69392a3fab4dcf00a * Added Sponsor Button * Reenable convert number block translations in zh_tw, zh_cn (mit-cml#1864) * Reenable convert number block translations in zh_tw, zh_cn * Reuse flydown SVG rather than making orphans (mit-cml#1876) Change-Id: I34fc7bb333208d59e9186800fe2696621c9971af * Make "Display hidden components in Viewer" checkbox screen-dependent (mit-cml#1852) * Cache checkbox state for each screen * Make hidden components checkbox screen-dependent * Raise error when using boxed primitive types in component APIs (mit-cml#1846) * Raise error when using boxed primitive types in component APIs * Make ComponentProcessor error messages private * Fix translations of preview size dropdown options (mit-cml#1877) * [GSOC] Implementing Trash Can Functionality in MIT App Inventor. (mit-cml#1783) This functionality keeps the deleted project in a folder called Trash and if the project is accidentally deleted will not directly go away from App Inventor but will exist in Trash. In Trash Window users will have functionality to permanently delete the project or restore back to My Projects or simply keep in Trash. * Update Dutch translations (mit-cml#1863) * Remove unused context constructor param (mit-cml#1890) * Fix exception caused by attempting to open flydown during drag from toolbox Change-Id: Iaac765df9371acb8672df71bb12b22e02fd40cb9 * Implement extra null checks on flydown Change-Id: I9fc9e5516c329ac8b286fc075ad0b863018164bb * Fix wrong reference to FieldFlydown (was FieldDropdown) Change-Id: I7be76fd01960ae8f333ea7bd54d8cd8f33dc51e8 * Skip dragging bubbles of icons without locations Change-Id: I9a087d73674b4afe842a300693324ff559afa1cd * Set open flydown only once flydown is open Change-Id: I81b2f7bfc1f6806f3a0d1aef9e658050b46050fd * Hide more chaff Change-Id: Iae1a102a0323a65a936b21cfa36326c686e3a2c5 * Make empty component setter sockets errors, not warnings Change-Id: I59456500e2e89b0ce43f0f80f5d447dae8b8a2ea * Implement option to disable project auto load Autoload behavior can be overriden per session by including autoload=false or autoload=true in the query string when loading App Inventor. This commit also refactors the menu construction into individual pieces so that they can be called to be reconfigured. At the moment, this feature is only used for the Settings menu, but it makes the creation of each menu independent of any other menu. Change-Id: Id220991cef5f7643465ef9648f663a52be1486ae * Fix global keyword internationalization (mit-cml#1902) The global keyword that prefixes global variables is translated, and this translation ends up in the Blockly XML. We need to keep the translation separate from the underlying representation so that projects still work when switching between languages. Change-Id: I7bc88f0a26c8dce6d256010c188d7233d8cc43f8 * Enable multiple component selection using shift key presses (mit-cml#1891) * Enable multiple component selection using shift key presses * Add highlight to select components and show number of components selected * Make selected component properties default when there is no full intersection * Allow unselection of already selected components * Fix tutorial panel sizing (mit-cml#1904) Change-Id: Ib3142c60ecb389da2b304d96c30308cb08939ebb
I’m trying to connect to a Spring RESTful service on the same server where my webapp is running.
I’d like to use a «relative» path because it could be installed on several environments (localhost, test, production) but I get the error message: URI is not absolute
.
How can I call a service running on another webapp on the same server?
My code is like following:
final RestTemplate restTemplate = new RestTemplate();
URI uri;
try {
String url = "app2/myservice?par=1";
uri = new URI(url);
String result = restTemplate.getForObject(uri, String.class);
System.out.println(result);
} catch (URISyntaxException e) {
logger.error(e.getMessage());
}
Thanks.
Update:
I solved it by getting the host, port, etc… from the request
, could it be a right and elegant solution? This’s my actual simplified code:
String scheme = request.getScheme();
String userInfo = request.getRemoteUser();
String host = request.getLocalAddr();
int port = request.getLocalPort();
String path = "/app2/myservice";
String query = "par=1";
URI uri = new URI(scheme, userInfo, host, port, path, query, null);
boolean isOK = restTemplate.getForObject(uri, Boolean.class);
if (isOK) {
System.out.println("Is OK");
}
java.lang. IllegalArgumentException: URI is not absolute occurs when a relative url is used to identify the resource. In the spring boot RestTemplate, the complete url will be used to invoke the rest call. If the relative url is used in the restful call, the java exception java.lang. IllegalArgumentException: URI is not absolute would be thrown.
A resource can be invoked in java using a complete url. If the relative url is used, the relative url can not be converted to an absolute url. Therefore, the resource can’t be identified. The exception URI is not absolute will be thrown.
Exception
The exception java.lang. IllegalArgumentException: URI is not absolute stack trace will be shown as below in the spring boot. The root cause will be thrown from the java.
2020-10-06 17:15:08.417 ERROR 20534 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalArgumentException: URI is not absolute] with root cause
java.lang.IllegalArgumentException: URI is not absolute
at java.net.URI.toURL(URI.java:1088) ~[na:1.8.0_101]
at org.springframework.http.client.SimpleClientHttpRequestFactory.createRequest(SimpleClientHttpRequestFactory.java:145) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.http.client.support.HttpAccessor.createRequest(HttpAccessor.java:124) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:735) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
How to recreate this exception
If a relative url is sent to a rest call in the RestTemplate, a relative url can not be converted to an absolute url. This is why the exception “java.lang.IllegalArgumentException: URI is not absolute” would be thrown. In the “/getstudent” rest call invokes another rest call using the relative url “/student”.
package com.yawintutor;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
@RestController
public class TestController {
@GetMapping(value = "/student")
public Student getStudent() {
return new Student(1, "name1");
}
@GetMapping(value = "/getstudent")
private Student getStudentObject(HttpServletRequest request)
{
String uri = "/student";
RestTemplate restTemplate = new RestTemplate();
Student result = restTemplate.getForObject(uri, Student.class);
return result;
}
}
Solution 1
If a relative url is sent to a rest call in the RestTemplate, the relative url has to be changed to an absolute url. The RestTemplate will use the absolute url to identify the resource. In the example below, the complete url “http:/localhost:8080/student” is used to invoke a rest call using RestTemplate.
package com.yawintutor;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
@RestController
public class TestController {
@GetMapping(value = "/student")
public Student getStudent() {
return new Student(1, "name1");
}
@GetMapping(value = "/getstudent")
private Student getStudentObject(HttpServletRequest request)
{
String uri = "http://localhost:8080/student";
RestTemplate restTemplate = new RestTemplate();
Student result = restTemplate.getForObject(uri, Student.class);
return result;
}
}
Solution 2
If you are using a relative url in a rest call that refers to the same tomcat server, use the HTTPRequest object to construct a complete url before submitting it to the rest template. The example below demonstrates how to create a complete url from the relative url to the same server.
package com.yawintutor;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
@RestController
public class TestController {
@GetMapping(value = "/student")
public Student getStudent() {
return new Student(1, "name1");
}
@GetMapping(value = "/getstudent")
private Student getStudentObject(HttpServletRequest request)
{
String requestURL = request.getRequestURL().substring(0, request.getRequestURL().indexOf(request.getRequestURI()));
String uri = requestURL + "/student";
RestTemplate restTemplate = new RestTemplate();
Student result = restTemplate.getForObject(uri, Student.class);
return result;
}
}
Solution 3
If the relative url is used in RestTemplete that must be referred to an external host server, the external host server url can be externalized in the application.properties files. The properties can be added to the relative url as shown in the example below.
application.properties
external.server.url=http://www.yawintutor.com
TestController.java
package com.yawintutor;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
@RestController
public class TestController {
@Value("${external.server.url}")
String externalServerURL;
@GetMapping(value = "/student")
public Student getStudent() {
return new Student(1, "name1");
}
@GetMapping(value = "/getstudent")
private Student getStudentObject()
{
String uri = externalServerURL + "/student";
RestTemplate restTemplate = new RestTemplate();
Student result = restTemplate.getForObject(uri, Student.class);
return result;
}
}
* Trim extraneous whitespace from base64-encoded aia The base64 utility on macOS writes a carriage return at the end of the base64 encoded string. When App Inventor attempts to read a project template with this extra whitespace, it causes an exception to be thrown since the server's decode() implementation expects a string with a length multiple of 4. This change switches to using decodeLines(), which ignores whitespace. Change-Id: I34f6c7b1ef1fcd12b82eab67c98ffb422bbf5894 * Stop propagation of mouse events on warning toggle button In Firefox, Blockly seems to handle mouse events differently than in Chrome. This generally isn't a problem, but it affects the warning indicator toggle button. Blockly starts a drag at the mousedown but then we never will see a mouseup or click event. This change registers a mouse down listener on the toggle to stop propagation to Blockly so that the warning indicator can receive the click event. We also update to include support for touch events on the toggle button to support App Inventor on tablets. Change-Id: Iba4e1e274dd3eac86939bb122a1c7f15cc7d41f9 * Changes for Java 8 and the Buildservers We properly close the HttpURLConnection between App Engine (the App Inventor server) and the buildserver infrastructure. If we don’t App Engine sends RST packets which causes issues for some buildserver infrastructures. Also limit project size to 10MB up-front (rather then after an IOException is thrown). Add reporting to the buildserver status page to report the number of Java threads. Change-Id: I934df537dfe9419f5f8effafe80f0a2460091cdd * Fix GeoJSON Source processing in MockFeatureCollection (mit-cml#1248) If there were multiple features of the same type in a GeoJSON file and the file did not include names for the components, one would receive multiple components with the same name (e.g., LineString1). LineString processing was also broken, resulting in a coordinate string without values. Setting the Source to None... would remove the components but not clear the features off the map. This commit addresses three changes: 1. Refactors how naming of map features is handled during the loading of GeoJSON into a MockFeatureCollection so that each component has a unique name. 2. It corrects handling of LineString coordinates when the line string is not part of a MultiLineString construct. 3. It cleans up how features are removed when a feature collection is cleared. Change-Id: Iccbcab65989169ab730239b8915b62ca6b6f636c * Fix clearing of MockFeatureCollection when Source is None Change-Id: Icf74d804689dcaa323bac3b4d1f0400631b74a5e * Remove BOM from GeoJSON files While GeoJSON files should not have a BOM per the spec, sometimes systems will include the UTF byte order marker (BOM). This breaks the JSON parsing on both in the web client and app. This change will check for and strip out the BOM before passing the JSON string along for further processing. Change-Id: I9452871e19b3985f9beea48b30cf49b60e4835cb * Bugfix to AARLibrary Some aar files do not have an explicit directory entry for every object. Make sure we create the needed directories. Change-Id: Ic79d8852b6cc48f2399794c4087507e8f9c3bbaf * Reset min size of button with images (mit-cml#1398) * Reset min size of button with images If someone sets an image on a button in a non-Classic theme, the minimum width/height settings in the theme will force the button to sometimes resize the image arbitrarily to fit the minimum constraints rather than allowing the button to assume the shape of the image like it would in the Classic theme. This fix sets the minimum size of a button to 0x0 so that it can take on the image size regardless of what the platform's default dimensions for a button. Change-Id: I590eb1bec860cda221e821c663c03c5cd81a65fe * Replace use of isRenderingOn with Blockly event management When the 2017 Blockly update was done, it used isRenderingOn to determine when to position and render the blocks. This was to optimize the interaction between the load/upgrade process and workspace resizes. However, in rare instances it seems to result in blocks not being placed correctly. This change removes the special handling of upgrading. Instead, it disables and enables the Blockly event system during a load/upgrade operation. At the end of the upgrade process (if needed), it will also force a save of the blocks workspace. Fixes mit-cml#1071 Change-Id: I6bec41dd67bc6371e794e93850ea1455b9acf8c7 * Force MockCircle default position to (0, 0) Fixes mit-cml#1379 Change-Id: I2682c4b12806e13a78524fce2d47293d46123f93 * Make annotation processors target Java 7 Change-Id: Ie2ae31c90304d6278541f22513adfcf731f999a0 * Restore button ripple effect for material theme phones Fixes mit-cml#1318 * Enable debug panel logging only when admin Projects with many components may cause a large number calls to OdeLog.log, which appends messages by converting the debugger panel's content to HTML and back. This change enables logging only if the user is an Admin, since only Admins have access to the debugger panel to begin with. This reduces the number of cycles spent on logging for the vast majority of App Inventor users. We also optimize how the log is constructed so that users with Admin rights have reasonable performance on complicated projects. Change-Id: I62cc2af0e421d3f5fda668f72de62c1895414092 * Numerous Changes in order to target Android API 26 Set target api to 26 which corresponds to Android verison 8.0 (Oreo). Numerous changes where required in order to target api 26 while still having minSdk set to 7. As a trade-off, some “theme” selections will not be available on older devices, but the apps packaged with this code will operate on API 7 (Android 2.1). Author: Evan W. Patton <ewpatton@mit.edu> Author: Jeffrey I. Schiller <jis@mit.edu> Change-Id: Ia307c080072c76d4699550892c99a07b65d3465e * Communicate with the Companion with WebRTC Add support for using WebRTC to communicate between the browser and the Companion. While using WebRTC assets (images, sounds, etc.) are downloaded directly to the Companion from the MIT App Inventor server without being redirected through the user’s browser. By supporting WebRTC we pave the way for offering MIT App Inventor over https. The current HTTP based communications system used today (without WebRTC) prohibits us from using https for MIT App Inventor itself. This version of code supports both the new WebRTC approach as well as the pre-WebRTC approach both within the MIT App Inventor client (browser) and the Companion. The new Companion will use WebRTC by default, but can be told to use the HTTP based system (called a “Legacy Connection”) by checking a box on the Companion home screen. We will have to remove HTTP (Legacy) support prior to serving MIT App Inventor over https. Change-Id: Ib7b2db4261f2c852a7593b7a7b32b7356ff8cb6c * Update Companion Version to 2.48 Change-Id: Ic1a9060e2664a9709267e6dc3a36116f79ecca49 * Fix null pointer when logging before user info available Change-Id: Ie39c3a9e0e35c58a97a9307db8cd31a086e602b5 * Fix GeoJSON parsing in MockFeatureCollection Change-Id: Ifd5cd24c006bac1acc996fcb7d3763c58c54dd84 * Make Backpack open in Firefox Change-Id: If360e42e1fc497b7cdd5ffdc0756513ade51af14 * Ensure connections added to ConnectionDB on load Change-Id: Ia29c8c4ed94486098c069b33298b1c66f59d6dde * Fix connection DB bug when workspace contains blocks with errors Change-Id: I47f76f80ac48b37f2fb9bc82c174021fb918da0f * Stop resetting list of connections when errors occur Change-Id: I0377e3c1958885587d1a2a6336ec9c9b30e7c7cb * Fix processing of // in File and add unit tests Fixes mit-cml#1457 Change-Id: I73ff292d87e8ba22a5900eac774d8ae576f05ef2 * Fix handling of Map.ZoomLevel when animating changes Change-Id: If652e6759e95e47884a1324f8dfd203d8b15e65a * Fix PlayApp build on Windows due to wrong slash Change-Id: Idbd09280429ee9a786a4c476224fcae0e69f7e6c * Fix permissions handling on older Android versions Change-Id: If93a3e452908781c35e577c5d72df88eb028ade8 * Fix backpack icon state with multiple screens Change-Id: Ib55f66b4b15aea0ca2889916d8bb76dda9f3fa70 * Implement versionName and dateBuilt annotation fields This change adds two new fields toe @DesignerComponent. The first is a versionName field so that extensions can display custom version names rather than the version number. This can be used to mark an extension build as beta or a release candidate, for example. The second change is a dateBuilt field that is populated by ComponentProcessor at compile time. This is useful for knowing when an extension is compiled. Both pieces of information appear in the component help widget, and version name is preferred over version if provided. Change-Id: I12c97c9c0a3b18abd64a539f1c5072b975d47d14 * Update Companion Version to 2.49 Change-Id: I882136070e9d651a5acdffd26fdf8c2d4cb310d1 * Patch Blockly core to fix extension blocks in Backpack Change-Id: I6d4299fc43c8d3e4ea17053af950b36906f4ef39 * Chunk large Messages to the Companion WebRTC can only safely send messages of 16K. So we will only send up to 8K characters (ok, a margin of safety). Most projects do not need to send YAIL forms larger then this, but a few do. To “chunk” the code into smaller pieces would normally require changes both on the browser side and the Companion side. However we wish to avoid changing the Companion at this time. So instead, we break the large YAIL forms into smaller YAIL forms that can each be evaled on the device correctly. Change-Id: I865e39cad3c55ea35b2a56582d50136f8303e90e * Added context menu items to show and hide all comments This commit adds two new options to the block editor's context menu to show and hide all the comments on the workspace. Resolves mit-cml#1422 * Add two css styles to textarea * Align labeled text boxes in the middle * Add bitwise operator blocks Added bitwise-and. bitwise-or, and bitwise-xor Math blocks. * Implement scale bar for Map Change-Id: I8824cde5d7481a6349e7604dd97a372b67abc7dc * Add ScaleUnits property to control scale unit system Change-Id: I8638eca2fe11daf4ad353b8e7fad4e25ee7ca496 * Bump YOUNG_ANDROID_VERSION Change-Id: I58c4b564491185a15fd8900989866309775838aa * Make removeDupes run in linear time In the previous version, removeDupes used Array.splice, which ends up moving the end of the array up in O(n) time, and makes the loop effectively O(n^2). This version uses a dictionary for bookkeeping so that duplicates can be removed in linear time. Change-Id: I78e23b97e9cc932ee653823674fcc19eb90be342 * Implement upgrader for Map version 5 Change-Id: I65db61ca7fa1f9652e84c814208f333f331f5831 * Update testing R classes to include SDK 26 resources Change-Id: I62cf1eb54cb627620f7164263ff206fa2adda38e * Extract SDK 26 resources for testing Change-Id: I849f9fefe7db94e106d0ee2e2883112aa055754e * Fix default background color on SDKs prior to 14 Change-Id: I46562b4a2668303862940456bec490fe6c757bdc * Updates HELPURL links so that all HELP context menu options should work. (mit-cml#1501) * Updates HELPURL links so that all HELP context menu options should work. * Add HELPURLs for Maps components Also made whitespace in METHODS_HELPURLS match the rest of the document Change-Id: I5044ceb07befa2db74590bd00de2b4f1cba70b9c * Allow for Any Marker, LineString, and Polygon with Maps When one dynamically loads map content from the web, one might want to manipulate that content. To do that today, you must add one of each of the relevant types to a Map and make them invisible so that the "Any ..." tree items are shown. This change makes it so that as long as the Map exists it will add the any component options for Marker (Point), LineString, and Polygon components. Change-Id: Ifb6837be89231c7f713a140318858da366113c21 * Update Companion Version to 2.50 Change-Id: I627e10b911c013482e2dfa153f4aedf341733942 * Fix HELPURL for Screen component selector block * Added instructions for combining DatePicker and TimePicker Instants Also changed related anchor links to relative links Change-Id: I6433975f0055a29a86843a1ba32e6c0f6a9513e8 * Provide Deprecation Warning for FusiontablesControl Google will be turning off Fusion Tables on December 3, 2019. This change provides a warning when a FusiontablesControl is dragged into a project. Change-Id: I275ab12eeb664252a312602598afab94ef5c52c3 * Documentation Updates * Make help for neg block match the actual neg block Issue #mit-cml#1368 * Refine TinyDB documentation * Fix link for tinywebdb server * Add TinyDB namespace documentation Change-Id: I7c844ce85ada92ab63f46d747ac1d7782506bfa1 * Fix error 1101 on Android versions before Nougat (mit-cml#1526) Installing a package via the QR code scanner fails on Android versions before SDK 24. The issue is that we switched to using content: URIs, which is required on SDK 24+, but this fails to resolve the package installer activity on SDK < 24. This commit adds a helper method for constructing the correct URI based on the device's SDK version. Change-Id: Ieaec37b79d6189f75535b5a9be4d0f38b756e63a * Simplify javadoc classpath (mit-cml#1495) Change-Id: I09c53561646b6172fd85746e54b08db612bbbe95 * Update README.md for update from Java 7 to Java 8 Change-Id: I98cb72ed416705d43228525b7196a86f889fe970 * Fix for WebRTC on Safari Use the “urls” property of ICEServer instead of the deprecated “url” property. Change-Id: I391f06eaffd26261a7a106e9fb35eedf2e0d84ee * Ensure Polygon Points and HolePoints invalidate map view Change-Id: I35b143a3dbe3aecdc6c57352468c73e9baf40b72 * Create a Connection Progress Bar (mit-cml#1534) WebRTC Connections can take a while to negotiate. This change gives the user some feedback while negotiation is taking place. We remove the ProgressBarDialog functionality from AssetManager and place it in a new module which is called from AssetManager and from replmgr.js. This permits us to put up the progress dialog at connection attempt time instead of at asset download time. Change-Id: I28772eb92a49b8ed2aa9af9ab84b1ea10d915bcc * Fix mapview invalidation when Marker visibility changed Change-Id: Iea7872a0896e39c30353cd89d950c6d3779370bf * Implement conditional permissions for Texting and PhoneCall (mit-cml#1506) * Implement conditional permissions for Texting and PhoneCall Change-Id: Id4b526eb0ebd83d9b811c137f6628e503333db84 * Implement default event handlers for GotFeatures and LoadError Until now, app developers needed to define event handlers for GotFeatures and LoadError to process map features being loaded dynamically onto a map. This is not intuitive for beginners. This change makes it so that if an event handler isn't defined, we will do basic handling of these events. App developers may still override the default behavior by defining their own event handling. Change-Id: Iaeb972e28aee51abc5957c84e8d499710b343b41 * Generalize support classpath (mit-cml#1539) Change-Id: Id03a84c068f1fbf698f968dc0b7f1b48c5e1888a * Correctly convert bignums to strings in YailList (mit-cml#1546) Change-Id: Ia3b29e30091e88e1db0fb5ec02c6b0d270c17f15 * Update Companion Version to 2.51 Change-Id: Ib22f2b97c0bdec3a8f24f9c60b3f5cfcc8287d7c * Limit Certain Permissions Google has defined a set of permissions that they consider “dangerous” and can only be used in an application under certain specific circumstances and then only with special permission from Google. This is enforced when an application is submitted to the Google Play Store, not on a device. This change causes these permissions to not be included in the MIT AI2 Companion. However it is controlled by the “limitPermissions()” flag in the AppInventor features module. Change the return value to “false” to give the Companion these permissions. Change-Id: I0fa3b2e928e7aa53c70cd339f50ed11008fe1876 * Update WebViewer docs to include StringChange event * Add drop down menu for designer preview size Resolves mit-cml#1428 * Address Power User identified issues Fixes mit-cml#1449 Screen1 Documentation Fixes mit-cml#1450 Screen Development Guidance Fixes mit-cml#1452 Procedure Blocks Change-Id: I572cc17f088ae443a45c6126298f3fdcb46ba46a * Hold number for Augmented Reality Error Messages * Refactor of App Inventor messages to standardize naming and facilitate internationalization Change-Id: Ib180d8e18b6056e9f75e882c4bd9b8faf49f5548 * Made blocks return to original position if trash is canceled Change-Id: I07d684643df2f5ceaa63be8c2f45c39c8a3c0099 * Move "Empty Backpack" menu item to Backpack menu * Add password dialog option to Notifier (mit-cml#1550) Closes mit-cml#1431 * Improve Blockly controls Fixed Issue mit-cml#1352: 1. Cursor changes to pointer when hovering over the backpack and zoom elements on the right side of screen. 2. Zoom elements and trashcan are now black to increase their visibility on the screen, especially when the grey sidebar is extended over them. 3. Shifted the positioning of the zoom control images from the sprites.png image so that no more ugly lines display around the controls. * Cycle through warning and error blocks Change-Id: I7d3f5864bd65c3607a0f7083e8df44aef79c8cb9 * Make preview size listbox invisible when Sizing = Fixed * Fixed getVersionName translations (mit-cml#1564) * Fix buggy ask for write permissions when not in REPL (mit-cml#1579) Change-Id: I4a4b0af5365581cf4663f66181991ca3c747146e * Use per-app User-Agent for OpenStreetMap (mit-cml#1582) Change-Id: I9409f6f3f503d467b6014461d51c6f213dcb76ff * Attempt HTTPS version of URL if HTTP redirect fails due to lack of CORS Change-Id: I32f1bba6e7f1db17321665612a8ff2c2236446fb * Add Clock MakeDate, MakeTime, MakeInstantFromParts methods Change-Id: Ibe249c4de10d8d8213c009728771062eabba9630 * Implement list reverse block This commit introduces a new block to list operations that reverses the order of input list and outputs the result as new list. Change-Id: If22a6641a2586ecc6586ead9ea046cc119a2a9fc * Move shared constants from Compiler and ComponentListGenerator into ComponentDescriptorConstants * Move copy before paste in workspace menu * Add Stop method to VideoPlayer Change-Id: I09bec5aca529b51746d3b56a5f2c4c9a4bcf5eea * Implement join-with-separator block Change-Id: I6d7899a36e7e2ee4dd748948a98ce6693af18650 * Add generic events for component Change-Id: I1925eb15feb0e5f6b51e409538491fb0b5257928 * Implement menu option to make component blocks generic Change-Id: I62ae3fed73342a5f6cb7652903a09e4dd9c6d620 * Allow component blocks and property getters in global declarations It is often the case that people will want to construct a list of components or store some information about a copmonent so that it can be restored later. this currently requires putting all of the initialization into the Screen's Initialize event handler. However, many people intuitively expect that they can construct a list of components as part of the global declaration. This changes allows for component blocks and property getters to be used in a blocks tree with a global declaration root node. Change-Id: I69d26716ebf4bfcdd52465f15eaf75af1c4170cf * Update LocationSensor documentation Change-Id: I00d6063b297aa17da1e30cd140cf0403b0d3642c * Fix build system dependency relationships (mit-cml#1605) PR mit-cml#1569 moved some constants into the shared ComponentConstants.jar file. Building the full system works with this change, but only due to implicit relationships in the order of how targets are executed. Unfortunately, these implicit relationships are not present when running either `ant extensions` or `ant RunLocalBuildServer`, which results in a broken build. This changes does two things: 1. Add an explicit dependency to CopyToRunLibDir in buildserver on the target to build ComponentConstants.jar 2. Breaks a cyclic dependency of the components module on the buildserver module on the components module due to the extensions mechanism wanting to build the buildserver to aggregate the dependencies of the AndroidRuntime into a single directory. This is accomplished by breaking the move into two parts, one which moves the files into the public build directory, which is now populated by the components build.xml, and the second which copies them into the buildserver in its build.xml. This allows the extensions mechanism to use the public directory so it no longer needs to reference the buildserver. Change-Id: I8df1a373dbb4e98a53e9a41817a15b1dfd4856c6 * Fix ill-encoding of UriBuilder class (mit-cml#1598) This method misses URLEncode.encode() encapsulation, which leaves the danger of URL injection. * First Step and Using the Website CSS for documentation (mit-cml#1601) * First Step and Using the Website CSS for documentation * Change “Create Apps!” to “Go Back” in header * Fix dead links * Fix palette not showing when removing screen from blocks editor * Add menu option to hide workspace controls * App Inventor Hungarian translation (mit-cml#1622) Hungarian translation by Faragó Csaba and Zsolt Kolbay * Remove bad image file from webassets (mit-cml#1624) * Fix logic bug when property value is the empty string (mit-cml#1618) The conditional properties change added the ability to use a default value when a property isn't specified. However, there is a logic bug due to the fact that the empty string is falsey in JavaScript. This fix also checks specifically for the empty string as well so that the default value will be sent. * Simplify AndroidRuntime classpath further (mit-cml#1617) PR mit-cml#1605 made components manage parts of the classpath instead of the buildserver. This move means that all of AndroidRuntime's dependencies are managed within components/build.xml, and so we can further simplify the classpath for all of the targets within the components module. This change introduces an AndroidRuntime.path reference that is constructed from the dependencies set created by the aforementioned PR. It becomes a single point to introduce dependencies targetting the Android platform, including extension writing, and is used both for compilation and unit test evaluation. * Make FormPropertiesAnalyzer handle Windows line endings (mit-cml#1556) Change-Id: Id58ad71b23a4132db983e8a2c9d8dce6919c4433 * WidthPercent, HeightPercent, Width & Height Tooltips, Documentation (mit-cml#1595) * Use built-in (rejection algorithm) random sampling The original method, uniform integer modulo 100000, is biased in distribution. Now it's replaced by built-in sampling method. Java 7 API has comments on random.nextInt(int n): https://docs.oracle.com/javase/7/docs/api/java/util/Random.html#nextInt(int) * De-Bounce the “Connect with Code” Button De-Bounce the “Connect with Code” Button in the MIT AI2 Companion The Companion's design is to setup communications with the user's browser and get to work. Once this process starts, enough things are in motion that it is best to quit the Companion and start a fresh copy if a different code is needed. If the same code is entered more then once, we just ignore the second attempt. This often happens when someone scans a QR Code and then presses the "Connect" Button because they do not know that they don't have to do that. Effectively we are "de-bouncing" Change-Id: I06b20c5d9cdb07999a380d9f877edd111e0357c5 * Rename image joinwithseparator.png Changed the extension from PNG to png (because case matters!) Fixes mit-cml#1620 Change-Id: I6a334cfb18caa5b2a50ac4ea34109a6325a3586f * Add DrawShape & DrawArc into Canvas component Allow drawing shapes (made up with lines) and arcs (or sectors) * Implement toggle switch control This is a toggle switch component. Functionally, it behaves the same as a checkbox: the ON state is equivalent to checked. Since iOS does not have a checkbox and only offers toggle switches, this component paves the way for an on/off component that is shared by both Android and iOS. The toggle switch is a 2-color control, which means that there are 4 configurable colors, 2 for on and 2 for off. * Simplify the WebRTC Poller Eliminate the single threaded executor because it is not needed. Instead use Timer.scheduleAtFixedRate() to trigger the Poller once per second. This approach is more correct and simpler. Also, ignore an empty response from the Rendezvous server (which means that it hasn’t received any ICE Candidates from the browser yet). Previously we attempted to JSON parse it and threw an exception (which was logged and ignored). Change-Id: If0bc95c754a3fd052ac32cfa966fcbcfe658f55d * Add field to specify maximum permission request code The value of this variable can be changed if any class other than Activity is used as base class for Form. * Fix handling of percent lengths when changing width/height in blocks Change-Id: Ic56482d73262b9a1ddab955e8560f975f42d87a0 * Have Companion Create a unique ID Have the Companion create a unique “InstallationId” which it reports to the Rendezvous Server. This will help us keep track of how many Companions are out there and what version of Android (and the Companion) they are running on. Note: The id is generated by the ACRA Library and is persistent across upgrades of the Companion. However it will be re-created if the Companion is uninstalled and then re-installed. It is not related in any way to any Android provided identifier, which minimizes the privacy impact of this identifier. Change-Id: I7b85afe1451f4d44b4e0d412b3f37904425e3112 * Fix MockSwitch sizing and positioning interactions with FontSize * Handle transitive nature of disabled blocks in conditional permissions Null value shouldn't add to map, and blocks under a disabled block should be ignored. * Pass query string parameters through the TOS (mit-cml#1634) * Fix logic bug in MakePhoneCallDirect (mit-cml#1633) * Do not show 'no project dialog' in gallery view (mit-cml#1638) Change-Id: I103da79effba61d8255d6189b6e0bcef55b8875d * Fix theme issue due to property/component initialization (mit-cml#1632) The change to make component reference blocks usable in globals changed the ordering of initialization in such a way that components that rely on the theme applied to Screen1 end up getting the wrong theme. This corrects the order of initialization so that Screen1's properties are set immediately before any other components are created. * Update Closure Library to fix typeblocking autocomplete Change-Id: Ia732cb6a35725ef49bb5605f1ab0bc6a808fe33b * Fix bug in closure-library use of alias in goog.scope * Unified file provider source (mit-cml#1563) * Unified file provider source * Clean up old blocks editor code Change-Id: I44ce7d4cda5623b482283c30ebb63aea9053da83 * Save and restore user preferred locale For non-English users of App Inventor, if they go to the main page or click a link without a locale specified, for example, a repo link, then they will be presented App Inventor in English. This is bad from a UX perspective as the user then has to change the language and wait for the site to reload. It also interrupts whatever workflow they were currently doing (e.g., when opening a template project). This change stores the last locale from the query string as the user's preferred locale. When a locale isn't specified in the URL, we will check the locale and if it is set, redirect to that page automatically. To also save on performing actions that would be canceled by the redirect, we also reorder some initialization of Ode so that it only occurs if the redirect won't happen. Change-Id: I1b9ffa756aa08f05495832768b242341e4a30c38 * Add missing GWT DTD for validation Change-Id: I2502bb3bce93db98575655bfb0e0cf8dd92f1119 * Hide Progress Dialog on Companion Update When the “OK” button on the Companion Update dialog is pressed, properly hide the ConnectProgressBar as we are now no longer connecting. Change-Id: I4c5f24a5e8979757d6e7066c734ba40078e4a8ce * Fix blocks PNG export in Webkit (mit-cml#1646) Change-Id: I25a6e14773fb75a43a556bee57d49e8aa292d036 * Fix issues with HolePointsFromString in Polygon (mit-cml#1654) Change-Id: I9b23ee39bb46e63d56e4bd7b6cc24b8d32cdade3 * Fix failing PolygonTests Change-Id: I0548b10a840678e25baa2636e2891838a5c6775b * Updated Texting documents for Google Voice no receiving issue mit-cml#1015 (mit-cml#1648) * Updated Texting documents for Google Voice no receiving issue * Update macOS binaries to 64-bit for Mojave Change-Id: I6b527f899b08e488a191b39bcfc37976e5fe5af6 * Correct testShowScale() method Javadoc in the MapTest.java * Replace JarSigner with ApkSigner (mit-cml#1417) Replace JarSigner with ApkSigner * Fix performance issue in project list (mit-cml#1663) The onProjectAdded method of ProjectList will sort and refresh the table, which is an `O(n log n)` operation. However, when we load the list of projects initially, this will get called `O(n)` times, resulting in `O(n^2 log n)` performance. For many users, the number of projects might be small and this load time may appear negligible. However, for more prolific users with hunders of projects, this may result in multiple seconds wait time while the list is first loaded. This fix defers sorting the list until all projects have been added. Change-Id: I50332dd8f2993883428c79e8dafbebbe32e2c1fa * Use DomHelper to show Do It error dialog (mit-cml#1664) * Use DomHelper to show Do It error dialog * Disable Do It when companion not connected * 1439 german translation for ai (mit-cml#1671) German translation with multiple authors: Author: Marina de Queiroz Tavares <dqtm@zhaw.ch> Author: Matthias Müller <matthias.mueller.2@uni-jena.de> Author: Lyndsey Bonelli <lyn.bonelli@gmail.com> * Add support for a “secondary” Rendezvous Server The primary rendezvous server is used for the initial rendezvous, whether using WebRTC or not (Legacy Mode). This change provides the location for a secondary rendezvous server to use for the WebRTC negotiation. This is only done if the Companion indicates that it supports this feature (sets “r2” to true in the JSON object it posts). Any information provided by the Companion can be used by the primary rendezvous server to determine which secondary server to use. Change-Id: I8706c4f0fe66a0e902595689896003feff9cdff7 * Remove calls to the Package Installer Remove calls to the Package Installer in order to be compliant with Google Play Store rules. Change-Id: Iab89c09e815af14728f08682d02e4447077aed55 * Implement additional companion build targets We now need to build three different companions for every release. This change makes it so that we can build all three with a single run of ant rather than having to configure multiple different companions and performing three separate builds of App Inventor for a components release. Change-Id: Ia0ed7e85513081e1fbaff606223f7d88b4dbc638 * Fix German Translation Fix issues related to the merge of the translation into master Change-Id: If23bfb96f811467ee609ea92aa9ef53f518f4b92 * Update Companion Version to 2.52 Change-Id: Ia306d6a821dd00695d9721ead97bc81845ef7231 * Another minor fix to the German translation Change-Id: I31b6218b4e851822c701cc65eb7812d76895a83b * Make Image.Picture ask for read permissions if needed Change-Id: I98a2aa0ccb8b231634b4122044e7a82ee9e801bd * Fix translations of event params when switching languages Change-Id: I11fcadeac62427a9f03a5ef1173c3ca3a2523b06 * Make 'global' keyword internationalizable Change-Id: I326f2f64f03fcc43a85c6f498e22b36da407815c * Make English the blocks editor base language Change-Id: I44526bf5fce726673f615e8d61d1fe21e57d4deb * Fix NPE when only using Google login Change-Id: I588d0b4e6f8c4dcf896f88cdee67a79b883cd006 * Refactor GeoJSON processing in mock map features Change-Id: I89f5cd0b2ab49c08ea263323ce2d8a058b6cc8fb * Fallback to application/octet-stream for unknown file types Change-Id: I2dcc304bbca68827c0b92dd5b1ef012d21de1db1 * Apply AnchorHorizontal and AnchorVertical values to Marker Change-Id: I7720bb0df1e312769dfed12819a56ebb45e44e65 * Initialize polygons loaded at runtime Change-Id: I708b6f4f2d602ed227a1a6343461ee60273b40f8 * Improve WebRTC Stability Improve the stability of the WebRTC IceCandidate negotiation when the round trip time to the Rendezvous server is large (> 400ms) which can be the case when the Rendezvous server is on the other side of the planet! Change-Id: I7a8883d30696ada2ea13393fde82f1d8f49bbc0c * Mitigate WebRTC Issue The previous commit updates the Companion to better handle the case where the Rendezvous server is far away from the user (long round trip time). This commit does a mitigation, at the cost of 5 seconds, in replmgr.js that results in older Companions being more likely to connect with a long round trip time. Change-Id: Ice6b86b11a3c21beedf2c066ac46593659651713 * Update README This commit specifies installation of 32-bit libraries needed in 64-bit Linux Systems * Fix warning counter going to -1 Change-Id: If0ed5ffc8c8fbb4cc4306f6de2949ca733e0f482 * Add Build Fingerprint Add the source fingerprint, which is the git commit hash, to crash reports in the log. Change-Id: Icba88d8a26655fe3ee0917736888bcf973b7af85 * Handle compiled app installation via browser Change-Id: Ia72226088534933b61021100a990fc74979c1d5e * Remove charset declaration from Android MIME type Android apps are binary blobs, not UTF-8. It's possible that the archive includes byte sequences that are invalid UTF-8 and we can't expect clients to do the right thing when they encounter such data. Change-Id: Iad16c06f7e977c44e2c71ab3f7952036a03fb22e * Remove vestigial XML blocks generator Change-Id: I886416cefa1a0eb34311e656847fb5dc4c433bf0 * Add missing entry for German in languages.json Change-Id: I4edeb1edf44fefe5b5ada27b528ac76cefb81746 * Enable import/export block code as PNGs (mit-cml#1706) * Enable import/export block code as PNGs This commit adds a feature to download individual blocks as PNG files. In the PNG file there will be a code chunk that stores the Blockly XML representation for the block. Dragging and dropping one of these images into the blocks editor will import that block. This can be useful for writing tutorials because the images of the blocks will also contain the code, so one can drag the block image into the workspace from another page. In order for the cross-site drag to work, the server serving the document must allow CORS from the App Inventor server. Change-Id: I524bbfbef739554884caa31a8b677ce1bcc893d1 * More WebRTC fixes This set of changes appears to cause WebRTC to negotiate ICE Candidates in just about all reasonable cases. Change-Id: Iff20c75c4ca2611e4dce2a8f8f11badafe002253 * Re-Enable the “Update Companion” Menu Item Re-Enable the “Update Companion” Menu Item, but limit its use to the Emulator. Change-Id: I86e530b65fd7845de42cdccecb5550af6215db3c * Add Switch style for Classic theme Change-Id: If82b8a5bdb43b686680a27cdc473fd118a42edb5 * Update Companion Version to 2.53 Change-Id: I13f194f1d0030757fbff37b36c312cfcbf1619dc * Fix backpack remove Fixes mit-cml#1467 * Reconcile block deletion confirmation Change-Id: I110d180f67feef0a0cd34b12902dbc182cbf5e43 * Handle unbound variables and prompt user for input Change-Id: I19869c5f2fa32f384b3dbbd7d07c4cadd821ecd5 * Fix export projects in oneProject mode Change the scope of the “selectedProjects” variable so we do not call “getProjectList()” when we are not on the PROJECTS tab. This fixes an issue with “oneproject” mode (which isn’t in this source tree). Change-Id: I515a9c25fad12339810712b1f5b995c3a8a3855b * Implement component search filter Change-Id: Ia27c0510d7a19b3715dd21040320676d06b9b281 * Implement a StopListening method for SpeechRecognizer The major changes in this commit involve implementing IntentBasedSpeechRecognizer and ServiceBasedSpeechRecognizer. UseLegacy property has also been added. Resolves mit-cml#1013 Change-Id: I56f94cdadda486576d6462f798dbf78c29ea905b * Add phone skin to designer * Fix exception when deleting extension with hidden components Change-Id: Id3df87c907e20a3cc1241337a64594ca48c6ad29 * Fix unbound variable dialog button Fixes mit-cml#1735 * Make App Inventor target Android SDK 28 (Pie 9.0) Change-Id: Id830f9bad0ff873a8df6ddc29c58e24e98fae452 * Blocks Toolkit (mit-cml#1728) Feature adapted from Lynda Tang's graduate work. Adds project-level property "BlocksToolkit" (internally also called SubsetJSON), which is a JSON string describing UI components and code blocks to be displayed in the Designer and Blocks Editor. This allows projects to limit the options in the GUI to fit the curriculum and not overwhelm students. Change-Id: Ie37ecbaa31398fcfcc57320a01dd1f67d1b13522 * Update Companion Version to 2.54 Change-Id: I4c1447b782279a6c461ba89d2393df05d74d0a3f * Fixed empty dropdown * Fix screen names with underscore (mit-cml#1755) Logic that finds the screen name by taking the form name and removing everything up to the first _ character broke when the screen name contains an underscore. Change-Id: I5503b302477df77eaab5cdf5804e33acd35cc941 * Optimise code (mit-cml#1758) * Don’t require WiFi for the Emulator Change-Id: I5376ce35f0b858b11563c903a32c820e25f1aa2d * Move component creator README to the right place (mit-cml#1738) * Fix blocks missing from editor after Blocks Toolkit enhancement Change-Id: Id1365f151e87f28c15e130e81e19885694158a0f * Clean up toolkit code, restore old code that worked better. Change-Id: Id33564e88afac4a331296e4af4af48b769e6120a * Add internationalization to component block tooltips in Blocks Editor Change-Id: I4a399d8a3defb239f7cd74384a3ba4b465710234 * Move CloudDB from Experimental to Storage Category Fixes mit-cml#1747 Change-Id: I03fdbcc0ba553fb43e0ffc401a0b462bc89ddb01 * Update README This commit specifies installation using commands based on Google Cloud SDK instead of App Engine SDK. * Remove Obsolete Docs from Service The knownIssues and ReleaseNotes pages here are ancient. These pages are now served from our website (and have been for the last 7 years!), so it is time to flush them from here! Change-Id: If109b83c02b6454ec1ae7c55ec7e96efd83f9547 * Make ScaledFrameLayout only save matrix Previous versions of ScaledFrameLayout saved the entire layer. This isn't great for performance reasons, but it also had the side effect on Android > 8.0 of messing with how WebView draws to the screen since it is drawing to a back buffer. This change switches to only calling save(), which saves the various transformations without creating a secondary buffer. This seems to make the WebView happy again. Change-Id: I9188e68d943fdc56bca7a57a24d0d17b2f9b49e7 * Korean translation update (mit-cml#1726) * Fix REPL bug when switching to freshly opened projects Change-Id: If71bbaee9000dc6332d1452cb02be63a1c3402e2 * Create built-in repo for YR Media templates Change-Id: I331cfcebc9e9053dec399d5b724495f8ef7a51f0 * Polish translation (mit-cml#1729) Translation Credit to: Krzysztof Kucner Change-Id: I29298525dd017abdf4880e9d2f80a23aa4936a82 * Make PhoneCall request READ_PHONE_STATE dangerous permission also Change-Id: Ibacdc5f81f57ab6e49dc906daec47ae593fc94bc * Make template wizard dialog fit smaller screens Change-Id: I558443f2afbe08ee192d06f468bcd173f31997d0 * Remove horizontal scroll from template wizard dialog * Add missing android.arch.lifecycle dependency Change-Id: I3f616e1a4c42416b8e33b40fb3183e65cc862e58 * Fix project download bug reported by @barreeeiroo Change-Id: Ibe01541a106b37bffbde21f05ea7f1b2c134070a * Update Companion Version to 2.55 Change-Id: I6ffef0b3bc66d55adea643bccf34ed4dae2d6d57 * Add missing extension to emulator build to allow package installation Change-Id: I004e2beda3cd26a1f25e19f38370cca4f2f1fbf5 * Fix author info problem * Add direct link to download in Barcode link dialog * Remove unused code * Add legacy connection information to README.md * Fix missing tooltips in extension blocks (mit-cml#1804) * Fix missing tooltips in extension blocks * Add regression testing for component blocks translation Change-Id: I524b4639234b51d55b82f84a02abdca0db40a4a7 * Add not-equal to text compare block * Remove debug logging * Make blocks collapse/expand on double click (mit-cml#1809) Change-Id: Ia4964537d457316824325bdf351a26820a51144a * Add Javadoc extraction for property descriptions (mit-cml#1811) Change-Id: I7fdc2d77430473420ed2d0e17d798a485ea16325 * Fix landscape navigationbar orientation in designer * Implement substring search on components palette (mit-cml#1814) * Implement substring search on components palette * Add "Target Android SDK" information to Help > About menu * Add media preview Change-Id: I6702e49a89777c1aa65c6a9fb766e0980d0fc380 * Add %type% as a token in component descriptions App Inventor doesn't present a type hierarchy even though internally it makes sense for objects to have shared methods defined in super classes. However, the documentation for the properties, methods, and events of an App Inventor component shared in this way must typically be written generic enough so that they make sense when shown on concrete classes. This can lead to either awkward/generic sounding documentation or requires that the component author override all of the relevant features on the component to provide component-specific descriptions. This change makes it so that descriptions of components, properties, methods, and events can contain one or more %type% tokens that can be substituted with the name of the concrete representation shown to the App Inventor user. This allows for documentation to be shared at the super class level while still making it sound specific to the individual component type. Change-Id: Ida4eb22bec12b2e33ac73de2bb5706d1683b227a * Update Sort By Category Function Change-Id: If1fe3358fb87be47a90dd90a79c794a751ab7288 * Register YaFormEditor and YaBlocksEditor earlier Prior to this change, YaFormEditor and YaBlocksEditor are registered in loadDesigner, which is called from onShow. This is problematic because if the screen hasn't been opened in the current session and the user deletes an extension, the unopened screens are not notified of the change. When the project is reloaded, it will fail to load because the unopened screens still referenced the deleted extension. This change moves the registration of YaFormEditor and YaBlocksEditor as FormChangeListeners to the onFileLoaded method so that they are made aware of project-level changes (like removing an extension) even if they are never viewed in a session. Change-Id: I8306ede85f5fb3576d810c9bd213e5e00df938ff * Redesign the dialog box that appears when a user has no projects Change-Id: I9802f22cbe9fba8ed768de995d40b315ec3483ed * Add OpenDyslexic font as alternative user setting * Use border box sizing for MockTextBox (mit-cml#1721) Change-Id: Ic374dbabd9fad57c06b1b070ab3d84a63ba0b4e6 * Update AssetList.java * Give deprecation warning for FusiontablesControl Give a warning when a project that uses the FusiontablesControl is loaded. Google will be shutting down the Fusiontables service on December 3rd, 2019. Change-Id: I6a56853ea8a56790495b4462b1c59d5c3059eaef * Support disabling events in the REPL (mit-cml#1849) * Cancel focusing on TreeItems in Tree widgets (mit-cml#1848) Change-Id: Ib3e663aae8135694ddf423611ebcf7a7caffbd39 * Add GitHub templates (mit-cml#1850) * Add GitHub templates * Update AIStarter to Python 3 Also supports Windows, Linux & Mac OS all in one file Co-authored-by: Evan W. Patton <ewpatton@mit.edu> * Associate marker asset with Map for runtime markers (mit-cml#1868) Change-Id: I9338893e68d64d67207c107b039dc4d7cfbfb556 * Make AWT run in headless mode in buildserver On macOS, the application icon preparation step causes Java AWT to create an app window. This window gains focus, even though the buildserver is a background process. This really only affects developers working with the sources on OS X. This change sets a flag to inform AWT to run in headless mode, which prevents it from creating the app window. Change-Id: Ida725b80e67c55777437cdd69392a3fab4dcf00a * Added Sponsor Button * Reenable convert number block translations in zh_tw, zh_cn (mit-cml#1864) * Reenable convert number block translations in zh_tw, zh_cn * Reuse flydown SVG rather than making orphans (mit-cml#1876) Change-Id: I34fc7bb333208d59e9186800fe2696621c9971af * Make "Display hidden components in Viewer" checkbox screen-dependent (mit-cml#1852) * Cache checkbox state for each screen * Make hidden components checkbox screen-dependent * Raise error when using boxed primitive types in component APIs (mit-cml#1846) * Raise error when using boxed primitive types in component APIs * Make ComponentProcessor error messages private * Fix translations of preview size dropdown options (mit-cml#1877) * [GSOC] Implementing Trash Can Functionality in MIT App Inventor. (mit-cml#1783) This functionality keeps the deleted project in a folder called Trash and if the project is accidentally deleted will not directly go away from App Inventor but will exist in Trash. In Trash Window users will have functionality to permanently delete the project or restore back to My Projects or simply keep in Trash. * Update Dutch translations (mit-cml#1863) * Remove unused context constructor param (mit-cml#1890) * Fix exception caused by attempting to open flydown during drag from toolbox Change-Id: Iaac765df9371acb8672df71bb12b22e02fd40cb9 * Implement extra null checks on flydown Change-Id: I9fc9e5516c329ac8b286fc075ad0b863018164bb * Fix wrong reference to FieldFlydown (was FieldDropdown) Change-Id: I7be76fd01960ae8f333ea7bd54d8cd8f33dc51e8 * Skip dragging bubbles of icons without locations Change-Id: I9a087d73674b4afe842a300693324ff559afa1cd * Set open flydown only once flydown is open Change-Id: I81b2f7bfc1f6806f3a0d1aef9e658050b46050fd * Hide more chaff Change-Id: Iae1a102a0323a65a936b21cfa36326c686e3a2c5 * Make empty component setter sockets errors, not warnings Change-Id: I59456500e2e89b0ce43f0f80f5d447dae8b8a2ea * Implement option to disable project auto load Autoload behavior can be overriden per session by including autoload=false or autoload=true in the query string when loading App Inventor. This commit also refactors the menu construction into individual pieces so that they can be called to be reconfigured. At the moment, this feature is only used for the Settings menu, but it makes the creation of each menu independent of any other menu. Change-Id: Id220991cef5f7643465ef9648f663a52be1486ae * Fix global keyword internationalization (mit-cml#1902) The global keyword that prefixes global variables is translated, and this translation ends up in the Blockly XML. We need to keep the translation separate from the underlying representation so that projects still work when switching between languages. Change-Id: I7bc88f0a26c8dce6d256010c188d7233d8cc43f8 * Enable multiple component selection using shift key presses (mit-cml#1891) * Enable multiple component selection using shift key presses * Add highlight to select components and show number of components selected * Make selected component properties default when there is no full intersection * Allow unselection of already selected components * Fix tutorial panel sizing (mit-cml#1904) Change-Id: Ib3142c60ecb389da2b304d96c30308cb08939ebb
Не получается записать данные из mysql в xml
xml должен выглядеть так
<?xml version="1.0" encoding="utf-8"?> <kaspi_catalog date="string" xmlns="kaspiShopping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="kaspiShopping http://kaspi.kz/kaspishopping.xsd"> <company>CompanyName</company> <merchantid>CompanyID</merchantid> <offers> <offer sku="232130213"> <model>iphone 5s white 32gb</model> <brand>Apple</brand> <availabilities> <availability available="yes" storeId="myFavoritePickupPoint1"/> <availability available="yes" storeId="myFavoritePickupPoint2"/> </availabilities> <price>6418</price> </offer> <offer sku="232130223"> <model>iphone 6s white 32gb</model> <brand>Apple</brand> <availabilities> <availability available="yes" storeId="myFavoritePickupPoint1"/> <availability available="yes" storeId="myFavoritePickupPoint2"/> </availabilities> <cityprices> <cityprice cityId="750000000">193000</cityprice> <cityprice cityId="710000000">195000</cityprice> </cityprices> </offer> </offers> </kaspi_catalog>
Вот мой код
$simplexml= new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?> <kaspi_catalog/>'); $simplexml->addAttribute('xmlns:date', 'string'); $simplexml->addAttribute('xmlns:xmlns', 'kaspiShopping'); $simplexml->addAttribute('xmlns:xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); $simplexml->addAttribute('xmlns:xsi:schemaLocation', 'kaspiShopping http://kaspi.kz/kaspishopping.xsd'); $simplexml->addChild("company", "CompanyName"); // Название компании $simplexml->addChild("merchantid", "CompanyID"); // ID Компании // $offers = $simplexml->addChild('offers'); foreach($result as $key => $val) { $offer = $offers->addChild('offer'); $offer->addAttribute('offer:sku', $val['sku']); $offer->addChild("model", $val['model']); $offer->addChild("brand", $val['brand']); $availabilities = $offer->addChild("availabilities"); $availabilities->addChild($val['available']); } file_put_contents('price_list.xml', $simplexml->asXML());
Выходит такая ошибка
Подскажите, что я делаю не так?
Issue
My Controller calls the service to post information about a car like below and it works fine. However, my unit test fails with the IllegalArgumentException: URI is not absolute exception and none of the posts on SO were able to help with it.
Here is my controller
@RestController
@RequestMapping("/cars")
public class CarController {
@Autowired
CarService carService;
@PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<CarResponse> getCar(@RequestBody CarRequest carRequest, @RequestHeader HttpHeaders httpHeaders) {
ResponseEntity<CarResponse> carResponse = carService.getCard(carRequest, httpHeaders);
return carResponse;
}
}
Here is my service class:
@Service
public class MyServiceImpl implements MyService {
@Value("${myUri}")
private String uri;
public void setUri(String uri) { this.uri = uri; }
@Override
public ResponseEntity<CarResponse> postCar(CarRequest carRequest, HttpHeaders httpHeaders) {
List<String> authHeader = httpHeaders.get("authorization");
HttpHeaders headers = new HttpHeaders();
headers.add("Authorization", authHeader.get(0));
HttpEntity<CarRequest> request = new HttpEntity<CarRequest>(carRequest, headers);
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<CarResponse> carResponse = restTemplate.postForEntity(uri, request, CarResponse.class);
return cardResponse;
}
}
However, I am having trouble getting my unit test to work. The below tests throws IllegalArgumentException: URI is not absolute exception:
public class CarServiceTest {
@InjectMocks
CarServiceImpl carServiceSut;
@Mock
RestTemplate restTemplateMock;
CardResponse cardResponseFake = new CardResponse();
@BeforeEach
void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
cardResponseFake.setCarVin(12345);
}
@Test
final void test_GetCars() {
// Arrange
HttpHeaders headers = new HttpHeaders();
headers.add("Authorization", anyString());
ResponseEntity<CarResponse> carResponseEntity = new ResponseEntity(carResponseFake, HttpStatus.OK);
String uri = "http://FAKE/URI/myapi/cars";
carServiceSut.setUri(uri);
when(restTemplateMock.postForEntity(
eq(uri),
Mockito.<HttpEntity<CarRequest>> any(),
Mockito.<Class<CarResponse>> any()))
.thenReturn(carResponseEntity);
// Act
**// NOTE: Calling this requires real uri, real authentication,
// real database which is contradicting with mocking and makes
// this an integration test rather than unit test.**
ResponseEntity<CarResponse> carResponseMock = carServiceSut.getCar(carRequestFake, headers);
// Assert
assertEquals(carResponseEntity.getBody().getCarVin(), 12345);
}
}
UPDATE 1
I figured out why the «Uri is not absolute» exection is thrown. It is because in my carService
above, I use @Value
to inject uri
from application.properties
file, but in unit tests, that is not injected.
So, I added public property to be able to set it and updated the code above, but then I found that the uri
has to be a real uri to a real backend, requiring a real database.
In other words, if the uri
I pass is a fake uri, the call to carServiceSut.getCar
above, will fail which means this turns the test into an integration test.
This contradicts with using mocking in unit tests.
I dont want to call real backend, the restTemplateMock
should be mocked and injected into carServiceSut
since they are annotated as @Mock
and @InjectMock
respectively. Therefore, it whould stay a unit test and be isolated without need to call real backend. I have a feeling that Mockito and RestTemplate dont work well together.
Solution
You need to construct your system under test properly.
Currently, MyServiceImpl.uri
is null.
More importantly, your mock of RestTemplate is not injected anywhere, and you construct a new RestTemplate in method under test.
As Mockito has no support for partial injection, you need to construct the instance manually in test.
I would:
Use constructor injection to inject both restTemplate and uri:
@Service
public class MyServiceImpl implements MyService {
private RestTemplate restTemplate;
private String uri;
public MyServiceImpl(RestTemplate restTemplate, @Value("${myUri}") uri) {
this.restTemplate = restTemplate;
this.uri = uri;
}
Construct the instance manually:
- drop @Mock and @InjectMocks
- drop Mockito.initMocks call
- use Mockito.mock and constructor in test
public class CarServiceTest {
public static String TEST_URI = "YOUR_URI";
RestTemplate restTemplateMock = Mockito.mock(RestTemplate.class);
CarServiceImpl carServiceSut = new CarServiceImpl(restTemplateMock, TEST_URI):
}
Remove creation of restTemplate
in method under test.
If needed, add a config class providing RestTemplate bean (for the application, the test does not need that):
@Configuration
public class AppConfig {
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
Note that RestTemplate is thread-safe, one instance per app is enough: Is RestTemplate thread safe?
Answered By — Lesiak
У меня есть файл
/user/guest/work/test/src/main/java/Test.java
И файл -объект:
File f = new File("/user/guest/work/test/src/main/java/Test.java");
Мне нужны эти выводы
System.out.println(f); -> src/main/java/Test.java
System.out.println(f.getAbsolutePath()); -> /user/guest/work/test/src/main/java/Test.java
Я устал:
File relativeTo = new File("/user/guest/work/test");
new File(relativeTo.toURI().relativize(f.toURI()));
Но это бросает
java.lang.IllegalArgumentException: URI is not absolute
at java.io.File.<init>(File.java:416)
at Test.<init>(Test.java:43)
Как получить нужный вывод?
2 ответа
Лучший ответ
relativize
возвращает URI.
new File(URI uri)
занимает …
uri — абсолютный , иерархический URI
Вместо этого вы можете попробовать использовать конструктор String.
new File(relativeTo.toURI().relativize(f.toURI()).toString());
У вас есть доступ к этому файлу другими способами, однако
Например, вы можете попробовать пройти через java.nio.file.Path
API вместо java.io.File
Подобно
Path path = Paths.get("/", "user", "guest", "workspace",
"test", "src", "main", "java", "Test.java");
Path other = ...
Path relPath = other.relativize(path);
// relPath.toString(); // print it
// relPath.toFile(); // get a file
4
OneCricketeer
1 Июн 2018 в 13:43
Вы можете использовать разрешение пути для релятивизации путей к файлам
File f = new File("/user/guest/workspace/test/src/main/java/Test.java");
File relativeTo = new File("/user/guest/workspace/test");
System.out.println(new File(relativeTo.toPath().resolve(f.toPath()).toUri()));
4
Pulkit
4 Мар 2017 в 04:04