Re: [akka-user] Re: Akka Http how to add charset utf-8 to the content-type header

2017-05-06 Thread Thibault Meyer
Hi Greg,


how to do this ? I see no arguments in completeOKWithFuture 
or Jackson.marshaller() to do this. I'm using Java version of akka-http.

Thanks

Le samedi 6 mai 2017 00:49:14 UTC+2, Greg Methvin a écrit :
>
> There is no charset parameter defined for application/json. See 
> https://www.iana.org/assignments/media-types/application/json
>
> The encoding should not be determined by looking at the charset parameter, 
> but rather by looking at the first four octets: 
> https://tools.ietf.org/html/rfc4627#section-3
>
> If you absolutely have to deal with non-conforming parsers, the custom 
> media type is probably the right way to go.
>
> On Fri, May 5, 2017 at 2:23 PM, Alan Burlison  > wrote:
>
>> On 05/05/17 18:42, Alex Cozzi wrote:
>>
>> funny, I was looking into this yesterday!
>>> I am by no means an expert, but I think that what it is happening is the
>>> following:
>>> application/json implies UTF-8: if you look at the MediaType class from
>>> akka http you se the declaration:
>>>
>>
>> I believe you are correct, http://www.ietf.org/rfc/rfc4627.txt says:
>>
>> 3.  Encoding
>> JSON text SHALL be encoded in Unicode.  The default encoding is UTF-8.
>>
>> so an explicit MIME type isn't required if the content is UTF-8 - but 
>> other JSON frameworks do often seem to include the UTF-8 charset.
>>
>> As far as I know there's no "proper" way of forcing the addition of the 
>> charset to the application/json content type in Akka-HTTP but it is 
>> possible to hack around it:
>>
>> val ct = ContentType(MediaType.custom("application/json", 
>> false).asInstanceOf[MediaType.WithOpenCharset], HttpCharset.custom("utf-8"))
>>
>> -- 
>> Alan Burlison
>> --
>>
>>
>> -- 
>>
>>>  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 .
>> To post to this group, send email to akka...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/akka-user.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> *Greg Methvin*
> *Tech Lead - Play Framework*
> Lightbend, Inc. 
>
>

-- 
>>  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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


[akka-user] Akka Http how to add charset utf-8 to the content-type header

2017-05-05 Thread Thibault Meyer
Hello,

I dont find how to set the content type to "*application/json; 
charset=UTF-8*" with the *completeOKWithFuture* and Jackson marshaller. 
Currently, Akka Http return the Content-Type "application/json" without 
specifying the charset. So in some browsers (like Opera or Chrome) the 
output text is not good.


get(() -> {
  final MessageDispatcher dispatcher = akkaSystem.dispatchers().lookup(
"application.dispatcher");
  return completeOKWithFuture(CompletableFuture.supplyAsync(() -> {
final Map result = new HashMap<>();
result.put("trackingNumber", trackingNumber);
ArrayList> status;
if (this.cache == null) {
  status = TrackingCrawler.parseDocument(trackingNumber);
} else {
  status = this.cache.readFromCache("tracking." + trackingNumber);
  if (status == null) {
status = TrackingCrawler.parseDocument(trackingNumber);
this.cache.writeToCache(
  "tracking." + trackingNumber,
  status
);
  }
}
result.put("status", status);
return result;
  }, dispatcher).exceptionally(ex -> {
LOG.error("Something goes wrong", ex);
return new HashMap<>();
  }), Jackson.marshaller());
})



Sincerly.

-- 
>>  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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


[akka-user] Blocking operation and dispatcher thread

2017-04-30 Thread Thibault Meyer
Hello,


what is the best way to proceed with blocking operation ?


1. Rise up the number of thread of the default-dispatcher  or change it to 
fixed size thread pool?

or

2. don't touch default values for default-dispatcher and use another 
dispatcher (eg : my-blocking-dispatcher) with a fixed size thread pool?



What is the criteria to determine if this is a blocking operation or not ? 
By example, is this code blocking or not ?


path(PathMatchers.segment("uuid-v4")
.slash(PathMatchers.integerSegment()), count ->
get(() -> {
final Source source = Source
.fromIterator(
() ->
Stream.generate(() ->
UUID.randomUUID().toString() + "\n"
).iterator()
)
.map(ByteString::fromString)
.take(count < 10 ? count : 10);
return complete(HttpResponse.create()
.withEntity(
HttpEntities.createChunked(ContentTypes.
TEXT_PLAIN_UTF8, source)
)
);
})
),



Thanks

-- 
>>  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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


Re: [akka-user] Re: Akka HTTP - Can't return completeWithFuture

2017-04-30 Thread Thibault Meyer
Thanks for response

Le samedi 29 avril 2017 23:32:52 UTC+2, Michal Borowiecki a écrit :
>
> Hi Thibault,
>
> Looks like the docs are out of date.
>
> If you read the compilation error message carefully, you'll notice 
> Jackson.marshaller is giving you a Marshaller<java.lang.Integer,akka.http.
> javadsl.model.*Request**Entity*>
> while completeWithFuture is expecting a akka.http.javadsl.marshalling.
> Marshaller<T,akka.http.javadsl.model.*HttpResponse*>) 
>
> Instead you, try complet*OK*WithFuture which takes a Marshaller<T,akka.
> http.javadsl.model.*Request**Entity*>
>
> It's tough to spot the difference and RouteDirectives comes with a lot of 
> overrides. 
> I only knew what to look for because this hit me when calling 
> complete[OK]WithSource on FramedEntityStreamingDirectives which 
> fortunately only has 2 completeXxx methods
>
> Hope that helps,
> Michał
>
> On 29/04/17 21:56, Thibault Meyer wrote:
>
> According to 
> http://doc.akka.io/docs/akka-http/10.0.5/java/http/common/json-support.html 
>  we have to use  
>
> akka.http.javadsl.marshallers.jackson.Jackson.marshaller(T.class)
>
>
> But this method does not exists anymore.
>
> akka.http.javadsl.marshallers.jackson.Jackson.marshaller()
> akka.http.javadsl.marshallers.jackson.Jackson.marshaller(ObjectMapper o)
>
>
>
>
>
> Le samedi 29 avril 2017 20:52:12 UTC+2, Thibault Meyer a écrit : 
>>
>> Hello, 
>>
>> I have a blocking operation that I would like to run on the custom 
>> dispatcher. But I can't return completeWithFuture.
>>
>> I'm using the latest version of Akka Http on Java 8.
>>
>>
>> public Route createRoute() {
>> return route(
>> path(PathMatchers.segment("shipment")
>> .slash(PathMatchers.segment()), trackingNumber ->
>> get(() -> {
>> final MessageDispatcher dispatcher = akkaSystem.
>> dispatchers().lookup("application.dispatcher");
>> final CompletionStage c = CompletableFuture
>> .supplyAsync(() -> 666, dispatcher);
>> return completeWithFuture(c, Jackson.
>> marshaller());
>> }))
>> )
>> );
>> }
>>
>>
>>
>>
>> I get the following compilation error :
>>
>>
>> method akka.http.javadsl.server.directives.RouteDirectives.
>> completeWithFuture(scala.concurrent.Future,akka.http.javadsl.
>> marshalling.Marshaller<T,akka.http.javadsl.model.HttpResponse>) is not 
>> applicable
>>   (cannot infer type-variable(s) T
>> (argument mismatch; java.util.concurrent.CompletionStage> lang.Integer> cannot be converted to scala.concurrent.Future))
>> method akka.http.javadsl.server.directives.RouteDirectives.
>> completeWithFuture(java.util.concurrent.CompletionStage,akka.http.
>> javadsl.marshalling.Marshaller<T,akka.http.javadsl.model.HttpResponse>) 
>> is not applicable
>>   (cannot infer type-variable(s) T
>> (argument mismatch; akka.http.javadsl.marshalling.Marshaller> .lang.Integer,akka.http.javadsl.model.RequestEntity> cannot be converted 
>> to akka.http.javadsl.marshalling.Marshaller<T,akka.http.javadsl.model.
>> HttpResponse>))
>>
>>
>>
>> Thanks
>>
> -- 
> >>>>>>>>>> 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 .
> To post to this group, send email to akka...@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>
>
> -- 
> <http://www.openbet.com/> Michal Borowiecki 
> Senior Software Engineer L4 
> T: +44 208 742 1600 
>
>
> +44 203 249 8448 
>
>
>   
> E: michal.b...@openbet.com  
> W: www.openbet.com 
> OpenBet Ltd 
>
> Chiswick Park Building 9 
>
> 566 Chiswick High Rd 
>
> London 
>
> W4 5XT 
>
> UK 
> <https://www.openbet.com/email_promo> 
> This message is confidential and intended only for the addressee. If you 
> have received this message in error, 

[akka-user] Re: Akka HTTP - Can't return completeWithFuture

2017-04-29 Thread Thibault Meyer
According 
to http://doc.akka.io/docs/akka-http/10.0.5/java/http/common/json-support.html 
 we have to use 

akka.http.javadsl.marshallers.jackson.Jackson.marshaller(T.class)


But this method does not exists anymore.

akka.http.javadsl.marshallers.jackson.Jackson.marshaller()
akka.http.javadsl.marshallers.jackson.Jackson.marshaller(ObjectMapper o)





Le samedi 29 avril 2017 20:52:12 UTC+2, Thibault Meyer a écrit :
>
> Hello,
>
> I have a blocking operation that I would like to run on the custom 
> dispatcher. But I can't return completeWithFuture.
>
> I'm using the latest version of Akka Http on Java 8.
>
>
> public Route createRoute() {
> return route(
> path(PathMatchers.segment("shipment")
> .slash(PathMatchers.segment()), trackingNumber ->
> get(() -> {
> final MessageDispatcher dispatcher = akkaSystem.
> dispatchers().lookup("application.dispatcher");
> final CompletionStage c = CompletableFuture.<
> Integer>supplyAsync(() -> 666, dispatcher);
> return completeWithFuture(c, Jackson.
> marshaller());
> }))
> )
> );
> }
>
>
>
>
> I get the following compilation error :
>
>
> method akka.http.javadsl.server.directives.RouteDirectives.
> completeWithFuture(scala.concurrent.Future,akka.http.javadsl.
> marshalling.Marshaller<T,akka.http.javadsl.model.HttpResponse>) is not 
> applicable
>   (cannot infer type-variable(s) T
> (argument mismatch; java.util.concurrent.CompletionStage .Integer> cannot be converted to scala.concurrent.Future))
> method akka.http.javadsl.server.directives.RouteDirectives.
> completeWithFuture(java.util.concurrent.CompletionStage,akka.http.
> javadsl.marshalling.Marshaller<T,akka.http.javadsl.model.HttpResponse>) is 
> not applicable
>   (cannot infer type-variable(s) T
> (argument mismatch; akka.http.javadsl.marshalling.Marshaller lang.Integer,akka.http.javadsl.model.RequestEntity> cannot be converted 
> to akka.http.javadsl.marshalling.Marshaller<T,akka.http.javadsl.model.
> HttpResponse>))
>
>
>
> Thanks
>

-- 
>>>>>>>>>>  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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


[akka-user] Akka HTTP - Can't return completeWithFuture

2017-04-29 Thread Thibault Meyer
Hello,

I have a blocking operation that I would like to run on the custom 
dispatcher. But I can't return completeWithFuture.

I'm using the latest version of Akka Http on Java 8.


public Route createRoute() {
return route(
path(PathMatchers.segment("shipment")
.slash(PathMatchers.segment()), trackingNumber ->
get(() -> {
final MessageDispatcher dispatcher = akkaSystem.
dispatchers().lookup("application.dispatcher");
final CompletionStage c = CompletableFuture.<
Integer>supplyAsync(() -> 666, dispatcher);
return completeWithFuture(c, Jackson.marshaller
());
}))
)
);
}




I get the following compilation error :


method akka.http.javadsl.server.directives.RouteDirectives.
completeWithFuture(scala.concurrent.Future,akka.http.javadsl.marshalling.
Marshaller) is not applicable
  (cannot infer type-variable(s) T
(argument mismatch; java.util.concurrent.CompletionStage cannot be converted to scala.concurrent.Future))
method akka.http.javadsl.server.directives.RouteDirectives.
completeWithFuture(java.util.concurrent.CompletionStage,akka.http.javadsl
.marshalling.Marshaller) is not 
applicable
  (cannot infer type-variable(s) T
(argument mismatch; akka.http.javadsl.marshalling.Marshaller cannot be converted to 
akka.http.javadsl.marshalling.Marshaller))



Thanks

-- 
>>  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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


[akka-user] Re: Chunked response with akka-http 10.x

2017-04-20 Thread Thibault Meyer
Thanks for your responses. It working very well !

Le jeudi 20 avril 2017 12:02:53 UTC+2, Johannes Rudolph a écrit :
>
> Hi Thibault,
>
> if you have the body of the response already as a Source<ByteString, ?>, 
> you can create a response with a chunked entity from it like this:
>
> HttpResponse.create()
>   .withEntity(HttpEntities.create(contentType, source))
>
> Johannes
>
> On Thursday, April 20, 2017 at 9:56:47 AM UTC+2, Thibault Meyer wrote:
>>
>> Hi,
>>
>> I trying akka-http (version 10.x) by creating a small API who generate 
>> UUID on demand. For a bulk UUID creation (ex: */uuid1/5000* to get 5000 
>> UUID v1), I would like to return a chunked response to avoir building a 
>> list of  item on memory.
>>
>> From Play 2.5 I usually using final Source<ByteString, ?> source = 
>> Source.fromGraph(...) but I don't find how to do this with akka-http and 
>> akka-stream.
>>
>> Do you have any idea how to do this ?
>>
>

-- 
>>>>>>>>>>  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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


[akka-user] Re: Chunked response with akka-http 10.x

2017-04-20 Thread Thibault Meyer
Hi,


thanks for your response. It working very well !



Le jeudi 20 avril 2017 12:02:53 UTC+2, Johannes Rudolph a écrit :
>
> Hi Thibault,
>
> if you have the body of the response already as a Source<ByteString, ?>, 
> you can create a response with a chunked entity from it like this:
>
> HttpResponse.create()
>   .withEntity(HttpEntities.create(contentType, source))
>
> Johannes
>
> On Thursday, April 20, 2017 at 9:56:47 AM UTC+2, Thibault Meyer wrote:
>>
>> Hi,
>>
>> I trying akka-http (version 10.x) by creating a small API who generate 
>> UUID on demand. For a bulk UUID creation (ex: */uuid1/5000* to get 5000 
>> UUID v1), I would like to return a chunked response to avoir building a 
>> list of  item on memory.
>>
>> From Play 2.5 I usually using final Source<ByteString, ?> source = 
>> Source.fromGraph(...) but I don't find how to do this with akka-http and 
>> akka-stream.
>>
>> Do you have any idea how to do this ?
>>
>

-- 
>>>>>>>>>>  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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


[akka-user] Chunked response with akka-http 10.x

2017-04-20 Thread Thibault Meyer
Hi,

I trying akka-http (version 10.x) by creating a small API who generate UUID 
on demand. For a bulk UUID creation (ex: */uuid1/5000* to get 5000 UUID 
v1), I would like to return a chunked response to avoir building a list of 
 item on memory.

>From Play 2.5 I usually using final Source source = 
Source.fromGraph(...) but I don't find how to do this with akka-http and 
akka-stream.

Do you have any idea how to do this ?

-- 
>>  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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


[akka-user] Can't configure min thread number

2017-04-02 Thread Thibault Meyer
Hi, 

I'm using Akka 2.4.17 and I try to configure the "default-dispatcher" to 
have at least 50 thread (arbitrary). But Java Mission Control only show 6 
or 8. 

How I can pre-allocate a pool of 50 ready to go threads ?

Thanks


*MainEntry.java*

/**
 * Entry point.
 *
 * @param args The program arguments
 * @since 17.04.02
 */
public static void main(final String[] args) {
final Injector injector = Guice.createInjector(new ApplicationModules());
final ActorSystem akkaSystem = ActorSystem.create(
"akka-system",
injector.getInstance(Config.class)
);

final Camel camel = CamelExtension.get(akkaSystem);
final SimpleRegistry simpleRegistry = new SimpleRegistry();
camel.context().setRegistry(simpleRegistry);
camel.context().addComponent(
"rabbitmq",
new RabbitMQComponent(camel.context())
);
camel.activationFutureFor(
akkaSystem.actorOf(Props.create(TransformActorConsumer.class)),
new Timeout(Duration.create(5, TimeUnit.SECONDS)),
akkaSystem.dispatcher()
);

LOG.debug("Hello World!");
}




*application.conf*

akka {

  # Tell to Akka to use Slf4J rather than built-in logger.
  # http://doc.akka.io/docs/akka/2.4/java/logging.html
  loggers = ["akka.event.slf4j.Slf4jLogger"]
  loglevel = "DEBUG"
  logging-filter = "akka.event.slf4j.Slf4jLoggingFilter"

  actor {
default-dispatcher {
  # Dispatcher is the name of the event-based dispatcher
  type = Dispatcher

  # What kind of ExecutionService to use
  executor = "fork-join-executor"

  # Configuration for the fork join pool
  fork-join-executor {
# Min number of threads to cap factor-based parallelism number to
parallelism-min = 50
# Parallelism (threads) ... ceil(available processors * factor)
parallelism-factor = 1.0
# Max number of threads to cap factor-based parallelism number to
parallelism-max = 125
  }

  # Throughput defines the maximum number of messages to be
  # processed per actor before the thread jumps to the next actor.
  # Set to 1 for as fair as possible.
  throughput = 1
}
  }
}




sdf

-- 
>>  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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.