As per my understanding, ThingWorx services can be exposed as REST, but URI would be /Thing/ThingName/Services/ServiceName.
Exposing services in this way could expose business data/entities as well.
My question is that, can we MASK thingworx service URL in a custom or a REST way i.e. /resources ?
I actually tried this one time with a URL Rewrite called 'Tuckey' but I couldn't make it work, so it may not be possible. But that is what I would recommend. 'Theoretically' it could work, but when I tried it, I couldn't make it work, although I didn't go very deep.
Thanks for replying.
As you mentioned that you tried URL Rewriting, what error/issues you encountered? I will also try out at my end.
I think, the changes can be made in domain setup (probably CNAME or URL Forwarding/Redirection) which can redirect a domain to another URL.
It's been a rather long time so I don't remember.
We are able to mask thingworx service URL successfully using Tomcat 8 which supports RewriteRule.
Please find below URL rewrite impl changes:
1. Add RewriteValve in server.xml(tomcat)
2. Add rewrite.config and mention RewriteRules.
3. Add rule to rewrite.config file. RewriteRule <new URL> <Old URL>
Example: RewriteRule /abc/resources /Thingworx/Things/<thingname>/Services/<servicename>
4. You can also mention RewriteCondition. Query and Path params are supported.
Please let me know in case more details or sample required on URL masking side.
Hi, so this method can hide any API REST calls, but it doesn't mask the "/Thingworx" in the URL while navigating bewteen mashups.
If I have "RewriteRule /FormLogin /Thingworx/FormLogin", the part "/Thingworx" in the URL is hidden on LoginPage. But after logging in, the webapp name appears again in the URL. Do you know if it's possible to hide also "/Thingworx" in every mashups' URL ?
Hi Eklavya,
I need some samples on Rewrite URL for thingworx. Could you please send me ?
PFB examples:
Original request:
<host>:<port>/Thingworx/Things/TestThing/Services/TestService?method=post&appKey=<app_key>
Rewrite request:
<host>:<port>/resource/Thingworx/abc
RewriteRules
/Thingworx/Things/TestThing/Services/TestService?method=post&appKey=<app_key>
/Thingworx/Things/TestThing/Services/TestService?method=post&id=31&appKey=<app_key>
Also, RewriteRules support all types of Regex.
Thanks.
Hi,
I followed steps below, but still getting error Http status 404. Please correct me what to do.
1. I added, <Valve className="org.apache.catalina.valves.rewrite.RewriteValve" asyncSupported="true"/> into context.xml in webapps/Thingworx/META-INF/context.xml
2. Placed rewrite.config in webapps/Thingworx/WEB-INF/
3. The rules i added like,
i) RewriteRule /Thingworx/Home /Thingworx/Runtime/index.html#master=Sample_Master&mashup=Sample_Home
But, getting error like, The requested resource is not available.
Hello Thangavel,
Instead of doing that add your user to some Organization and set Sample_Home as its home mashup.
Regards,
Constantine
Hi Constantine, Thanks for your reply. Let me try this.
Hi Constantine and Eklavya Sirohi,
For example.
to access home page,
RewriteRule /Thingworx/Home /Thingworx/Runtime/index.html#master=Sample_Master&mashup=Sample_Home
My url should be like,
localhost:8080/Thingworx/Home should rewrite to
localhost:8080/Thingworx//Runtime/index.html#master=Sample_Master&mashup=Sample_Home
Please help me to achive this.
Once again, you should not use Rewrite Rules for that. There is an out-of-the-box standard ThingWorx functionality to redirect the user to some default mashup. The only practical use for Rewrite Rules is to do this kind of things:
1. Remove "Thingworx" from the URL
2. Change "Thingworx" to something else like "Myapp"
That's it. All other types of rewrite rules don't really work because they break relative URLs and I guess for many other reasons.
In short -- avoid using RR, they don't work.
I second to Constantine.
This simple nginx configuration works for me:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location /service {
proxy_pass http://localhost:8080/Thingworx/Things/Neuron/ServiceDefinitions/GetConfigurationTables;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
}
It exposes "GetConfigurationTables" service as http://localhost/service, while forwarding the rest of the requests to the port 8080.
Does the reverse proxy approach still work with a websocket connection from the edge? I was under the impression that reverse proxy broke websockets.
Nginx supports websockets in reverse proxy mode under certain circumstances, needs to be tested with EDGE SDK: WebSocket proxying