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.
Related
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));
I'm trying to make a webflux client to connect to a remote websocket. There is an example websocket located at https://www.websocket.org/echo.html. I can have my browser make a wss request there simply by pressing "connect". In my browser developer toolbar I can then see that a succesful request is made to wss://echo.websocket.org/?encoding=text
This url is also mentioned in https://stackify.com/reactive-spring-5/ (the code there doesn't work because "input" is not defined).
However, when I try to access the same url from spring boot 2.0.0 with webflux, I get a 404:
#PostConstruct
public void run() throws URISyntaxException {
WebClient webClient = WebClient.create();
Flux<String> r =
webClient.get().uri("wss://echo.websocket.org/?encoding=text")
.retrieve()
.bodyToFlux(String.class)
.log();
r.subscribe(res -> System.out.println("ok: " + res), ex -> System.out.println(ex));
}
error:
org.springframework.web.reactive.function.client.WebClientResponseException: ClientResponse has erroneous status code: 404 Not Found
My best guess is that it somehow does not work with urls that start with "wss://". Can I change the code so that the request will be successful?
WebClient is not a WebSocket client, ReactorNettyWebSocketClient (mentioned in the article you linked) is a WebSocketClient. Please use this instead.
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
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
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