Consuming External REST Service

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

PeteM
Ebase User
Posts: 31
Joined: Thu Apr 21, 2016 1:04 pm

Consuming External REST Service

#1

Postby PeteM » Tue Jan 23, 2018 11:04 am

(edited - original post had incorrect object assignment)
Hi,

I'm attempting to consume an external rest service , I've setup in the visual designer, but when testing I get a connection error.

Code: Select all

ERROR Error performing request: Connect to beta.check-mot.service.gov.uk:443 [beta.check-mot.service.gov.uk/149.126.74.146] failed: Connection timed out: connect
Do I need to setup the proxy configuration? For example -the same service when called from C# I'd put:

Code: Select all

     var client = new RestClient("https://beta.check-mot.service.gov.uk/trade/vehicles/mot-tests?registration=myreg")

     var request = new RestRequest();
     request.AddHeader("x-api-key", "mykeygoeshere");
    client.Proxy = new WebProxy("http://myproxygoeshere:8080");    <-- assign the proxy 
    client.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
            
    IRestResponse response = client.Execute(request);
    var content = response.Content;
And all is fine - I'd get a response with the relevant JSON.

I can't see anywhere I'd define that in the service. The proxy server is set in the server admin console as far as I can see?

I also had a stab at doing it within code, bypassing the visual, following the Spotify example you've published - but the x-api-key bit fails

[EDIT] - My bad - altered the object assignment, now get same error as above

Code: Select all

importPackage(com.ebasetech.xi.api);
importPackage(com.ebasetech.xi.services);

var header = {};
var param ={};
param["registration"]="myreggoeshere";
header["x-api-key"]="myapikeygoeshere";  

var response= services.rest.get("https://beta.check-mot.service.gov.uk/trade/vehicles/mot-tests", header, param);
log("here");
if(response.isSuccess())
{
	
  if(response.getBody())

  {
	log(response.getBody());
  }
}
A nudge in the correct direction much appreciated!! :-)

Cheers,

Pete
0 x

Steve
Moderator
Moderator
Posts: 414
Joined: Fri Sep 07, 2007 3:44 pm
Location: Sandy, UK
Contact:

Re: Consuming External REST Service

#2

Postby Steve » Tue Jan 23, 2018 5:02 pm

Hi Pete,

Yes you do need to setup proxy config. I tested your URL and I got a valid response back from the server... although it did say forbidden.

You can setup the proxy by clicking on the 'Start Server Admin App' on the top right hand corner of the Ebase Designer under the Manage Server icon.

Click on the general settings and expand the Proxy Settings, you can set the proxy host and port here and save it the changes.

It also looks as though you need to set the username and password for the proxy also.

Kind regards

Steve
0 x

PeteM
Ebase User
Posts: 31
Joined: Thu Apr 21, 2016 1:04 pm

Re: Consuming External REST Service

#3

Postby PeteM » Wed Jan 24, 2018 9:38 am

Thanks Steve,

If i fill in the proxy settings into ebase, the same thing happens - it hangs for 10 seconds then refuses connection.

Is it to do with it the call being https?

If i fill in the https proxy settings into the start_server.bat file, ebase responds immediately with a null pointer in ProxyAuthenticator

Code: Select all

Caused by: java.lang.NullPointerException
        at com.ebasetech.ufs.designer.client.preferences.ProxyAuthenticator.getPasswordAuthentication(ProxyAuthenticator.java:19)
        at java.net.Authenticator.requestPasswordAuthentication(Authenticator.java:317)
        at org.apache.http.impl.client.SystemDefaultCredentialsProvider.getSystemCreds(SystemDefaultCredentialsProvider.java:96)
        at org.apache.http.impl.client.SystemDefaultCredentialsProvider.getCredentials(SystemDefaultCredentialsProvider.java:115)
        at org.apache.http.impl.client.AuthenticationStrategyImpl.select(AuthenticationStrategyImpl.java:197)
For reference - it's ebase 5.2.0 if that makes any shakes, and this runs within SoapUI and C#.

Thanks again,

Pete
0 x

Steve
Moderator
Moderator
Posts: 414
Joined: Fri Sep 07, 2007 3:44 pm
Location: Sandy, UK
Contact:

Re: Consuming External REST Service

#4

Postby Steve » Wed Jan 24, 2018 11:37 am

Hi Pete,

I have tested with V5.2 and I can still get through to the web service call.

The error this is showing is that you do not have a password for your proxy and this setting is mandatory. Does your proxy require a password?

Kind regards

Steve
0 x

PeteM
Ebase User
Posts: 31
Joined: Thu Apr 21, 2016 1:04 pm

Re: Consuming External REST Service

#5

Postby PeteM » Wed Jan 24, 2018 11:47 am

Hi Steve,

Yeah, got the username /password etc in there - they're like this in the server.properties file:

Ufs.proxyUsername=myntdomain\\myusername
Ufs.proxyPassword=mypassword
Ufs.proxyHost=myproxyserver
Ufs.proxyPort=8080

...

If it's of any odds - the "mypassword" bit, I have it ending with a exclaimation, which is stored as mypassword\! (backslash exclaimation ). So if the password was sausages!, it stores it as sausages\!

As I said, the null pointer only happens if I stick the "https.proxy" settings in the server_startup. If I leave that out I don't get the null pointer, it just hangs then errors.
0 x

Steve
Moderator
Moderator
Posts: 414
Joined: Fri Sep 07, 2007 3:44 pm
Location: Sandy, UK
Contact:

Re: Consuming External REST Service

#6

Postby Steve » Wed Jan 24, 2018 12:41 pm

Hi Pete,

You have found a bug in the system where the proxy password should be saved encrypted but it is saved (and entered) as clear text. This then causes and issue trying to decrypt the password from the properties file.

I will email you a patch fix for V5.2

Kind regards

Steve
0 x

PeteM
Ebase User
Posts: 31
Joined: Thu Apr 21, 2016 1:04 pm

Re: Consuming External REST Service

#7

Postby PeteM » Wed Jan 24, 2018 1:43 pm

Thanks for the response Steve,

I've placed the class files in the directory - same issue if I don't specify https.proxy in the server.startup (it hangs and then rejects connection).

If i put in the https stuff, I get base64 errors:

Code: Select all

Wed Jan 24 13:37:33: ERROR Unexpected error occurred
java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Base64.<init>(I)V
        at org.apache.http.impl.auth.GGSSchemeBase.<init>(GGSSchemeBase.java:85)

        at org.apache.http.impl.auth.SPNegoScheme.<init>(SPNegoScheme.java:54)
        at org.apache.http.impl.auth.SPNegoSchemeFactory.create(SPNegoSchemeFact
ory.java:83)
        at org.apache.http.impl.client.AuthenticationStrategyImpl.select(Authent
icationStrategyImpl.java:188)
The password is being encrypted within the admin page and the file.

I'll have a look at seeing if I can consume this external service within a local C# rest WCF service and point that at ebase in the meantime.
0 x

Steve
Moderator
Moderator
Posts: 414
Joined: Fri Sep 07, 2007 3:44 pm
Location: Sandy, UK
Contact:

Re: Consuming External REST Service

#8

Postby Steve » Wed Jan 24, 2018 2:11 pm

Hi Pete,

You will definitely need the proxy settings. You have fixed the other error, but this is a new one :o It looks as though there is a missing Java library or one of the libraries is out of date.

Can you email the entire server log to me? or copy and past the entire exception to:

support@ebasetech.com

Kind regards

Steve
0 x

PeteM
Ebase User
Posts: 31
Joined: Thu Apr 21, 2016 1:04 pm

Re: Consuming External REST Service

#9

Postby PeteM » Wed Jan 24, 2018 3:10 pm

Cheers Steve, will do.
0 x


Who is online

Users browsing this forum: Google [Bot] and 4 guests