I need to responses messageID in logica SMPP async mode - sms

In logica smpp I need to stored response message ID in asynchronous mode.
if (sb.asynchronous)
{
System.out.println("Submit request " + request.debugString());
sb.getSession().submit(request);
//messageId = response.getMessageId();
} else {
response = sb.getSession().submit(request);
messageId = response.getMessageId().trim();
}
In the above code. How we can get messageID in asynchronous mode.

You can get Message id by getSmDefaultMsgId() by calling it with SubmitSM 's object . like below:
if (sb.asynchronous)
{
System.out.println("Submit request " + request.debugString());
sb.getSession().submit(request);
messageId = request.getSmDefaultMsgId();
}
For more documentation you can read this tutorial
Thanks. Let me know if it helped.

Related

Sending URL Link to Email ASP.NET WEB API

I'm trying to generate a confirmation link to be sent to the email. The email was sent and received but the link is just not there.
heres the code
[HttpPost]
public async Task<IActionResult> SendEmail(Otp request)
{
randomcode = CreateRandomToken();
var confirmationLink = Url.Action("confirmotp", "Authentication", new {randomcode}, Request.Scheme);
var email = new MimeMessage();
email.From.Add(MailboxAddress.Parse(_config.GetSection("EmailUsername").Value));
email.To.Add(MailboxAddress.Parse(request.EmailAddress));
email.Subject = "Confirmation Link For" + (request.EmailAddress);
email.Body = new TextPart(TextFormat.Html)
{
Text = "Hello " + request.EmailAddress + ", click on the link: " + confirmationLink
}
using var smtp = new SmtpClient();
smtp.Connect(_config.GetSection("EmailHost").Value, 587, SecureSocketOptions.StartTls);
smtp.Authenticate(_config.GetSection("EmailUsername").Value, _config.GetSection("EmailPassword").Value);
smtp.Send(email);
smtp.Disconnect(true);
return Ok();
}
and this is the email I received :
Hello xxx#gmail.com, click on the link:
the link is just not being read. appreciate any help i can get thank you.
Please try this to create the URL:
Uri uri = new Uri(url);
More details can be found in How to build a Url?

Spring Websocket convertAndSendToUser doesn't work

I successfully subscribe to a queue, but when sending a message, another user does not receive it
message broker configuration:
override fun configureMessageBroker(config: MessageBrokerRegistry) {
config.enableSimpleBroker("/queue", "/topic")
config.setApplicationDestinationPrefixes("/app")
}
How i send message
messageTemplate.convertAndSendToUser(recipientId.toString(), "/queue/chat", message)
Creating custom user principal on ws connection
override fun preSend(message: Message<*>, channel: MessageChannel): Message<*>? {
val accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor::class.java)
if (accessor != null && StompCommand.CONNECT == accessor.command) {
val customPrincipal = CustomPrincipal(userId)
val authentication = CustomAuthToken(customPrincipal, roles)
accessor.user = authentication
return MessageBuilder.createMessage(message.payload, accessor.messageHeaders)
}
return message
}
}
On client side i connect socket
this.stompClient.connect(headers, () => {
this.stompClient.subscribe(headers, "/user/queue/chat", (message) => {
console.log("connected");
console.log(message);
});
});
When i connect to stomp i see in browser console next message
<<< CONNECTED
user-name:1
heart-beat:0,0
version:1.2
content-length:0
user-name is my actual id for this user
I subscribe user with id 1 and user with id 2 to same queue, when i send a message from user 1 to user 2 second user doesn't receive it.
Did i miss something?
After 5 hours of debugging Spring i found how to fix this issue
Just set accessor (in preSend method) immutable
accessor.setLeaveMutable(false)
Still don't fully understand why this happend, would be useful if anyone could explain it
I didn't find anything in documentation about this

Oracle MCS Custom API call from MAF Application

I have created a custom API in Oracle MCS to get the user information and trying to call it from MAF application... As a response i am getting 200 as success code... but when i try to parse the response it shows a HTML page instead of actual responce....
Custom API
https://mobileportalsetrial1304dev-mcsdem0001.mobileenv.us2.oraclecloud.com:443/mobile/custom/rvs_ekkfetchuserinfo/fetchcontent
and userid=101 as parameter
Calling Method to get User information
#Override
public Response getUserInformation(int userId) {
System.out.println("In loginService");
String restURI = "https://mobileportalsetrial1304dev-mcsdem0001.mobileenv.us2.oraclecloud.com:443/mobile/custom/rvs_ekkfetchuserinfo/fetchcontent?userid=" + userId;
String jsonRequest = "";
Response response = new Response();
response = RestUtil.callGet(restURI, jsonRequest);
return response;
}
callGet Method
public static Response callGet(String restURI, String jsonRequest) {
String responseJson = "";
Response response = new Response();
System.out.println("restURI:" + restURI);
RestServiceAdapter restServiceAdapter = Model.createRestServiceAdapter();
restServiceAdapter.clearRequestProperties();
restServiceAdapter.setConnectionName("MiddlewareAPI");
restServiceAdapter.setRequestType(RestServiceAdapter.REQUEST_TYPE_GET);
restServiceAdapter.addRequestProperty("Content-Type", "application/json");
restServiceAdapter.addRequestProperty("Accept", "application/json; charset=UTF-8");
restServiceAdapter.addRequestProperty("Oracle-Mobile-Backend-Id", "da5c7d86-29c0-43e8-b613-53de55a7ae6c");
restServiceAdapter.addRequestProperty("Authorization", "Basic TUNTREVNMDAwMV9NT0JJTEVQT1JUQUxTRVRSSUFMMTMwNERFVl9NT0JJTEVfQU5PTllNT1VTX0FQUElEOmR5Nm91NW5wX3RnbE5r");//+new String(encodedBytes));
restServiceAdapter.setRequestURI(restURI);
restServiceAdapter.setRetryLimit(0);
try {
responseJson = restServiceAdapter.send(jsonRequest);
System.out.println("response" + responseJson);
int responseCode = restServiceAdapter.getResponseStatus();
System.out.println("responseCode" + responseCode);
response.setResponseCode(responseCode);
response.setResponseMessage(responseJson);
response.setHeader(restServiceAdapter.getResponseHeaders());
} catch (Exception e) {
System.out.println("Error in calling API" + e.getStackTrace());
int responseCode = restServiceAdapter.getResponseStatus();
response.setResponseCode(responseCode);
response.setResponseMessage(responseJson);
}
return response;
}
Json Parsing
JSONObject obj = new JSONObject(response);
JSONArray arr = obj.getJSONArray("posts");
for (int i = 0; i < arr.length(); i++)
{
String user_id = arr.getJSONObject(i).getString("UserId");
}
Here what i am getting is JSONObject["items"] is not found... when i print the responce message it gives a HTML Script file
Expected Output
{
"items": [
{
"UserId": "101",
"AgentId": null,
"Category": "Rental",
"Division": "KDR",
"Status": null,
"LocationId": null,
"Operation": "CheckOut",
"Admin": "N",
"createdBy": "mcs-demo_user09#oracleads.com",
"createdOn": "2015-09-25T11:29:10.215564+00:00",
"modifiedBy": "mcs-demo_user09#oracleads.com",
"modifiedOn": "2015-09-25T11:29:10.215564+00:00"
}
]
}
what is the content of the HTML page (it will have some JavaScript I assume but should have a HTML title as well). Anyway, a user Id in MCS is not 101 but an internal ID, so I don't know if you've chosen 101 for simplification in this question.
In MAF, the REST connection is defined through a REST connection with the root URL and the relative URI. In your example, the REST connection is referenced as "MiddlewareAPI". Unless the value of this connection is null, the restURI you provide needs to be reduced to not contain the root URL.
The HTTP 200 you get because the request is answered by the server. However, it appears to be missing either an authorized user (in case of a failed basic authorization for accessing the API) or the authenticated user is not allowed to request the user platform API (by default you can only request information about the user you re authenticated as).
Frank
Hi I got the solution...
I was trying to call customAPI through Oracle-MCS. I replaced RestServiceAdapter with HttpsURLConnection. Then it Works perfectly fine.

RestSharp on Windows Phone no set-cookie in response

I have a problem with using the RestSharp client on the Windows Phone device. Starting form the beginning, I have the ASP.NET Web Api service hosted online. I have a request user address: POST: http://my-service-url.com/token where I send Email and Password as a body parameters and I get 201 status code and a cookie in the response. When I do it in fiddler everything works fine. I also have the functional test for my API which is using the RestSharp which is also working correctly:
[Given(#"I fill email and password with correct data and I click log in button")]
public void GivenIFillEmailAndPasswordWithCorrectDataAndIClickLogInButton()
{
//Delete user if he exists
_testUserHelper.DeleteTestUser(TestEmail);
//Create new activated user
Assert.IsTrue(_testUserHelper.CreateTestUser(TestEmail, TestPassword));
//Prepare client
var client = new RestClient(CarRentalsConstants.HostAddress);
var restRequest = new RestRequest("api/token", Method.POST) { RequestFormat = DataFormat.Json };
//Add parameters to request
restRequest.AddBody(new { Email = TestEmail, Password = TestPassword });
//Perform request
_response = client.Execute(restRequest);
}
[When(#"the log in login process finishes")]
public void WhenTheLogInLoginProcessFinishes()
{
Assert.AreEqual(HttpStatusCode.Created, _response.StatusCode, _response.Content);
Assert.IsNotNull(_response.Cookies.SingleOrDefault(q => q.Name == ".ASPXAUTH"););
}
The one above works properly, and the cookie is in the response object.
Now what I try to do on my windows phone looks like this:
var restRequest = new RestRequest("token", Method.POST) {RequestFormat = DataFormat.Json};
restRequest.AddBody(new {Email = email, Password = password});
myWebClient.ExecuteAsync(restRequest, (restResponse, handle) =>
{
switch (restResponse.StatusCode)
{
case HttpStatusCode.Created:
{
var cookie = restResponse.Cookies.SingleOrDefault(q => q.Name == ".ASPXAUTH");
successLogicDelegate(cookie);
}
break;
case HttpStatusCode.BadRequest:
{
HandleBadRequest(restResponse.Content, failureLogicDelegate);
}
break;
default:
msgBox.Show(StringResources.ServerConnectionError);
failureLogicDelegate(null);
break;
}
});
And in this case, the response returns the "Created" status code, but the cookie is then set to null. I have no idea what is happening here, but I am fairly certain that server is sending this cookie, so where does it get lost?
Any help will be really appreciated.

RestSharp on Windows Phone with Request Parameters

I'm working on Windows phone client for one service with Oauth1 API.
In API docs I have something like this:
url: http://example.com/iphone/json/users/
method: GET
parameters:
page_num=[int] - page number, >=1, default=1.
For default page num everything works well:
RestClient HabraClient = new RestClient("http://habrahabr.ru");
HabraClient.Authenticator = OAuth1Authenticator.ForProtectedResource("xxx", "yyyyyy", App.Tokens.Key, App.Tokens.Secret);
var TokenRequest = new RestRequest("/iphone/json/users/", Method.GET);
HabraClient.ExecuteAsync(TokenRequest, (response =>
{
try
{
if (response.StatusCode == HttpStatusCode.OK)
{
When I execute this request I receive correct response with data.
But if I add parameter (uncomment TokenRequest.AddParameter("page_num", 2); ) I receive "Invalid signature". I have tried to send both int and string parameter.
var TokenRequest = new RestRequest("/iphone/json/users/", Method.GET);
TokenRequest.AddParameter("page_num", 2);
HabraClient.ExecuteAsync(TokenRequest, (response =>
{
try
{
if (response.StatusCode == HttpStatusCode.OK)
{
I receive message "Invalid signature". I have tried string parameter too:
TokenRequest.AddParameter("page_num", "2");
API provider told me, that I have a problem with signature base
string http://oauth.net/core/1.0/#sig_base_example
So, how can i view it? Or maybe you can help me to solve all this
problem?
I think you are breaking the request structure... better to check the request over Fiddler, but try to write something like
var TokenRequest = new RestRequest("/iphone/json/users/?page_num=2", Method.GET);
instead of
var TokenRequest = new RestRequest("/iphone/json/users/", Method.GET);
TokenRequest.AddParameter("page_num", 2);
Hope, it would help.

Resources