Null endpoint is passed when using soap ui project custom properties - web-services

I am trying to pass the endpoint for a project using the project custom properties. Say I created a custom property "EndPoint" and am trying to pass http://${#Project#EndPoint} in the endpoint field for the get request, it is throwing me null response. The request sent is not having the endpoint value.
GET http://null///int/locations/v1/destinations?
Should we able to override the properties?

Related

In AWS how do I add an API key to my API?

Hello: I've been following two tutorials in the AWS documentation:
creating the sample pet store API (https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-create-api-from-example.html)
...and creating an API key (https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-setup-api-key-with-console.html#api-gateway-usage-plan-create-apikey).
When I test the pet store get method with the provided URL, it returns:
Welcome to your Pet Store API You have successfully deployed your
first API. You are seeing this HTML page because the GET method to the
root resource of your API returns this content as a Mock integration.
The Pet Store API contains the /pets and /pets/{petId} resources. By
making a GET request to /pets you can retrieve a list of Pets in your
API. If you are looking for a specific pet, for example the pet with
ID 1, you can make a GET request to /pets/1.
You can use a REST client such as Postman to test the POST methods in
your API to create a new pet. Use the sample body below to send the
POST request:
{
"type" : "cat",
"price" : 123.11 }
Now I go to the API Gateway -> API -> Resources -> -> Method Request -> API Key Required and change it to "True" and redeploy.
When I go to the provided URL to test, now the page returns:
{"message":"Forbidden"}
Which makes sense... I told it API required = true, right?
So my question is, how do I pass the API key? So that I don't get the "forbidden" result? I didn't see that in the tutorial links I pasted above and haven't been able to find elsewhere.
You Create a Usage Plans
Attach this usage plan to your API and Stage
Create an API Key
Now invoke your API with header named x-api-key and value of it is the API Key created in step-3
Sample:
curl -i -H "x-api-key: Cd2YiWs8Fv8Lg6njI0wXf1iiNOE94XjM3EQe8567" -X GET https://7r9cvghbf4.execute-api.ap-northeast-2.amazonaws.com/dd/pets
Assuming you've followed all steps for creating the API key you can use this API key by specifying it in the x-api-key header within your request.
You distribute API keys to your customers and require them to pass the API key as the X-API-Key header of each incoming request.
More information for using API keys in API Gateway is available on: Choose an API key source - Amazon API Gateway

Obtain endpoint URL programatically inside wso2 custom handler

I have a custom mediator which obtains the endpoint url from message context property ENDPOINT_PREFIX.
I am trying to do the same in my authentication handler, but the get property returns null.
Is there a different way to obtain this information inside a custom handler?
Note that I am not after the endpoint itself (e.g. /api/1.0.0) but after the url to which it points to (in the publisher ui it appears as production/sandbox url).

Obtain HTTP_METHOD programatically inside WSO2 Custrom Handler?

I have a custom authentication handler in which I need to figure out the HTTP_METHOD.
In my custom mediators I can get this easily from the synapse context, from api.ui.HTTP_METHOD property. For example
api.ut.HTTP_METHOD ==> POST
But I do not have this property in my custom authentication handler. Is there another way to get hold on the HTTP METHOD of the API inside a custom authentication handler?
In a custom handler, you have access to the message context. Using that message context , you can retrieve HTTP_METHOD like below.
((Axis2MessageContext) messageContext).getAxis2MessageContext().get‌Property("HTTP_METHOD")
Can refer Writing Custom Handlers and Axis2 Java doc for more info.

how to pass the variable from api gateway to the url of another service running on EC2

I am new to AWS. I am asked to use the services that is written in java and already exist in java EC2 to serve the UI. I need to use API gateway to call the services so the UI will first call the API gate way and then API gate way will call my service. Also I know that in Select Integration Request if I choose http proxy and add the url of my services on Ec2 I can achieve this. However the problem is that I have a service like this:
http://domainname/article/{id}
As you can see the id is a variable and the above service should be called via API Gateway so API gate way should be able to pass the id to the service url. Lets say the following is the url of API gateway:
https://my-api-id.execute-api.region-id.amazonaws.com/stage-name/article?id=1
How can I handle the above scenario? is it possible to do that?
While you can use a Lambda function for this, you can also do it directly from API Gateway using basic request mapping.
Define your API in API Gateway with a resource having path /article
Add a GET method.
In the Method Execution pane, choose Method Request.
Expand "URL Query String Parameters"
Hit "Add query string"
Type id as the name and hit the checkbox on the right to save
Go back to the Method Execution pane, choose Integration Request.
Edit your endpoint URL to add the path parameter, if you have not already done so.
The URL should be: http://domainname/article/{id}
Choose the arrow next to "URL Path Parameters" to expand that section.
Click "Add path".
Enter id as the name
Under "Mapped from" enter: method.request.querystring.id
Click the check box on the right to save.
Go back to Method Execution and click Test.
Add an id value under query strings and click test.
There are some similar examples in the documentation here
I would suggest using Lambda to re-assemble the request. API Gateway will invoke the Lambda function that would receive the request
http://domainname/article/1
and will perform an HTTP request to your service
https://my-api-id.execute-api.region-id.amazonaws.com/stage-name/article?id=1

When using Amazon API Gateway, how do I get the API key used in the request from a Django backend?

Pretty self explanatory title. I'm using API Gateway in AWS, requiring an API key to access a backend written in Django (not using lambda). I need to know how to access the API key used in the request to keep track of who did what at the app level.
You can use mapping templates and get the API Key from the $context variable, it’s the apiKey property inside the identity object: http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html#context-variable-reference
Create a mapping template for your requests and include the property in it. For example, if you wanted to include the entire request body + the API Key you would do this:
{
"body": $input.json('$'),
"apiKey": "$context.identity.apiKey"
}
Depending on how your backend application is built, you could send the API key to your application in a HTTP parameter (path, query string, or header) or in the request body. Please have a read through the docs on how to move data between the two systems.
Thanks,
Ryan
Here is how I finally made it work. At the top or bottom of the template, include this line.
#set($context.requestOverride.header.x-api-key = $context.identity.apiKey)
When your backend receives this request, the api key will be in the header x-api-key.
Here is a basic mapping template that just forwards the (json) body and the header.
$input.json("$")
#set($context.requestOverride.header.x-api-key = $context.identity.apiKey)
API Gateway uses the X-API-Key header, so I like for my backend to also use that. That way I can use the same testing commands with only the URL being different.