I want to send a client's public key (java.security.publickey) in JSON format to my server. I'm using Google's Gson library to convert in between, however, I'm getting a runtime exception which tells me that Key is an interface and I need some kind of adapter to parse it. Have anyone encountered this problem? Any solution is welcome, I just need to transfer the key via HTTP.
Thank you!
You can get the encoded key using the getEncoded() method and send that via JSON to your server.
Related
trying to understand how to work with kryonet, it is quite easy to send and receive message from java client, but what if I want to send it from some UI tool like Hercules, or not java code. As I see it uses kryo for Serialization, is there way to serialize object to this fromat without java? Or use plain String or json for comunication?
You can easily create a server using json instead of kryo:
import com.esotericsoftware.kryonet.Server;
import com.esotericsoftware.kryonet.serialization.JsonSerialization;
new Server(16384, 2048, new JsonSerialization());
I'm trying to utilise com.google.cloud.dialogflow.v2.WebhookResponse to interact with my dialogflow agent. But I'm having trouble responding back to the agent during fulfillment.
The response created doesn't follow the specifications required i.e the agent expect the json to be fulfillmentText: "something" but the builder builds it in the format of fulfillment_text. There's not enough documentation on how to use API client correctly
Anyone has experience doing this in java/kotlin?
val response = WebhookResponse
.newBuilder()
.setFulfillmentText("Hello")
.build()
println(response)
println(Gson().toJson(response))
Output:
fulfillment_text: "Hello"
{"bitField0_":0,"fulfillmentText_":"Hello","fulfillmentMessages_":
[],"source_":"","outputContexts_":[],"memoizedIsInitialized":1,"unknownFields":{"fields":{}},"memoizedSize":-1,"memoizedHashCode":0}
I'm using 'com.google.cloud:google-cloud-dialogflow:0.75.1-alpha' from https://cloud.google.com/dialogflow-enterprise/docs/reference/libraries/java
The library you're using is primarily designed as a client library, letting you send text to Dialogflow and having it determine the Intent and parameters (and possibly a response) from that text.
It sounds like you're trying to use this on the other end - in a webhook to handle fulfillment. It just isn't designed for that. The Class was automatically generated from the ProtoBuf definition, which does not serialize to JSON, and isn't designed to represent things that way.
You will need to build the JSON for the response yourself.
I am working on a Java Client Library for the recently exposed unofficial Snapchat API. As an aside, the GitHub for my library so far is here: https://github.com/hatboysam/JavaSnap
I have most requests working fine, I can log in, download images, etc. I am using UniRest for all of those requests so far because I like the simplicity of the API.
I am trying to upload media following the format outlined here: http://gibsonsec.org/snapchat/fulldisclosure/#uploading-and-sending-snaps-phupload-phsend
I have no problem generating any of the fields. The data is a byte[] of AES-ECB encrypted data that I read from a file and ran through the specified encryption algorithm.
I have tried a few things:
Use UniRest's .field(String name, File file) method to add the file as a parameter. I use a temporary Dile I create from the byte[]. This gets me a 401 UNAUTHORIZED from the server, so I think UniRest is adding some headers I don't want when I do this.
Serialize the byte[] as a String using the String(byte[] bytes, String encoding) constructor with the UTF-8 encoding. This gets me a 500 SERVER ERROR.
Not send the data field at all, just to see what happens. This gets me a 400 BAD REQUEST.
If you look at the upload method in the Python library pysnap (init.py">https://github.com/martinp/pysnap/blob/master/pysnap/init.py) you can see that what I am trying to do has been done before very simply with Python's requests library. I can't figure out how to get the same behavior in Java.
My understanding is that you need to encode the byte[] data as a string using base-64 encoding. Try using javax.xml.bind.DatatypeConverter.printBase64Binary or a third-party library for base-64.
Converting to a string using String(byte[] bytes, String encoding) is completely different.
I am using Java Servlet as my server side. However I don't know how to decode the message sent from the function NetConnection.call of Flash.
I download BlazeDS as my AMF3 decoder. But how can I read "methodName" and parameters from the byteArray.
This probably should have been a comment, as I'm not sure how BlazeDS works. I've used NetConnection.call() with Flash Media Server (FMS). However, it might work the same way with any other AMF server:
With FMS, you don't try to read the method name or the parameters from a byte array. Instead, you define a method on the server that so this method has the same name and accepts the same parameters that you are passing when you use NetConnection.call().
I am getting this exception
Character decoding failed. Parameter [updatedLocalInfo] with value
org.apache.tomcat.util.buf.UDecoder$DecodeException: isHexDigit
I am passing request post data as JSON string and one of the values contains'%'
Because of this '%' i am getting this exception.
I am not able to figure out why this exception is Coming and how to fix it.
For information, The json which i am passing is
[{"taxInformation":"Applicable Taxes Extra","happyHourDesc":"40% off","happyHourTime":"4 to 8 PM","offer":"No Offers"}]
I am passing request post data as JSON string
My guess would be you're passing the JSON string without properly encoding it. When you send information from the client to the server via HTTP GET or POST, the information must be properly encoded. The most common way to do that is via URL encoding (even if it's POST data).
You haven't said how you're sending the data, but it sounds like you probably need to use encodeURIComponent at some stage during the generation of the data you're sending from the client to the server.