cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

URL Masking for ThingWorx REST Service

esirohi
1-Newbie

URL Masking for ThingWorx REST Service

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 ?

17 REPLIES 17
paic
1-Newbie
(To:esirohi)

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.

esirohi
1-Newbie
(To:paic)

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.

paic
1-Newbie
(To:esirohi)

It's been a rather long time so I don't remember.

esirohi
1-Newbie
(To:paic)

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.

qngo
5-Regular Member
(To:esirohi)

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

  • /resource/Thingworx/abc

        /Thingworx/Things/TestThing/Services/TestService?method=post&appKey=<app_key>

  • /resource/Thingworx/abc/id=31

     /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.

esirohi
1-Newbie
(To:ckulak)

I second to Constantine.

ckulak
1-Newbie
(To:esirohi)

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.

jamesm1
5-Regular Member
(To:ckulak)

Does the reverse proxy approach still work with a websocket connection from the edge? I was under the impression that reverse proxy broke websockets.

ckulak
1-Newbie
(To:jamesm1)

Nginx supports websockets in reverse proxy mode under certain circumstances, needs to be tested with EDGE SDK: WebSocket proxying

Top Tags