I have Eureka running in my localhost:8090 . I have independent Java Apps registered in that Eureka and I am able to access them with my Zuul URL which is registered to that Eureka as well.
Now I am have another Python(3.7.3)+Flask App that I am trying to register in same Eureka and access that through same Zuul URL.
My Python app runs fine in local through a DOCKERFILE with these commands -
EXPOSE 8443
CMD ["python", "PythonFlaskSample.py"]
This opens a web-page with this URL -
http://localhost:8443/home
Then to register this App in Eureka, I followed this documentation -
https://github.com/Netflix/eureka/wiki/Eureka-REST-operations
and
https://automationrhapsody.com/json-format-register-service-eureka/
Also trying same through REST clients with POST URL as -
http://localhost:8090/eureka/v2/apps/PythonFlaskApp
Content-Type: application/json
{
"instance": {
"hostName": "localhost",
"app": "PythonFlaskSample",
"vipAddress": "localhost",
"secureVipAddress": "localhost",
"ipAddr": "<Which IP>????",
"status": "STARTING",
"port": {"$": "8090", "#enabled": "true"},
"securePort": {"$": "8443", "#enabled": "true"},
"healthCheckUrl": "http://localhost:8090/health",
"statusPageUrl": "http://localhost:8090/info",
"homePageUrl": "http://localhost:8090",
"dataCenterInfo": {
"#class": "com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo",
"name": "MyOwn"
},
}
}
But it is throwing a 405 and no other clue for what happened in Restlet client or Postman.
When I try to put the JSON Payload in python file and use POST from there,
request_body = {
"instance": {
"hostName": "localhost",
"app": "PythonFlaskSample",
"vipAddress": "localhost",
"secureVipAddress": "localhost",
"ipAddr": "<Which IP>????",
"status": "STARTING",
"port": {"$": "8090", "#enabled": "true"},
"securePort": {"$": "8443", "#enabled": "true"},
"healthCheckUrl": "http://localhost:8090/health",
"statusPageUrl": "http://localhost:8090/info",
"homePageUrl": "http://localhost:8090",
"dataCenterInfo": {
"#class": "com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo",
"name": "MyOwn"
},
}
}
data=json.dumps(request_body)
url="http://localhost:8090"
response = requests.post(url,data=json.dumps(request_body), headers = {'Content-type':'application/json'}).json()
print(response)
it shows following error-
docker run -p 8443:8443 dockerpython {'timestamp': 1555717403333,
'status': 405, 'error': 'Method Not Allowed', 'exception':
'org.springframework.web.HttpRequestMethodNotSupportedException',
'message': "Request method 'POST' not supported", 'path': '/'}
What am I missing ?
This is an error with Eureka API documentation in - https://github.com/Netflix/eureka/wiki/Eureka-REST-operations. Once I tried same REST URLs without "/v2" , everything worked fine.enter image description here
Related
I've an Artemis Broker (2.17) running on my dev machine for local testing.
From the web-console I've extractet the request to get the names of all queues.
When I execute the request from the browser console i get a JSON result like this:
{
"request": {
"mbean": "org.apache.activemq.artemis:broker=\"MyBroker\"",
"arguments": [
"ANYCAST"
],
"type": "exec",
"operation": "getQueueNames(java.lang.String)"
},
"value": [
"DLQ",
"ExpiryQueue"
],
"timestamp": 1624274952,
"status": 200
}
When I execute the same request from my code I get a very different result:
{
"request": {
"type": "version"
},
"value": {
"agent": "1.6.2",
"protocol": "7.2",
"config": {
"listenForHttpService": "true",
"authIgnoreCerts": "false",
"agentId": "192.168.1.41-30064-15b82644-servlet",
"debug": "false",
"agentType": "servlet",
"policyLocation": "file:/C:/Artemis/MyBroker/etc//jolokia-access.xml",
"agentContext": "/jolokia",
"serializeException": "false",
"mimeType": "text/plain",
"dispatcherClasses": "org.jolokia.http.Jsr160ProxyNotEnabledByDefaultAnymoreDispatcher",
"authMode": "basic",
"authMatch": "any",
"streaming": "true",
"canonicalNaming": "true",
"historyMaxEntries": "10",
"allowErrorDetails": "false",
"allowDnsReverseLookup": "true",
"realm": "jolokia",
"includeStackTrace": "false",
"mbeanQualifier": "qualifier=hawtio",
"useRestrictorService": "false",
"debugMaxEntries": "100"
},
"info": {
"product": "jetty",
"vendor": "Eclipse",
"version": "9.4.27.v20200227"
}
},
"timestamp": 1624274809,
"status": 200
}
Jsr160ProxyNotEnabledByDefaultAnymoreDispatcher seams very strange. But when searching for this name I couldn't realy find anything usefull. Also I cannot find any usefull information in the Artemis logs.
Here is my code:
using System;
using System.Net.Http;
using System.Text;
using System.Threading;
const String username = "admin";
const String password = "password";
var encoded = Convert.ToBase64String( Encoding.GetEncoding( "ISO-8859-1" )
.GetBytes( username + ":" + password ) );
var url = "http://localhost:8161/console/jolokia/?maxDepth=7&maxCollectionSize=50000&ignoreErrors=true&canonicalNaming=false";
var http = new HttpClient();
http.BaseAddress = new("http://localhost:8161/");
http.DefaultRequestHeaders.Add( "Authorization", "Basic " + encoded );
http.DefaultRequestHeaders.Add( "Origin", "http://localhost:8161/" );
var request = new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new(url),
Content = new StringContent( "{\"type\":\"exec\",\"mbean\":\"org.apache.activemq.artemis:broker=\\\"MyBroker\\\"\",\"operation\":\"getQueueNames(java.lang.String)\",\"arguments\":[\"ANYCAST\"]}" )
};
request.Content.Headers.ContentType = new("text/json");
var response = await http.SendAsync( request, HttpCompletionOption.ResponseHeadersRead, CancellationToken.None );
if ( response.IsSuccessStatusCode )
{
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine( content );
}
else
Console.WriteLine( "Request failed...." );
Console.ReadLine();
In the bootstrap.xml the binding is set to 0.0.0.0 which should be ok.
jolokia-access.xml contained <allow-origin>*://localhost*</allow-origin> which should be fine but just to be sure I've replaced it with <allow-origin>*</allow-origin>
Is there something I need to configure to make this work?
Jolokia requests can be sent in two ways: Either as a HTTP GET request, in which case the request parameters are encoded completely in the URL. Or as a POST request where the request is put into a JSON payload in the HTTP request's body. See the Jolokia Protocol for further details.
When the Jolokia service doesn't get any request it will answer with service information, ie:
{
"request": {
"type": "version"
},
"value": {
...
To request the queue names using an HTTP GET request
curl -H "Origin:http://localhost:8161" -u admin:admin http://localhost:8161/console/jolokia/exec/org.apache.activemq.artemis:broker=\"MyBroker\"/getQueueNames/ANYCAST
To request the queue names using an HTTP POST request
curl -X POST -H "Content-Type: application/json" -H "Origin:http://localhost:8161" -u admin:admin http://localhost:8161/console/jolokia -d '{"type" : "EXEC", "mbean" : "org.apache.activemq.artemis:broker=\"MyBroker\"", "operation" : "getQueueNames", "arguments" : ["ANYCAST"]}'
Your code is using an HTTP GET, but it is using a fixed URL (i.e. http://localhost:8161/console/jolokia/?maxDepth=7&maxCollectionSize=50000&ignoreErrors=true&canonicalNaming=false and a payload (i.e. {"type":"exec","mbean":"org.apache.activemq.artemis:broker="MyBroker","operation":"getQueueNames(java.lang.String)","arguments":["ANYCAST"]}"). This does not conform with the Jolokia protocol.
If you use an HTTP GET then everything should be in the URL itself presumably just like it was your browser console. For example, use this:
http://localhost:8161/console/jolokia/exec/org.apache.activemq.artemis:broker="MyBroker"/getQueueNames/ANYCAST
My http request send to this: https://myhost.com/ap
My http request with body :
{
"Body": {
"CommandName": "GetApplicationProfile"
},
"Header": {
"Command": "GetApplicationProfile",
}
}
I want to mapping this request by WireMock.
Here WireMock's mapping file.
{
"request": {
"url": "/my_host/ap",
"bodyPatterns": [
{
"contains": "GetApplicationProfile"
}
]
},
"response": {
"headers": {
"Content-Type": "application/json"
},
"status": 200,
"bodyFileName": "get_profile.json"
}
}
I start wireMock like this:
java -jar wiremock-standalone-2.18.0.jar --port 8080 --enable-browser-proxying -verbose
But when request was started the WireMock not map this request. Nothing happened.
why?
The problem you're having is that you shouldn't have the hostname in the url part. This is not needed. Your example message can be sent and will be matched using the following rule.
{
"request": {
"url": "/app",
"bodyPatterns": [
{
"contains": "GetApplicationProfile"
}
]
},
"response": {
"headers": {
"Content-Type": "application/json"
},
"status": 200,
"body": "ddd"
}
}
The URL should not contain the host name. It should only contain the resource path.
The url format should start with "/" e.g. /https://myhost.com/ap.
Now if u r trying this on localhost then the URL should be localhost:<port>/https://myhost.com/ap.
The file should be present at src/test/resources/__files
If not it will give error file not present.
I see 2 issues here:
1. you need to remove the host name from the url in the mapping file.
2. your request is HTTPS which means you need to start your wiremock port with https: --https-port 8080 or you change your request to HTTP
Recently I build presto with cluster mode, 1 coordinator & 1 worker, it works.
Then I repackage "presto-main-0.148.jar" without any change , and replace it to production environment, it doesn't work! Always get response with "No worker nodes available"
I search the Server.log and see below messages:
ERROR Discovery-0 io.airlift.discovery.client.CachingServiceSelector Cannot
connect to discovery server for refresh (collector/general): Lookup
of collector failed for
ht*p://10.3.2.33:18080/v1/service/collector/general
ERROR Discovery-0 io.airlift.discovery.client.CachingServiceSelector Cannot
connect to discovery server for refresh (presto/general): Lookup of
presto failed for ht*p://10.3.2.33:18080/v1/service/presto/general
INFO Discovery-1 io.airlift.discovery.client.CachingServiceSelector Discovery
server connect succeeded for refresh (collector/general)
INFO Discovery-2 io.airlift.discovery.client.CachingServiceSelector Discovery
server connect succeeded for refresh (presto/general)
So I guess discover server is not started,But I use command curl "h*tp://10.3.2.33:18080/v1/service/collector/general",
and get response below, and I also get coordinator status as 'ACTIVE'
{
"environment": "presto_**_flt",
"services": [
{
"id": "954e886d-7506-4f00-b954-eeab49209835",
"nodeId": "4c0f2596-7e6e-11e6-ae22-56b6b6499611",
"type": "presto",
"pool": "general",
"location": "/4c0f2596-7e6e-11e6-ae22-56b6b6499611",
"properties": {
"node_version": "a0e36ae",
"coordinator": "false",
"http": "h*tp://10.3.2.24:18080",
"http-external": "h*tp://10.3.2.24:18080",
"datasources": "hive,system"
}
},
{
"id": "6790b522-cd17-48ef-b077-e4e8fa97e310",
"nodeId": "4c0f2366-7e6e-11e6-ae22-56b6b6499611",
"type": "presto",
"pool": "general",
"location": "/4c0f2366-7e6e-11e6-ae22-56b6b6499611",
"properties": {
"node_version": "c34bef3-dirty",
"coordinator": "true",
"http": "h*tp://10.3.2.33:18080",
"http-external": "h*tp://10.3.2.33:18080",
"datasources": ""
}
}
]
}
I think this is because that you have two different node_version in these two services.
If you are repackaging presto-main or any other component, make sure you are using the same binaries on all the nodes.
I am working with the Orion Context Broker and wanna get notifications for the following subscription, added to orion.lab.fiware.org:1026:
curl -v orion.lab.fiware.org:1026/v2/subscriptions -X POST -s -S --header 'Content-Type: application/json' --header "X-Auth-Token: <myToken>" -d #- <<EOF
{
"description": "A subscription to get info about Room1",
"subject": {
"entities": [
{
"id": "11582",
"type": "User"
}
],
"condition": {
"attrs": [
"temperature"
]
}
},
"notification": {
"http": {
"url": "http://<myIPAddress>:8080"
},
"attrs": [
"temperature"
]
},
"expires": "2040-01-01T14:00:00.00Z",
"throttling": 5
}
EOF
myToken: the token generated by the FIWARE server
myIPAddress: the IP address of my PC
However, in my sample HTTP server program (Node.js) on port 8080 I do not receive any notifications. I should note that after adding the above subscription, I add the entity with id 11582 through another POST request to orion.lab.fiware.org:1026/v2/entities.
When I read later the added subscription, it confirms that the notification has been sent (through lastNotification):
{
"id": "5768088c70dce43aa351cf9b",
"description": "A subscription to get info about Room1",
"expires": "2040-01-01T14:00:00.00Z",
"status": "active",
"subject": {
"entities": [
{
"id": "11582",
"idPattern": "",
"type": "User"
}
],
"condition": {
"attrs": [
"temperature"
]
}
},
"notification": {
"timesSent": 1,
"lastNotification": "2016-06-20T15:16:04.00Z",
"attrs": [
"temperature"
],
"attrsFormat": "normalized",
"http": {
"url": "http://<myIPAddress>:8080"
}
},
"throttling": 5
}
Any idea why I do not receive the notification i my HTTP server program? My firewall is also off.
Thanks!
The following test has been donde in orion.lab.fiware.org. The termina1l.txt file shows the subscriptions and entity creation request sent to Orion (note we use localhost:10026, as the test has been done in the orion.lab.fiware.org host itself) and terminal2.txt file shows the notification received at the listener process (nc).
We have also done the same test (using UserTest2 type this time) running the listener on a VM machine at FIWARE Lab (which IP cannot be disclosed for security reasons) with the 1028 port openend in the Security Group and everything worked fine again, getting:
POST / HTTP/1.1
user-agent: orion/1.2.1 libcurl/7.19.7
host: 130.206.112.29:1028
accept: application/json
content-length: 146
content-type: application/json; charset=utf-8
fiware-correlator: 0870b41c-378d-11e6-910f-52540003a38e
ngsiv2-attrsformat: normalized
X-Forwarded-For: 127.0.0.1
Connection: keep-alive
{"subscriptionId":"5768ff6a70dce43aa351cfaa","data":[{"id":"11582","type":"UserTest2","temperature":{"type":"Float","value":23.5,"metadata":{}}}]}
Thus, I understand that something between orion.lab.fiware.org and your process is blocking the traffic. Note that apart for the firewall running in your machine (which you mention is off) another firewall layer could be blocking (e.g. FIWARE cloud or AWS cloud security group, coorporate firewalls, etc.)
I create my Instance on the CLOUD but when try to do a POST the data are not send to the VM, something is wrong with the data I use ?
I'm using Rest Client on Firefox.
This is the body of the code (Json) :
{
"contextElements": [
{
"type": "Room",
"isPattern": "false",
"id": "Room1",
"attributes": [
{
"name": "temperature",
"type": "float",
"value": "23"
},
{
"name": "pressure",
"type": "integer",
"value": "720"
}
]
}
],
"updateAction": "APPEND"
}
The URL is http://10.0.22x.6x:1026/NGSI10/updateContext and the headers are:
Content-Type: application/json
Accept: application/json
Note that you are sending your REST request to a private IP (10.0.22x.6x). However, I guess that you run your Firefox REST Client in a PC or laptop computer without direct connectivity to that IP.
The solution would be to allocate a public IP to the VM, then access to that public IP from your external REST Client. Note that you need the port 1026 opened in the security group associated to that VM (otherwise the cloud will block any attemp to connect to it from an external host).