Can I use one servlet to receive xmpp messages, and another to send them in App Engine? - google-app-engine

Does the required servlet URL mapping (/_ah/xmpp/message/chat/) for the xmpp service restrict me to using only that servlet for both sending and receiving xmpp messages?
My application receives messages, adds them to an 'inQueue' for processing, and once processed, the results are added to an 'outQueue'. Ideally I'd like the worker servlet assigned to the outQueue to send the response.
I am using push queues and the servlets are obviously invoked by an HTTP POST request...
When I try to use the xmpp service to send the message from my outQueue worker ( which is obviously not mapped to /_ah/xmpp/message/chat/ ), it expectedly does nothing.
In the servlet mapped to /_ah/xmpp/message/chat/:
//Generate a Memcache key
String key = generateMemcacheKey(message);
//Serialize the message as xml using getStanza (for now, just put in the senderJID as string)
String senderJIDString = message.getFromJid().getId();
//Cache the message in Memcache
cache.put(key, senderJIDString);
//Enqueue a task for the message
private Queue queue = QueueFactory.getQueue("inQueue");
queue.add(TaskOptions.Builder.withUrl("/xmppParser").param("memcacheKey", key));
In xmppParser servlet doPost method:
//Extract message from memcache
String key = req.getParameter("memcacheKey");
String recipientJIDString = (String)cache.get(key);
//Todo Detect language
//Todo Parse Message into an Imperative accordingly (For now, just reply hello)
//Todo Handle Session status
//Put Imperative into memcache (For now, just put recipientID in)
cache.put(key, recipientJIDString);
//Enqueue appropriately
Queue queue = QueueFactory.getQueue("outQueue");
queue.add(TaskOptions.Builder.withUrl("/responseServlet").param("memcacheKey", key
));
Now I would like this responseServlet to send the reply:
//Get a handler on the memcache
MemcacheService cache = MemcacheServiceFactory.getMemcacheService();
//Extract the key to the response from the request
String key = req.getParameter("memcacheKey");
//Extract the message from the memcache ( For now it's just the JID of the sender)
String recipientJIDString = (String)cache.get(key);
//Parse it into a message (For now just make a simple "I hear you" message)
JID recipientJID = new JID(recipientJIDString);
Message response = new MessageBuilder()
.withMessageType(MessageType.NORMAL)
.withRecipientJids(recipientJID)
.withBody("I hear you")
.build();
//Send the message
XMPPService xmpp = XMPPServiceFactory.getXMPPService();
xmpp.sendMessage(response);
The servlet mappings are all kosher, and the xmpp service is unable to send the message. It raises a null pointer exception, but the memcache viewer confirms the recipientJID is kosher as well... I'm guessing only the servlet mapped to /_ah/xmpp/message/chat/ is able to send messages, or am I wrong?
I am forced to test on the live site itself as XMPP does not seem to be supported by the development server, adding the possibility of my having overlooked some production environment configuration...
Much obliged!
ram

Related

Salesforce Rest API (upsert): System.Web.Services.Protocols.SoapException: EXCEEDED_MAX_SIZE_REQUEST: size of unauthenticated request is too large

I am facing this issue intermittently but not for every request. Can you please help me on this. Below is my code for sending request to salesforce rest api:
loginResult = _sfCachingManager.GetLoginResult();
if (_loginResult != null && _loginResult.userInfo != null)
{
_sforceService.Url = _loginResult.serverUrl;
_sforceService.SessionHeaderValue = new SessionHeader();
_sforceService.SessionHeaderValue.sessionId = _loginResult.sessionId;
Account account = _sfModelMapping.AccountMapping(agency);
UpsertResult[] result = _sforceService.upsert("Agency_ID__c", new sObject[] { account });
Some times, when I tried to send the request it generates exception as :
System.Web.Services.Protocols.SoapException: EXCEEDED_MAX_SIZE_REQUEST: size of unauthenticated request is too large at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall) at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
Any help would be appreciated.
You'll get this error sending requests to the login endpoint, it seems likely that you're sharing _sforceService across threads and when one of the decides it needs to login, it sets the Url to the login endpoint, and a concurrent request on another thread that thinks it sending a request to the authenticated endpoint actually ends up sending it to the login endpoint. Carefully review how you sharing the _sforceService across threads.

Sending a chat message in GAE doesn't work

I am trying to send out a simple Chat message to myself from a GAE Python app following the example in this GAE document.
My code on the /chat postback is simply:
class Chat(webapp2.RequestHandler):
def post(self):
message = self.request.get('content')
status_code = xmpp.send_message("xxxxx#gmail.com", message)
self.response.write("<html><body><p>Message: %s</p><p>Status Code: %i</p></body></html>"
% (message, status_code))
The code is deployed at http:http://mindful-braid-368.appspot.com where you can test it out. Each time the status code returned is 0, but no message is received at my Google account (xxxxx#gmail.com).
Is the example in the GAE document complete? Is there anything else I must set up to send Chat/Talk/Hangouts messages?

not receive email in google app engine java

I'm writing code for receive email and change into todo. I received fresh email and converted todo but I sent forward email or reply email app engine not receive the email. What's the problem. I used session and getdefaultinstance that's all rest of the code same as receive email code.please do the needful.thanks
IN SERVLET Properties props = new Properties();
Session email = Session.getDefaultInstance(props, null);
try
{
MimeMessage message = new MimeMessage(email,req.getInputStream());
String summary = message.getSubject();
String description = getText(message);
Address[] addresses = message.getFrom();
User user = new User(addresses[0].toString(), "gmail.com");
Date date =new Date();
DaoComments.INSTANCE.add(addresses[0].toString(),lid,date,description,"selcom‌​ment"); 
}catch (Exception e)
{ e.printStackTrace();
}
IN WEB.XML
EmailTicket
com.cloudnowtech.EmailAgentServlet
EmailTicket
/_ah/mail/*
IN appengine-web-app
mail
HERE I'M SENDING THE CODE. PLEASE CORRECT IT – 
An important part of sending email is to, well, to send it. Perhaps you missed this part:
// Hand the message to the default transport service for delivery.
Transport.send(msg);
If you take a peek over on the right there ---->,
Wander the related questions for yourself and you should find some helpful tidbits.
Welcome to StackOverflow and have a nice day.
It looks like this:
I got answer. there is no setting for forward and reply email to receive. I declared field as String but reply or forward mail size as more than 500 character. so change as Text. now its working fine. thanks for all.
Thanks
Murugavel

Using DispositionNotification with Javamail

I am working with a set of specialized email servers that are configured to return Message Disposition Notifications (MDNs) upon successful receipt of the message. I have developed a Javamail client that is used to send messages to one of these servers and retrieve returned MDNs from the user's POP3 INBOX folder.
How do I go about getting at the disposition notification body part from the returned MimeMessage I retrieve from the user's inbox? I've found the com.sun.mail.dsn.DispositionNotification class but haven't seen an example of how to correctly create an instance of a DispositionNotification using the constructor:
DispositionNotification(InputStream)
Should I be able get the InputStream from a MimeMessage and use it to create the DispositionNotification, like so?
Message[] msgs = getInboxMessages();
DispositionNotification dn = new DispositionNotification(msgs[0].getInputStream();
Or is there some other way this should be done?
The getContent method on such a message should return a MultipartReport object (a special subclass of the usual MimeMultipart object), from which you can access the parts of the report. The MultipartReport.getReport() method will return either a DeliveryStatus or DispositionNotification object, depending on the type of the report.

how can I get more error messages out of solrj SolrException

When I send queries to Solr using solrj, I sometimes get SolrException's thrown. When I dig through the exception, it just says "Bad Request", and gives the HTTP return code (which is 400).
When I take the request URL and put it in my browser, I was able to see a richer error message. The browser displays an error message saying one of the fields names is not valid.
I would like to be able to capture this inside my log file. I was able to capture this by copying all the parameters to an Apache HTTP Client POST request (I'm using POST and not GET because GET made the URL too long) and re-executing the request, but this is inefficient. Is there a way to get error message out of SolrException directly?
Here's what I'm doing:
catch (SolrServerException e) {
if(e.getRootCause() instanceof SolrException) {
SolrException ee = (SolrException) e.getRootCause();
HttpClient client = new HttpClient();
PostMethod method = new PostMethod(SOLR_URL);
// copy params over
Iterator<String> iter = request.getParams().getParameterNamesIterator();
while(iter.hasNext()) {
String p = iter.next();
method.setParameter(p, request.getParams().get(p));
}
int statusCode;
try {
// re execute and display the error message
statusCode = client.executeMethod(method);
logger.error(method.getResponseBodyAsString());
} catch (Exception e1) {
// TODO Auto-generated catch block
}
}
These messages aren't available via SolrJ. You can see them in solr's log file, but there is no way to capture them in your client, since solr only returns the 400 error status with a generic message to the client :(

Resources