Azure blob Storage: Synchronous copy of block blobs across containers within the same Azure storage account is not working - azure-storage

I'm using the startCopy API from azure-storage java sdk version 8.6.5 to copy blobs between containers within the same storage account.
String copyJobId = cloudBlockBlob.startCopy(srcBlob, srcBlob.getProperties().getContentMD5(), true,
null, null, null, null)
And I am getting the following exception -
[17:25:42.976] - [STDERR] com.microsoft.azure.storage.StorageException: The specified resource does not exist.
[17:25:42.977] - [STDERR] at com.microsoft.azure.storage.StorageException.translateException(StorageException.java:87)
[17:25:42.977] - [STDERR] at com.microsoft.azure.storage.core.StorageRequest.materializeException(StorageRequest.java:305)
[17:25:42.977] - [STDERR] at com.microsoft.azure.storage.core.ExecutionEngine.executeWithRetry(ExecutionEngine.java:196)
[17:25:42.978] - [STDERR] at com.microsoft.azure.storage.blob.CloudBlob.startCopy(CloudBlob.java:791)
[17:25:42.978] - [STDERR] at com.microsoft.azure.storage.blob.CloudBlockBlob.startCopy(CloudBlockBlob.java:302)
[17:25:42.978] - [STDERR] at com.microsoft.azure.storage.blob.CloudBlockBlob.startCopy(CloudBlockBlob.java:252)
If I use the other API without sync, copy works fine -
String copyJobId = cloudBlockBlob.startCopy(srcBlob); //This works
Any idea if I am missing anything here?
Thanks in advance!!!
EDITS - Adding the screenshot of exception using the test sample code by #Bowman.

Below code works fine on my side:
import com.microsoft.azure.storage.*;
import com.microsoft.azure.storage.blob.CloudBlobClient;
import com.microsoft.azure.storage.blob.CloudBlobContainer;
import com.microsoft.azure.storage.blob.CloudBlockBlob;
public class testbowman {
public static void main(String[] args) throws Exception {
String accountname = "0730bowmanwindow";
String accountkey = "xxxxxx";
String containername = "test";
String source_blobname = "test1.txt";
String sink_blobname = "test2.txt";
StorageCredentials credentials = new StorageCredentialsAccountAndKey(accountname,accountkey);
CloudStorageAccount account = new CloudStorageAccount(credentials);
CloudBlobClient client = account.createCloudBlobClient();
CloudBlobContainer container = client.getContainerReference(containername);;
CloudBlockBlob source_cbb = container.getBlockBlobReference(source_blobname);
CloudBlockBlob sink_cbb = container.getBlockBlobReference(sink_blobname);
sink_cbb.startCopy(source_cbb,source_cbb.getProperties().getContentMD5(),true,null,null,null,null);
System.out.println("This is a test.");
}
}
And this is my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>org.example</groupId>
<artifactId>testbowman</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.11</maven.compiler.source>
<maven.compiler.target>1.11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-storage</artifactId>
<version>8.6.5</version>
</dependency>
</dependencies>
</project>
And this is my storage configuration:
Success copy with sync:
You can check what is the different between you can me.(By the way, startCopy(CloudBlockBlob sourceBlob) also works on my side.)

Related

Bean Validation on Jax-RS Resource stops working while using CDI on Apache TomEE 8.0.10

I'm having troubles getting bean validation to work with the following minimalised project consisting only of this three java files plus pom.xml. I'm using Apache TomEE 8.0.10.
LoginMessage.java
package org.example;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import javax.validation.constraints.NotBlank;
#Getter
#Setter
#ToString
public class LoginMessage {
#NotBlank
private String username;
#NotBlank
private String password;
}
SessionService.java
package org.example;
import lombok.extern.java.Log;
import javax.enterprise.context.RequestScoped;
#Log
#RequestScoped
public class SessionService {
public void login(final LoginMessage loginMessage) {
log.info(loginMessage.toString());
}
}
SessionController.java
package org.example;
import lombok.extern.java.Log;
import javax.inject.Inject;
import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;
#Log
#Path("/session")
public class SessionController {
#Inject
private SessionService sessionService;
#POST
#Consumes(MediaType.APPLICATION_JSON)
public void postLoginMessage(#Valid final LoginMessage loginMessage) {
sessionService.login(loginMessage);
}
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>
<packaging>war</packaging>
<groupId>org.example</groupId>
<artifactId>beanval</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
</dependency>
</dependencies>
</project>
If you post an empty JSON object it ignores the #Valid annotation in SessionController#postLoginMessage() and directly outputs the log message containing the toString() content of the LoginMessage object through SessionService#login() method.
POST http://localhost:8080/beanval-1.0-SNAPSHOT/session
Content-Type: application/json
{
}
13-Mar-2022 01:30:39.700 INFORMATION [http-nio-8080-exec-6] SessionService.login LoginMessage(username=null, password=null)
If you remove or comment out the #RequestScoped annotation from SessionService and post the empty JSON-Object after restart of TomEE then bean validation works and logs:
13-Mar-2022 01:52:51.594 WARNUNG [http-nio-8080-exec-6] org.apache.cxf.jaxrs.validation.ValidationExceptionMapper.toResponse Value (null) of SessionController.postLoginMessage.arg0.password: must not be blank
13-Mar-2022 01:52:51.595 WARNUNG [http-nio-8080-exec-6] org.apache.cxf.jaxrs.validation.ValidationExceptionMapper.toResponse Value (null) of SessionController.postLoginMessage.arg0.username: must not be blank
I would like to use CDI in combination with Bean-Validation in JAX-RS Resource.
What am I doing wrong?
Thanks in advance.
This appears to be a bug in OpenWebBeans or TomEE. So what's happening is the first the actual instance of the bean is managed by JAX-RS, and the second, the bean is managed by the CDI container. In the second case, there needs to be some sort of interceptor the invokes the Bean Validation framework.
I would start a discussion on the mailing list and open a bug on in the JIRA. If you can create a sample project that reproduces the problem it helps the devs out tremendously.
As a workaround, you can #Inject private Validator validator and if there are any constraint violations returned, throw new ConstraintViolationException(constraintViolations);.
After all to come up to some kind of a solution I will stop using bean validation at controller layer. It works at service layer and so I can continue to work on my web app.
The solution is using the #Valid annotation in SessionService#login() method and remove it from SessionController#postLoginMessage() method.
If it is really a bug in TomEE the alternative could also be to use another application server until it is fixed.

JavaFX, JLink/JPackage Module issue - adding Libraries "Error occurred during initialization of boot layer java.lang.module.FindException"

IDE: IntelliJ.
Trying to use JavaFX for the first time with some additional libraries, and with an installable package - (c/o JLink/JPackage)
Have followed directions from OpenJFX for a Modular Project from IDE and can get this to work no problem.
https://openjfx.io/openjfx-docs/
Adding libraries though I am just getting this error:
"Error occurred during initialization of boot layer
java.lang.module.FindException: Module eu.hansolo.medusa not found, required by ModuleName"
Have read a number of similar threads on this error but no joy here specifically.
Have tried adding adding to VM on run configuration ie:
--module-path
${PATH_TO_FX}:mods/production
--add-modules
javafx.controls,javafx.fxml,eu.hansolo.medusa - still getting "Error occurred during initialization of boot layer
java.lang.module.FindException: Module eu.hansolo.medusa not found"
However.. If I delete the "module-info.java" file.. I can run the application in IntelliJ no problem.. however.. I then can't use JLink to make the custom runtime image.
Any advice or pointers to reading I can do would be greatly appreciated and many thanks in advance.
So the issue appears to be that you haven't added Medusa to your module path. The way I accomplished this is by using maven.
I added the dependencies to my pom file and created a module-info.java and everything seemed to work.
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<groupId>org.example</groupId>
<artifactId>MavenFxied</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>14.0.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>14.0.1</version>
</dependency>
<dependency>
<groupId>eu.hansolo</groupId>
<artifactId>Medusa</artifactId>
<version>11.5</version>
</dependency>
</dependencies>
</project>
module-info.java
module mavenfxied {
requires javafx.controls;
requires eu.hansolo.medusa;
exports example;
}
I made an example class to test it out.
Main.java
package example;
import eu.hansolo.medusa.Gauge;
import eu.hansolo.medusa.GaugeBuilder;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class Main extends Application {
public void start(Stage stage) throws Exception {
StackPane pane = new StackPane();
Gauge g = GaugeBuilder.create()
.skinType(Gauge.SkinType.SPACE_X)
.animated(true)
.decimals(0)
.title("SpaceX")
.unit("km/h")
.maxValue(30000)
.threshold(25000)
.build();
pane.getChildren().add(g);
Scene scene = new Scene(pane);
stage.setScene(scene);
stage.show();
}
}
If you aren't using maven, then the solution proposed in the comments of adding the jar file to a location on the module-path might be the only way.

java.lang.ClassCastException: org.glassfish.jersey.jackson.internal.JacksonAutoDiscoverable cannot be cast to spi.AutoDiscoverable

I am new to implementing REST API services. I have tried the simple resources to implement. unfortunately I stuck with this exception. I have googled and tried many options but no luck. I am unsure what am doing wrong. Please help me.
Created a Dynamic Web project "JersyJson"
Created a resouce named - JSONService.java (source is from googling)
Created a Java Bean class - Track.java (source is from googling)
Converted the project into Maven project
Created a Application file - JersyJson.java file for Application Annotation
using the latest Jersy Jars (version: 2.22.2)
Imported & configured jersey-media-json-jackson and jersey-media-moxy jars (2.22.2) in pom.xml
Pom.xml
<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>
<groupId>JersyJson</groupId>
<artifactId>JersyJson</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<!-- if your container implements Servlet API older than 3.0, use "jersey-container-servlet-core" -->
<artifactId>jersey-container-servlet</artifactId>
<version>2.22.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.22.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
<version>2.22.2</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>JersyJson</display-name>
<servlet>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
</servlet>
<servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/json/metallica/*</url-pattern>
</servlet-mapping>
</web-app>
JersyJson.java (ApplicationAnnotation file)
#ApplicationPath("json")
public class JersyJson extends ResourceConfig {
public JersyJson() {
packages("com.sai.jersyjson");
}
}
JSONservice.java:
package com.sai.jersyjson;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
#Path("/json/metallica")
public class JSONService {
#GET
#Path("/get")
#Produces(MediaType.APPLICATION_JSON)
public Track getTrackInJSON() {
Track track = new Track();
track.setTitle("Enter Sandman");
track.setSinger("Metallica");
return track;
}
#POST
#Path("/post")
#Consumes(MediaType.APPLICATION_JSON)
public Response createTrackInJSON(Track track) {
String result = "Track saved : " + track;
return Response.status(201).entity(result).build();
}
}
Track.java (simple bean class)
package com.sai.jersyjson;
public class Track {
String title;
String singer;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getSinger() {
return singer;
}
public void setSinger(String singer) {
this.singer = singer;
}
#Override
public String toString() {
return "Track [title=" + title + ", singer=" + singer + "]";
}
}
After I run this project in Eclispe using Tomcat webserver, I get the following
error with 404-Error Status
SEVERE: StandardWrapper.Throwable
java.lang.ClassCastException: org.glassfish.jersey.jackson.internal.JacksonAutoDiscoverable cannot be cast to org.glassfish.jersey.internal.spi.AutoDiscoverable
at org.glassfish.jersey.model.internal.CommonConfig$2.compare(CommonConfig.java:594)
at java.util.TreeMap.put(Unknown Source)
at java.util.TreeSet.add(Unknown Source)
at java.util.AbstractCollection.addAll(Unknown Source)
at java.util.TreeSet.addAll(Unknown Source)
at org.glassfish.jersey.model.internal.CommonConfig.configureAutoDiscoverableProviders(CommonConfig.java:616)
at org.glassfish.jersey.server.ResourceConfig.configureAutoDiscoverableProviders(ResourceConfig.java:811)
at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:447)
at org.glassfish.jersey.server.ApplicationHandler.access$500(ApplicationHandler.java:184)
at org.glassfish.jersey.server.ApplicationHandler$3.call(ApplicationHandler.java:350)
at org.glassfish.jersey.server.ApplicationHandler$3.call(ApplicationHandler.java:347)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.processWithException(Errors.java:255)
at org.glassfish.jersey.server.ApplicationHandler.(ApplicationHandler.java:347)
at org.glassfish.jersey.servlet.WebComponent.(WebComponent.java:392)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:177)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:369)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1238)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1041)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4996)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
I had the exact same problem in Weblogic. It seems to be that the JacksonAutoDiscoverable and AutoDiscoverable came from different class loaders and therefore different versions. AutoDiscoverable exists in jersey-common and JacksonAutoDiscoverable exists in jersey-media-json-jackson.
I got around this by letting Weblogic have all the discoverable classes and instead specifying 'com.fasterxml.jackson.*' as prefer-application-packages/resources to have my own version of jackson.
I had this same problem, but I got a fix. There's an issue with conflicting dependencies. You've included the jersey-media-json-jackson dependency, but the Tomcat web container already provides those classes.
Just add the scope tag to your dependency:
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.27</version>
<scope>provided</scope>
</dependency>
Refer to the link for more information: https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#
In my case I worked with Glassfish and I had the Glassfish descriptor (glassfish-web.xml) in the project as follow:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
<class-loader delegate="false"/>
<parameter-encoding default-charset="UTF-8"/>
<jsp-config>
<property name="keepgenerated" value="true">
<description>Keep a copy of the generated servlet class' java code.</description>
</property>
</jsp-config>
</glassfish-web-app>
The class-loader property was marked with the attribute
delegate=false
, I think that was my mistake, because as Glassfish Deployment Guide say, this attribute must be true when you are exposing services.
https://javaee.github.io/glassfish/doc/4.0/application-deployment-guide.pdf#G11.1006531
The solution that worked for me was remove that file and keep only the Standard Deployment Descriptor(web.xml).
Hope this help.
I had this same problem with JBOSS6 server. After adding jersey-media-moxy dependency to pom file, it was worked.
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
<version>2.25.1</version>
</dependency>
I solved the issue by adding both jersey-common and jersey-media-json-jackson. Removed jersey-bean-validation.
<dependency>
<artifactId>jersey-common</artifactId>
<groupId>org.glassfish.jersey.core</groupId>
<version>2.29.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.29.1</version>
</dependency>
<!--<dependency>
<artifactId>jersey-bean-validation</artifactId>
<groupId>org.glassfish.jersey.ext</groupId>
<version>2.29.1</version>
</dependency>-->

Attaching attachments in Allure reports using cucumber jvm after hooks

With Allure report framework when a step fails we can attach a screenshot or logs by calling a method with #Attachment annotation.
#Attachment(value = "Message", type = "text/plain")
public String attachLog(){
return "Hello, Test failed!";
}
But this means I have to explicitly call this method ( attachLog() ) in every step before assertions. Which seems unreasonable.
In CucumberJvm the "after" hooks are a great way to attach screenshots or logs. we do this by checking the scenario status and attach screenshots/logs based on the outcome.
I tried invoking the above method ( attachLog() ) in the cucumberJvm "after" hook. But unfortunately did not work.
Is there a solution to make this work?
Cheers
Vinod
You can override test failure method from ru.yandex.qatools.allure.cucumberjvm.AllureRunListener
public class CustomAllureListener extends AllureRunListener {
#Override
public void testFailure(Failure failure) {
super.testFailure(failure);
if (!failure.getDescription().isSuite()) { // check is needed to avoid double attaching
attachFailed();
}
}
#Attachment(value = "Message", type = "text/plain")
public String attachFailed(){
return "Test failed!";
}
}
And don't forget to change listener in pom.xml file
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<testFailureIgnore>false</testFailureIgnore>
<argLine>
-javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar
</argLine>
<properties>
<property>
<name>listener</name>
<value>com.mycompany.testing.CustomAllureListener</value>
</property>
</properties>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>

Apache Camel failed to create endpoint

I'm new on Apache Camel and I need to integrate it with Apache ActiveMQ.
I tried a basic example, I installed on my computer FileZilla Server and ActiveMQ (works both) and I want to copy a file from the local server to the JMS queue that I created in Active MQ; the problem is that the method start() of CamelContext throws org.apache.camel.FailedToCreateRouteException
Here is my code (the address in ftpLocation is the static address of my computer):
import javax.jms.ConnectionFactory;
import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jms.JmsComponent;
import org.apache.camel.impl.DefaultCamelContext;
public class FtpToJmsExample
{
private static String url = ActiveMQConnection.DEFAULT_BROKER_URL;
private static String ftpLocation = "ftp://192.168.1.10/incoming?username=Luca&password=Luca";
public void start() throws Exception
{
CamelContext context = new DefaultCamelContext();
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
context.addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
context.addRoutes(
new RouteBuilder() {
public void configure()
{
from(ftpLocation).
process(executeFirstProcessor()).
to("jms:TESTQUEUE");
}
});
System.out.println("START");
context.start();
System.out.println("wait");
System.out.println(loaded);
Thread.sleep(3000);
while (loaded == false)
{
System.out.println("in attesa\n");
}
context.stop();
System.out.println("stop context!");
System.out.println(loaded);
}
public static void main(String args[]) throws Exception
{
FtpToJmsExample example = new FtpToJmsExample();
example.start();
}
private Processor executeFirstProcessor()
{
return new Processor() {
#Override
public void process(Exchange exchange)
{
System.out.println("We just downloaded : "+
exchange.getIn().getHeader("CamelFileName"));
loaded = true;
}
};
}
}
This is the POM.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel</groupId>
<artifactId>examples</artifactId>
<version>2.11.0</version>
</parent>
<artifactId>camel-example-jms-file</artifactId>
<name>Camel :: Example :: JMS-File</name>
<description>An example that persists messages from FTP site to JMS</description>
<dependencies>
<!-- Camel dependencies -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jms</artifactId>
</dependency>
<!-- ActiveMQ dependencies -->
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-broker</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-client</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-camel</artifactId>
</dependency>
<dependency>
<groupId>org.apache.xbean</groupId>
<artifactId>xbean-spring</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<profiles>
<profile>
<id>Example</id>
<properties>
<target.main.class>com.ftpToJms.FtpToJMSExample</target.main.class>
</properties>
</profile>
</profiles>
</project>
And this is the report of the error
Exception in thread "main" org.apache.camel.FailedToCreateRouteException: Failed to create route route1: Route(route1)[[From[ftp://192.168.1.10/incoming?username=Luc... because of Failed to resolve endpoint: ftp://192.168.1.10/incoming?password=Luca&username=Luca due to: No component found with scheme: ftp
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:181)
at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:750)
at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:1829)
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1609)
at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:1478)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:1446)
at ftptojms.FtpToJmsExample.start(FtpToJmsExample.java:51)
at ftptojms.FtpToJmsExample.main(FtpToJmsExample.java:73)
Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: ftp://192.168.1.10/incoming?password=Luca&username=Luca due to: No component found with scheme: ftp
at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:514)
at org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:62)
at org.apache.camel.model.RouteDefinition.resolveEndpoint(RouteDefinition.java:191)
at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:108)
at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:114)
at org.apache.camel.model.FromDefinition.resolveEndpoint(FromDefinition.java:72)
at org.apache.camel.impl.DefaultRouteContext.getEndpoint(DefaultRouteContext.java:90)
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:861)
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:176)
... 8 more
Someone can help me?
Sorry for the long post and the not-perfect english.
You need to add camel-ftp to your classpath. If you use Maven then its easy as just add it as dependency to the pom.xml