Java.net.MalformedURLException POST request - java

I am trying to send a POST Request to a gateway.
The URL I am trying to get to is http://pg.staging.weareswat.com/payment-reference/create
I am using insomnia to send the POST request
This is what I am trying to send:
{
"supplier" : {
"name":"Easypay"
},
"client-id": "some-id",
"amount": 3.25,
"currency": "EUR",
"callback": "http://httpstat.us/200"
}
But for some reason the answer is a 500 server error with this body:
{
"error": "Cannot JSON encode object of class: class java.net.MalformedURLException: java.net.MalformedURLException: no protocol: "
}
The application I am trying to reach is written in clojure.
That only happens when I send the name "Easypay". When I send something like HiPay it works.
That logic is on the app side, and although I have access to the code, I didn't wrote it.
Can you help me? Thanks

Related

Filtered Stream never returning

I'm trying to build a bot using Twitter API. I'm testing Filtered stream to read the latest tweets with some words.
To test I create a single rule with a trending topic from Brasil:
{
"data": [
{
"id": "1360964144200110081",
"value": "carnaval lang:pt",
"tag": "Carnaval"
}
],
"meta": {
"sent": "2021-02-14T15:47:31.321Z"
}
}
But when I execute the GET Stream https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/get-tweets-search-stream, it never returns. I believe this can be a WebSocket, but I can't find that information on docs.
I'm doing a request on https://api.twitter.com/2/tweets/search/stream?tweet.fields=created_at&expansions=author_id&user.fields=created_at using the Authorization token and I'm getting 200 as a response, but the connection is never closed and no content.
I'm using the following code to call: github.com/vepo/twitter4j
Solved!
The problem is that I was expecting a String, but, as it is a WebSocket, the Response never ends. I change it to an InputStream and it starts working.

Sending a proactive message via Graph API and custom Request I get a 401 unauthorized

I want to send a proactive message with a team bot. For that I:
created a bot in the bot framework
created an app with AppStudio in teams
assigned the bot to my app
assigned the app to my team
Now I would like to send a request to this Url:
https://smba.trafficmanager.net/de/v3/conversations/{teamId}/activities/
to send a message to the channel.
For this I have to get a Bearer Token with this Token Url:
https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token
I get this back without any problems.
Now I want to use the GraphAPI to execute a custom request
First of all I have to create a GraphServiceClient like this:
OAuth2AuthenticationProvider authProvider = new OAuth2AuthenticationProvider(_getBotToken(botClientId, botClientSecret, BOT_SCOPE));
graphBotClient = GraphServiceClient.builder().authenticationProvider(authProvider).buildClient();
After I created the client I do the request.
graphBotClient.customRequest("https://smba.trafficmanager.net/de/v3/conversations/" + pTeamId + "/activities").buildRequest().post(messageAsJson);
I need to use a custom query because there are no methods for it in Java.
messageAsJson is a Json object that looks like an activity object, which is needed to write messages.
{
"type": "message",
"from": {
"id": "{clientBotIdFromAzure}",
"name": "Botname"
},
"conversation": {
"id": "{teamId}",
"name": "ChannelName"
},
"text": "My bot's reply"
}
When I execute this command I get the following exception:
401 : Unauthorized
Strict transport security : max-age=31536000
Cache control : private
x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter": "West Europe", "Slice": "SliceC", "Ring": "5", "ScaleUnit": "002", "RoleInstance": "AGSFE_IN_102"}}
client-request-id : 9a7197en-dd0f-4c90-8b2b-8dc5bb1200ee
WWW-Authenticate : Bearer realm="", authorization_uri="https://login.microsoftonline.com/common/oauth2/authorize", client_id="00000003-0000-0000-c000-000000000000"
request-id : b07b1399-7175-40d3-9891-266abe1144b9
Content-Length : 262
Date : Wed, 22 Apr 2020 08:24:28 GMT
Content-Type : application/json
{
"error." {
"code." "InvalidAuthenticationToken"
"message": "Access token validation failure. Invalid audience."
"innerError": {
"request-id": "b07b1399-7175-40d3-9891-266abe1144b9"
"date": "2020-04-22T08:24:29"
}
}
}
Exception in thread "main" com.microsoft.graph.http.GraphServiceException: Error code: InvalidAuthenticationToken
Error message: Access token validation failure. Invalid audience.
If I execute the same request in Postman, with the same token, url and body, the request works fine and my message appears in MSTeams
Message sent out of Postman appears in MSTeams
Why does it not work with the GraphAPI? Where is my mistake? What am I missing?
Many greetings
I think the issue might be the mix of authentication against the bot framework itself versus an authentication against the Microsoft Graph - they're not a complete 1-1, I don't think.
That said, it's much easier to use the bot framework directly - it has a mechanism for proactive messages as well. You can create a ConversationContext instance and interact with that. To do this, you do need to have certain information, in particular a conversation id, serviceurl, and so on, which you need to get and store beforehand. There are multiple ways to get this info, but the easiest is to save this information any time a user sends your bot a message (every message will have these bits of info) and then just save it in a database/blob/whatever.
I've got some more detail on this over here: Programmatically sending a message to a bot in Microsoft Teams
Here's also a Node example: Sending Proactive Messages from Azure functions to botservice - node
Of course, don't forget to check out the docs on this for more info: https://learn.microsoft.com/en-us/azure/bot-service/bot-builder-howto-proactive-message?view=azure-bot-service-4.0&tabs=javascript

Using Java gcm-server to send message to topic

I'm using Java gcm-server to send messages to Android client apps, and I would like to send a message to a specific topic as showed here.
My problem is that I only managed to send a message using the Sender class, to a list of registration_ids, and I can't figure out how to use parameter "to": "/topics/myTopic" (I read the source code and it seems it is not implemented).
Any advice?
Yes,Right Now... Not Implemented yet,
you need to make a HTTP POST request to :
https://android.googleapis.com/gcm/send
with body
{
"data":
{
"title": "Test Title",
"message": " Your Message"
},
"to" : "/topics/global"
}
For more Help -
https://github.com/googlesamples/google-services/blob/master/android/gcm/gcmsender/src/main/java/gcm/play/android/samples/com/gcmsender/GcmSender.java

Json getting corrupted over http POST when recieved by alfresco webscript

I am working on developing a REST-API, ie Alfresco based java-backed webscript.
Where I am supposed to pass a Json as POST request parameter field.
When I try to retrieve the parameter field on server side using:
webScriptRequest.getParameter(json);
I am recieving a corrupted Json.
Based on analysis its getting corrupted because of one of the below fields or may be combination of them,
I don't know exactly which special character is causing this corruption problem.
Can anybody help me out in figuring-out this issue.
My hunch is some special character combination in below field is corrupting the json:
2014-04-23T13:42:24.962-04:00
/case/77777777/doc/x-search-found.pdf
http://temp.com/doc/source/url
/case/77777777/doc/my-findings.pdf
2014-04-23T13:42:24.962-04:00
"docGroupNames": ["working", "suggested"]
If I remove above fields, I start receiving the healthy json on server side.
Below is the sample JSON:
{
"documentAlias": "DocNameForTmngUiDisplay",
"modifiedByUserId": "User XYZ",
"sourceSystem": "TMNG",
"sourceMedia": "electronic",
"sourceMedium": "upload",
"accessLevel": "public",
"scanDate": "2014-04-23T13:42:24.962-04:00",
"docList": [
{
"documentId": "/case/77777777/doc/x-search-found.pdf",
"metadata": {
"modifiedByUserId": "User XYZ",
"documentAlias": "nickname",
"sourceMedia": "paper",
"docSourceUrl": "http://test/doc/source/url",
"docCategory": "web"
}
},
{
"documentId": "/case/77777777/doc/my-findings.pdf",
"metadata": {
"sourceMedium": "fax",
"accessLevel": "public",
"scanDate": "2014-04-23T13:42:24.962-04:00",
"evidenceSourceTypeId": "123",
"docGroupNames": [
"working",
"suggested"
]
}
}
]
}
Additional Disclosure:
This looks like REST-Client issue, try changing your Rest Client is one probable solution to json corruption issue.
This issue is happening specifically on SoapUI 5.0.0 Above issue is NOT happening on DHC 0.7.2.2 (Chrome based rest client extension)

how to send JSON data with server error response code 500

I wanted to know if theres a way to send a JSON data along with HTTP response code 500. Basically I want my rest client to know that there is some error on the backend and along with it send a JSON error data structure like this.
{"error" : [
{"code": "1001", "desc": "Some error description"},
{"code": "1002", "desc": "Some other error description"}
]
}
This is using the following java stack = Java 6/JAX-RS/Jersey/Tomcat
If not, then is there a way to send a custom response code along with JSON data. Basically looking from JAX-RS API it looks that you can only send JSON data along with 200 OK??
Any thoughts?? I am guessing RESTEasy would be the same, right??
You simply need to set the HTTP header response to whatever you want before starting to output the actual response using something like setStatus(). Response.status(500)

Categories

Resources