how to implement rest client with gluon plugin - rest

I am following the gluon rest sample to access to a rest server. But I get nothing from the server. the object is null. so what is wrong with the code. The object is there and reachable by http.
RestClient restClient = RestClient.create()
.method("GET")
.host("https://storage.waw.cloud.ovh.net")
.path("/v1/AUTH_17fd5ed14d1440b0abc4918f6a492bd9/dataCours/pourShema.json")
.contentType("charset=utf-8");
InputStreamInputConverter<CoursFrancaisJson> converter = new JsonInputConverter<>(CoursFrancaisJson.class);
GluonObservableObject<CoursFrancaisJson> retrieveObject = DataProvider.retrieveObject(restClient.createObjectDataReader(converter));

Related

404 Errors using Vert.x web proxy code taken from its documentation

I am using the Vert.x Web library to create a test application for a reverse proxy. I am using the information provided on the Vert.x site:
https://vertx.io/docs/4.1.0/vertx-web-proxy/java/#_using_vert_x_web_proxy
I have written some simple test code, based on the documentation at the above site:
public class WebTest
{
public static void main(String[] args)
{
Vertx vertx = Vertx.vertx();
HttpClient client = vertx.createHttpClient();
HttpProxy proxy = HttpProxy.reverseProxy(client);
proxy.origin(8080,"localhost");
HttpServer server = vertx.createHttpServer();
Router router = Router.router(vertx);
router.route(HttpMethod.GET,"/foo").handler(ProxyHandler.create(proxy));
server.requestHandler(router);
server.listen(8010);
}
}
I have a web server (the so- called "origin" in Vert.x terminology) running on Port 8080. The only difference between the code above and the code on the web site is that I am using different port numbers for the proxy and the origin server. According to the documentation on the Vert.x website, a browser going to http://localhost:8010/foo should access the origin server.
Instead, I am getting 404 Not found errors.
Is there something missing in this code? Maybe something not covered in the documentation?
Does anyone have any idea how to make it work properly?
#Factor Three you are missing backend part of the guide and also you are mixing parts in an unorganized way. Following the guide it can be like this:
Vertx vertx = Vertx.vertx();
// Origin Server (Backend 8080)---------
// Here you deploy the real server with the endpoint ("hello world" in this case)
HttpServer backendServer = vertx.createHttpServer();
Router backendRouter = Router.router(vertx);
backendRouter
.route(HttpMethod.GET, "/foo")
.handler(
rc -> {
rc.response().putHeader("content-type", "text/plain").end("hello world");
});
backendServer.requestHandler(backendRouter).listen(8080);
// Proxy Server (8010)
// Here you deploy the server that will act as a proxy
HttpServer proxyServer = vertx.createHttpServer();
Router proxyRouter = Router.router(vertx);
proxyServer.requestHandler(proxyRouter);
proxyServer.listen(8010);
// Proxy Magic
// Here you route proxy server requests (8010) to the origin server (8080)
HttpClient proxyClient = vertx.createHttpClient();
HttpProxy httpProxy = HttpProxy.reverseProxy(proxyClient);
httpProxy.origin(8080, "localhost");
proxyRouter.route(HttpMethod.GET, "/foo").handler(ProxyHandler.create(httpProxy));

how to access the SOAP request in the groovy script - SOAP UI

I am writing a groovy script to consume the SOAP web service. First i imported my
WSDL in SOAP and created a project.
Then all the SOAP request are generated automatically.
Now am trying to write a groovy to call the SOAP service using the SOAP request generated.
Now here it is my groovy script
import org.apache.commons.httpclient.methods.PostMethod;
import org.w3c.dom.*;
class Example {
static void main(String[] args) {
String serviceInput="";
PostMethod post = new PostMethod("http://server:30280/so_ws/SO?WSDL");
post.setRequestHeader("Accept", "application/soap+xml,application/dime,multipart/related,text/*");
post.setRequestHeader("SOAPAction", "");
// access CreateNote SOAP request here to call PostMethod
}
}
I want to access the same SOAP request generated in SOAP UI - CreateNote.
How can I access it?
My actuall requirement is to access all SOAP request in the groovy script - so that i can write one single script to test all the SOAP services in one go and that too in the sequence as per required
Here is the Groovy Script which gets the request from its previous step of the same test case like you have your test case currently.
Script
def req = context.testCase.getTestStepAt(context.currentStepIndex - 1).httpRequest.requestContent
log.info req

RESTful call testing in Eclipse

In my case, I am running a eclipse project providing the Restful api, and I will call that api like in the following example. I am curious if I should create another project in the eclipse to run the following code to test the api.
Jersey Example
Form form = new Form();
form.add("x", "foo");
form.add("y", "bar");
Client client = ClientBuilder.newClient();
WebTarget resource = client.target("http://localhost:8080/someresource");
Builder request = resource.request();
request.accept(MediaType.APPLICATION_JSON);
Response response = request.get();
if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
System.out.println("Success! " + response.getStatus());
System.out.println(response.getEntity());
} else {
System.out.println("ERROR! " + response.getStatus());
System.out.println(response.getEntity());
}
you can run your code as a java application using main method.
Or since you are saying you have you services running you can use POSTMAN REST Client available as a plugin for chrome and chromium browsers. i don't know about the support for the same in other browsers.
Using postman you'll be able to see exactly how your restful service is working. you'll be able to send request headers and other parameters as a part of the rest request. Postman is the way to go for end to end web service testing.

Authentication from NativeScript App(android/ios) to Sharepoint 2013 REST API

I'm trying to call Sharepoint 2013 REST API from an application developped with NativeScript(android/ios).
Using xhr or fetch NativeScript module I'm not able to authenticate correctly and call rest api.
Using Java I'm able to connect to the sharepoint server and call Rest API without problem Using this maven dependency: org.apache.httpcomponents httpclient 4.4.1.
public class SharePointClientAuthentication {
public static void main(String[] args) throws Exception {
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope(AuthScope.ANY),
new NTCredentials("username", "password", "https://hostname", "domain"));
CloseableHttpClient httpclient = HttpClients.custom()
.setDefaultCredentialsProvider(credsProvider)
.build();
try {
HttpGet httpget = new HttpGet("http://hostname/_api/web/lists");
System.out.println("Executing request " + httpget.getRequestLine());
CloseableHttpResponse response = httpclient.execute(httpget);
try {
System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
EntityUtils.consume(response.getEntity());
} finally {
response.close();
}
} finally {
httpclient.close();
}
}
}
Any one know what's the equivalent to the java code with NativeScript or a way to get Windows authentication(NTLM) to work.
Thanks in advance.
Initially I thought this should be handled by the native HTTP library and exposed as a part of the XMLHttpRequest implementation in NativeScript, but then I discovered ntlm.js. It's a small library that takes care of the NTLM challenge-response for you.
I patched it up a bit, to get rid of the browser dependency and push some polyfills, and got it running. I put up a demo project here:
https://github.com/hdeshev/nativescript-ntlm-demo

Outgoing http requests not showing in Fiddler from java spring mvc web app

Hi I'm sending some http requests from a java spring mvc web app and when I have fiddler open I don't see any outgoing responses.
Using this code to send to an address similar to: http:///getstuff?stuff="whatever"
HttpGet httpget = new HttpGet(url);
log.info("Executing request " + httpget.getURI());
// Create a response handler...
ResponseHandler<String> responseHandler = new BasicResponseHandler();
responseBody = httpclient.execute(httpget, responseHandler);
Does anybody know why these outgoing calls are not showing up in fiddler?
Did you remember to configure your JVM to proxy its HTTP requests? http://fiddler2.com/documentation/Configure-Fiddler/Tasks/ConfigureJavaApp