I have created webflux app and it's generating stream.
#GetMapping(value = "/stream/tweets", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<Tweet> streamAllTweets() {
return tweetRepository.findAll();
}
Now issue is that contentType "text/event-stream" is not supported into Postman and not able to see stream without refresh.
How to check stream in postman or any other tools
Please use Content-Type: "application/stream+json" instead of "text/event-stream" in the postman headers.
Related
I am trying to create some postman test cases for an old web api.
What I realized is that the web api expects binary content in the HttpRequest body other than a Json message. We have a c# client, which does this before sending request:
var body = new ByteArrayContent( SerializeToByteArray(info));
using ( var result = await Client.Post<HttpResponseMessage>( options , body , Configuration , ct ).ConfigureAwait( false ) )
In postman, can I call a routine(either existing function or some custom dll) to convert body to byte array before sending the request out?
No, Postman does not support this.
No, it is not possible directly.
What you can do is to run a (local) server, send a request to it from Postman's prerequest script, and the server then executes the binary.
An approach is drafted at the Postman community forum: https://community.postman.com/t/is-it-possible-to-execute-an-external-program-from-postman/5693/2?u=chrissbaumann
I am exposing a SOAP service using Tomcat, Apache CXF and Spring Boot. The web service has MTOM enabled and it works as expected when testing it from SOAP UI.
The problem is that when I try to get the message with MTOM disabled from SOAP UI, I still get the message with an XOP attachment. The options from SOAP UI that I use are: Enable MTOM: false; Force MTOM: false.
I have tried to set the Accept header on the request to application/xml instead of application/xop+xml, but I still get the same thing.
The only time when I get the Byte64 stream is when I test with a file which is smaller than the threshold that I've set:
#MTOM(enabled = true, threshold = 2048)
What I would need is MTOM to be optional when it is set to enabled and to depend on the request, not only on the threshold, could this be a problem with SOAP UI or does my current configuration ignore the request parameters?
I need this because some clients of the web service don't support MTOM.
Here is the object I return from the exposed method:
public class Document {
private DataHandler fileData;
public DataHandler getFileData() {
return fileData;
}
public void setFileData(DataHandler fileData) {
this.fileData = fileData;
}
}
You can't control from the client whether you want the server to respond with an xop attachment or without.
JAX-WS, and I think none of its implementations such as CXF for example, care about the Accept header since it's not specified in the SOAP specifications that the server has to read if from the request, nor which value it should write on the response. So it makes no difference if you put application/xml or text/xml or any other.
If the server has MTOM enabled it must always (as long as it falls into the threshold range) send back a soap response using MTOM.
The options from SOAP UI that I use are: Enable MTOM: false; Force MTOM: false
These are options for the request message, so in case you are sending a file in your request it would be encoded as a base64 attachment, meaning you are just disabling MTOM for the request.
It's a bummer but basically you are just left with two options:
Modify the server and disable MTOM or try to do something with interceptors like reading a value from the request and enabling/disabling mtom programatically for that single message based on that value. It's like implementing yourself a mechanism to decide wether that client supports MTOM or not.
Modify the clients that don's support MTOM which probably you can't do if you are asking this question.
I am trying to use spring security in my application developing restful web services and not getting the way how to send request to j_spring_security_check directly so that i can provide same url as a web service to Authorization of username and password.
Currently i am using following request pattern:
URL: "http://localhost:8080/CabFMS/j_spring_security_check"
Content-type: application/x-www-form-urlencoded
Body: {'j_username':'user','j_password':'123'}
Response: is Bad credentials
I am not sure about Content-type and body parameters. Please provide suggestion. To send request i am using REST Client
Tarun Gupta
As you correctly noticed j_spring_security_checks expects application/x-www-form-urlencoded content, therefore you need to encode it as such:
j_username=user&j_password=123
Your request pattern should be :
/j_spring_security_check?j_username=user&j_password=123
with method "POST" type.
other then this you can change request action & parameters text "j_spring_security_check" and "j_username" ,"j_password" by configuring alternate text in attributes :
login-processing-url,
username-parameter,
password-parameter
of spring "form-login" tag in security configuration xml file.
Create an AuthenticationSuccessHadler for this, in the authenticationSuccess method, return base64 encoded authorization header with the pattern username:password
Then, on each request, set the header as Basic yourtokenhere
In my Spring web application I need to make an HTTP request to a non-RESTful API, and parse the response body back as a String (it's a single-dimension CSV list).
I've used RestTemplate before, but this isn't RESTful and doesn't map nicely on to classes. Whenever I implement something like this 'by hand' (eg using HttpClient) I invariably find out later that Spring has a utility class that makes things much simpler.
Is there anything in Spring that will do this job 'out of the box'?
If you look at the source of RestTemplate you will find that internally it uses
java.net.URL
and
url.openConnection()
that is the standard way in Java to make HTTP calls, so you are safe to use that. If there would be a "HTTP client" utility in spring then the RestTemplate would use that too.
I use the Spring Boot with Spring 4.3 Core inside and found a very simple way to make Http request and read responses by using OkHttpClient. Here is the code
Request request = new Request.Builder().method("PUT", "some your request body")
.url(YOUR_URL)
.build();
OkHttpClient httpClient = new OkHttpClient();
try
{
Response response = httpClient.newBuilder()
.readTimeout(1, TimeUnit.SECONDS)
.build()
.newCall(request)
.execute();
if(response.isSuccessful())
{
// notification about succesful request
}
else
{
// notification about failure request
}
}
catch (IOException e1)
{
// notification about other problems
}
I want Play to call a webservice. The webservice accepts application/json and returns this as well. With the following code I'm trying to achieve this. (Note, the headers.put(xxx) are added later in an effort to solve the problem).
WSRequest request = WS.url(targetURL);
request.body = new Gson().toJson(user);
request.headers.put("Content-type","application/json");
request.headers.put("Accept","application/json");
request.post();
The strange thing is that my JBOSS server replies: "Cannot consume content type". If I use my 'Simple REST client' plugin in my Chrome browser, and provide the entire JSON Body GSon created and add the content-type header, I get a valid response. Is this not the way to send JSON to the server? Or am I missing some fundamental piece here?
While checking the API documentation on the WSRequest class i noticed the field mime-type
By setting it as follows JBOSS (resteasy) accepted my request succesfully.
request.mimeType = "application/json";