Skip to content

Commit b8c143f

Browse files
committed
Fix merge conflicts
2 parents 3b5335e + 6384831 commit b8c143f

File tree

374 files changed

+21740
-27271
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

374 files changed

+21740
-27271
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ hs_err_pid*
1919
# generated files
2020
target
2121
/gen
22+
23+
# mac
24+
.DS_Store

docs/index.rst

+3
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ This documentation will help you get up and running fast and provides a full lan
1515

1616
intro
1717
quick-tour
18+
tutorial
19+
key-concepts
20+
samples

docs/intro.rst

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ What is Ballerina?
33
==================
44
Ballerina is the premier programming language designed for integration. It allows you to connect apps and services to handle all types of integration scenarios, such as collecting top tweets from a specific location and adding them to a Google spreadsheet, generating emails with real-time quotes pulled from a stock quote service, transforming and routing data based on advanced logic, and much more.
55

6-
Ballerina includes a visual editor that allows you to create sequence diagrams to build your integrations. This allows you to easily visualize your integration scenario and all the components that need to interact. As you create the diagram, the integration code is written for you, and at any time you can switch to the Source view to see and modify the code.
6+
Ballerina is:
77

8-
Ballerina is open source, so you can see exactly how it works and join the growing community of users contributing to its code base. It includes an API that allows you to incorporate its functionality in your own code.
8+
* **Flexible**. You can use the visual editor to build your integration from sequence diagrams, or write code directly into the source editor. You can also use the IDEA plug-in to write your Ballerina code in IntelliJ IDEA. Ballerina is open source, so you can see exactly how it works and join the growing community of users contributing to its code base.
9+
10+
* **Powerful**. The Ballerina language was designed from the ground up specifically for integration and can handle everything from a simple Hello World program to complex service chaining and content-based routing scenarios. The runtime is lightweight and incredibly fast. And it includes an API that allows you to incorporate its functionality in other applications.
11+
12+
* **Beautiful**. Ballerina's visual editor allows you to easily visualize your integration scenario and all the components that need to interact by dragging and dropping elements onto a canvas. As you create the diagram, the integration code is written for you, and at any time you can switch to the Source view to see and modify the code.
913

1014
To get started, go to the :doc:`quick-tour` and take Ballerina for a spin!

docs/key-concepts.rst

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
============
2+
Key Concepts
3+
============
4+
Each Ballerina program represents a discrete unit of functionality that performs an integration task. You can create a Ballerina program as a **service** that runs in the Ballerina server and awaits requests over HTTP. Or you can create your program as an executable program that executes a ``main()`` function and then exits (see below). Your Ballerina programs can be as simple or as complex as you like, but for best results, each program should focus on a specific task.
5+
6+
As you create your program, there are several constructs available that you can use:
7+
8+
* **Service**: When defining a Ballerina program as a service instead of an executable program, the ``service`` construct acts as the top-level container that holds all the integration logic and can interact with the rest of the world. Its base path is the context part of the URL that you use when sending requests to the service. Note that you can have multiple services in a single Ballerina program, each with their own base path. This is useful in more complex scenarios like the Content-Based Routing sample.
9+
* **Resource**: A resource is a single request handler within a service. When you create a service in Ballerina using the visual editor, a default resource is automatically created as well. The resource contains the integration logic.
10+
* **Function**: A function is a single operation. Ballerina includes a set of native functions you can call, such as the ``ConvertToResponse()`` function you used in the Tutorial, and you can define additional functions within your Ballerina programs.
11+
* **Connector**: A connector represents a participant in the integration and is used to interact with an external system or a service you've defined in Ballerina. Ballerina includes a set of standard connectors that allow you to connect to Twitter, Facebook, and more, and you can define additional connectors within your Ballerina programs.
12+
* **Action**: An action is an operation you can execute against a connector. It represents a single interaction with a participant of the integration.
13+
14+
You can also define constants, variables, structured types, and more as you do with other programming languages, and you can use logic statements like if and while. For more information, see the Language Reference.
15+
16+
TODO: add a diagram without workers
17+
18+
-------------------
19+
Executable programs
20+
-------------------
21+
An executable program contains the core integration logic within the ``main()`` function. For example::
22+
23+
import ballerina.lang.system;
24+
25+
function main (string[] args) {
26+
system:println("Hello, World!");
27+
}
28+
29+
When you run this program, the ``main()`` function executes, and then the program terminates. You can define additional functions, connectors, etc. inside the program and call them from ``main()``. For a more complex example of an executable Ballerina program, see the Twitter Connector sample.

docs/language-ref

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
==================
2+
Language Reference
3+
==================
4+
5+
This section provides information on the syntax of the Ballerina language and how to write a program.

docs/samples.rst

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
=======
2+
Samples
3+
=======
4+
The best way to start writing your Ballerina program is to use the samples as templates. Each sample includes a walk-through of the code so you can see how it's done.
5+
6+
* **helloWorld**: A simple executable program that prints "Hello World" to the command line.
7+
* **helloWorldService**: A service that prints "Hello World" to the command line.
8+
* **echoService**: A service that takes text from the incoming request message and sends it back to the client as a response.
9+
* **passThroughService**: A service that sends the incoming request message to a backend service and sends a response back to the client.
10+
* **restfulService**: A RESTful service that comprises three resources and illustrates how you can build the business logic for each resource.
11+
* **routingServices**: Contains two separate services that route messages to different backends based on the message content or header value.
12+
* **serviceChaining**: Contains a composite service, ATMLocatorService, which illustrates how to chain services together to get the required information. It calls one service to find the nearest ATM by ZIP code, it calls a second service to get the address of that ATM, and then it composes the response and sends the information back to the client.
13+
* **twitterConnector**: An executable program that defines a connector that you can use to connect to a Twitter account and post a status update (tweet).
14+
* **tweetOpenPR**: An executable program that uses the GitHub API to get the open pull requests for a specific repository and then tweets the total number of pull requests on Twitter.
15+
* **tweetMediumFeed**: An executable program that retrieves the feed for WSO2 from Medium.com and tweets the first item's title.

docs/tutorial.rst

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
==================
2+
Tutorial
3+
==================
4+
Now that you’ve taken the :doc:`/quick-tour`, let's dig a little deeper and take the leap into writing your first Ballerina integration program. This tutorial will teach you how to run Ballerina in standalone and server mode, use the editor to build your integration, understand the key concepts, and get familiar with the Ballerina language.
5+
6+
-----------------
7+
Running Ballerina
8+
-----------------
9+
In the :doc:`/quick-tour`, you learned how to start Ballerina and run a sample program with a single command::
10+
11+
./ballerina run helloworld.bal
12+
13+
After the HelloWorld program executed, Ballerina stopped. This approach is called **standalone mode**, and it's useful when you want to execute a program once and then stop as soon as it has finished its job. It runs the main() function of the program you specify and then exits.
14+
15+
You can also run Ballerina as a **server**, so that it can deploy a program as a service that waits for requests. To see how this works, let's go to the Ballerina ``bin`` directory, and then run Ballerina in server mode and deploy the HelloWorldService program::
16+
17+
./ballerina service ../samples/helloWorldService/helloWorldService.bal
18+
19+
In this case, Ballerina ran and deployed the HelloWorldService program as a service, which is waiting for a request. Let's send it one now. The Ballerina server is available at ``localhost:9090``, and HelloWorldService is available at context ``hello``. Open another command line and use the `curl <https://curl.haxx.se>`_ client to call the service as follows::
20+
21+
curl -v http://localhost:9090/hello
22+
23+
The service receives the request and executes its logic, printing "Hello, World" on the command line. Notice that the Ballerina server is still running in the background, waiting for more requests to come in.
24+
25+
----------------
26+
Using the Editor
27+
----------------
28+
Now that you understand how to run Ballerina in standalone and server mode, let's play with the editor. Run it from the command line like this (omit the ``sh`` prefix if you're running on Windows)::
29+
30+
sh editor
31+
32+
And now access it from the following URL in your browser: http://localhost:9091
33+
34+
The Ballerina editor appears. Notice that on the left you have a tool palette of the various constructs that you'll use to build your integration. On the right, you have a visual editor with a canvas onto which you drag those constructs. This is where you'll build your sequence diagrams that define your integration logic.
35+
36+
Additionally, look for the source code icon in the lower right corner (``</>``). Click it now, and you'll see the source code that represents the sequence diagram as code in the Ballerina language. In a new file with no content, the only source code will be a line importing the Ballerina language package. Click the icon again to return to the visual editor. You can go back and forth between the visual editor and the source code and make your edits in either place.
37+
38+
-----------------------
39+
Building an integration
40+
-----------------------
41+
It's time to build your first integration! In this exercise, we are going to build a service that takes an incoming message, extracts the text, and sends a message back to the client with that same text.
42+
43+
^^^^^^^^^^^^^^^^^^^^^^^^^^
44+
Add a service and resource
45+
^^^^^^^^^^^^^^^^^^^^^^^^^^
46+
First, we add a service construct to the canvas. A **service** is a container for all the other constructs and represents a single unit of functionality that can be accessed remotely. Technically, it's an HTTP web service described by a Swagger definition file.
47+
48+
On the tool palette, click and drag the service icon ``{S}`` to the canvas. A box appears with the name ``newService``, and inside it is another box called ``newResource`` with some logic already created for you.
49+
50+
A **resource** is is a single request handler within a service. This is where we will program the logic describing how to handle the incoming message to this service. By default, the resource is configured to accept a message ``m``. You can see this by clicking the Parameters icon (a box with an arrow pointing into it) in the upper right corner of the resource box. When you click it, you'll see ``message m`` listed below the fields. Click the Parameters icon again to close its window.
51+
52+
Let's rename both the service and resource. Highlight the name ``newService`` and type ``echo`` in its place. Change ``newResource`` to ``echoResource`` in the same way.
53+
54+
^^^^^^^^^^^^^^^^^
55+
Set the base path
56+
^^^^^^^^^^^^^^^^^
57+
Now, let's set the base path for this service. This will be the context portion of the URL that is used to send requests to this service. In the upper right corner of the service box (not the resource box this time), click the ``@`` symbol. Make sure BasePath is selected in the list, type ``/echo2`` in the text box, and then press Enter or click the + symbol to its right. (We are naming it ``/echo2`` so that it doesn't conflict with the existing echo sample.) The base path is now set, so that when you deploy this service, clients will be able to send requests to it using the URL http://localhost:9090/echo2.
58+
59+
^^^^^^^^^^^^^^^^^^
60+
Change GET to POST
61+
^^^^^^^^^^^^^^^^^^
62+
When you added the service, Ballerina configured the resource to use the GET method by default. Because we are going to use the incoming message to post a reply, let's change it to POST. Click the ``@`` symbol in the upper right corner of the resource box, highlight ``GET``, and type ``POST``. Then click the ``@`` symbol again to hide the box. You can click the symbol again to confirm that GET was in fact changed to POST. You can also click the source (``</>``) icon in the lower right corner to see the changes that are being made to the code as you work with the visual editor.
63+
64+
^^^^^^^^^^^^^^
65+
Add a function
66+
^^^^^^^^^^^^^^
67+
Now we are ready to add a function that will take the incoming message and convert it to a response that gets sent back to the client. The ballerina.net.http package includes a native function called ``convertToResponse`` that does exactly this, so let's import that package and add the function to our flow.
68+
69+
In the upper right corner of the canvas, click the package icon (it looks like a cube), type ``ballerina.net.http``, and press Enter. You have now imported the package containing the native function we want to use.
70+
71+
In the Statements section of the tool palette, grab the Function Invocation icon and drag it under the start box in the sequence diagram. Click the function box you just added and click the Edit icon (it looks like a pencil). For the package name, type ``http``. For the FunctionName, type ``convertToResponse``. And in Params, type ``m``, which is the incoming message.
72+
73+
Now that we've added the function that will convert the incoming message text to a response, we just need to instruct the program to send the response back to the client.
74+
75+
^^^^^^^^^^^^^
76+
Add the reply
77+
^^^^^^^^^^^^^
78+
On the tool palette, grab the Reply icon (the straight left arrow) and drag it to the canvas under the function invocation you just added. You'll see that it appears as a box with an arrow going back to the client. Click the box, click the Edit icon, and set the response message to m, which instructs the program to send the message processed by the convertToResponse function back to the client.
79+
80+
This completes the sequence, so you are now ready to save and run your integration program.
81+
82+
^^^^^^^^^^^^^^^^
83+
Save the program
84+
^^^^^^^^^^^^^^^^
85+
Click the **File** menu and choose **Save As**. Let's save it as ``myEcho.bal`` in your Ballerina ``bin`` directory. After you save it, a file explorer on the left shows the bin directory. You can expand it to see that the file is there, then click the file explorer icon to close the file explorer. The file explorer is a handy way to open files inside the editor in the future.
86+
87+
^^^^^^^^^^^^^^^
88+
Run the program
89+
^^^^^^^^^^^^^^^
90+
At your command prompt, navigate to your Ballerina ``bin`` directory, and enter the command to run the Ballerina server and deploy your myEcho program::
91+
92+
./ballerina service myEcho.bal
93+
94+
Your service is now deployed and running on the Ballerina server. From a separate command prompt, use curl to send a request to your program::
95+
96+
curl -v http://localhost:9090/echo2 -d "Hello World......"
97+
98+
The service receives the request, takes the text ``Hello World......`` from the incoming message, converts it into a response, and sends it back to the command line where the request was sent.
99+
100+
----------------
101+
Where to go next
102+
----------------
103+
Now that you're familiar with running Ballerina in standalone and server mode, using the editor to build an integration program, and creating a service and resource, you are ready to learn more about the constructs you can use in your program, the native functions available in Ballerina, and the Ballerina language syntax.
104+
105+

modules/ballerina-core/src/main/java/org/wso2/ballerina/core/exception/LinkerException.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323
public class LinkerException extends BallerinaException {
2424
/**
25-
* Constructs a new {@link BallerinaException} with the specified detail message.
25+
* Constructs a new {@link LinkerException} with the specified detail message.
2626
*
2727
* @param message Error Message
2828
*/
@@ -31,7 +31,7 @@ public LinkerException(String message) {
3131
}
3232

3333
/**
34-
* Constructs a new {@link BallerinaException} with the specified detail message and cause.
34+
* Constructs a new {@link LinkerException} with the specified detail message and cause.
3535
*
3636
* @param message Error message
3737
* @param cause Cause
@@ -41,7 +41,7 @@ public LinkerException(String message, Throwable cause) {
4141
}
4242

4343
/**
44-
* Constructs a new {@link BallerinaException} with the cause.
44+
* Constructs a new {@link LinkerException} with the cause.
4545
*
4646
* @param cause
4747
*/

modules/ballerina-core/src/main/java/org/wso2/ballerina/core/exception/ParserException.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class ParserException extends BallerinaException {
2525
private static final long serialVersionUID = 1L;
2626

2727
/**
28-
* Constructs a new {@link BallerinaException} with the specified detail message.
28+
* Constructs a new {@link ParserException} with the specified detail message.
2929
*
3030
* @param message Error Message
3131
*/
@@ -34,7 +34,7 @@ public ParserException(String message) {
3434
}
3535

3636
/**
37-
* Constructs a new {@link BallerinaException} with the specified detail message and cause.
37+
* Constructs a new {@link ParserException} with the specified detail message and cause.
3838
*
3939
* @param message Error message
4040
* @param cause Cause
@@ -44,7 +44,7 @@ public ParserException(String message, Throwable cause) {
4444
}
4545

4646
/**
47-
* Constructs a new {@link BallerinaException} with the cause.
47+
* Constructs a new {@link ParserException} with the cause.
4848
*
4949
* @param cause
5050
*/

modules/ballerina-core/src/main/java/org/wso2/ballerina/core/interpreter/BLangExecutor.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -356,12 +356,7 @@ public BValue[] visit(ResourceInvocationExpr resourceIExpr) {
356356
ControlStack controlStack = bContext.getControlStack();
357357
BValue[] valueParams = new BValue[resource.getStackFrameSize()];
358358

359-
BMessage messageValue = new BMessage(bContext.getCarbonMessage());
360-
361-
valueParams[0] = messageValue;
362-
363-
int valueCounter = 1;
364-
359+
int valueCounter = populateArgumentValues(resourceIExpr.getArgExprs(), valueParams);
365360
// Populate values for Connector declarations
366361
// valueCounter = populateConnectorDclValues(resource.getConnectorDcls(), valueParams, valueCounter);
367362

modules/ballerina-core/src/main/java/org/wso2/ballerina/core/model/ParameterDef.java

+13
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.wso2.ballerina.core.model.types.BType;
2222
import org.wso2.ballerina.core.model.types.SimpleTypeName;
2323

24+
import java.util.ArrayList;
2425
import java.util.List;
2526

2627
/**
@@ -57,6 +58,18 @@ public void setAnnotations(List<Annotation> annotations) {
5758
this.annotations = annotations;
5859
}
5960

61+
/**
62+
* Add an {@code Annotation} to the Argument.
63+
*
64+
* @param annotation Annotation to be added to the Argument
65+
*/
66+
public void addAnnotation(Annotation annotation) {
67+
if (annotations == null) {
68+
annotations = new ArrayList<>();
69+
}
70+
annotations.add(annotation);
71+
}
72+
6073
@Override
6174
public void accept(NodeVisitor visitor) {
6275
visitor.visit(this);

0 commit comments

Comments
 (0)