EzDevInfo.com

finatra

Fast, testable, Scala services built on Twitter-Server and Finagle Home - Finatra

Finatra - unable to update cookie

I am trying to update a cookie in finatra like this:

import com.twitter.finatra.Request
import com.twitter.finagle.Cookie

def updateCookie(req:Request, cookieName:String, newVal:String) = {
  // I tried also: 
  // req.response.removeCookie(cookieName)
  // req.response.addCookie(new Cookie(cookieName, newVal))
  req.response.cookies.update(cookieName, new Cookie(cookieName, newVal))
}

but it is not working. The cookie value I obtain in the following request is always the old one. Does anyone have an idea of what I am doing wrong?


Source: (StackOverflow)

How to remove cookies on Finatra?

How do I remove a cookie after processing the request and building the response?

I have tried the following code, but it does not seem to work:

get("/login") { request =>
  val message = request.cookies.get("flash-message").map(_.value)
  request.removeCookie("flash-message")
  render.view(LoginView(message)).toFuture
}

I could not find any methods on ResponseBuilder that would remove a cookie, either.


Source: (StackOverflow)

Advertisements

Disable http in finatra app

I am deploying a Finatra app to Heroku. Thanks to Twitter guys together with Heroku this is a very easy task. The thing is that Heorku gives you https out of the box (if im trying to reach my service through https it just works). Nevertheless it also works with http requests. Is there any way to disable http requests and leave only https?

Thanks


Source: (StackOverflow)

finatra - getting the response data

I'm trying to extract the response data\context. I have a server which listens to incoming get requests and I'm sending back a plain text. the server is running and when I sending get request from my browser I see good results, but I want to create tests for my server. the test is creating an HttpRequest and the promise gives me back the HttpResponse when I'm trying to compare my expected result to the response all i get is:

HTTP/1.1 200 OK

Content-Type: text/plain

Content-Length: 11

Thanks, Dana


Source: (StackOverflow)

Finatra - reading a request in chunks

Here's my use case: I am implementing a finatra server, that should be able to receive many concurrent large requests. These requests have a large body (several megabytes) comprised of many small json objects, concatenated.

I'd like to avoid loading the entire request body into memory. I'm looking for a way to read the request body in chunks, and use a json parser that supports this sort of async parsing.

In node.js this can be achieved by using the jsonp package (see the example - https://github.com/jaredhanson/node-jsonsp/blob/master/examples/twitter-stream/app.js).

Can I do something similar with finatra (and how)?

PS - I also posted the question here, but got no answer so far.


Source: (StackOverflow)

Problems with finatra and mustache lambdas

I am experiencing some problems in using mustache lambdas within my finatra project. I would like to create my own translation function so I created something like this

import com.github.mustachejava.TemplateFunction

class TranslateFunction extends TemplateFuction {
  override def apply(input:String):String = {
   println("Translate " + input)
   return input
  }
}

but I cannot build it, sbt complains

[error] not found: type TemplateFuction
[error]   class TranslateFunction extends TemplateFuction {
[error]                                   ^

I am using finatra version 1.5.3 plus scala 2.10.3, does anyone has a project that works fine with finatra and mustache lambdas?


Source: (StackOverflow)

Scala & Finatra: send file server response directly from disk to network w/o loading into memory

I was tasked at work to send our clients a file via finatra, directly from disk without loading into memory(these are very large files). Here are my questions:

0) How do I interact with the disk i/o without ever loading the information into memory?

1) When connecting a file inputstream to an http outputstream, does that actually load memory into ram?

2) I thought everything has to be loaded into memory to work with, transport, and send. How can one actually send contents directly to a network port w/o being loaded into memory?

3) Would the flow of memory be from the disk, to the cpu registers, onto network adapters buffer for it to be sent? How do I ensure that this is the flow without loading ram?

4) Is it possible to do this in Finatra


Source: (StackOverflow)

Scala/Java HTTP parse POST data form-encoded arrays

I use Finatra. If I send POST data of the kind application/x-www-form-urlencoded; charset=UTF-8 where the data is of the kind

options[0][name]:option1
options[0][value]:1
options[1][name]:option2
options[1][value]:2

what is a good way to get a List of (name, value) on the server?


Source: (StackOverflow)

Finatra - how to add url encoder

I have a finatra server, in the response string there are currency symbols. which looks fine in the server but in the browser I get £5.25 instead of £5.25

any advice on how to fix this issue? recommended url encoder?

thanks, Dana


Source: (StackOverflow)