Giter VIP home page Giter VIP logo

Comments (18)

brikis98 avatar brikis98 commented on June 12, 2024

See sample-app-java for a sample app written in Java.

from ping-play.

shay-te avatar shay-te commented on June 12, 2024

hey, thanks.
i was referring to the common files here
https://github.com/brikis98/ping-play/tree/master/sample-app-common/src/main/scala/data

from ping-play.

brikis98 avatar brikis98 commented on June 12, 2024

Ah, that code is intentionally in a single place to try to reduce duplication. I'm not sure I'd want to convert it to Java and have to maintain both separately...

from ping-play.

shay-te avatar shay-te commented on June 12, 2024

hmmm.... i understand :-)
it will be more easy for me, as one that don't know scala.
i have a bit of difficulties converting to java.

from ping-play.

brikis98 avatar brikis98 commented on June 12, 2024

What specifically are you struggling with?

from ping-play.

shay-te avatar shay-te commented on June 12, 2024

FutureUtil has lots of errors when i am trying to convert it, like he can't recognize Feature, even when he is ok with the import import scala.concurrent.Future;. i can't get the timeout method signature right... after trying to convert to java, the first and last methods results the same signature.

i don't know how to convert "Response" to java. since i am not a scala developer.
i can guess case class Response(id: String, delay: Long)
means

public class Response {

    private String m_id;
    private Long m_delay;

    public Response(String id, Long delay) {
        m_id    = id;
        m_delay = delay;
    }
}

as for

object Response {
  implicit val responseWrites = Json.writes[Response]
} 

i have no idea, :) well ill have to learn scala for that

from ping-play.

brikis98 avatar brikis98 commented on June 12, 2024

First, just to confirm, are you converting all of this stuff as a learning project? Because if you're using ping-play for a real-world use case, you don't need any of the code from the sample apps; you would swap them out with libraries that do real work, such as calling an actual remote service instead of using FutureUtil, which just returns fixed data.

That said, there are a quite a few issues with your conversion.

First, Future should typically only be used with Scala code. For Java code, you should be using Promise. The Java sample app I linked earlier does exactly that.

Second, a case class is just (wonderful) syntactic sugar for a standard Java POJO, with auto generated getters, setters, equals, hashCode, and lots of other goodies. The rough equivalent of the Response class would be something like (with most of the goodies omitted, since you probably don't need them for a simple example):

public class Response {
  public final String id;
  public final long delay;

  public Response(String id, long delay) {
    this.id = id;
    this.delay = delay;
  }

Finally, the Json.writes bit is the way Play does JSON serialization for Scala apps. For Java apps, it's done differently: https://playframework.com/documentation/2.4.x/JavaJsonActions

from ping-play.

shay-te avatar shay-te commented on June 12, 2024

thank for the answers, and the time, i want it for a real project.
so i guess for a real project i just have to
replace this
,,,
F.Promise profilePromise = serviceClient.fakeRemoteCallMedium("profile")
,,,
With calling some other entry in the controller, and get the result as a promise object.

from ping-play.

brikis98 avatar brikis98 commented on June 12, 2024

Yes. For example, you could use Play's Web Services Client:

F.Promise<WSResponse> examplePromise = WS.url("http://www.example.com").get()

from ping-play.

shay-te avatar shay-te commented on June 12, 2024

thanks for the response. i am trying to convert some other entry to piglet, can you help me please
i am trying something much simples

promiseFoo.map(views.html.foo) what should i transfer to the map
also
return ok(HtmlStreamHelper.toChunks(views.stream.application.apply(bigPipe, profile)));
views.stream.application.apply? when trying to convert from withBigPipe example

public class Application extends Controller {

    public Result foo() {
        return ok("Got request " + request() + "!");
    }

    public Result index() {

        Promise<Result> promiseFoo = Promise.promise(new F.Function0<Result>() {
            @Override
            public Result apply() throws Throwable {
                return foo();
            }
        });

        Pagelet profile = new HtmlPagelet("profile", promiseFoo.map(views.html.foo));

        BigPipe bigPipe = new BigPipe(PageletRenderOptions.ClientSide, profile);
        return ok(HtmlStreamHelper.toChunks(views.stream.application.apply(bigPipe, profile)));
    }

}

from ping-play.

brikis98 avatar brikis98 commented on June 12, 2024

And what happens when you do that?

from ping-play.

shay-te avatar shay-te commented on June 12, 2024

(inside eclipse)
views.html.foo cannot be resolved
also
views.stream cannot be resolved

i think i am missing something :)

from ping-play.

brikis98 avatar brikis98 commented on June 12, 2024

In your example, you used views.stream.application. This is referencing a file application.scala.stream. Do you have such a file?

If you're using views.html.foo, then you would need an application.scala.html.

from ping-play.

shay-te avatar shay-te commented on June 12, 2024

in my example i was trying to stick to the WithBigPipe example as possible
so i 'kind of' trying to replace the template and the controller names with mine, which docent make sense.
i don't have application.scala.stream, i called it same as in the example. just replaces withBigPipe with application

this is what i am asking, how to do this right, i will say that ill trying to stick with java as much as possible

thank you for you patient !!

from ping-play.

brikis98 avatar brikis98 commented on June 12, 2024

It seems that the things you're struggling with are not ping-play specific, but basic Play problems. Out of curiosity, have you used Play before? Do you understand how templates get compiled into classes? BigPipe streaming is a somewhat advanced topic, so if you're new to Play, it's probably not the best way to get started.

from ping-play.

shay-te avatar shay-te commented on June 12, 2024

i have been using play 1.2, and its my more strong side .
and i do understand big pipe as a web optimization.
i am not sure big-pipe advantage is only by taking pagelets from other sites. (using web service)
the main use of it is to compile parts of same site.
those entry should also be available to ajax calls, and not be restricted only to "pagelet" loading.
i guess i don't understand something here. or most of the code is scala. so its hard for me to learn from it. any way. if i am a hard nut. it's ok, ill stragle with it till ill get it :)

from ping-play.

brikis98 avatar brikis98 commented on June 12, 2024

Play 2 is very different than Play 1. It was a complete rewrite from the ground up. Before diving into ping-play, please spend some time going through the Play 2 documentation (especially Play 2 for Java Developers) until you get a feel for how the built-in controllers, libraries, and templating mechanism work. Pay special attention to how templates are compiled. You can also find examples in Typesafe Activator.

Once you get a feel for that, come back to this project, and I suspect you'll know how to solve the issues you're seeing now.

from ping-play.

shay-te avatar shay-te commented on June 12, 2024

thanks

from ping-play.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.