C# net RSocket client invalid mime type "binary" with Java RSocket server - rsocket

I am getting an error 0000 Error {000}: [00000003] Invalid mime type "binary": does not contain '/'
var client = new RSocketClient(new WebSocketTransport("ws://127.0.0.1:7000/quotes"), new RSocketOptions() {
InitialRequestSize = 3,
DataMimeType = "application/x-binary",
MetadataMimeType = "application/x-binary"
});
await client.ConnectAsync();
what's the mime type format to use for rsocket request stream of various binary object types? The client shows that there is a mime type.
A wireshark capture shows the error that appears to come from port 7000 the Java Server saying that the Net client has produced the wrong mime type

it is a bug in RSocket-.Net. you shell pass your RSocketOptions derictly into ConnectAsync instead of passing them into the RSocketClient constructor:
var client = new RSocketClient(new WebSocketTransport("ws://127.0.0.1:7000/quotes"));
await client.ConnectAsync(new RSocketOptions() {
InitialRequestSize = 3,
DataMimeType = "application/x-binary",
MetadataMimeType = "application/x-binary"
});

Related

How do you send MIME format emails using Microsoft Graph Java SDK?

The official documentation does not provide an example for any SDK's (including the Java SDK): https://learn.microsoft.com/en-us/graph/api/user-sendmail?view=graph-rest-1.0&tabs=java#example-4-send-a-new-message-using-mime-format. As there is no example, I have tried in vain to send the MIME content using the SDK (microsoft-graph 5.0.0):
Message sending = new Message();
ItemBody body = new ItemBody();
final String mimeMessageRFC822 = input.getMimeMessageRFC822();
body.content = Base64.getMimeEncoder().encodeToString(mimeMessageRFC822.getBytes());
sending.body = body;
GraphServiceClient service = getService(acHost, configuration);
service
.me()
.sendMail(UserSendMailParameterSet.newBuilder().withMessage(sending).withSaveToSentItems(true).build())
.buildRequest(new HeaderOption("Content-Type", "text/plain"))
.post();
The above code sets the request's content-type to text/plain, however the request body that is being sent is JSON (xxxxxx below is a placeholder for a valid Base64 encoded MIME content string).
{
"message":
{
"body":
{
"content": xxxxxx
}
},
"saveToSentItems": true
}
The response is a 404, stating:
GraphServiceException: Error code: ErrorMimeContentInvalidBase64String
Error message: Invalid base64 string for MIME content.
I can understand why it is responding with this error as the graph endpoint is parsing the text/plain content as base64 encoded MIME but finds the JSON structure instead. I have been on a video call with a Microsoft Graph support agent, and they have seen that my MIME content is valid. Sadly, they are not able to help with the Microsoft Graph Java SDK even though it is developed by Microsoft!
This suggests that we are not supposed to use the Java SDK at all for sending MIME formatted emails. Is this correct? Surely it can't be otherwise what is the point of a library that can receive MIME formatted emails but can't send them? Does anyone have a solution?
For now at least the solution is to send a CustomRequest with MIME content instead of using the fluent API provided by the Graph client.
final String encodedContent = Base64.getMimeEncoder().encodeToString(mimeMessageRFC822.getBytes());
CustomRequest<String> request = new CustomRequest<>(requestUrl, service, List.of(new HeaderOption("Content-Type", "text/plain")), String.class);
request.post(encodedContent);

Sending a Post request using VB.Net

I want to send a Post request from the server side to another server. I want to create some form data in the code (not using a webpage) and send it over.
From what I have read online I have ended up with the code below. However, I am just guessing and not sure if it is correct, especially because I cannot get it to work (the exception I am getting has been included as a comment in the code). Is this a fault on my part or is it an external problem to do with where I am sending the request?
Dim client = New HttpClient
Dim request = WebRequest.CreateHttp("https://something.com/test")
request.Credentials = CredentialCache.DefaultCredentials
request.UserAgent = "value"
request.Method = HttpMethod.Post.Method
request.ContentType = "application/x-www-form-urlencoded"
Dim params = New Dictionary(Of String, String)
params.Add("key1", "value1")
params.Add("key2", "value2")
params.Add("key3", "value3")
params.Add("key4", "value4")
Dim stream = request.GetRequestStream()
Dim content = New FormUrlEncodedContent(params)
content.CopyToAsync(stream)
' Exception occurs when executing the line below:
' The underlying connection was closed: An unexpected error occurred on a send.
' InnerException = {"Unable to read data from the transport connection:
' An existing connection was forcibly closed by the remote host."}
Dim result = request.GetResponseAsync().Result
Console.WriteLine(result.ToString)
Are you sure that the server has a valid https certificate?
The cert was issued to the URI that you are hitting
The cert is not expired
The cert was issued by a trusted authority (e.g.: Verisign)
Of these criteria, #3 is the most commonly failed check. You can programatically ignore any or all of these errors (at your own risk). Here is an example on how to do that. (Reference: https://stackoverflow.com/a/10390388/8081260)
Also it would be helpful to provide the full (inner) exception

Error passing InputStream through multiple Jersey-Client requests

I’m using jersey-client v1.18.1
I need to make 2 sequential requests where the 1st request has an InputStream and then must pass that same InputStream along to the 2nd request (eg. sort of like a proxy). The 2nd request will then write the InputStream to disk and send back to the 1st request the fully qualified path to the location on disk where the 2nd request wrote the file.
The following code-snippet outlines what I have tried, but cannot get to work properly. I’m currently receiving the error:
"com.sun.jersey.api.client.ClientHandlerException: A message body writer for Java type, class org.seleniumhq.jetty9.server.HttpInputOverHTTP, and MIME media type, application/octet-stream, was not found”
I believe I have all the proper Maven dependencies in my project for the MIME and message body writers.
1st Request originating on Host 1 going to Host 2
Client client = Client.create();
client.resource(uri_for_request_1)
client.path(“request_1_servlet");
client.queryParam(“uri_for_request_2", uri_for_request_2);
client.queryParam("targetFilename", targetFilename);
ClientResponse response = client.accept(MediaType.APPLICATION_JSON).entity(inputStream).post(ClientResponse.class);
2nd Request originating on Host 2 going to Host 3
Client client = Client.create();
client.resource(request.getParamater(“uri_for_request_2"))
client.path(“request_2_servlet");
client.queryParam("targetFilename", request.getParamater(“targetFilename");
ClientResponse response = client.accept(MediaType.APPLICATION_JSON).entity(request.getInputStream()).post(ClientResponse.class);
Host 3
Writes InputStream to file and sends back to Host 2 fully qualified path.
Host 2
Sends back to Host 1 fully qualified path.
Variations I’ve tried on post calls:
client.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_OCTET_STREAM).entity(inputStream).post(ClientResponse.class);
client.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_OCTET_STREAM).post(ClientResponse.class, inputStream);
I can confirm the 1st request is being made on Host 1 and reaches Host 2. It is the 2nd request on Host 2 that fails during the post() call.

Ruby on rails: error in sending xml message

I try to send a xml file to a web service, but it's not working. The web service supplier has no idea.
If you read the error message, it looks like there is a wrong soap version used, but the supplier tried it with the same xml file and he had no problems with this file. I have no idea what's wrong.
The code:
#Declaration
host = "bar.foo.nl";
path = "/services/setu.asmx";
port = 443;
username = "xxx"
password = "yyy";
ssl = true;
#Create connection
req = Net::HTTP::Post.new(path)
req.basic_auth(username, password)
http = Net::HTTP.new(host, port)
http.use_ssl = ssl
#send file
res = http.request(req, 'D:/test.xml')
#show result
puts res.code
puts res.body
EDIT: The xml file: XML FILE
The error (500 code):
Possible SOAP version mismatch: Envelope namespace
http://ns.hr-xml.org/2007-04-15 was unexpected. Expecting
http://schemas.xmlsoap.org/soap/envelope/.
I don't see any soap declarations in the file you've uploaded, and it looks like the service you're contacting requires it.
Start with http://www.w3schools.com/xml/xml_soap.asp and rework your content to be wrapped in a soap envelope.

I am sending data over HTTPS but the server side says it is not receiving it

I create an application that sends some data to a secured network.
At the server side they need the data as JSON object. For that am creating the data as JSON object and writing that data in the OutputStream of the connection.
But the response from the server side telling it is not getting the data that I am passing.
The code snippet that am using is something like given below:
HttpsConnection _connection = (HttpsConnection)Connector.open("https://gmail.com/",Connector.READ_WRITE, true); _connection.setRequestMethod(HttpsConnection.POST);
_connection.setRequestProperty("If-Modified-Since", "29 Oct 1999 19:43:31 GMT");
_connection.setRequestProperty("User-Agent","Profile/MIDP-2.0 Configuration/CLDC-1.0");
_connection.setRequestProperty("Content-Language", "en-US");
_connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
byte[] postData = jsonObject.toString().getBytes("UTF-8");
_connection.setRequestProperty("Content-Length", Integer.toString(postData.length));
_connection.setRequestProperty("jsondata",jsonObject.toString());
OutputStream os = _connection.openOutputStream();
os.write(postData);
os.flush();
Please help me to solve the issue.
I guess the reason is "Content-Type" => "application/x-www-form-urlencoded". This type of a POST exists for sending a list of key=value pairs. So the server on its side will parse the post data in terms of key=value pairs. I believe in your case it just fails to parse the got post data, because you don't send the data in the key=value pairs form (instead you just pour the entire json string jsonObject.toString().getBytes("UTF-8") in it).
So basically you need to form a key value pair "json=YOUR_JSON_HERE". Then on the server you will get your data as the json parameter value:
URLEncodedPostData encPostData = new URLEncodedPostData("UTF-8", false);
encPostData.append("json", jsonObject.toString());
byte[] postData = encPostData.toString().getBytes("UTF-8");
Another option (and BTW it would be the most proper way to do this particular task) would be to use "multipart/form-data" POST type. However it will be a bit harder to implement it if you've never done that before on BB.
You have to append appropriate suffix to to your url
eg: If you use simulator use:https://gmail.com/;deviceside=true etc
I have same this problem but finally find solution:
HttpConnection c = (HttpConnection)Connector.open(url);
c.setRequestMethod(HttpConnection.POST);
c.setRequestProperty(
HttpProtocolConstants.HEADER_CONTENT_TYPE, PostData.getContentType());
c.setRequestProperty(
HttpProtocolConstants.HEADER_CONTENT_LENGTH,String.valueOf(oPostData.size()));
c.setRequestProperty("Content-Length", Integer.toString(oPostData.size()));
c.setRequestProperty("Content-Type","application/json");
byte [] postDataBytes = jobj.toString().getBytes("UTF-8");
os = c.openOutputStream();
os.write(postDataBytes);
os.flush();

Resources