how to create SIP uri using java.net.URI class? - java

The server or you can say VOIP provider is ekiga.net.
I want to call this contact sip:500#ekiga.net. I have created sip headers as defined in rfc3261 and I want to create a sip uri using URI class. This is what I need help with.
The Purpose for creating uri is to send the udp packet that contains sip headers and messages to the server. I don't know what address to use because DataGram class needs destination ip and port. I know the port is 5060 but I don't know which url to use.
Thanks

Java don't have built-in support for SIP, so you don't need java for SIP URI.
Optionally first you might perform a DNS lookup like this:
InetAddress inetAddress = InetAddress.getByName("ekiga.net");
(this will lookup A record only. For VoIP you should use SRV DNS records, but that requires a seprate lib and A record is usually just fine)
Then create an UDP socket like this:
DatagramSocket socket = new DatagramSocket();
Then send any message like this (buff must hold a valid SIP message):
socket.send(new DatagramPacket(buf, buf.length, InetAddress.getByName("ekigaaddresshere"), 5060));
Then read the answer(s) and send other requests.

Related

Configure Proxy under AWS KinesisAsyncClient in java

I need to configure proxies for the Kinesis client. Currently I m using KinesisAsyncClient object for performing async operations on the kinesis stream.
After a bit of a search over internet, I came to a conclusion that there is no proper resource which helps to configure proxies over async clients.
So is there any way we can configure the proxy host, port, username, password and non-proxy-hosts under the KinesisAsyncClient object.
Thanks in Advance!
I am able to set Proxy host and port and pass to the KinesisAsyncClient using the following code:
String hostString="127.0.0.1";
int port=8080;
ProxyConfiguration proxyConfiguration =ProxyConfiguration.builder().host(hostString).port(port).build();
SdkAsyncHttpClient httpClient = NettyNioAsyncHttpClient.builder().proxyConfiguration(proxyConfiguration).build();
KinesisAsyncClient client = KinesisAsyncClient.builder().httpClient(httpClient).build();
Please note I have set a sample hostString and Port.
Hope this helps.

java.security.cert.CertificateException: No subject alternative names matching IP address

I have different issues with this exception, Please try to understand.
I'm sending data from one application to another through web service call in Java.
whenever I called it will connect to some other application. in that
a situation I get the above exception, this problem occur only in
byte Grid server.
We solved above problem like this our admin removed security,
means we have https they removed s so we are working with
HTTP, but it's not good, I want to connect through web service call with security, can any one give me the best idea.Please see my sample code
byte[] postData = urlParameters.getBytes(StandardCharsets.UTF_8);
int postDataLength = postData.length;
String request = PropertyFactory.getProperty("someUrl");
url = new URL(request);
postConnection = (HttpURLConnection) url.openConnection();
can I handle through code?
If you are using Oracle JDK between 1.8.0_51 and 1.8.0_60, there was an issue when connecting via IP address instead of hostname. In the case of using the IP-address, this address also has to be mentioned in the Subject alternative names of the cert. According to Mulesoft Support a workaround would be to set the JVM argument "jdk.tls.trustNameService" to true - resulting in a reverse name lookup for the IP address.
Byte grid having internal firewall so its may be stop, Please contact with byte grid team.

why ServletRequest.getRemoteAddr cannot be forged?

I am trying to find the client's IP. And I was told that 'request.getHeader("HTTP_X_FORWARDED_FOR")' cannot be trusted since it may be forged and I should use request.getRemoteAddr instead.(In my case it's ok to just get the proxy's IP)
So my question is:
why ServletRequest.getRemoteAddr cannot be forged?
another question:
what's the difference between HTTP_X_FORWARDED_FOR and X_FORWARDED_FOR?
If you do request.getRemoteAddr();
and if the user is behind a proxy server or accessing your web server through a load balancer then the above code will get the IP address of the proxy server or load balancer server, not the original IP address of a client.
So if
In my case it's ok to just get the proxy's IP
you are ok with this then request.getRemoteAddr(); is enough.
But in Ideal case you should try this
//is client behind something?
String ipAddress = request.getHeader("X-FORWARDED-FOR");
if (ipAddress == null) {
ipAddress = request.getRemoteAddr();
}
X_FORWARDED_FOR
The X-Forwarded-For (XFF) HTTP header field is a de facto standard for identifying the originating IP address of a client connecting to a web server through an HTTP proxy or load balancer.
HTTP_X_FORWARDED_FOR
A header HTTP_X_FORWARDED_FOR is set by proxy servers to identify the ip-address of the host that is making the HTTP request through the proxy.
In short they're all the same header, just referred to differently by various implementations. For more view this : HTTP Headers: What is the difference between X-FORWARDED-FOR, X_FORWARDED_FOR and HTTP_X_FORWARDED_FOR?

How to restrict broadcasting to a single client with Atmosphere

I'm trying to use Atmosphere for a client server communication. I've read the message here on stackoverflow about one-to-one chat and the relevant page on the Atmosphere Wiki "Creating private channel of communication between Browsers" but i'm still stuck. Though i'm creating a 'private' channel for each uuid the messages are received in other browsers too that connect to the same URL.
In my scenario i need to restrict the communication between a single browser client and the server.
I managed to solve the problem by adding a unique key to the request URI and using a URI template as suggested in the multichat example.
#ManagedService(path = "/msg/{xfid}")
and
#PathParam("xfid")``
private String xfSession;
Then i used the path param to lookup a specific Broadcaster
Broadcaster privateChannel = BroadcasterFactory.getDefault().lookup(xfSession,true);
Now updates send from the server are only broadcasted to the client associated with the path param.

How to get the subnet ip adress from http request

I'm writing a web application, I need to do a audit log for all the actions in the application. For this purpose I need to get the IP Address of the client systems.
I'm using request.getRemoteAddr() to get the remote IP Address. But this has a problem, if the client is behind a proxy this method will give the IP of the proxy system.
When I did some search I found a header attribute called 'X-FORWARDED-FOR' in the HttpRequest object.
Can somebody tell me how exactly this header property works and how can I used this header to get the IP address of the client system.
Thank you
getRemoteIP returns the remote IP address of the user (assuming all HTTP intermediaries are well behaved wrt XFF header).
String getRemoteIP(HttpServletRequest request) {
String xff = request.getHeader("X-Forwarded-For");
if (xff != null) {
return xff.split("[\\s,]+")[0];
}
return request.getRemoteAddr();
}
The client's proxy - typically a firewall or somesuch - will populate the x-forwarded-for header with the ip it receives from its client, which is typically, but is not required to be (in the case of a user going through multiple proxies or firewalls) the ip of the user's machine.
'X-FORWARDED-FOR' is used for identifying the originating/actual IP address of a client connecting to a web server through an HTTP proxy.
You can simply use the value for this attribute to find out the originating client IP, even if it's behind a proxy.

Categories

Resources