diff --git a/.gitignore b/.gitignore index 8801278..789da79 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ /target/ /.classpath /.project -/.settings \ No newline at end of file +/.settings +/conf/ +/conf2/ +/bruno/ diff --git a/bruno/bruno.json b/bruno/bruno.json deleted file mode 100644 index e4d2338..0000000 --- a/bruno/bruno.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "version": "1", - "name": "camel-springboot-xml-example", - "type": "collection", - "ignore": [ - "node_modules", - ".git" - ] -} \ No newline at end of file diff --git a/bruno/collection.bru b/bruno/collection.bru deleted file mode 100644 index 81213d3..0000000 --- a/bruno/collection.bru +++ /dev/null @@ -1,8 +0,0 @@ -auth { - mode: basic -} - -auth:basic { - username: - password: -} diff --git a/bruno/findSession.bru b/bruno/findSession.bru deleted file mode 100644 index e7d74cd..0000000 --- a/bruno/findSession.bru +++ /dev/null @@ -1,20 +0,0 @@ -meta { - name: findSession - type: http - seq: 4 -} - -get { - url: http://localhost:8761/services/api/session/a3518555-5a96-42a6-a5ec-958c4963a65e - body: none - auth: basic -} - -headers { - operationName: findUsers -} - -auth:basic { - username: cxfrs - password: password -} diff --git a/bruno/findSessions.bru b/bruno/findSessions.bru deleted file mode 100644 index c583471..0000000 --- a/bruno/findSessions.bru +++ /dev/null @@ -1,20 +0,0 @@ -meta { - name: findSessions - type: http - seq: 2 -} - -get { - url: http://localhost:8761/services/api/session - body: none - auth: basic -} - -headers { - operationName: findUsers -} - -auth:basic { - username: cxfrs - password: password -} diff --git a/bruno/login.bru b/bruno/login.bru deleted file mode 100644 index 2baa818..0000000 --- a/bruno/login.bru +++ /dev/null @@ -1,20 +0,0 @@ -meta { - name: login - type: http - seq: 5 -} - -post { - url: http://localhost:8761/services/api/login/a3518555-5a96-42a6-a5ec-958c4963a65e - body: none - auth: basic -} - -headers { - operationName: findUsers -} - -auth:basic { - username: cxfrs - password: password -} diff --git a/bruno/updateSession.bru b/bruno/updateSession.bru deleted file mode 100644 index 3e83e0d..0000000 --- a/bruno/updateSession.bru +++ /dev/null @@ -1,33 +0,0 @@ -meta { - name: updateSession - type: http - seq: 3 -} - -post { - url: http://localhost:8761/services/api/session - body: json - auth: basic -} - -headers { - Content-Type: application/json - X-MethodName: updateUser -} - -auth:basic { - username: cxfrs - password: password -} - -body:json { - { - "sessionId": "{{uuid}}", - "username": "admin1", - "password": "password1" - } -} - -script:pre-request { - bru.setVar('uuid', require("uuid").v4()); -} diff --git a/conf/logback.xml b/conf/logback.xml deleted file mode 100644 index 43014b7..0000000 --- a/conf/logback.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - %-5level %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %logger{36} - %msg%n - - - - logs/server.log - - logs/server.%d{yyyy-MM-dd}.log.gz - 3 - 300MB - - - %-5level %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %logger{36} - %msg%n - - - - - - - \ No newline at end of file diff --git a/conf/springboot.yml b/conf/springboot.yml deleted file mode 100644 index c3cd420..0000000 --- a/conf/springboot.yml +++ /dev/null @@ -1,37 +0,0 @@ -server: - port: 8761 - -camel: - springboot: - main-run-controller: true - -spring: - application: - name: eureka-server - activemq: - broker-url: "tcp://localhost:61616" - ldap: - urls: ldap://localhost:10389 - base: dc=example,dc=com - username: uid=admin,ou=system - password: secret - -app: - queue-name: "SessionServiceQueue" - database: - url: "jdbc:h2:tcp://localhost/~/h2/db/appdb" - username: "app" - password: "app" - mapper-package: "com.example.sbcamel.mapper" - htmlunit: - login-url: "" - login-btn-selector: "" - home-page-selector: "" - logout-btn-selector: "" - -eureka: - client: - service-url: - defaultZone: http://cxfrs:password@localhost:8761/eureka/,http://cxfrs:password@localhost:8762/eureka/ - register-with-eureka: false - fetch-registry: false \ No newline at end of file diff --git a/conf2/logback.xml b/conf2/logback.xml deleted file mode 100644 index 43014b7..0000000 --- a/conf2/logback.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - %-5level %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %logger{36} - %msg%n - - - - logs/server.log - - logs/server.%d{yyyy-MM-dd}.log.gz - 3 - 300MB - - - %-5level %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %logger{36} - %msg%n - - - - - - - \ No newline at end of file diff --git a/conf2/springboot.yml b/conf2/springboot.yml deleted file mode 100644 index 6cf157a..0000000 --- a/conf2/springboot.yml +++ /dev/null @@ -1,37 +0,0 @@ -server: - port: 8762 - -camel: - springboot: - main-run-controller: true - -spring: - application: - name: eureka-server - activemq: - broker-url: "tcp://localhost:61616" - ldap: - urls: ldap://localhost:10389 - base: dc=example,dc=com - username: uid=admin,ou=system - password: secret - -app: - queue-name: "SessionServiceQueue" - database: - url: "jdbc:h2:tcp://localhost/~/h2/db/appdb" - username: "app" - password: "app" - mapper-package: "com.example.sbcamel.mapper" - htmlunit: - login-url: "" - login-btn-selector: "" - home-page-selector: "" - logout-btn-selector: "" - -eureka: - client: - service-url: - defaultZone: http://cxfrs:password@localhost:8761/eureka/,http://cxfrs:password@localhost:8762/eureka/ - register-with-eureka: false - fetch-registry: false \ No newline at end of file diff --git a/pom.xml b/pom.xml index 847e7a9..fb7cdcd 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.example camel-springboot-activemq6-example - 3.0.2 + 3.0.3 camel-springboot-activemq6-example @@ -16,7 +16,6 @@ 2024.0.1 3.5.19 3.0.4 - 4.11.1 33.1.0-jre 3.14.0 diff --git a/src/main/java/com/example/sbcamel/processor/LoginProcessor.java b/src/main/java/com/example/sbcamel/processor/LoginProcessor.java index e4c209d..f13ca29 100644 --- a/src/main/java/com/example/sbcamel/processor/LoginProcessor.java +++ b/src/main/java/com/example/sbcamel/processor/LoginProcessor.java @@ -2,9 +2,7 @@ package com.example.sbcamel.processor; import org.apache.camel.Exchange; import org.apache.camel.Processor; -import org.htmlunit.Page; import org.htmlunit.WebClient; -import org.htmlunit.html.DomNode; import org.htmlunit.html.HtmlButton; import org.htmlunit.html.HtmlForm; import org.htmlunit.html.HtmlPage; @@ -26,11 +24,14 @@ public class LoginProcessor implements Processor { @Value("${app.htmlunit.login-btn-selector}") private String loginBtnSelector; - @Value("${app.htmlunit.home-page-selector}") - private String homePageSelector; + @Value("${app.htmlunit.login-wait-millis:3000}") + private Long loginWaitMillis; - @Value("${app.htmlunit.logout-btn-selector}") - private String logoutBtnSelector; + @Value("${app.htmlunit.user-page-url}") + private String userPageUrl; + + @Value("${app.htmlunit.logout-url}") + private String logoutUrl; @Override public void process(Exchange exchange) throws Exception { @@ -40,6 +41,8 @@ public class LoginProcessor implements Processor { try (final WebClient webClient = new WebClient()) { final HtmlPage loginPage = webClient.getPage(loginUrl); + logger.info("loginPage: {}", loginPage.asXml()); + final HtmlForm form = loginPage.getForms().get(0); final HtmlTextInput usernameField = form.getInputByName("username"); usernameField.type(session.getUsername()); @@ -50,16 +53,15 @@ public class LoginProcessor implements Processor { logger.info("entered password: {}", session.getPassword()); HtmlButton loginBtn = loginPage.querySelector(loginBtnSelector); - HtmlPage defaultPage = loginBtn.click(); - logger.info("loginBtn clicked, defaultPage: {}", defaultPage); + logger.info("loginBtn type: {}", loginBtn.getType()); + loginBtn.click(); - HtmlButton homePageBtn = defaultPage.querySelector(homePageSelector); - HtmlPage homePage = homePageBtn.click(); - logger.info("homePageBtn clicked, homePage: {}", homePage); + Thread.sleep(loginWaitMillis); + HtmlPage userPage = webClient.getPage(userPageUrl); + logger.info("loginBtn clicked, userPage: {}", userPage.asXml()); - HtmlButton logoutBtn = homePage.querySelector(logoutBtnSelector); - HtmlPage loginPage2 = logoutBtn.click(); - logger.info("logoutBtn clicked, loginPage2: {}", loginPage2); + HtmlPage logoutPage = webClient.getPage(logoutUrl); + logger.info("logoutPage: {}", logoutPage.asXml()); } catch (Exception e) { logger.error("LoginProcessor process error!", e);