I have below code which handle requests from other apps which pass the traceId through Traceparent header. I expect it will hydrate the parent traceId from the request, and in zipkin dashboard I should see the connection between this app and other apps. It used to work with spring-cloud-sleuth-zipkin. Now I migrated to spring boot 3 and the package is changed to micrometer-tracing-bridge-otel (See pom.xml). Now it no longer hydrate the parent traceId from the request but generate a default parent traceId which is all 0 instead, causing the app to disconnect from other apps in the zipkin dashboard
I tested with a simple curl request with the header Traceparent: curl --location --request GET 'http://localhost:8080/test' --header 'Traceparent: 00-63cf0173620c57b0aed605ee94255089-1444ca74c3d2133a-01' but this code does not extract the parent context from the header. Any idea how to make this work?
#RestController
public class Test {
#Autowired
private Tracer tracer;
#GetMapping(path="/test")
public ResponseEntity<?> handleTest() {
ScopedSpan span = tracer.startScopedSpan("test span");
return ResponseEntity.ok();
}
}
pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.2</version>
</parent>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-otel</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-zipkin</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-sender-urlconnection</artifactId>
</dependency>
Related
I was working on the Spring Boot Update to 3.0.1 and with it the Upgrade of Spring Integration 6.0.0 and Spring Cloud Stream 4.0.0. After upgrading however my previously working Spring Integration Flow is failing with underlying ClassCastException:
class org.springframework.messaging.handler.HandlerMethod$HandlerMethodParameter cannot be cast to class java.lang.reflect.Type (org.springframework.messaging.handler.HandlerMethod$HandlerMethodParameter is in unnamed module of loader 'app'; java.lang.reflect.Type is in module java.base of loader 'bootstrap')
Update: The exception originates from JsonMessageConverter inside of Spring Cloud Function Context, when trying to cast an object conversionHint (in my case of type HandlerMethodParameter) to Type.
Cannot cast 'org.springframework.messaging.handler.HandlerMethod$HandlerMethodParameter' to 'java.lang.reflect.Type'
Any hints or suggestions as to what might be the problem are highly appreciated.
Following is a highly shortened version of the affected integration flow and corresponding code snippets and a more detailed explanation:
#Bean
IntegrationFlow extract(SessionFactory<SftpClient.DirEntry> sftpSessionFactory,
XmlFileTransformer xmlFileTransformer){
return IntegrationFlow
.from(Sftp.inboundAdapter(sftpSessionFactory)
.preserveTimestamp(true)
.remoteDirectory("foo")
.regexFilter(".*\\.txt$")
.localDirectory(new File("sftp-inbound")), e -> e.id("sftpInboundAdapter")
.autoStartup(true)
.poller(Pollers.fixedDelay(5000))
)
.log(LoggingHandler.Level.DEBUG, "ExtractFlow", m -> "Successfully reached")
.wireTap(MONITORING_FLOW)
.log(LoggingHandler.Level.DEBUG, "ExtractFlow", m -> "Successfully done wire tap")
.transform(xmlFileTransformer)
.log(LoggingHandler.Level.DEBUG, "ExtractFlow", m -> "Successfully done transformation")
.handle(m -> xmlProcessor.process((XmlFile) m.getPayload())
.get();
}
#RequiredArgsConstructor
#Component
public class XmlFileTransformer implements GenericTransformer<Message<File>, XmlFile> {
#Override
public XmlFile transform(Message<File> message) {
return new XmlFile(message.getPayload().toPath(), message.getHeaders().get("x-origin", String.class));
}
}
The Integration Flow from the wiretap again transforms by implementing GenericTransfomer (similary written as XmlFileTransformer and then uses Amqp.outboundAdapter to send messages.
The method xmlProcessor.process takes XmlFile as argument. However it never reaches the actual method because it breaks when trying to go through the wire tap, and in case I comment the wire tap it breaks when trying to transform with xmlFileTransformer. So after log message "Successfully reached" the exception happens.
I'm using following relevant dependencies (other used dependencies not listed for better overview):
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>2022.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.1</version>
<relativePath/>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-rabbit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-sftp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-xml</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-amqp</artifactId>
</dependency>
</dependencies>
I was checking and rechecking my dependencies to ensure that I don't have any old dependencies that might clash with the update. However those should be fine as I'm using mostly the versions from spring-boot-starter-parent.
According to the migration guide of Spring Integration 6.0.0 there shouldn't be any major breaks that I forgot to handle.
I was trying to find any information about similar cases however it seems not too many have either tried to upgrade to Spring Boot 3 yet or just didn't have the same issues as me.
Could this be a bug in Spring Integration or do I need to refactor code so it's still running in Spring Integration 6.0? Or did I overlook issues with my dependencies?
I am trying to create a standalone application to collect Hystrix stream from other applications. But it does not expose the /turbine.stream endpoint by default. I am sure what is missing in my project.
Spring Boot: 2.0.4.RELEASE, Spring Cloud: Finchley.SR1
The application class:
#SpringBootApplication
#EnableDiscoveryClient
#EnableTurbine
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
The content of applicaiton.yml:
server:
port: 8383
spring:
application:
name: hystrix-turbine
management:
endpoints:
web.exposure.include: '*'
applications: hystrix
turbine:
aggregator:
clusterConfig: ${applications}
appConfig: ${applications}
# instanceUrlSuffix.default: actuator/hystrix.stream
And the maven dependencies:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
I created a sample project for this.
I'd suggest you check the configuration steps below:
1) Your stream URL in the Hystrix Dashboard should be:
http://localhost:{turbine app port}/turbine.stream?cluster={configured cluster in properties file}
The url should be pointing to the port of the application that has #EnableTurbine annotation in your main class.
2) Check if you are getting a response for:
http://localhost:{client app port}/actuator/hystrix.stream
(use your browser for this) (this should be coming from the application you have enabled hystrix on using #EnableCircuitBreaker)
If you're getting pings, then atleast your hystrix stream is accessible. If not, Check if you have: org.springframework.boot:spring-boot-starter-actuator in your client side dependencies and
make sure you have the below property set in application.properties file of the application that has #EnableCircuitBreaker in the main class:
management.endpoints.web.exposure.include= hystrix.stream, info, health
Check the URL again.
3) Once your get a reponse from hystrix.stream, you can now configure your cluster on the turbine app properties file:
turbine:
appConfig: {serviceId in lower case}
aggregator:
clusterConfig: {above serviceId in upper case}
after running the app, check if you've configured the cluster correctly:
http://localhost:{turbine app port}/clusters
you should'nt be getting a "[]" on your browser if all's well.
Once you see a response on the clusters endpoint, you will now be able to see the details on the dashboard when you point it to the turbine app
Problem
I build an application using a Neo4j database. I like to test some custom Cypher queries using Spring Boot's #DataNeo4jTest annotation (see also Spring Boot Test - Neo4j), but I run in either one of the following problems:
The test tries to connect to a Neo4j instance using the BOLT driver.
The test fails to load the embedded driver.
Details
My dependencies are managed with Maven following the Spring Data Neo4j Reference Documentation. Section 10.3.1 of the SDN documentation explains:
By default, SDN will use the BOLT driver to connect to Neo4j and you don’t need to declare it as a separate dependency in your pom. If you want to use the embedded or HTTP drivers in your production application, you must add the following dependencies as well. (This dependency on the embedded driver is not required if you only want to use the embedded driver for testing. See the section on Testing below for more information).
Therefore, the relevant parts of my pom.xml are:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi=...>
...
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
...
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>
<dependency>
<groupId>org.neo4j.test</groupId>
<artifactId>neo4j-harness</artifactId>
<version>3.3.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
...
</project>
My main/resources/application.yml is:
spring:
data:
neo4j:
uri: bolt://localhost
username: <username>
password: <password>
My test/resources/application.yml is:
spring.data.neo4j.uri: file:///neo4j.db
Without the test/resources/application.yml I get the following exception, which I assume is caused by using the BOLT driver:
org.springframework.transaction.CannotCreateTransactionException: Could not open Neo4j Session for transaction;
nested exception is org.neo4j.driver.v1.exceptions.AuthenticationException: The client is unauthorized due to authentication failure.
With the test/resources/application.yml I get the following exception:
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'neo4jAuditionBeanFactoryPostProcessor': Unsatisfied dependency expressed through constructor parameter 0;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.class]: Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.neo4j.ogm.session.SessionFactory]: Factory method 'sessionFactory' threw exception;
nested exception is org.neo4j.ogm.exception.core.ConfigurationException: Could not load driver class org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver
Questions
Are there any dependencies missing?
Is the configuration wrong?
Does anyone have a link to a working example using the Spring Boot annotation #DataNeo4jTest?
Any suggestion is welcome.
I have found a solution to my problem. It seems as if the BOLT driver is used as default for testing as well - which is confusing given the Spring Data Neo4j (SDN) documentation. Finally, the pom.xml of the GitHub project movies-java-spring-data-neo4j helped me. I added the following test dependency to my pom.xml:
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-embedded-driver</artifactId>
<version>${neo4j-ogm.version}</version>
<scope>test</scope>
</dependency>
I kept the test/resources/application.yml but removed the line:
spring.data.neo4j.uri: file:///neo4j.db
Now, the test context starts with the embedded driver, and creates a temporary database file like file:/C:/Users/Me/AppData/Local/Temp/neo4j.db6943517458205762238/, which is awesome. I can get a clean database instance for every test method.
I hope this answer will help others, who have the same problem. I'm happy to provide more details if necessary.
#DataNeo4JTest works great with Spring Boot 2.x.
Example Test:
#RunWith(SpringRunner.class)
#DataNeo4jTest
public class WidgetRepositoryTest {
#Autowired
private WidgetRepository repository;
private Widget widget;
#Before
public void setUp() {
widget = WidgetTestData.builder().build();
}
#Test
public void itShouldSaveAndRetrieve() {
final Widget saved = repository.save(widget);
assertThat(saved.getId()).isNotNull();
assertThat(saved.getName()).isEqualTo(widget.getName());
final Optional<Widget> found = repository.findById(saved.getId());
assertThat(found).hasValueSatisfying(w-> {
assertThat(w.getId()).isEqualTo(saved.getId());
assertThat(w.getName()).isEqualTo(saved.getName());
});
}
}
The Neo4J-related dependencies in my Maven POM:
<dependency>
<groupId>org.neo4j.test</groupId>
<artifactId>neo4j-harness</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-embedded-driver</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>
This question already has answers here:
Servlet returns "HTTP Status 404 The requested resource (/servlet) is not available"
(19 answers)
Closed 5 years ago.
i have been tring to send a request to my configured servlet from my JSP file, but i keep getting error 404 - The requested resource is not available.
i know that this question have been asked several times but it seems like none of the answer solved the problem for me.
i'm using IntelliJ ide with tomcat 9 and Java maven project.
my servlet named ControllerServlet config is:
#WebServlet(name = "ControllerServlet", urlPatterns = {"/category", "/addToCart", "/viewCart","/updateCart", "/checkout", "/purchase"},loadOnStartup = 1)
my pom.xml file have those dependencies:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
</dependency>
</dependencies>
my project tree structure is like so:
pcstore
-src
-main
-java
-com
-pcStore
-controller
-ControllerServlet.java
-web
-WEB-INF
-view
-category.jsp
-web.xml
-index.jsp
-pom.xml
i was trying almost anything but ended up with no dice.
my context root is /pcStore , and i hit pcStore/category?{id} this is part of the servlet, i just want to pile up too much unnessesary code:
#Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//checks in which path the request is
String userPath = request.getServletPath();
// if category page is requested
if (userPath.equals("/category")) {
check if you have some collistions between your classpath jars and maven's.
maybe you should try to copy the same project and try to run a sample servlet using module source without Maven or vice versa.
I have a Spring Boot project with Vaadin, I would like to integrate the Vaadin4Spring EventBus framework:
https://github.com/peholmst/vaadin4spring/tree/master/spring-vaadin-eventbus
The author says:
Please note, that the Event Bus API changed in version 0.0.5
However, if I add the Maven dependency inside my pom.xml:
...
<dependency>
<groupId>org.vaadin.spring</groupId>
<artifactId>spring-vaadin-eventbus</artifactId>
<version>LATEST</version>
</dependency>
...
Maven downloads the 0.0.4.RELEASE version. I have tried to explicitly set the following versions:
...
<dependency>
<groupId>org.vaadin.spring</groupId>
<artifactId>spring-vaadin-eventbus</artifactId>
<version>0.0.5</version>
</dependency>
...
...
<dependency>
<groupId>org.vaadin.spring</groupId>
<artifactId>spring-vaadin-eventbus</artifactId>
<version>0.0.5.RELEASE</version>
</dependency>
...
...
<dependency>
<groupId>org.vaadin.spring</groupId>
<artifactId>spring-vaadin-eventbus</artifactId>
<version>0.0.5-SNAPSHOT</version>
</dependency>
...
I also tried to set the entire Spring4Vaadin addon as a dependency:
<dependency>
<groupId>org.vaadin.spring</groupId>
<artifactId>spring-boot-vaadin</artifactId>
<version>LATEST</version>
</dependency>
...
<dependency>
<groupId>org.vaadin.spring</groupId>
<artifactId>spring-boot-vaadin</artifactId>
<version>0.0.5</version>
</dependency>
...
<dependency>
<groupId>org.vaadin.spring</groupId>
<artifactId>spring-boot-vaadin</artifactId>
<version>0.0.5-SNAPSHOT</version>
</dependency>
...
<dependency>
<groupId>org.vaadin.spring</groupId>
<artifactId>spring-boot-vaadin</artifactId>
<version>0.0.5.RELEASE</version>
</dependency>
But neither of them worked.
Basically, I cannot do this:
#Autowired
EventBus.ApplicationEventBUs appEventBus;
#Autowired
EventBus.UIEventBus UIEventBus;
...
Because, as said in the README.md on GitHub:
Please note, that the Event Bus API changed in version 0.0.5. From now
on, you have to declare which event bus to inject by using a specific
interface (previously, everything was EventBus and you used an
annotation to specify which bus to get). The reasons for this change
were
So in the version 0.0.4.RELEASE (which Maven sees as LATEST), the inner interfaces ApplicationEventBus and UIEventBus are not defined.
So, how can I use the true latest version of the addon?
Putting the answer I put in the vaadin forums, over here as well:
Vaadin addons has a nice Event Bus implementation. Check https://github.com/peholmst/vaadin4spring/tree/master/samples/eventbus-sample
I have done this using a spring enabled (NOT spring boot) Vaadin application, but it might work without Spring as well I guess, Short steps:
1. Add the following dependency
<dependency>
<groupId>org.vaadin.spring.addons</groupId>
<artifactId>vaadin-spring-addon-eventbus</artifactId>
<version>0.0.7.RELEASE</version>
</dependency>
Import EventBusConfiguration.class into your Spring configuration (may not be required if Spring Boot is used with #EnableAutoConfiguration)
Wire in appropriate event bus (check doumentations for different types available), here I am using one that works per UI instance:
#Autowired
private EventBus.UIEventBus uiEventBus;
Publish event as required, eg:
uiEventBus.publish(this, new RefreshMainViewEvent(this, "Usage details updated"));
Subscribe to event in the other component class
#PostConstruct
public void afterPropertiesSet() {
uiEventBus.subscribe(this, false);
}
Add the action to be done on event (in the same class here) :
#EventBusListenerMethod
public void closeSymmUsageWindow(RefreshMainViewEvent event) {
logger.debug("Received {}", event);
//blah
}