I send INVITE to a sip server in a J2ME app and use rtp for data transmision.There is a conflict in VIA header which is that,implecite via header contain UDP instead of rtp. But I haven't use 'upd' any where in my code.If we consider the JAINSIP we can modify the VIA header header.But j2m2 api doesn't allow to modify the VIA header(here).
How can I solve this?how to avoid implicitly adding udp to VIA header in my request.Where I should see again??
Here is my sending INVITE Code
try { final String ip = scn.getLocalAddress();
contact = "sip:user#" + scn.getLocalAddress() + ":" + scn.getLocalPort();
scc = (SipClientConnection) Connector.open("sip:user#xxx.xxx.xxx.x:5060;transport=tcp");
scc.setListener(this);
scc.initRequest("INVITE", scn);
scc.setRequestURI("sip:user#xxx.xxx.xxx.x:5060;transport=tcp");
scc.setHeader("From", "sip:user#" + scn.getLocalAddress() + ":" + scn.getLocalPort() + ";transport=tcp");
scc.setHeader("To", "sip:user#xxx.xxx.xxx.x:5060;transport=tcp");
scc.setHeader("Contact", contact);
System.out.println("Session id is :" + sId);
scc.setHeader("Session-Id", sId);
scc.setHeader("Content-Type", "application/sdp");
String sdp = "....";
OutputStream os = scc.openContentOutputStream();
os.write(sdp.getBytes());
os.close();
Related
I have an Ionic app (client), with a Java 8 backend (server), and I have set up push notifications.
client
let topics: string[] = [this.personModelLoggedIn.uid];
const options: PushOptions = {
android: {
senderID: "XXXXXXXXXXXX",
sound: "true",
vibrate: "true",
topics: topics
},
ios: {
senderID: "XXXXXXXXXXXX",
alert: "true",
badge: true,
sound: "true",
topics: topics
},
windows: {}
};
For Android, I can receive notifications, send from the following:
server
private String sendAndroidPushNotification(String device_token, String topics, String title, String message)
throws Exception {
String pushMessage = null;
if (device_token != null && !device_token.equals("null")) {
pushMessage = "{\"data\":{\"title\":\"" + title + "\",\"message\":\"" + message + "\"},\"to\":\""
+ device_token + "\"}";
} else {
pushMessage = "{\"data\":{\"title\":\"" + title + "\",\"message\":\"" + message + "\"},\"to\": \"/topics/"
+ topics + "\"}";
}
// Create connection to send FCM Message request.
URL url = new URL("https://fcm.googleapis.com/fcm/send");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Authorization", "key=" + SERVER_KEY);
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestMethod("POST");
conn.setDoOutput(true);
// Send FCM message content.
OutputStream outputStream = conn.getOutputStream();
outputStream.write(pushMessage.getBytes());
return "Android Push Notification: " + conn.getResponseCode() + " " + conn.getResponseMessage() + " - " + pushMessage;
}
Problem
I have the following code for iOS, but the client does not receive the push notifications.
/**
* import com.notnoop.apns.APNS; import com.notnoop.apns.ApnsService;
* https://github.com/notnoop/java-apns.
*/
private String sendIOSPushNotification(String device_token, String topics, String title, String message)
throws Exception {
ApnsService service = APNS.newService().withCert(PATH_TO_P12_CERT, CERT_PASSWORD).withSandboxDestination()
.build();
String payload = APNS.newPayload()
// .customFields(map)
.alertBody(title + " " + message).sound("default").build();
service.push(Utilities.encodeHex(topics.getBytes()), payload);
return "iOS Push Notification: " + title + " " + message;
}
If you look at the com.notnoop.apns api, it is supposed to push to a device token, however, I need it to rather push to a uid. I have implemented the above code to push to a uid, but it doesn't work.
Question
Id it possible for the com.notnoop.apns api to push notifications to a topic? Otherwise, is there another api that will be able to do this?
If neither is possible, should the client rather listen on the device token? But the problem here is, that the sender of the push notification does not know the receivers device token. The sender does know the receivers uid though.
Thanks
I want to send SMS using android application. For that I had refer following sites.
ozekisms.com
Java Sms Example
How To Make HTTP POST Request To Server
And from following site I had registered and from using that API URL I had make that request.
http://websms.24x7sms.com/
http://www.24x7sms.com/downloads/24x7sms_http_api2.pdf
For that I used the following code.
protected void sendSMS(){
Log.d("in","booking sms function");
String nm1 = name.getText().toString();
String ara1 = area.getSelectedItem().toString();
String add1 = address.getText().toString();
String mob1 = mobile.getText().toString();
String message1 = "Name:"+ nm1 + "\n" + "Area:" + ara1 + "\n" + "Address:" + add1 + "\n"
+ "Mobile:" + mob1;
BufferedReader reader = null;
// Defined URL where to send data
String requesturl = "http://smsapi.24x7sms.com/api_2.0/SendSMS.aspx?APIKEY=********" +
"MobileNo=+91**********&SenderID=SMSMsg&Message=You%20have%20new%20booking%20fro%20(variable%20please%20collect%20from%20them." +
"ServiceName=TEMPLATE_BASED";
try {
URL url = new URL(requesturl);
HttpURLConnection huc = (HttpURLConnection)url.openConnection();
huc.setRequestMethod("POST");
Log.d("after connection open",huc.getResponseMessage());
Log.d("RESPONSE FROM SERVER", huc.getResponseMessage());
}
After Running program I had get following message in logcat window.
11-06 20:14:57.830 6513-6513/com.******.*******.********* D/in: booking sms function
11-06 20:14:58.555 6513-6513/com.******.*******.********* D/after connection open: OK
11-06 20:14:58.556 6513-6513/com.******.*******.********* D/RESPONSE FROM SERVER: OK
But i never receive the message on particular mob number. Please Help me.
Thanks In ADVANCE....
I have been playing around with UPnP, to get an understanding of how it all works, before I try working with any of the APIs that are out there, or doing anything more substantial. I have been reading through the UPnP documentation, and have used that information to format the messages that I am sending. I am just working from the command line right now, and have gotten discovery messages to work without issue. Now, I'm trying to return content from a ContentDirectory Browse() request (I have also tried TransportAV GetMediaInfo() because it takes only one argument). However, no matter what I try, I am getting a Null response from the MediaServer.
public class SOAPSocket2 {
public static void main(String[] args) {
try {
String xmldata = "<?xml version=\"1.0\"?>" +
"<s:Envelope " +
"xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/ \"" +
"s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" +
"<s:Body>" +
"<u:GetMediaInfo xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\">" +
"<InstanceID>0</InstanceID>" +
"</u:GetMediaInfo>" +
"</s:Body>" +
"</s:Envelope>";
//Create socket
String hostname = args[0];
int port = Integer.parseInt(args[1]);
Socket sock = new Socket(hostname, port);
//Send header
String path = args[2];
BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream(),"UTF-8"));
// You can use "UTF8" for compatibility with the Microsoft virtual machine.
wr.write("POST " + path + " HTTP/1.1\r\n");
wr.write("HOST: " + hostname + ":" + port +"\r\n");
wr.write("CONTENT-TYPE: text/xml; charset=\"utf-8\"\r\n");
wr.write("SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#GetMediaInfo\"");
wr.write("\r\n");
//Send data
wr.write(xmldata);
wr.flush();
// Response
BufferedReader rd = new BufferedReader(new InputStreamReader(sock.getInputStream()));
String line;
line = rd.readLine();
System.out.println(line);
while((line = rd.readLine()) != null)
System.out.println(line);
} catch (Exception e) {
e.printStackTrace();
}
}
}
I know this isn't the most proper code, but I borrowed it from here: http://users.skynet.be/pascalbotte/rcx-ws-doc/xmlpost.htm. I figured that if I could actually get some sort of data in a response, then I could work on building it properly. I have modified it so that I pass the IP address and Port of the Media Server from the command line, as well as the path to the Control URL. However, I am getting nothing but 'null' from the Media Server. Any thoughts on what I'm doing incorrectly? Thanks
I am getting a Null response from the MediaServer
Is that a response from MediaServer? I would imagine it's just BufferedReader telling you there's nothing to return.
You have two things here you can debug (sending and receiving) but the same tools should help with both. Use wireshark or another network traffic capture tool to see the actual data that goes through the network. Wireshark will tell you if the response is sent (but you are failing to receive it properly) or if the reply never comes (implying your message is incorrect). It will also show your message as it is on the wire, making it easier to notice mistakes.
Doing the above (and pasting the messages here if you can't figure it out) is the best way to continue debugging, but I can see some problems in the code already:
SOAPACTION-line is missing "\r\n" in the end
There is no CONTENT-LENGTH header (this is required in normal cases)
These aren't even UPnP problems really, the message just isn't proper HTTP. Still, the UPnP Device Architecture document will help with problems like this.
I have been trying to implement the paypal IPN system in our company website. When I test my script in the IPN sandbox tool, it is validated and everything goes well, however when I move it live, the IPN returned as INVALID but the payment has been completed well.
When I check the IPN history in my account, I can see this IPN message with the HTTP Response 200:
mc_gross=0.01&invoice=40&protection_eligibility=Ineligible&item_number1=&payer_id=mypayerId&tax=0.00&payment_date=08:06:52 Sep 03, 2013 PDT&payment_status=Completed&charset=windows-1252&mc_shipping=0.00&mc_handling=0.00&first_name=myName&mc_fee=0.01¬ify_version=3.7&custom=18528&payer_status=verified&business=bussiness_mail&num_cart_items=1&mc_handling1=0.00&verify_sign=AJ.HL1f2A9aoBiFQCLn.3J-QkKQGAF.RVW8er5rbGJ6SsQFWBbStuRtD&payer_email=myMail&mc_shipping1=0.00&tax1=0.00&txn_id=61052338B4613440H&payment_type=instant&last_name=MySurname&item_name1=Paquete Lite&receiver_email=mybussiness_mail&payment_fee=&quantity1=1&receiver_id=SVRXVCZYE2AYC&txn_type=cart&mc_gross_1=0.01&mc_currency=EUR&residence_country=ES&transaction_subject=18528&payment_gross=&ipn_track_id=38c492cbe6257
Paypal live credentials are OK.
URL is OK (https://www.paypal.com/cgi-bin/webscr)
My IPNHandler is a Java Servlet. The doPost Action is:
#Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// Java JSP
log.error("IPN doPost " + new Date().getHours() + ":" + new Date().getMinutes() + ":" + new Date().getSeconds());
// read post from PayPal system and add 'cmd'
Enumeration en = request.getParameterNames();
String str = "cmd=_notify-validate";
while (en.hasMoreElements()) {
String paramName = (String) en.nextElement();
String paramValue = request.getParameter(paramName);
paramValue = new String(paramValue.getBytes("iso-8859-1"), "utf-8");
str = str + "&" + paramName + "=" + URLEncoder.encode(paramValue);
}
boolean isSandbox = "true".equals(PropertiesManager.getProperty("signbox", "PaypalSandbox"));
// post back to PayPal system to validate
// NOTE: change http: to https: in the following URL to verify using SSL (for increased security).
// using HTTPS requires either Java 1.4 or greater, or Java Secure Socket Extension (JSSE)
// and configured for older versions.
String url = null;
if (isSandbox){
url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
}else{
url = "https://www.paypal.com/cgi-bin/webscr";
}
log.error("La url de a la que redirigimos a Paypal es " + url);
URL u = new URL(url);
URLConnection uc = u.openConnection();
uc.setDoOutput(true);
uc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
PrintWriter pw = new PrintWriter(uc.getOutputStream());
pw.println(str);
pw.close();
BufferedReader in = new BufferedReader(
new InputStreamReader(uc.getInputStream()));
String res = in.readLine();
in.close();
log.error("Tras abrir la conexión, res es = " + res);
// assign posted variables to local variables
String idUser = request.getParameter("custom");
String idCompra = request.getParameter("invoice");
String paymentStatus = request.getParameter("payment_status");
String paymentAmount = request.getParameter("mc_gross");
String fee = request.getParameter("mc_fee");
String paymentCurrency = request.getParameter("mc_currency");
String txnId = request.getParameter("txn_id");
String receiptId = request.getParameter("receipt_id");
String receiverEmail = request.getParameter("receiver_email");
String payerEmail = request.getParameter("payer_email");
String paymentType = request.getParameter("payment_type");
String txnType = request.getParameter("txn_type");
if (!"instant".equals(paymentType) || !"cart".equals(txnType)) {
log.debug("NO ES UN CART CHECKOUT. Detalles:");
log.debug("idCompra=" + idCompra);
log.debug("status=" + paymentStatus);
log.debug("amount=" + paymentAmount);
log.debug("currency=" + paymentCurrency);
log.debug("transactionId=" + txnId);
log.debug("receiptId=" + receiptId);
log.debug("receiverEmail=" + receiverEmail);
log.debug("payerEmail=" + payerEmail);
log.debug("paymentType=" + paymentType);
log.debug("txnType=" + txnType);
return;
}
**//HERE THE RESPONSE IS INVALID IN LIVE MODE**
if (res != null && res.equals("VERIFIED")) { //res = "VERIFIED" res = "INVALID"
// more code not important for this issue....
Any idea? As I said, payments are completed but the IPN is sended INVALID.
I know this is old but it might help someone else, I think you need to POST the data for validation.
According to Paypal IPN Docs:
//After receiving an IPN message from PayPal,
//you must respond to PayPal with a POST message
//that begins with "cmd=_notify-validate".
//Append to your message a duplicate of the
//notification received (the same IPN fields
//and values in the exact order you received them)
...
URL u = new URL(url);
HttpURLConnection uc = (HttpURLConnection) u.openConnection();
uc.setRequestMethod("POST");
...
To receive IPN message data from PayPal, your listener must follow this request-response flow:
1.Your listener listens for the HTTPS POST IPN messages that PayPal sends with each event.
2.After receiving the IPN message from PayPal, your listener returns an empty HTTP 200 response to PayPal. Otherwise, PayPal resends the IPN message.
3.Your listener sends the complete message back to PayPal using HTTPS POST.
Prefix the returned message with the cmd=_notify-validate variable, but do not change the message fields, the order of the fields, or the character encoding from the original message.
Send response messages back to PayPal:
https://ipnpb.sandbox.paypal.com/cgi-bin/webscr (for Sandbox IPNs)
https:/ipnpb.paypal.com/cgi-bin/webscr (for live IPNs)
for more info see also:
https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNImplementation/#specs
I'am trying to implement a simple HTTP/1.1 client application against a remote HTTP server. If I have a 301 Moved Permanently response from server, I will try to download the file from it's new location given in server's response. I am able to send first GET message to server and retrieve the new URL where the file I asked was moved.
The problem is that when I send second GET request from my client with new location of the file, server returns null. Not sure if anything goes wrong with writing the client message or reading the server response. Here is my code, any help is appreciated.
else if(serverMessage.equals("HTTP/1.1 301 Moved Permanently"))
{
System.out.println(" A new permanent URL is assigned to the file " + fileName);
serverMessage="";
lineCount=0;
while((serverMessage = reader.readLine()) != null)
{
lineCount++;
System.out.println("reply: " + serverMessage);
if(serverMessage.indexOf("Location") >= 0 )
{
for(int x=serverMessage.indexOf("Location")+10; x<serverMessage.length(); x++)
{
newURL= newURL + serverMessage.charAt(x);
}
}
}
System.out.println("newURL : " + newURL);
host = findHost(newURL);
path = findPath(newURL);
fileName=findFileName(newURL);
clientMessage = "GET ";
clientMessage = clientMessage + path;
clientMessage = clientMessage + " HTTP/1.1\r\nHost: ";
clientMessage = clientMessage + host;
clientMessage = clientMessage + "\r\n\r\n";
System.out.println("client message: \"" + clientMessage +"\"");
writer.newLine();
writer.write(clientMessage);
writer.flush();
serverMessage = reader.readLine();
System.out.println("reply2: " + serverMessage); //returns null!!!
while((serverMessage=reader.readLine())!=null)
{
System.out.println("reply2: " + serverMessage);
}
}
EDIT: Variables of client message are the followings (they all work correctly, tested for existing file - successfully downloaded!)
newURL : http://wlab.cs.bilkent.edu.tr/~cs421/pa1/302-redirect-success.txt
host2: wlab.cs.bilkent.edu.tr
path2: /~cs421/pa1/302-redirect-success.txt
fileName2: 302-redirect-success.txt
Are you using a persistent URLConnection / HttpURLConnection?
You may be receiving null if the connection has been closed by the server.
If you are using persistent connections, the server might have not had the time to respond.
This might describe the problem a little better. Check out the timeout given in doHttpUrlConnectionAction(String desiredUrl). You might find the answer there.
If this is your problem, you can try to do multiple reads at 0.1 second intervals for say ... 1-5 seconds. This is to make sure you get the response fast and don't have to wait the full timeout to make sure that the server has responded.