Re: [akka-user] [Akka Http 1.0-M4] startHandlingWith / starting server with routes

2015-02-27 Thread Peter Neyens
That works, thank you very much Roland.

Not as nice as the convenience method indeed :-)

Op vrijdag 27 februari 2015 21:33:40 UTC+1 schreef rkuhn:

 Hi Peter,

 the documentation is obviously still lacking, and the Activator template 
 you are citing has not yet been ported to 1.0-M4. But worse than that, 
 bindAndStartHandlingWith has a really stupid bug :-( As a work-around, 
 please use the following instead:

   val server = Http().bind(localhost, 8080)

   
   val future = server.to(Sink.foreach { conn =
 println(sconnection from ${conn.remoteAddress})
 conn.flow.join(route).run()
   }).run()

   

 and then for example:


   future.flatMap(s = {
 println(sbound to ${s.localAddress})
 StdIn.readLine()
 s.unbind()
   }).map(_ = system.shutdown())
   .recover{
 case e: Exception =
   e.printStackTrace()
   system.shutdown()
   }

 (The .run() in the connection handler is missing—we are also obviously 
 lacking a test for the convenience method.)

 Regards,

 Roland

 27 feb 2015 kl. 18:56 skrev Peter Neyens peter@gmail.com 
 javascript::

 Hello,

 I have been playing around with Akka Http the last few days, starting with 
 the excellent Typesafe Activator akka-http-microservice 
 https://github.com/theiterators/akka-http-microservice template.

 When i tried out my application with 
 akka-stream-and-http-experimental-1.0-M4, the easy way to start a http 
 server with routes, stopped working.
   Http().bind(
 interface = config.getString(http.interface),
 port = config.getInt(http.port)
   ).startHandlingWith(routes)

 I tried to look in the source code of Http 
 https://github.com/akka/akka/blob/releasing-akka-stream-and-http-experimental-1.0-M4/akka-http-core/src/main/scala/akka/http/Http.scala,
  
 Route 
 https://github.com/akka/akka/blob/releasing-akka-stream-and-http-experimental-1.0-M4/akka-http/src/main/scala/akka/http/server/Route.scala,
  
 ... milestone 4, but couldn't figure out how to get it working.

 I tried
   Http().bindAndstartHandlingWith(
 handler = Route.handlerFlow(routes),
 interface = config.getString(http.interface),
 port = config.getInt(http.port)
   )
 (also there seems to be a camelCase typo in this method)
 and
   Http().startHandlingWithAsyncHandler(
 handler = Route.asyncHandler(routes),
 interface = config.getString(http.interface),
 port = config.getInt(http.port)
   )

 and with both the server starts up and it logs the requests, but I don't 
 get any results.

 I hope this is not a stupid question, but there could be others who will 
 have the same question.

 Thanks
 Peter

 -- 
  Read the docs: http://akka.io/docs/
  Check the FAQ: 
 http://doc.akka.io/docs/akka/current/additional/faq.html
  Search the archives: https://groups.google.com/group/akka-user
 --- 
 You received this message because you are subscribed to the Google Groups 
 Akka User List group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to akka-user+...@googlegroups.com javascript:.
 To post to this group, send email to akka...@googlegroups.com 
 javascript:.
 Visit this group at http://groups.google.com/group/akka-user.
 For more options, visit https://groups.google.com/d/optout.




 *Dr. Roland Kuhn*
 *Akka Tech Lead*
 Typesafe http://typesafe.com/ – Reactive apps on the JVM.
 twitter: @rolandkuhn
 http://twitter.com/#!/rolandkuhn
  


-- 
  Read the docs: http://akka.io/docs/
  Check the FAQ: 
 http://doc.akka.io/docs/akka/current/additional/faq.html
  Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups Akka 
User List group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


Re: [akka-user] Stop TestActorRefs that fail?

2015-02-27 Thread Sam Halliday
Aah, yes, good spot. Let's also add some type safety:

/**
 * `TestActorRef`s are restarted by default on exceptions, but this
 * just stops them.
 *
 * https://groups.google.com/forum/#!topic/akka-user/0Ene7WaDyng
 */
trait StoppingTestActorRefs {
  this: TestKit =

  private class StoppingSupervisor extends Actor {
def receive = Actor.emptyBehavior
override def supervisorStrategy = SupervisorStrategy.stoppingStrategy
  }
  private val supervisor = system.actorOf(Props[StoppingSupervisor])
  private def randomName = UUID.randomUUID().toString.replace(-,)

  def StoppingTestActorRef[T : Actor : ClassTag](props: Props) =
TestActorRef[T](props, supervisor, randomName)
}


Now it's not even a one liner change in the tests to get the behaviour I 
want :-)


On Friday, 27 February 2015 13:08:05 UTC, rkuhn wrote:

 Hi Sam,

 yes, that should work as intended; you can shave two lines off by using 
 SupervisorStrategy.stoppingStrategy.

 Regards,

 Roland

 27 feb 2015 kl. 11:37 skrev Sam Halliday sam.ha...@gmail.com 
 javascript::

 My hack:

 /**
  * `TestActorRef`s are restarted by default on exceptions, but this
  * just stops them.
  *
  * https://groups.google.com/forum/#!topic/akka-user/0Ene7WaDyng
  */
 class StoppingSupervisor extends Actor {
   def receive = Actor.emptyBehavior
   import SupervisorStrategy._
   override def supervisorStrategy: SupervisorStrategy = 
 OneForOneStrategy()({
 case _: Exception = Stop
   })
 }
 trait StoppingTestActorRefs {
   this: TestKit =

   private val supervisor = system.actorOf(Props[StoppingSupervisor])
   private def randomName = UUID.randomUUID().toString.replace(-,)

   def StoppingTestActorRef(props: Props) =
 TestActorRef.apply(props, supervisor, randomName)

 }


 On Thursday, 26 February 2015 16:24:44 UTC, Sam Halliday wrote:

 Hi,

 I am testing an Actor and mocking out one of its dependencies. When the 
 test fails, e.g. an unexpected call to the mock (which causes an exception) 
 the Actor is restarted and all I end up with is several GB of logging 
 because it gets into an infinite restart loop.

 Is there any *simple* way (e.g. an extra parameter somewhere) that lets 
 me change the supervisor strategy of TestActorRefs to Stop instead of 
 Restart? (I don't really want to have to wrap it in a monitor as that would 
 be a pain).

 Best regards,
 Sam


 -- 
  Read the docs: http://akka.io/docs/
  Check the FAQ: 
 http://doc.akka.io/docs/akka/current/additional/faq.html
  Search the archives: https://groups.google.com/group/akka-user
 --- 
 You received this message because you are subscribed to the Google Groups 
 Akka User List group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to akka-user+...@googlegroups.com javascript:.
 To post to this group, send email to akka...@googlegroups.com 
 javascript:.
 Visit this group at http://groups.google.com/group/akka-user.
 For more options, visit https://groups.google.com/d/optout.




 *Dr. Roland Kuhn*
 *Akka Tech Lead*
 Typesafe http://typesafe.com/ – Reactive apps on the JVM.
 twitter: @rolandkuhn
 http://twitter.com/#!/rolandkuhn
  


-- 
  Read the docs: http://akka.io/docs/
  Check the FAQ: 
 http://doc.akka.io/docs/akka/current/additional/faq.html
  Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups Akka 
User List group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


Re: [akka-user] The mapAsync and the mapAsyncUnordered an unexpected behavior

2015-02-27 Thread Boris Lopukhov
Thanks for response!

I created issue https://github.com/akka/akka/issues/16959

пятница, 27 февраля 2015 г., 13:54:35 UTC+4 пользователь drewhk написал:

 Hi Boris,

 On Fri, Feb 27, 2015 at 10:41 AM, Boris Lopukhov 89b...@gmail.com 
 javascript: wrote:

 I have a simple actor publisher:

 class TestActor extends ActorPublisher[Int] {

   println(RUN)

   def receive = {
 case Request(elements) = while (totalDemand  0  isActive) {
   onNext(1)
 }
 case Cancel = println(CANCEL)
   }
 }

 and i found a strange feature:

   Source[Int](Props[TestActor])
 .map { x = throw new Exception(); x }
 .runForeach { x = }

 printed RUN and CANCEL


 This is itself fine, you get the error in the Future returned by 
 runForeach.
  


   Source[Int](Props[TestActor])
 .mapAsync(Future.successful)
 .map { x = throw new Exception(); x }
 .runForeach { x = }

 printed only RUN 


 This is not fine though.
  


   Source[Int](Props[TestActor])
 .mapAsyncUnordered(Future.successful)
 .map { x = throw new Exception(); x }
 .runForeach { x = }
  
 throwed java.lang.OutOfMemoryError


 This is also not fine. I suspect there is a problem handling already 
 completed Futures. You should file a ticket, this seems like a bug. If you 
 could also try using a not already completed Future that would help.

 -Endre
  


 i use 1.0-M3 version of akka-streams

  -- 
  Read the docs: http://akka.io/docs/
  Check the FAQ: 
 http://doc.akka.io/docs/akka/current/additional/faq.html
  Search the archives: https://groups.google.com/group/akka-user
 --- 
 You received this message because you are subscribed to the Google Groups 
 Akka User List group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to akka-user+...@googlegroups.com javascript:.
 To post to this group, send email to akka...@googlegroups.com 
 javascript:.
 Visit this group at http://groups.google.com/group/akka-user.
 For more options, visit https://groups.google.com/d/optout.




-- 
  Read the docs: http://akka.io/docs/
  Check the FAQ: 
 http://doc.akka.io/docs/akka/current/additional/faq.html
  Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups Akka 
User List group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


[akka-user] ANNOUNCE: Akka Streams HTTP 1.0 MILESTONE 4

2015-02-27 Thread Roland Kuhn
Dear hakkers,

we are pleased to announce the availability of the fourth milestone of Akka 
Streams  HTTP. The biggest directly visible feature of this release is a 
completely new and fluent Java DSL for writing FlowGraphs:

final RunnableFlowFutureListString result = FlowGraph.factory()
.closed(
Sink.ListString head(),
(builder, out) - {
  final UniformFanOutShapeInteger, Integer bcast = 
builder.graph(Broadcast.create(2));
  final UniformFanInShapeInteger, Integer merge = 
builder.graph(Merge.create(2));
 
  
builder.from(in).via(f1).via(bcast).via(f2).via(merge).via(f3.grouped(1000)).to(out);
  builder.from(bcast).via(f4).to(merge);
});

The biggest internal change shines through this sample as well: the type 
returned from the FlowGraph factory describes the result of its 
materialization. In this example we import Sink.head() into the graph as an 
argument to the factory method, which will propagate the materialized value to 
the overall graph—materializing and thereby running this graph will return the 
Future that the head-Sink materializes to. In order to wire this sink up to the 
rest of the graph, its so-called “shape” (called “out” above) is passed into 
the block that constructs the graph.

Another thing to notice is that we explicitly import the Merge and Broadcast 
junctions into the graph, yielding UniformFanInShape and UniformFanOutShape, 
respectively. This demonstrates that our Graph type is no longer “untyped”, 
every graph now has a Shape. A Source[T, M] is just a Graph[SourceShape[T], M], 
which means that it has a shape that has a single output and materializes to a 
value of type M. Please take a look at the freshly rewritten documentation 
http://doc.akka.io/docs/akka-stream-and-http-experimental/1.0-M4 to see this 
all in action.

You might be wondering why we did such a big change to the already quite good 
DSL, in particular one which will break a lot of source code (sorry guys and 
gals, but you knew what you signed up for when using pre-alpha software in your 
projects, right? ;-) ). The reason is a deep and foundational one. The central 
promise and design goal of Akka Streams is “supreme compositionality”, we have 
been calling stream elements “blueprints that can be freely reused”. When 
trying to implement these semantics, we discovered that the approach of using 
the MaterializedMap structure was fundamentally flawed: importing for example a 
Sink twice would lead to incorrect results when trying to obtain both 
materialization results, because the user code has only one Key in its hands. 
The only principled solution to this problem is that materialization results 
must be combined explicitly when multiple are generated from the same graph, 
and this principle applies in a hierarchical fashion. For an example see the 
docs for Java 
http://doc.akka.io/docs/akka-stream-and-http-experimental/1.0-M4/java/stream-flows-and-basics.html#Stream_Materialization
 and Scala 
http://doc.akka.io/docs/akka-stream-and-http-experimental/1.0-M4/scala/stream-flows-and-basics.html#Stream_Materialization,
 here’s an excerpt:

import FlowGraph.Implicits._
val r: RunnableFlow[(Promise[Unit], Cancellable, Future[Int])] =
  FlowGraph.closed(source, flow, sink)((_, _, _)) { implicit builder =
(src, f, dst) = src ~ f ~ dst
  }

The second argument list combines the three values generated by the source, 
flow and sink into a Tuple3 (using Scala’s lambda short-hand notation, the Java 
example would use «(src, f, dst) - new Triplet(src, f, dst)» for a suitably 
defined Triplet class).

In addition to these fundamental things we have also worked on new features:
configurable supervision strategy for stream processing stages (PR 
https://github.com/akka/akka/pull/16772)
add ContentEncoding negotiation https://github.com/akka/akka/issues/16593 
(thanks André / @2beaucoup !)
add Referer https://github.com/akka/akka/issues/16822 header to HTTP model
make ShortNumber https://github.com/akka/akka/issues/16814 path matcher work 
and add minimum number to repeat https://github.com/akka/akka/issues/16833 
modifier
refactor HTTP RejectionHandler https://github.com/akka/akka/issues/16835 to 
make it more predictable
For a list of all closed issues, see the milestone on github 
https://github.com/akka/akka/issues?q=is:issue+milestone:streams-1.0-M4+is:closed.

Happy hakking!


Dr. Roland Kuhn
Akka Tech Lead
Typesafe http://typesafe.com/ – Reactive apps on the JVM.
twitter: @rolandkuhn
 http://twitter.com/#!/rolandkuhn

-- 
  Read the docs: http://akka.io/docs/
  Check the FAQ: 
 http://doc.akka.io/docs/akka/current/additional/faq.html
  Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups Akka 
User List group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.

Re: [akka-user] Re: [akka-http] Routing dsl and streams integration

2015-02-27 Thread Giovanni Alberto Caporaletti
Hi Martynas,

what if I wanted to marshal a source (the head) of a type for which a 
ToResponseMarshaller is available? Do I need to materialize it like this? 

  implicit def streamMarshaller[T](implicit mat: FlowMaterializer, marshaller: 
ToResponseMarshaller[T]): ToResponseMarshaller[Source[T]] = {
Marshaller { s: Source[T] =
  s.mapAsync(marshaller).runWith(Sink.head)
}
  }


Thanks
On Thursday, 26 February 2015 15:00:43 UTC, Martynas Mickevičius wrote:

 Hi Alexey,

 I wonder if you have found a solution. You can complete requests with 
 anything as long as there is a marshaller for that. As you have noticed 
 akka-http is build on top of akka-stream so writing a marshaller for a 
 Source is quite trivial:

 val flow = Flow.empty[(Int, String)].map { case (param, cookie) = sParam: 
 $param and cookie $cookie }  implicit def stringStreamMarshaller(implicit 
 ec: ExecutionContext): ToResponseMarshaller[Source[String]] =
   Marshaller.withFixedCharset(MediaTypes.`text/plain`, HttpCharsets.`UTF-8`) 
 { s =
 HttpResponse(entity = HttpEntity.CloseDelimited(MediaTypes.`text/plain`, 
 s.map(ByteString(_
   }

 val routes = {
   path(test) {
 get {
   complete {
 Source.single(123, crunchy).via(flow)
   }
 }
   }}

 You can find runable example here: 
 https://github.com/2m/akka-stream-sandbox/blob/b5d77fd025a0997d6943886bdf92b2ac6063d107/src/main/scala/HttpFlow.scala


 On Tue, Feb 10, 2015 at 6:48 PM, Alexey Romanchuk alexey.r...@gmail.com 
 javascript: wrote:

 Hi!

 My first implementation was almost the same - one flow instantiation for 
 one request. Right now I have one long living flow and push elements into 
 it and then send them back to akka-http. What I want to achieve is to wire 
 my flow with flow processing inside akka-http

 вторник, 10 февраля 2015 г., 9:39:15 UTC+6 пользователь Steve Myers 
 написал:

 Hi, have you seen the recent akka-http-microservice 
 https://github.com/theiterators/akka-http-microservice example?  It 
 may not be exactly what you want but does a great job showing how to do 
 akka-http routing.

 On Monday, February 9, 2015 at 7:21:52 PM UTC-8, Alexey Romanchuk wrote:

 Hello!

 As I understand from docs akka-http seamless integrates with 
 akka-stream by passing flow to handleWith method. Also we have well known 
 routing dsl from spray with all these nested directives. But I can not 
 figure out how to use them together. 

 I want to have routing dsl together with seamless akka streams 
 integration. Something like this:

 val flow1 = Flow[(Int, String), X] //X can be marshalled

 respondWithHeaders(...) {
 path(...) {
 get {
 parameters(as[Int]?) { param =
  optionalCookie(...) { cookie =
  (param, cookie) - flow1
  }
 }
 }
 } ~
 ...
 }

 Dsl is very useful to extract parameters and matches and flows is very 
 natural way to build responses. This is not concrete API, but an idea how 
 it may looks like. Any thoughts?

 Thanks!

 p.s. If I miss something obvious form docs please point me to it :)

  -- 
  Read the docs: http://akka.io/docs/
  Check the FAQ: 
 http://doc.akka.io/docs/akka/current/additional/faq.html
  Search the archives: https://groups.google.com/group/akka-user
 --- 
 You received this message because you are subscribed to the Google Groups 
 Akka User List group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to akka-user+...@googlegroups.com javascript:.
 To post to this group, send email to akka...@googlegroups.com 
 javascript:.
 Visit this group at http://groups.google.com/group/akka-user.
 For more options, visit https://groups.google.com/d/optout.




 -- 
 Martynas Mickevičius
 Typesafe http://typesafe.com/ – Reactive 
 http://www.reactivemanifesto.org/ Apps on the JVM
  

-- 
  Read the docs: http://akka.io/docs/
  Check the FAQ: 
 http://doc.akka.io/docs/akka/current/additional/faq.html
  Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups Akka 
User List group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


Re: [akka-user] akka-http custom directives

2015-02-27 Thread Roland Kuhn
Thanks for sharing, Giovanni and Tim!

 27 feb 2015 kl. 16:07 skrev Tim Pigden tim.pig...@optrak.com:
 
 I'll contribute a code example of my own then. Not particularly elegant but 
 it might help someone else. 
 In essence I create a directive with the path, then map and filter it to 
 insert the required rejections then map to get rid of my option. 
 
 // My route already knows the user and the role required. It needs to check 
 the user has the right role within the client
 
 def validateRoles(user: User, role: Role)(optClient: Tuple1[Option[Client]]) 
 = {
   (for {
 client - optClient._1
 // returns Int bit map of roles for this (client, user) as option
 roles - 
 authenticationHolder.model.clientUsers.get(ClientUserNames(client.name, 
 user.name))   } yield {
 logger.debug(sclient is $client roles $roles looking for $role)
 (role  roles) != 0
   }).getOrElse(false)
 }
 
 // simply checks the client exists. Note the mucking around with Tuple1 - 
 this seems to be necessary as it's tuples all the way
 val clientOf : (Tuple1[String]) = Option[Client] = { ts = 
 authenticationHolder.model.clients.get(ts._1) }
 
 def clientRole(user: User, role: Role) = path( Segment ) // match a string 
 for client name
   .tmap[Option[Client]](clientOf)  // get the client
   .tfilter(validateRoles(user, role)(_), AuthorizationFailedRejection) // 
 filter out non-existent client or no authorisation
   .tmap[Client](_._1.get) // turns it into the client itself. Couldn't figure 
 out if I could combine filter and map more elegantly
 
 // not pretty but all I've got time for today
 
 On Friday, February 27, 2015 at 9:56:18 AM UTC, Tim Pigden wrote:
 Hi - is there any documentation (even in draft form) about custom directives 
 for akka-http? Or has anyone any code examples?
 Thanks
 Tim
 
 -- 
  Read the docs: http://akka.io/docs/ http://akka.io/docs/
  Check the FAQ: 
  http://doc.akka.io/docs/akka/current/additional/faq.html 
  http://doc.akka.io/docs/akka/current/additional/faq.html
  Search the archives: https://groups.google.com/group/akka-user 
  https://groups.google.com/group/akka-user
 --- 
 You received this message because you are subscribed to the Google Groups 
 Akka User List group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to akka-user+unsubscr...@googlegroups.com 
 mailto:akka-user+unsubscr...@googlegroups.com.
 To post to this group, send email to akka-user@googlegroups.com 
 mailto:akka-user@googlegroups.com.
 Visit this group at http://groups.google.com/group/akka-user 
 http://groups.google.com/group/akka-user.
 For more options, visit https://groups.google.com/d/optout 
 https://groups.google.com/d/optout.



Dr. Roland Kuhn
Akka Tech Lead
Typesafe http://typesafe.com/ – Reactive apps on the JVM.
twitter: @rolandkuhn
 http://twitter.com/#!/rolandkuhn

-- 
  Read the docs: http://akka.io/docs/
  Check the FAQ: 
 http://doc.akka.io/docs/akka/current/additional/faq.html
  Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups Akka 
User List group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


[akka-user] Re: akka system shutdown in sub actor

2015-02-27 Thread George Lu
Ok, thanks Jim.

Can I ask another question, if I shutdown akka in one of the actor 
(getContext().system().shutdown()), what is the behavior?

Thanks!

George

On Friday, 27 February 2015 13:32:51 UTC+8, Jim Hazen wrote:

 Seems logical.

 From an actor within a running system you ask the system if it's dead.  It 
 says no, because it still has actors running (there's at least the one 
 asking the question).

 Then, from outside the system you wait for it to terminate, and then check 
 that it has terminated, which it confirms to be true.


-- 
  Read the docs: http://akka.io/docs/
  Check the FAQ: 
 http://doc.akka.io/docs/akka/current/additional/faq.html
  Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups Akka 
User List group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


[akka-user] Re: akka-http custom directives

2015-02-27 Thread Giovanni Alberto Caporaletti
Hi,
I just started to write one to check basic authentication with an external 
service, because the current implementation forces you to know the 
cleartext password to compare it with the provided one.

This is a basic test I made for the time being.  I was wondering if there 
is a better way of integrating existing flows with the directives, instead 
of sub-materializing them as I did in this example.


class AuthenticationDirectives(userService: UserService) {

  val failure = AuthenticationResult.failWithChallenge(HttpChallenge(scheme = 
Basic, realm = test))

  def authenticated: AuthenticationDirective[User] =
extractFlowMaterializer.flatMap { implicit mat =
  authenticateOrRejectWithChallenge[BasicHttpCredentials, User] {

case Some(BasicHttpCredentials(username, password)) =
  userService.authenticate(username, password)
.map {
  case None = failure
  case Some(user) = AuthenticationResult.success(user)
}
.runWith(Sink.head)

case None = Future.successful(failure)

  }
}

}


On Friday, 27 February 2015 09:56:18 UTC, Tim Pigden wrote:

 Hi - is there any documentation (even in draft form) about custom 
 directives for akka-http? Or has anyone any code examples?
 Thanks
 Tim


-- 
  Read the docs: http://akka.io/docs/
  Check the FAQ: 
 http://doc.akka.io/docs/akka/current/additional/faq.html
  Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups Akka 
User List group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


Re: [akka-user] The mapAsync and the mapAsyncUnordered an unexpected behavior

2015-02-27 Thread Endre Varga
Hi Boris,

On Fri, Feb 27, 2015 at 10:41 AM, Boris Lopukhov 89bo...@gmail.com wrote:

 I have a simple actor publisher:

 class TestActor extends ActorPublisher[Int] {

   println(RUN)

   def receive = {
 case Request(elements) = while (totalDemand  0  isActive) {
   onNext(1)
 }
 case Cancel = println(CANCEL)
   }
 }

 and i found a strange feature:

   Source[Int](Props[TestActor])
 .map { x = throw new Exception(); x }
 .runForeach { x = }

 printed RUN and CANCEL


This is itself fine, you get the error in the Future returned by runForeach.



   Source[Int](Props[TestActor])
 .mapAsync(Future.successful)
 .map { x = throw new Exception(); x }
 .runForeach { x = }

 printed only RUN


This is not fine though.



   Source[Int](Props[TestActor])
 .mapAsyncUnordered(Future.successful)
 .map { x = throw new Exception(); x }
 .runForeach { x = }

 throwed java.lang.OutOfMemoryError


This is also not fine. I suspect there is a problem handling already
completed Futures. You should file a ticket, this seems like a bug. If you
could also try using a not already completed Future that would help.

-Endre



 i use 1.0-M3 version of akka-streams

  --
  Read the docs: http://akka.io/docs/
  Check the FAQ:
 http://doc.akka.io/docs/akka/current/additional/faq.html
  Search the archives: https://groups.google.com/group/akka-user
 ---
 You received this message because you are subscribed to the Google Groups
 Akka User List group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to akka-user+unsubscr...@googlegroups.com.
 To post to this group, send email to akka-user@googlegroups.com.
 Visit this group at http://groups.google.com/group/akka-user.
 For more options, visit https://groups.google.com/d/optout.


-- 
  Read the docs: http://akka.io/docs/
  Check the FAQ: 
 http://doc.akka.io/docs/akka/current/additional/faq.html
  Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups Akka 
User List group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


[akka-user] akka-http custom directives

2015-02-27 Thread Tim Pigden
Hi - is there any documentation (even in draft form) about custom 
directives for akka-http? Or has anyone any code examples?
Thanks
Tim

-- 
  Read the docs: http://akka.io/docs/
  Check the FAQ: 
 http://doc.akka.io/docs/akka/current/additional/faq.html
  Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups Akka 
User List group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.