Failed to create Blob container in Microsoft Azure - java

I followed the tutorial of Azure Blob storage service here and supplied the connection string from my storage account to create a container but it did not work as the container is not created and the application runs until I terminate it manually. I used azure-blob-storage API version 12.4.0.
Here is the code:
// Create a BlobServiceClient object which will be used to create a container client
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder().connectionString(connectStr).buildClient();
//Create a unique name for the container
String containerName = "quickstartblobs" + java.util.UUID.randomUUID();
// Create the container and return a container client object
BlobContainerClient containerClient = blobServiceClient.createBlobContainer(containerName);
Here 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>aaaa</groupId>
<artifactId>ddada</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.327</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.cloud/google-cloud-storage -->
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
<version>1.108.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>de.hpi.cloudraid</groupId>
<artifactId>erasure</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>com.hiramsoft.commons</groupId>
<artifactId>jsalparser</artifactId>
<version>0.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>com.google.googlejavaformat</groupId>
<artifactId>google-java-format</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>com.google.crypto.tink</groupId>
<artifactId>tink</artifactId>
<version>1.3.0-rc3</version>
</dependency>
<dependency>
<groupId>dev.morphia.morphia</groupId>
<artifactId>core</artifactId>
<version>1.5.8</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.10</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-csv</artifactId>
<version>2.11.0.rc1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.11.0.rc1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.opencsv/opencsv -->
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>5.1</version>
</dependency>
<dependency>
<groupId>com.hierynomus</groupId>
<artifactId>sshj</artifactId>
<version>0.27.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.azure/azure-storage-blob -->
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-blob</artifactId>
<version>12.4.0</version>
</dependency>
</dependencies>
</project>
It also showed another error message like this:
May 29, 2020 3:39:49 PM io.netty.channel.AbstractChannelHandlerContext invokeExceptionCaught
WARNING: An exception 'java.lang.NoSuchMethodError: 'java.lang.String io.netty.handler.codec.http.HttpUtil.formatHostnameForHttp(java.net.InetSocketAddress)'' [enable DEBUG level for full stacktrace] was thrown by a user handler's exceptionCaught() method while handling the following exception:
java.lang.NoSuchMethodError: 'java.lang.String io.netty.handler.codec.http.HttpUtil.formatHostnameForHttp(java.net.InetSocketAddress)'
at reactor.netty.http.client.HttpClientConnect$HttpClientHandler.resolveHostHeaderValue(HttpClientConnect.java:593)
at reactor.netty.http.client.HttpClientConnect$HttpClientHandler.requestWithBody(HttpClientConnect.java:552)
at reactor.netty.http.client.HttpClientConnect$HttpIOHandlerObserver.lambda$onStateChange$0(HttpClientConnect.java:429)
at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:44)
at reactor.netty.http.client.HttpClientConnect$HttpIOHandlerObserver.onStateChange(HttpClientConnect.java:430)
at reactor.netty.ReactorNetty$CompositeConnectionObserver.onStateChange(ReactorNetty.java:473)
at reactor.netty.resources.PooledConnectionProvider$DisposableAcquire.onStateChange(PooledConnectionProvider.java:525)
at reactor.netty.resources.PooledConnectionProvider$PooledConnection.onStateChange(PooledConnectionProvider.java:434)
at reactor.netty.channel.ChannelOperationsHandler.channelActive(ChannelOperationsHandler.java:62)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelActive(AbstractChannelHandlerContext.java:213)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelActive(AbstractChannelHandlerContext.java:199)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelActive(AbstractChannelHandlerContext.java:192)
at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelActive(CombinedChannelDuplexHandler.java:414)
at io.netty.channel.ChannelInboundHandlerAdapter.channelActive(ChannelInboundHandlerAdapter.java:64)
at io.netty.channel.CombinedChannelDuplexHandler.channelActive(CombinedChannelDuplexHandler.java:213)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelActive(AbstractChannelHandlerContext.java:213)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelActive(AbstractChannelHandlerContext.java:199)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelActive(AbstractChannelHandlerContext.java:192)
at reactor.netty.tcp.SslProvider$SslReadHandler.userEventTriggered(SslProvider.java:731)
at io.netty.channel.AbstractChannelHandlerContext.invokeUserEventTriggered(AbstractChannelHandlerContext.java:329)
at io.netty.channel.AbstractChannelHandlerContext.invokeUserEventTriggered(AbstractChannelHandlerContext.java:315)
at io.netty.channel.AbstractChannelHandlerContext.fireUserEventTriggered(AbstractChannelHandlerContext.java:307)
at io.netty.handler.ssl.SslHandler.setHandshakeSuccess(SslHandler.java:1480)
at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1318)
at io.netty.handler.ssl.SslHandler.decodeNonJdkCompatible(SslHandler.java:1170)
at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1195)
at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:489)
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:428)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:265)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1359)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:935)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:138)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:645)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
at java.base/java.lang.Thread.run(Thread.java:830)
Any reasons why it did not work?

Update:
Thanks to Ihsan Haikal for sharing. If anyone who faces similar problems cannot create a container using the following method, please check the content of pom.xml The problem should not be the code but the configuration part.
Original Answer:
With this steps I can create container on my storage:
First, import:
import com.azure.storage.blob.BlobContainerClient;
import com.azure.storage.blob.BlobServiceClient;
import com.azure.storage.blob.BlobServiceClientBuilder;
And this is the code in my pom.xml:
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-blob</artifactId>
<version>12.0.0</version>
</dependency>
Second, use code:
// Create a BlobServiceClient object which will be used to create a container client
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder().connectionString("DefaultEndpointsProtocol=https;AccountName=0730bowmanwindow;AccountKey=xxxxxx;EndpointSuffix=core.windows.net").buildClient();
//Create a unique name for the container
String containerName = "quickstartblobs";
// Create the container and return a container client object
BlobContainerClient containerClient = blobServiceClient.createBlobContainer(containerName);
You should get connection string from this place:
Then, it creates the container:
You can check what different between you and me.:)

Related

Using confluent avro serializer in Java - NoSuchFieldError: PASSWORD

I'm using confluent avro producer in java but while running it getting below issue.I have added all the required jar .Don't have any clue what did i miss?
Exception in thread "main" java.lang.NoSuchFieldError: PASSWORD
at io.confluent.kafka.serializers.AbstractKafkaAvroSerDeConfig.baseConfigDef(AbstractKafkaAvroSerDeConfig.java:92)
at io.confluent.kafka.serializers.KafkaAvroSerializerConfig.<clinit>(KafkaAvroSerializerConfig.java:28)
at io.confluent.kafka.serializers.KafkaAvroSerializer.configure(KafkaAvroSerializer.java:48)
at org.apache.kafka.common.serialization.ExtendedSerializer$Wrapper.configure(ExtendedSerializer.java:60)
at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:341)
at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:302)
I have tried with below configurations.
Properties prop = new Properties();
prop.put("bootstrap.servers", "localhost:9092");
prop.put("schema.registry.url", "http://localhost:8081");
//prop.put("basic.auth.user.info", "");
prop.put("ssl.keystore.type",null);
prop.put("acks", "all");
prop.put("retries", "0");
prop.put("key.serializer", "io.confluent.kafka.serializers.KafkaAvroSerializer");
prop.put("value.serializer", "io.confluent.kafka.serializers.KafkaAvroSerializer");
prop.put("group.id", "test");
These are the dependency which i used it.All the jars with latest version.
<dependency>
<groupId>io.confluent</groupId>
<artifactId>kafka-schema-registry</artifactId>
<version>4.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.confluent/common-config -->
<dependency>
<groupId>io.confluent</groupId>
<artifactId>common-config</artifactId>
<version>3.3.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.confluent/common-utils -->
<dependency>
<groupId>io.confluent</groupId>
<artifactId>common-utils</artifactId>
<version>3.3.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.confluent/kafka-connect-avro-converter -->
<dependency>
<groupId>io.confluent</groupId>
<artifactId>kafka-connect-avro-converter</artifactId>
<version>5.2.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.confluent/kafka-schema-registry-client -->
<dependency>
<groupId>io.confluent</groupId>
<artifactId>kafka-schema-registry-client</artifactId>
<version>5.2.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.confluent.kafka/connect-utils -->
<dependency>
<groupId>io.confluent.kafka</groupId>
<artifactId>connect-utils</artifactId>
<version>0.1.18</version>
</dependency>
<dependency>
<groupId>io.confluent.kafka</groupId>
<artifactId>connect-checkstyle</artifactId>
<version>0.1.18</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.confluent/rest-utils -->
<dependency>
<groupId>io.confluent</groupId>
<artifactId>rest-utils</artifactId>
<version>4.1.0</version>
</dependency>
I've seen this error when mixing versions.
You should only need this as the common util, client, rest-utils, etc, are all transitive dependencies
<dependency>
<groupId>io.confluent</groupId>
<artifactId>kafka-avro-serializer</artifactId>
<version>5.2.1</version>
</dependency>
https://docs.confluent.io/current/app-development/index.html#native-clients-with-serializers
Remove the rest of the dependencies, or at least create a property for the version and re-use it

AEM CQ with JPA (Hibernate)

I'm working with Adobe Experience Manager (AEM) 6.4 with Service Pack 1, and the Forms Package.
I have a lot of extended Properties/attributes, so I made a Database diagram. I don't want to save all the additional stuff in crx I want to save it in an Oracle database.
The Database diagram is complex, so I want to USE JPA (Hibernate), at minimum. If Spring would help to make it easier to use, than that would be fine for me.
I read a lot that the OSGI is working with blueprint instead of Spring, but you can combine it.
I'm really searching for an good example how to make things work with JPA and a Oracle db.
Adobe is no Help at all, they can't show an example how to work with AEM and JPA/Hibernate/Spring/blueprint.
Can anybody help me to make things working? with AEM and JPA?
I think what I need is:
persistence.xml (RESOURCE_LOCAL or JTA?)
Entity classes with Annotation #Entity and other JPA annotations
Service classes with Transaction control and maybe manager classes to submit to work with the entity classes and get result from queries, maybe I could put it all in the service classes
hibernate-osgi (dependency)
ojdbc7 for connection (dependency)
org.apache.aries.jpa.api (dependency)
But how do I have to make things happen? Nothing works. I even don't know if this is the right way.
should I use blueprint or Spring or both?
I found this Aries thing from apache.
http://aries.apache.org
And weard different samples that I don't really understand how they work.
https://github.com/apache/aries-jpa/tree/master/examples
And some OSGI sample, they look very incomplete for my situation.
https://enroute.osgi.org/tutorial/032-tutorial_microservice-jpa.html
So is there anybody with some experience with AEM and JPA?
let me describe how it is implemented on our project. We are using AEM 6.3 with SP2.
We have next dependencies in the root pom.xml:
<!-- JPA -->
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.1.10.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.1.10.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>5.0.1.Final</version>
</dependency>
<dependency>
<groupId>com.ibm.db2.jcc</groupId>
<artifactId>db2jcc4</artifactId>
<version>11.1</version>
<scope>system</scope>
<systemPath>${project.root.path}/lib/db2jcc4.jar</systemPath>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<version>3.3.2.Final</version>
</dependency>
<dependency>
<groupId>com.fasterxml</groupId>
<artifactId>classmate</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
<version>2.7.7</version>
</dependency>
<!-- local development database -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.194</version>
</dependency>
<!-- /JPA-->
Then we have the bundle to provide JPA dependencies and the OSGI service that allows to get hibernate Session. The bundle 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>
<parent>
<groupId>com.myproject</groupId>
<artifactId>myproject-bundles</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>com.myproject.db</artifactId>
<packaging>bundle</packaging>
<name>myproject - DB bundle</name>
<description>OSGI bundle to work with a database</description>
<properties>
<bundle.export>
com.myproject.db.*,
javax.persistence,
org.hibernate,
org.hibernate.cfg,
org.hibernate.proxy,
org.hibernate.boot.registry,
org.hibernate.annotations,
org.hibernate.service,
org.hibernate.criterion,
org.hibernate.transform
</bundle.export>
<bundle.import>*;resolution:=optional</bundle.import>
<!-- Import JDBC driver dynamically -->
<bundle.dynamic.import>com.ibm.*,javassist.util.*</bundle.dynamic.import>
<bundle.embed>
hibernate-jpa-2.1-api,hibernate-core,hibernate-entitymanager,hibernate-commons-annotations,jboss-logging,antlr
</bundle.embed>
<project.root.path>${project.basedir}/../..</project.root.path>
</properties>
<dependencies>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</dependency>
<dependency>
<groupId>com.ibm.db2.jcc</groupId>
<artifactId>db2jcc4</artifactId>
</dependency>
<dependency>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.myproject</groupId>
<artifactId>com.myproject.common</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
In the bundle we have next service:
package com.myproject.db;
import org.hibernate.Session;
public interface JPASessionFactory {
Session openSession();
void closeSession(Session session);
}
implementation:
package com.myproject.db.impl;
import com.myproject.db.JPASessionFactory;
import org.apache.felix.scr.annotations.*;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import javax.sql.DataSource;
import java.util.Map;
#Service
#Component(metatype = true, policy = ConfigurationPolicy.REQUIRE)
#Properties({
#Property(label = "Hibernate SQL dialect", name = Environment.DIALECT),
#Property(label = "Show SQL", name = Environment.SHOW_SQL, boolValue = false),
#Property(label = "Bulk ID Strategy", name = Environment.HQL_BULK_ID_STRATEGY)
})
public class JPASessionFactoryImpl implements JPASessionFactory {
#Reference(target = "(datasource.name=myproject)")
private DataSource dataSource;
private SessionFactory sessionFactory;
#Activate
protected void activate(Map<String, Object> properties) {
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder()
.configure()
.applySetting(Environment.DIALECT, PropertiesUtil.toString(properties.get(Environment.DIALECT), ""))
.applySetting(Environment.SHOW_SQL, PropertiesUtil.toBoolean(properties.get(Environment.SHOW_SQL), false))
.applySetting(Environment.DATASOURCE, dataSource);
String bulkIdStrategy = PropertiesUtil.toString(properties.get(Environment.HQL_BULK_ID_STRATEGY), "");
if (!bulkIdStrategy.isEmpty()) {
builder.applySetting(Environment.HQL_BULK_ID_STRATEGY, bulkIdStrategy);
}
sessionFactory = new Configuration().buildSessionFactory(builder.build());
}
#Deactivate
protected void deactivate() {
if (sessionFactory != null) {
sessionFactory.close();
}
}
#Override
public Session openSession() {
return sessionFactory.openSession();
}
#Override
public void closeSession(Session session) {
if (session != null && session.isOpen()) {
session.close();
}
}
}
osgi config for the service:
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="sling:OsgiConfig"
hibernate.dialect="org.hibernate.dialect.H2Dialect"
hibernate.show_sql="{Boolean}true"/>
Configuration for DataSourceFactory apps/myproject-forms/configuration/config.local/org.apache.sling.datasource.DataSourceFactory-localh2.xml:
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="sling:OsgiConfig"
datasource.name="myproject"
driverClassName="org.h2.Driver"
url="jdbc:h2:./myprojectlocal;AUTO_SERVER=TRUE"
username="sa"
password=""
testOnBorrow="{Boolean}true"
testOnReturn="{Boolean}true"
testWhileIdle="{Boolean}true"
validationQuery="SELECT 1"/>
Also we have the Hibernate config file hibernate.cfg.xml in "resources" folder of the bundle
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hbm2ddl.auto">update</property>
<property name="current_session_context_class">thread</property>
<mapping class="com.myproject.db.Entity1"/>
<mapping class="com.myproject.db.Entity2"/>
</session-factory>
</hibernate-configuration>
I've found the solution and made a post here on the site.
https://forums.adobe.com/message/10640295#10640295
I feel like I'm the First Guy on earth which combined AEM with JPA/Hibernate. Now I could check if it's a benefit to work with spring, to operate with the Transactions.
And those two who voted the question down, I'm sure you are from adobe --> thanks, now I feel more expert than you on your own cms, because before my post there was no solution for this problem.
Update: Maven Dependencies. If you have problems with the dependencies you have to Embed them and add the property "Embed-Transitive to true"
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<inherited>true</inherited>
<configuration>
<instructions>
<Embed-Dependency>
*;scope=compile|runtime
</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<Export-Package>
<!--TODO export packages -->
</Export-Package>
<Private-Package>todo</Private-Package>
<Import-Package>
<!-- Attention this is really sensitive!!. -->
*;resolution:="optional"
</Import-Package>
<Bundle-Activator>path.to.Activator</Bundle-Activator>
</instructions>
</configuration>
</plugin>
There are some blog posts describing how to realise JPA persistence in AEM/CQ. In using-jpa-to-write-database-applications-in-an-osgi-container-e-g-felix-or-adobe-aem-cq5 they describe how to setup a JNDI datasource with a PersistenceUnit and how to #Reference a EntityManagerFactory.
We have integrated Hibernate 5.4.5 and JPA 2.2 into Adobe Experience Manager 6.4.4 using two approaches below. Please, check https://soft-werke.com/en/archives/news-en/how-to-install-hibernate-5-4-5-jpa-2-2-in-adobe-experience-manager-6-4-4/ for more details.
Classic approach - install zip package with all embedded Hibernate dependencies in AEM Package Manager with content-package-maven-plugin. Below is an example of Maven profile which can be later excluded to avoid installing Hibernate in each AEM deployment.
<profiles>
<profile>
<id>installHibernate</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.day.jcr.vault</groupId>
<artifactId>content-package-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<embeddedTarget>/apps/hibernate/install</embeddedTarget>
<embeddeds>
<embedded>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.antlr</artifactId>
</embedded>
<embedded>
<groupId>com.fasterxml</groupId>
<artifactId>classmate</artifactId>
</embedded>
<embedded>
<groupId>com.sun.activation</groupId>
<artifactId>javax.activation</artifactId>
</embedded>
<embedded>
<groupId>javax.activation</groupId>
<artifactId>javax.activation-api</artifactId>
</embedded>
<embedded>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
</embedded>
<embedded>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</embedded>
<embedded>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
</embedded>
<embedded>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.dom4j</artifactId>
</embedded>
<embedded>
<groupId>com.sun.istack</groupId>
<artifactId>istack-commons-runtime</artifactId>
</embedded>
<embedded>
<groupId>com.sun.xml.fastinfoset</groupId>
<artifactId>FastInfoset</artifactId>
</embedded>
<embedded>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.jaxb-runtime</artifactId>
</embedded>
<embedded>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
</embedded>
<embedded>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</embedded>
<embedded>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
</embedded>
<embedded>
<groupId>org.jboss</groupId>
<artifactId>jandex</artifactId>
</embedded>
<embedded>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
</embedded>
<embedded>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.javax-inject</artifactId>
</embedded>
<embedded>
<groupId>javax.interceptor</groupId>
<artifactId>javax.interceptor-api</artifactId>
</embedded>
<embedded>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
</embedded>
<embedded>
<groupId>org.jboss.spec.javax.interceptor</groupId>
<artifactId>jboss-interceptors-api_1.2_spec</artifactId>
</embedded>
<embedded>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.2_spec</artifactId>
</embedded>
<embedded>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</embedded>
<embedded>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</embedded>
<embedded>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-osgi</artifactId>
</embedded>
</embeddeds>
</configuration>
<executions>
<execution>
<id>install-package-hibernate</id>
<goals>
<goal>install</goal>
</goals>
<configuration>
<targetURL>http://${aem.host}:${aem.port}/crx/packmgr/service.jsp</targetURL>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<!-- ====================================================================== -->
<!-- D E P E N D E N C I E S -->
<!-- ====================================================================== -->
<dependencies>
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.antlr</artifactId>
<version>2.7.7_5</version>
</dependency>
<dependency>
<groupId>com.fasterxml</groupId>
<artifactId>classmate</artifactId>
<version>1.3.4</version>
</dependency>
<dependency>
<groupId>com.sun.activation</groupId>
<artifactId>javax.activation</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>javax.activation-api</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.9.11</version>
</dependency>
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.dom4j</artifactId>
<version>2.1.1_1</version>
</dependency>
<dependency>
<groupId>com.sun.istack</groupId>
<artifactId>istack-commons-runtime</artifactId>
<version>3.0.7</version>
</dependency>
<dependency>
<groupId>com.sun.xml.fastinfoset</groupId>
<artifactId>FastInfoset</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.jaxb-runtime</artifactId>
<version>2.3.1_1</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.24.0-GA</version>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<version>3.3.2.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>5.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jandex</artifactId>
<version>2.0.5.Final</version>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>2.2.5</version>
</dependency>
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.javax-inject</artifactId>
<version>1_2</version>
</dependency>
<dependency>
<groupId>javax.interceptor</groupId>
<artifactId>javax.interceptor-api</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.interceptor</groupId>
<artifactId>jboss-interceptors-api_1.2_spec</artifactId>
<version>1.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.2_spec</artifactId>
<version>1.1.1.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.46</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.5.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-osgi</artifactId>
<version>5.4.5.Final</version>
</dependency>
<dependency>
<groupId>com.adobe.aem</groupId>
<artifactId>uber-jar</artifactId>
<classifier>apis</classifier>
</dependency>
<dependency>
<groupId>javax.jcr</groupId>
<artifactId>jcr</artifactId>
</dependency>
</dependencies>
Another approach - install all Hibernate bundles in AEM Felix Console one-by-one in predefined order with sling-maven-plugin called by Java Maven Invoker API. Below is an example of Maven profile.
<profiles>
<profile>
<id>installHibernate</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>rg</groupId>
<artifactId>com.softwerke.jpa.hibernate.bundles</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${basedir}/src/main/content/jcr_root/apps/hibernate/install/
</outputDirectory>
<includeArtifactIds>
org.apache.servicemix.bundles.antlr,
classmate,
javax.activation,
javax.activation-api,
javax.persistence-api,
jaxb-api,
byte-buddy,
org.apache.servicemix.bundles.dom4j,
istack-commons-runtime,
FastInfoset,
org.apache.servicemix.bundles.jaxb-runtime,
javassist,
jboss-logging,
hibernate-commons-annotations,
jandex,
javax.el-api,
org.apache.servicemix.bundles.javax-inject,
javax.interceptor-api,
cdi-api,
jboss-interceptors-api_1.2_spec,
jboss-transaction-api_1.2_spec,
mysql-connector-java,
hibernate-core,
hibernate-osgi
</includeArtifactIds>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.softwerke.build.utils.HibernateInstaller</mainClass>
<classpathScope>compile</classpathScope>
<arguments>
<!-- Path to load Hibernate OSGi dependencies from -->
<argument>${basedir}/src/main/content/jcr_root/apps/hibernate/install</argument>
<!-- Path to XML file with a list of Hibernate bundles -->
<argument>${basedir}/src/main/content/META-INF/resources/hibernate-bundles.xml</argument>
<!-- User login to install bundle in AEM -->
<argument>${sling.user}</argument>
<!-- User password to install bundle in AEM -->
<argument>${sling.password}</argument>
<!-- Path to AEM Felix Console -->
<argument>http://${aem.host}:${aem.port}/system/console</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Java code for Hibernate bundle installation with Maven Invoker API:
public class HibernateInstaller {
public static void main(String[] args) throws Exception {
String bundleFolder,
xmlFilePath,
slingUser,
slingPassword,
url;
if (args != null && args.length == 5) {
bundleFolder = args[0];
xmlFilePath = args[1];
slingUser = args[2];
slingPassword = args[3];
url = args[4];
} else {
throw new Exception("Can't execute Hibernate install!\nPlease specify five arguments.");
}
StringBuilder mvnCmd = new StringBuilder();
mvnCmd.append("org.apache.sling:sling-maven-plugin:2.4.2:install-file");
mvnCmd.append(" -Dsling.user=" + slingUser);
mvnCmd.append(" -Dsling.password=" + slingPassword);
mvnCmd.append(" -Dsling.url=" + url);
mvnCmd.append(" -Dsling.deploy.method=WebConsole");
mvnCmd.append(" -Dsling.file=");
mvnCmd.append(bundleFolder);
mvnCmd.append("/");
// Read XML file with a list of the Hibernate OSGi dependencies (bundles)
File file = new File(xmlFilePath);
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.parse(file);
NodeList bundlesList = document.getElementsByTagName("bundle");
final InvocationRequest invocationRequest = new DefaultInvocationRequest();
// invocationRequest.setDebug(true);
final Invoker invoker = new DefaultInvoker();
for (int i = 0; i < bundlesList.getLength(); i++) {
String goal = mvnCmd.toString() + bundlesList.item(i).getTextContent();
installBundle(invocationRequest, invoker, goal);
}
}
private static void installBundle(InvocationRequest invocationRequest, Invoker invoker, String goal)
throws MavenInvocationException, CommandLineException {
invocationRequest.setGoals(Collections.singletonList(goal));
final InvocationResult invocationResult = invoker.execute(invocationRequest);
if (invocationResult.getExitCode() != 0) {
String msg = "Invocation Exception";
if (invocationResult.getExecutionException() != null) {
msg = invocationResult.getExecutionException().getMessage();
}
throw new CommandLineException(msg);
}
}
}
P.S.
In case you don't need different versions of same dependency on AEM instance, it's better to avoid using OSGi <Embed-Transitive>true</Embed-Transitive> as it might introduce security/performance/OSGi issues - see Embedding_Transitive_Dependencies_Into_a_Mega-Bundle_With_Maven-Bundle-Plugin for details.
In case you once decide to switch to another ORM framework, it's better to prefer JPA EntityManagerFactory approach instead of Hibernate-specific SessionFactory - check https://stackoverflow.com/a/5640796/12547140.

How to connect a Java project to an AWS mysql (mariadb) instance using Lambda Functions

Since my project is on AWS and I have to connect with other AWS related instances (such as API-Gateway, for example) I am trying to use a Lambda Function to connect to a RDS instance (and I know for a fact is up and running). Running in Eclipse with the AWS plugin, in java 8. So, the idea is I code on a local Eclipse, upload the function, run it, and then, on a serverless manner, it should execute the code.
No matter what combination of code I try, or what advice I follow, I do not get a succesful connection, so I can't query the database.
With the current iteration of code I have, I get
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
I can't for the life of me figure out why I can not connect from eclipse-java-awsLambdaFunction to a mysql-aws instance. If I try to access from terminal to the database, with the same credentials, I am allowed. I have read and followed the official documentation 4-5 times already (originally I was following this, now it is slightly tweaked, and I am unsure if with this is enough for a simple connection (I have been told and read that it is!), but I wonder if there is some other way of doing it).
This is what I execute, since the plugin makes me give "A" json, even though I do not need it, I give it one like this: {"key1" : "value1"}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.apache.log4j.Logger;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
public class Adapt_LambdaConnection implements RequestHandler<Object, String> {
private static Logger log = Logger.getLogger(Adapt_LambdaConnection.class.getName());
#Override
public String handleRequest(Object input, Context context) {
context.getLogger().log("Input: " + input);
//TODO: implement your handler
Connection con = null;
try {
con = DriverManager.getConnection("jdbc:mysql://cmf6lelghjzq.eu-west-1.rds.amazonaws.com:3306/botdb", "bot", "PassWordRandom");
}
catch (SQLException e) {
e.toString();
log.warn(e.toString());
System.out.println(e + "\nSQLException");
}catch (Exception e) {
e.toString();
System.out.println(e + "\ngenericException");
}
String status = null;
if (con != null) {
status = "connection stablished";
System.out.println(status);
}else status = "connetion failed";
return status;
}
And this is the POM (I was using a way lighter POM, but since nothing was working, I am now using one I know for sure is right since it is cloned from an unrelated proyect we run that has no issues.
<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>com.spa</groupId>
<artifactId>demo</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<properties>
<jdk.version>1.8</jdk.version>
<encoding>UTF-8</encoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hadoop.version>2.7.1</hadoop.version>
<scala.version>2.11.8</scala.version>
<scala.tools.version>2.11</scala.tools.version>
<spark.version>2.2.1</spark.version>
<aws.version>1.11.191</aws.version>
<spark-csv.version>1.5.0</spark-csv.version>
<commons-codec.version>1.10</commons-codec.version>
<log4j.version>1.2.17</log4j.version>
<json.version>20160212</json.version>
<slack.version>1.3.0</slack.version>
</properties>
<repositories>
<repository>
<id>SparkPackagesRepo</id>
<url>http://dl.bintray.com/spark-packages/maven</url>
</repository>
</repositories>
<build>
<finalName>TypeformSurveysTransformer</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-bom</artifactId>
<version>1.11.283</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.45</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-reflect</artifactId>
<version>${scala.version}</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
<version>${hadoop.version}</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_${scala.tools.version}</artifactId>
<version>${spark.version}</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_${scala.tools.version}</artifactId>
<version>${spark.version}</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-hive_${scala.tools.version}</artifactId>
<version>${spark.version}</version>
</dependency>
<dependency>
<groupId>com.databricks</groupId>
<artifactId>spark-csv_2.10</artifactId>
<version>${spark-csv.version}</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>${commons-codec.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>${json.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-events</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>net.gpedro.integrations.slack</groupId>
<artifactId>slack-webhook</artifactId>
<version>${slack.version}</version>
</dependency>
</dependencies>
</project>

migrating from stash to bitbucket

Mi company is migrating from stash to bitbucket and they have some REST Extensions plugin for Stash that are not working anymore in bitbucket. The plugins are developed by them, internally and uploaded in the add-ons section (manage add-ons).
I would like to know if it's any possibility to adapt those plugins and make them work in bitbucket or if we must rewrite the code.
According to this tutorial:
https://confluence.atlassian.com/bitbucketserver/how-to-update-your-add-on-779302412.html
all I have to do is to rename our package namespace from com.atlassian.stash to com.atlassian.bitbucket. I did that in the pom.xml file and in the code also but now I have lots of errors.
For example the class CommitService is not recognized anymore after I've changed imports in the code from :
import com.atlassian.stash.commit.CommitService;
to
import com.atlassian.bitbucket.commit.CommitService;
(Now this line:
private final CommitService commitService;
generates the error "Cannot resolve symbol CommitService").
Can anyone help please, since I don't have much experience with the plugins development.
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myCompany.bitbucket.plugins</groupId>
<artifactId>myCompany-rest-extensions</artifactId>
<version>1.2.2</version>
<organization>
<name>MyCompany</name>
<url>http://www.myCompany.com/</url>
</organization>
<name>myCompany-rest-extensions</name>
<description>This is the myCompany-rest-extensions plugin for Atlassian bitbucket.</description>
<packaging>atlassian-plugin</packaging>
<dependencies>
<dependency>
<groupId>com.atlassian.bitbucket</groupId>
<artifactId>bitbucket-parent</artifactId>
<version>${bitbucket.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.atlassian.sal</groupId>
<artifactId>sal-api</artifactId>
<version>${bitbucket.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.atlassian.bitbucket</groupId>
<artifactId>bitbucket-api</artifactId>
<version>${bitbucket.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.atlassian.bitbucket</groupId>
<artifactId>bitbucket-spi</artifactId>
<version>${bitbucket.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.atlassian.bitbucket</groupId>
<artifactId>bitbucket-page-objects</artifactId>
<version>${bitbucket.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.atlassian.bitbucket.server</groupId>
<artifactId>bitbucket-api</artifactId>
<version>${bitbucket.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${bitbucket.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
<scope>provided</scope>
</dependency>
<!-- WIRED TEST RUNNER DEPENDENCIES -->
<dependency>
<groupId>com.atlassian.plugins</groupId>
<artifactId>atlassian-plugins-osgi-testrunner</artifactId>
<version>${plugin.testrunner.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.7</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.2-atlassian-1</version>
</dependency>
<dependency>
<groupId>com.atlassian.plugins.rest</groupId>
<artifactId>atlassian-rest-common</artifactId>
<version>1.0.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<!-- <artifactId>maven-bitbucket-plugin</artifactId>-->
<artifactId>bitbucket-maven-plugin</artifactId>
<version>${amps.version}</version>
<extensions>true</extensions>
<configuration>
<products>
<product>
<id>bitbucket</id>
<instanceId>bitbucket</instanceId>
<version>${bitbucket.version}</version>
<dataVersion>${bitbucket.data.version}</dataVersion>
</product>
</products>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<bitbucket.version>${bitbucket.version}</bitbucket.version>
<bitbucket.data.version>${bitbucket.version}</bitbucket.data.version>
<amps.version>5.0.13</amps.version>
<plugin.testrunner.version>1.2.3</plugin.testrunner.version>
</properties>
import com.atlassian.bitbucket.commit.CommitService;
// other imports
#Path("/stash-projects")
public class ProjectsListRestResource{
private final CommitService commitService;
// other declarations
public ProjectsListRestResource( RefService refService, CommitService commitService , ......){
this.commitService = commitService;
// other initializations
}
#GET
#AnonymousAllowed
#Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public Response getMessage()
{
log.info("Rest plugin main function start");
List<ProjectRestResourceModel> projects = new ArrayList<ProjectRestResourceModel>();
PageRequest repoPageReq = new PageRequestImpl(0,100);
for(String projectkey : projectService.findAllKeys())
{
Project project = projectService.getByKey(projectkey);
ProjectRestResourceModel projectRestResourceModel = new ProjectRestResourceModel();
projectRestResourceModel.setKey(projectkey);
// ..............
Page<? extends Repository> repoPage = repositoryService.findByProjectKey(projectkey, repoPageReq);
Set<HashMap<String,String>> repoList=new HashSet<HashMap<String, String>>();
for (Repository r : repoPage.getValues()) {
HashMap<String, String> repo = new HashMap<String, String>();
repo.put("repoName", r.getName());
// .....
if(mirrorHook!=null && mirrorHook.isEnabled()) {
//....
}
repoList.add(repo);
}
projectRestResourceModel.setRepoList(repoList);
Map<Permission,Set<String>> groupMap=new HashMap<Permission,Set<String>>();
//....
groupMap.put(Permission.PROJECT_ADMIN, new HashSet<String>());
for ( PermittedGroup pg : permittedGroupProjectPage.getValues()) {
//...
}
projectRestResourceModel.setAdminGroups(groupMap.get(Permission.PROJECT_ADMIN));
userMap.put(Permission.PROJECT_ADMIN, new HashSet<String>());
for ( PermittedUser pu : permittedUserProjectPage.getValues()) {
//...
}
projectRestResourceModel.setAdminUsers(userMap.get(Permission.PROJECT_ADMIN));
projects.add(projectRestResourceModel);
}
return Response.ok(projects, MediaType.APPLICATION_JSON_TYPE).build();
}
}

org.nd4j.linalg.factory.Nd4jBackend$NoAvailableBackendException

I don't know what it wants from me. I am using
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-core</artifactId>
<version>${deeplearning4j.version}</version>
</dependency>
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-nlp</artifactId>
<version>${deeplearning4j.version}</version>
</dependency>
where
<deeplearning4j.version>0.4-rc3.8</deeplearning4j.version>
but I am getting
Caused by: org.nd4j.linalg.factory.Nd4jBackend$NoAvailableBackendException: null
at org.nd4j.linalg.factory.Nd4jBackend.load(Nd4jBackend.java:148) ~[nd4j-api-0.4-rc3.7.jar:na]
at org.nd4j.linalg.factory.Nd4j.initContext(Nd4j.java:4498) ~[nd4j-api-0.4-rc3.7.jar:na]
... 53 common frames omitted
if I try to load the Google word vector model:
#RequestMapping("/loadModel")
public Boolean loadModel(#RequestParam(value="model") String model) {
Resource resource = appContext.getResource("WEB-INF/word-vector-models/" + model);
try {
File modelFile = resource.getFile();
System.err.println(modelFile.getAbsolutePath());
WordVectors googleModel = WordVectorSerializer.loadGoogleModel(modelFile, true);
this.wordVectorsMap.put(model, googleModel);
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}
It looks like you don't have an nd4j backend specified in your pom file. You have to have one, and you should use only one (don't have multiple backends in your pom at once unless you use profiles). Currently, for version 0.4-rc3.8, I've had luck with nd4j-x86 on non-GPU enabled Mac, Windows and linux boxes. If you have access to GPUs, you could use one of the nd4j-jcublas-7.x jars, but be aware that there is a major Cuda rewrite going on according to their Gitter.
For now,
Read the "Dependencies and Backends" section of http://deeplearning4j.org/quickstart.html,
Determine which backend is right for you at http://nd4j.org/dependencies.html (Note that Jblas is only available if you downgrade to version 0.4-rc3.6)
Keep an eye on the dl4j Gitter
If you're trying to use GPUs like I am, keep an eye on Github issue #555
Here's how I set up my pom.xml dependencies. By default ((i.e. mvn clean install), it runs with nd4j-x86, but when I pull my code onto the GPU box, I just append the profile name (so mvn clean install -P cuda) and switch backends easily:
<!-- Platform-dependent backend selection (netlib is default) -->
<profiles>
<profile>
<id>cuda</id>
<dependencies>
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-jcublas-${cuda.version}</artifactId>
<version>${nd4j.version}</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>netlib</id>
<dependencies>
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-x86</artifactId>
<version>${nd4j.version}</version>
</dependency>
</dependencies>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
</profiles>
<!-- end platform-dependent backend selection -->
<dependencies>
<!-- dl4j dependencies -->
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-core</artifactId>
<version>${dl4j.version}</version>
</dependency>
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-ui</artifactId>
<version>${dl4j.version}</version>
</dependency>
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-scaleout-api</artifactId>
<version>${dl4j.version}</version>
</dependency>
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-scaleout-akka</artifactId>
<version>${dl4j.version}</version>
</dependency>
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-scaleout-zookeeper</artifactId>
<version>${dl4j.version}</version>
</dependency>
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-nlp</artifactId>
<version>${dl4j.version}</version>
</dependency>
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-aws</artifactId>
<version>${dl4j.version}</version>
</dependency>
<!-- end dl4j dependencies -->
<!-- nd4j dependencies -->
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>canova-nd4j-image</artifactId>
<version>${canova.version}</version>
</dependency>
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>canova-nd4j-codec</artifactId>
<version>${canova.version}</version>
</dependency>
<!-- end nd4j dependencies -->
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>net.java.openjfx.backport</groupId>
<artifactId>openjfx-78-backport</artifactId>
<version>1.8.0-ea-b96.1</version>
</dependency>
<!-- logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.13</version>
</dependency>
<!-- end logging -->
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-api</artifactId>
<version>2.2.1</version>
</dependency>
</dependencies>

Categories

Resources