How to restrict broadcasting to a single client with Atmosphere - java

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.

Related

consuming Java web services. Issues with id session

i am having some issues and almost no documentation on internet about id session tokens and Java web services. We have a server (Tomcat providing web services on JAX-WS + SOAP) that is providing an API to query an SQL server.
I have to code a simple Java client that communicates with the server through this web services. The issue is that before being able to use any of its server WSDL methods, the client has to authenticate through a web server method where you send the user/pass, and the server gives back to client a session-id (alfanumeric string).
The rest of the methods do not have any kind of parameter where i can pass the session id, so i suppose it has to be used as a "context". I have found information about how in JAX-WS you can maintain session-id:
https://weblogs.java.net/blog/ramapulavarthi/archive/2006/06/maintaining_ses.html
Hello port = new HelloService().getHelloPort();
((BindingProvider)port).getRequestContext().put(BindingProvider.
SESSION_MAINTAIN_PROPERTY,true);
in my case, if i want to receive the cookie session-id, i have to:
org.tempuri.RUWebService service = new org.tempuri.RUWebService();
org.tempuri.RUWebServiceSoap myport = new org.tempuri.RUWebServiceSoap();
String session-id = myport.Auth(user,pass);
where the session-id is an UUID variable is a String of a hex variable: 8-4-4-4-8 .. that i can change to real hex like:
java.util.UUID uuidFromHyphens = java.util.UUID.fromString("6f34f25e-0b0d-4426-8ece-a8b3f27f4b63");
I tried the following code, where i change "port" variable to "myport", trying to match both examples:
((BindingProvider)myport).getRequestContext().put(BindingProvider.
SESSION_MAINTAIN_PROPERTY,true);
It compiles, but when i consult the web server through some of its methods, i receive a "null", the same as if i do not make the auth procedure. My issue i think is that i don't know what i am doing wrong with cookie session-id auth procedure.
If somebody could help me, i would be grateful.
regards.
Either you pass it as Request Parameter using GET or POST methods
(or)
Put the session id in outgoing HTTP header, like
GET / HTTP/1.0
Accept: text/plain
Accept: text/html
Session-Id:DFF55566_SOMEID
But for both of this to work, your web server must expect the Session Id from client in some format either at server level (or) your application level.

How to match responses to requests in Netty client?

I'm implementing a http client app with Netty. The task is to send the same request to several endpoints and collect the answers for further processing. Many such requests can be sent concurrently to the same endpoints. The problem is to match responses received from one endpoint to requests.
One possible solution is to create a new handler (and pipeline) for each request as describe here https://stackoverflow.com/a/7905761/4926576. In this case request can be mapped to handler and handler can store the response. But this means creating new connection for each request which will degrade the performance.
I also don't want to change the protocol and include request ids in requests/responses only for the purpose of matching.
If both the client and server are respecting HTTP pipelining semantics, then the server must respond to requests in order. Therefore, for each connection, you can maintain a queue of requests. Each new request goes on the back of the queue and each response pops it's matching request from the front of the queue.
In the event of connection failure the queue also provides you with the list of requests that were sent but for which you have not received a response. You can then take appropriate error correcting action for each request.

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

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.

soap set parameter java

I am implementing a TV listing service and I have decided to use ROVI as my data provider.
They provide me with an API that allows me to exchange data between my application and their servers by means of SOAP requests.
Since I am programming in Java, I used wsimport to generate the classes that would enable me to interact with their server.
//Connection
service = new ListingsService();
port = service.getListingsServiceSoap();
I have come across a problem which Google doesn't seem to have the answer for.
According to their API, whenever I want to make a call to a SOAP service I have to add my API Key to the end of url.
The problem is, I don't know how to do that. Using the stubs generated by wsimport, I can create a request object as it should be; however the URL is not displayed as per their specification. The url I currently get is: http://api.rovicorp.com/v9/listingsservice.asmx and what is required is: http://api.rovicorp.com/v9/listingsservice.asmx?apikey=myAPIkey. I obtained that by printing the following code:
System.out.println(port.toString());
Trying to run the following code:
GetServicesRS servicesRS = port.getServices(getServicesRQ, auth)
Yields the following error:
Exception in thread "main" com.sun.xml.internal.ws.client.ClientTransportException: The server sent HTTP status code 403: Forbidden
What java method can I use to append this parameter into the SOAP request URL.
Thanks for your help.
Edit.
I am still struggling with this and haven't been lucky with responses, if anyone could point me in the direction of a framework or something that could facilitate this would be great!
Cheers
I manage to work around my problem using something called BindingProvider.
I added the following to my code:
//Connection
service = new ListingsService();
port = service.getListingsServiceSoap();
BindingProvider bindingProvider = (BindingProvider) port;
bindingProvider.getRequestContext()
.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
"http://api.rovicorp.com/v9/listingsservice.asmx?apikey=" + APIKey);
With the aforementioned code the call to the API is successful:
GetServicesRS servicesRS = port.getServices(getServicesRQ, auth)
Hope it helps someone in the future.

implementing GAE XMPP service as an external component to an existing XMPP server (e.g. ejabberd or OpenFire)

may i know what integration technique that you folks use to implement external component to an existing XMPP server (e.g. ejabberd or OpenFire) . Is it through sending xmpp message to another user#externaldomain directly or using mechanism like urlfetch?
Google app engine (Gae) does support XMPP just as CLIENT.
With XMPP Gae JAVA client feature you can:
SEND MESSAGE
JID jid = new JID("youraccount#jabber.org");
Message msg = new MessageBuilder()
.withRecipientJids(jid)
.withBody("Hello i'm a fancy GAE app, how are you?")
.build();
XMPPService xmpp = XMPPServiceFactory.getXMPPService();
if (xmpp.getPresence(jid).isAvailable()) {
SendResponse status = xmpp.sendMessage(msg);
}
RECEIVE MESSAGE
public class XMPPReceiverServlet extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws IOException {
XMPPService xmpp = XMPPServiceFactory.getXMPPService();
Message message = xmpp.parseMessage(req);
JID fromJid = message.getFromJid();
String body = message.getBody();
//Save to Big Table
}
}
Remember that JIDs can just be yourappid#appspot.com OR foo#yourappid.appspotchat.com
because Google domains are not supported yet.
For example, you could craft a toy Gae application with a simple page with:
An html form to send text
An html table that display the list of messages received and stored to big table.
To test your application:
Create an account on jabber.org
Download Smack
Try to send a message from Smack to yourappid#appspot.com
Try to send a message from Gae App to youraccount#jabber.org
In case you have your personal XMPP server (openfire) up and running, simply skip step 1 and use your domain account to receive message from your fancy Gae App.
Have a look to XMPP message delivery to understand how this works.
App Engine supports a very limited subset of XMPP. Basically, you can send messages (through the API), and you can receive messages (they come in as HTTP requests).
Java API
Python API
You could rig up an external component on your existing XMPP server, to send and receive messages with your app engine code. That component would have to keep track of whatever it is you want to send and receive from your app.

Categories

Resources