Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to get the simulator (2.1.1) responding to a GET request from browser #174

Open
hmmlopez opened this issue Sep 22, 2023 · 2 comments
Labels
Prio: Medium State: To discuss In case there are open questions concerning the issue Type: Question

Comments

@hmmlopez
Copy link

Hello, I'm trying to figure out how to setup a REST Scenario with the Simulator (in kotlin and gradle).
I've created two Scenarios:

@Scenario("Default")
@RequestMapping(path = ["/services/rest/test"], method = [RequestMethod.GET])
class DefaultScenario : AbstractSimulatorScenario() {

    override fun run(runner: ScenarioDesigner) {
        runner.receive().message(HttpMessage())
        runner.echo("Default scenario executed!")
        runner.send().message(HttpMessage("Welcome to the Citrus simulator").status(HttpStatus.OK))
    }
}

and

@Scenario("Test")
@RequestMapping(value = ["/services/rest/simulator/test"], method = [RequestMethod.GET])
class TestScenario: AbstractSimulatorScenario() {

    override fun run(designer: ScenarioDesigner) {
        designer.receive()
        designer.echo("Received get request")
        designer.send().payload("Welcome").message(HttpMessage().status(HttpStatus.OK))
    }
}

My main class is starting up and printing those two scenario out (so they are being loaded as bean to spring boot context):

@SpringBootApplication
class Simulator: SimulatorRestAdapter() {

}

fun main() {
    val context = runApplication<Simulator>()
    val scenarios = context.getBeansOfType(SimulatorScenario::class.java)
    scenarios.forEach { println("Scenario key: ${it.key}, value: ${it.value}") }
}

In my application.properties I have the following:

citrus.simulator.rest.enabled=true
citrus.simulator.defaultScenario=Default

When I start the application and try to invoke one of those endpoints from the browser I don't get any response.
Here is my logging:

C I T R U S  S I M U L A T O R  2.1.1
2023-09-22T21:42:23.622+02:00  INFO 106034 --- [           main] n.hlopez.example.simulator.SimulatorKt   : Starting SimulatorKt using Java 20.0.2 with PID 106034 (/home/hmmlopez/projects/citrus-framework/citrus-simulator-example/build/classes/kotlin/main started by hmmlopez in /home/hmmlopez/projects/citrus-framework/citrus-simulator-example)
2023-09-22T21:42:23.626+02:00  INFO 106034 --- [           main] n.hlopez.example.simulator.SimulatorKt   : No active profile set, falling back to 1 default profile: "default"
2023-09-22T21:42:24.582+02:00  INFO 106034 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2023-09-22T21:42:24.591+02:00  INFO 106034 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 4 ms. Found 0 JPA repository interfaces.
2023-09-22T21:42:24.628+02:00  INFO 106034 --- [           main] faultConfiguringBeanFactoryPostProcessor : No bean named 'errorChannel' has been explicitly defined. Therefore, a default PublishSubscribeChannel will be created.
2023-09-22T21:42:24.634+02:00  INFO 106034 --- [           main] faultConfiguringBeanFactoryPostProcessor : No bean named 'integrationHeaderChannelRegistry' has been explicitly defined. Therefore, a default DefaultHeaderChannelRegistry will be created.
2023-09-22T21:42:25.027+02:00  INFO 106034 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2023-09-22T21:42:25.033+02:00  INFO 106034 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2023-09-22T21:42:25.033+02:00  INFO 106034 --- [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.12]
2023-09-22T21:42:25.083+02:00  INFO 106034 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2023-09-22T21:42:25.083+02:00  INFO 106034 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1165 ms
2023-09-22T21:42:25.262+02:00  INFO 106034 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2023-09-22T21:42:25.381+02:00  INFO 106034 --- [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Added connection conn0: url=jdbc:h2:mem:5155a433-64f2-45fb-953c-d8bd6123173b user=SA
2023-09-22T21:42:25.382+02:00  INFO 106034 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2023-09-22T21:42:25.412+02:00  INFO 106034 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2023-09-22T21:42:25.444+02:00  INFO 106034 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 6.2.7.Final
2023-09-22T21:42:25.445+02:00  INFO 106034 --- [           main] org.hibernate.cfg.Environment            : HHH000406: Using bytecode reflection optimizer
2023-09-22T21:42:25.538+02:00  INFO 106034 --- [           main] o.h.b.i.BytecodeProviderInitiator        : HHH000021: Bytecode provider name : bytebuddy
2023-09-22T21:42:25.633+02:00  INFO 106034 --- [           main] o.s.o.j.p.SpringPersistenceUnitInfo      : No LoadTimeWeaver setup: ignoring JPA class transformer
2023-09-22T21:42:25.713+02:00  INFO 106034 --- [           main] o.h.b.i.BytecodeProviderInitiator        : HHH000021: Bytecode provider name : bytebuddy
2023-09-22T21:42:25.852+02:00  INFO 106034 --- [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2023-09-22T21:42:25.856+02:00  INFO 106034 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2023-09-22T21:42:25.885+02:00  WARN 106034 --- [           main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2023-09-22T21:42:26.009+02:00  INFO 106034 --- [           main] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page: class path resource [static/index.html]
2023-09-22T21:42:26.301+02:00  INFO 106034 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 1 endpoint(s) beneath base path '/actuator'
2023-09-22T21:42:26.427+02:00  INFO 106034 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
2023-09-22T21:42:26.427+02:00  INFO 106034 --- [           main] o.s.i.channel.PublishSubscribeChannel    : Channel 'application.errorChannel' has 1 subscriber(s).
2023-09-22T21:42:26.427+02:00  INFO 106034 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : started bean '_org.springframework.integration.errorLogger'
2023-09-22T21:42:26.436+02:00  INFO 106034 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2023-09-22T21:42:26.455+02:00  INFO 106034 --- [           main] n.hlopez.example.simulator.SimulatorKt   : Started SimulatorKt in 3.2 seconds (process running for 3.571)
Scenario key: Default, value: nl.hlopez.example.simulator.scenario.DefaultScenario@429dde4d
Scenario key: Test, value: nl.hlopez.example.simulator.scenario.TestScenario@610d0067
2023-09-22T21:42:26.667+02:00  INFO 106034 --- [on(1)-127.0.0.1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2023-09-22T21:42:26.667+02:00  INFO 106034 --- [on(1)-127.0.0.1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2023-09-22T21:42:26.668+02:00  INFO 106034 --- [on(1)-127.0.0.1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 1 ms

Any help setting up a simple Scenario would be very helpfull. I also tried the examples (cloning the repository) but couldn't get the project to compile/build correctly.

@hmmlopez
Copy link
Author

After upgrading the lombok dependency I manage to build the project, but still haven’t figured out how to do a simple GET request.

@bbortt
Copy link
Collaborator

bbortt commented May 14, 2024

hi @hmmlopez,

first of all: sorry! late to the 🚂

do you have any debug log available? it would be cool to see if your request actually reached the simulator. was it dispatched to the citrus simulation endpoint? did it not match (because of reasons)?

common reasons when handling UI's and backends is CORS. maybe you'll have to configure spring-security, although I think this is not part of older citrus-simulator releases. it will be with simulator v3, tho.

there is a REST sample contained in the project (here). if you cannot share a reproducer, maybe it would be a possibility to add a simple angular application to the sample that calls the REST endpoints? but I am 99% certain that will work :)

@bbortt bbortt added Type: Question Prio: Medium State: To discuss In case there are open questions concerning the issue labels May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Prio: Medium State: To discuss In case there are open questions concerning the issue Type: Question
Projects
None yet
Development

No branches or pull requests

2 participants