I have the following JSR223 Sampler which reads the image changes it a bit and sends a POST multipart/form-data request. I see that it is extensively using CPU compared to HTTP Sampler but I can't use HTTP sampler as it doesn't support changing the image without saving to file system.
Appreciate if anyone has any input to optimize the script in JSR223 sampler so it doesn't extensively lot of CPU.
import org.apache.http.HttpHeaders
import org.apache.http.client.config.RequestConfig
import org.apache.http.client.methods.HttpUriRequest
import org.apache.http.client.methods.RequestBuilder
import org.apache.http.conn.ssl.NoopHostnameVerifier
import org.apache.http.conn.ssl.SSLConnectionSocketFactory
import org.apache.http.conn.ssl.TrustStrategy
import org.apache.http.entity.StringEntity
import org.apache.http.impl.client.HttpClients
import org.apache.http.ssl.SSLContextBuilder
import org.apache.http.util.EntityUtils
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.HttpMultipartMode;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.awt.Graphics;
import java.io.ByteArrayOutputStream;
import org.apache.http.entity.ContentType;
import java.security.cert.CertificateException
import java.security.cert.X509Certificate
List<String> sendRequest(String url, String method, String body) {
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(40000)
.setSocketTimeout(50000)
.build();
BufferedImage image = ImageIO.read(new File("/home/4567/loadtest/Bank.JPG"));
Graphics graphics = image.getGraphics();
graphics.setFont(graphics.getFont().deriveFont(16f));
graphics.drawString("User " + ctx.getThreadNum() + '-' + Math.random() +"; iteration: " + ctx.getVariables().getIteration(), 50, 50);
graphics.dispose();
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
ImageIO.write(image, "jpg", bytes);
final MultipartEntityBuilder multipartEntity = MultipartEntityBuilder.create();
multipartEntity.setMode(HttpMultipartMode.STRICT);
multipartEntity.addBinaryBody("File", bytes.toByteArray(),ContentType.IMAGE_JPEG, "Bank.JPG");
HttpUriRequest request = RequestBuilder.create(method)
.setConfig(requestConfig)
.setUri(url)
.setHeader("x-ibm-client-id","248a20f3-c39b-45d0-b26a-9019c26e9be8")
.setHeader("X-Client-Id","2861D410-773B-4DD9-AE74-882116B08856")
.setHeader("ResponseMinLatencyMs","45")
.setHeader("ResponseMaxLatencyMs","55")
.setEntity(multipartEntity.build())
.build();
// String req = "REQUEST:" + "User " + ctx.getThreadNum() + "; iteration: " + ctx.getVariables().getIteration() + " " + request.getRequestLine() + "\n";
def builder = new SSLContextBuilder();
builder.loadTrustMaterial(null, new TrustStrategy() {
#Override
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
return true;
}
});
def trustAllFactory = new SSLConnectionSocketFactory(builder.build(), new NoopHostnameVerifier());
HttpClients.custom().setSSLSocketFactory(trustAllFactory).build().withCloseable { httpClient ->
httpClient.execute(request).withCloseable { response ->
// String res = "RESPONSE:" + "User " + ctx.getThreadNum() + "; iteration: " + ctx.getVariables().getIteration() + " " + response.getStatusLine() + (response.getEntity() != null ? EntityUtils.toString(response.getEntity()) : "") + "\n";
// log.info(req + "\n" + res);
// return Arrays.asList(req, res);
response.close()
}
httpClient.close()
}
image.flush()
bytes.flush()
bytes.close()
}
sendRequest("https://test-server.com/upload", "POST", "");
I believe normal HTTP Request sampler doesn't change the images before sending the request that's why it is not that CPU intensive.
Looking into Beanshell vs JSR223 vs Java JMeter Scripting: The Performance-Off You've Been Waiting For! article it seems that Java it still the best choice in terms of performance and resources usage so you might want to re-implement your code in Java and use JUnit or Java request samplers
If you run up above 85% of CPU on your JMeter machine most probably you won't get accurate results because JMeter won't be able to send requests fast enough, consider going for Distributed Testing
Related
I am getting this error, and cannot figure out what wrong I am doing:
Error invoking bsh method: eval In file: inline evaluation of: ``import java.util.Set; import java.util.Map; import java.util.List; try { // Map . . . '' Encountered "String" at line 17, column 9.
This is the code that I am using:
import java.util.Set;
import java.util.Map;
import java.util.List;
try
{
// Map<String,List<String>> map = new HashMap<String,List<String>>();
// map = vars.getObject("headerMap");
boolean isHeaderValid = false;
// String apiKeySent = "${x_api_key}"
// String clientIdSent = "${X_IBM_Client_id}"
// String clientSecretSent = "${X_IBM_Client_Secret}"
String apiKeySent = vars.get("x_api_key")
String clientIdSent = vars.get("X_Client_id")
String clientSecretSent = vars.get("X_Client_Secret")
log.info("apiKeySent: " + vars.get("x_api_key"))
log.info("clientIdSent: " + vars.get("X_Client_id"))
log.info("clientSecretSent: " + vars.get("X_Client_Secret"))
if(apiKeySent != "")
{
apiKeyRec = vars.get("apiKeyRec")
isHeaderValid = apiKeySent.equals(apiKeyRec)
}
Failure = isHeaderValid
}
catch(Exception e)
{
log.debug("Error in verification: ",e)
}
Could anyone please help me in figuring this out? Have been stuck at this for ages.
You need to add semicolons like this
import java.util.Set;
import java.util.Map;
import java.util.List;
try
{
// Map<String,List<String>> map = new HashMap<String,List<String>>();
// map = vars.getObject("headerMap");
boolean isHeaderValid = false;
// String apiKeySent = "${x_api_key}"
// String clientIdSent = "${X_IBM_Client_id}"
// String clientSecretSent = "${X_IBM_Client_Secret}"
String apiKeySent = vars.get("x_api_key");
String clientIdSent = vars.get("X_Client_id");
String clientSecretSent = vars.get("X_Client_Secret");
log.info("apiKeySent: " + vars.get("x_api_key"));
log.info("clientIdSent: " + vars.get("X_Client_id"));
log.info("clientSecretSent: " + vars.get("X_Client_Secret"));
if(apiKeySent != "")
{
apiKeyRec = vars.get("apiKeyRec");
isHeaderValid = apiKeySent.equals(apiKeyRec);
}
Failure = isHeaderValid;
}
catch(Exception e)
{
log.debug("Error in verification: ",e);
}
Since JMeter 3.1 you should be using JSR223 Test Elements and Groovy language for scripting so consider migrating to JSR223 Assertion and Groovy
Your script can be simplified to
AssertionResult.setFailure(vars.get('x_api_key') == vars.get('apiKeyRec'))
And you don't even need any scripting for comparing 2 variables, it can be done using "normal" Response Assertion
It looks like you are forgetting to end all of your statements with semicolons from line 12 on. Add semicolons and let me know how that works!
I have the following code in JSR223 Sampler and I get following errors when I run this jmeter command. Can anyone please advise if something is wrong with my code? I'm basically reading a image and changing it little bit and sending a multipart/form-data POST request.
jmeter -n -Jthreads=20 -Jrampup=30 -Jduration=60 -Jiterations=-1 -t script.jmx
javax.script.ScriptException: java.net.SocketTimeoutException: Read timed out
Uncaught Exception java.lang.OutOfMemoryError: Java heap space in thread Thread[Thread Group 1-10,5,main]
import org.apache.http.HttpHeaders
import org.apache.http.client.config.RequestConfig
import org.apache.http.client.methods.HttpUriRequest
import org.apache.http.client.methods.RequestBuilder
import org.apache.http.conn.ssl.NoopHostnameVerifier
import org.apache.http.conn.ssl.SSLConnectionSocketFactory
import org.apache.http.conn.ssl.TrustStrategy
import org.apache.http.entity.StringEntity
import org.apache.http.impl.client.HttpClients
import org.apache.http.ssl.SSLContextBuilder
import org.apache.http.util.EntityUtils
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.HttpMultipartMode;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.awt.Graphics;
import java.io.ByteArrayOutputStream;
import org.apache.http.entity.ContentType;
import java.security.cert.CertificateException
import java.security.cert.X509Certificate
List<String> sendRequest(String url, String method, String body) {
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(2000)
.setSocketTimeout(3000)
.build();
BufferedImage image = ImageIO.read(new File("C:/Users/bd3249/Pictures/5.JPG"));
Graphics graphics = image.getGraphics();
graphics.setFont(graphics.getFont().deriveFont(16f));
graphics.drawString("User " + ctx.getThreadNum() + '-' + Math.random() +"; iteration: " + ctx.getVariables().getIteration(), 50, 50);
graphics.dispose();
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
ImageIO.write(image, "jpg", bytes);
final MultipartEntityBuilder multipartEntity = MultipartEntityBuilder.create();
multipartEntity.setMode(HttpMultipartMode.STRICT);
multipartEntity.addBinaryBody("File", bytes.toByteArray(),ContentType.IMAGE_JPEG, "5.JPG");
HttpUriRequest request = RequestBuilder.create(method)
.setConfig(requestConfig)
.setUri(url)
.setHeader("x-ibm-client-id","248a20f3-c39b-45d0-b26a-9019c26e9be8")
.setHeader("X-Client-Id","2861D410-773B-4DD9-AE74-882116B08856")
.setEntity(multipartEntity.build())
.build();
String req = "REQUEST:" + "User " + ctx.getThreadNum() + "; iteration: " + ctx.getVariables().getIteration() + " " + request.getRequestLine() + "\n";
def builder = new SSLContextBuilder();
builder.loadTrustMaterial(null, new TrustStrategy() {
#Override
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
return true;
}
});
def trustAllFactory = new SSLConnectionSocketFactory(builder.build(), new NoopHostnameVerifier());
HttpClients.custom().setSSLSocketFactory(trustAllFactory).build().withCloseable { httpClient ->
httpClient.execute(request).withCloseable { response ->
String res = "RESPONSE:" + "User " + ctx.getThreadNum() + "; iteration: " + ctx.getVariables().getIteration() + " " + response.getStatusLine() + (response.getEntity() != null ? EntityUtils.toString(response.getEntity()) : "") + "\n";
log.info(req + "\n" + res);
return Arrays.asList(req, res);
}
}
}
List test1 = sendRequest("https://test.com/upload", "POST", "");
The error you're getting clearly indicates that you don't have sufficient Java Heap space, by default JMeter 5.3 comes with 1 GB of heap and depending on your image size and response size it might be not enough for your test.
Use i.e. Active Threads Over Time listener to see how many virtual users were online when the error occurs and increase the heap size proportionally.
More information: 9 Easy Solutions for a JMeter Load Test “Out of Memory” Failure
I am trying to read kafka messages using a kafka consumer in jmeter using jsr223 sampler. iam unable to understand the error
[Response message: javax.script.ScriptException: javax.script.ScriptException: java.lang.ClassCastException: [Ljava.lang.String; cannot be cast to java.util.List]
Please Help me solve the issue so that i can subscribe and consume messages using the kafka consumer.
import java.util.Properties;
import java.util.Arrays;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.ConsumerRecord;
Properties props = new Properties();
String groupID = "REQUEST_RESPONSE_JOB_GROUP";
String clientID = "REQUEST_RESPONSE_JOB_CLIENT";
String BSID = "kafka:9092";
String topic = "PROC_REST_EVENTS";
props.put("bootstrap.servers", BSID);
props.put("group.id", groupID);
props.put("client.id", clientID);
props.put("enable.auto.commit", "true");
props.put("auto.commit.interval.ms", "1000");
props.put("session.timeout.ms", "30000");
props.put("key.deserializer","org.apache.kafka.common.serialization.StringDeserializer");
props.put("value.deserializer","org.apache.kafka.common.serialization.StringDeserializer");
props.put("partition.assignment.strategy","org.apache.kafka.clients.consumer.RangeAssignor");
KafkaConsumer<String, String> consumer = new KafkaConsumer<String, String>(props);
//Kafka Consumer subscribes list of topics here.
consumer.subscribe(Arrays.asList(topic));
//print the topic name
System.out.println("Subscribed to topic " + topic);
while (true) {
ConsumerRecords<String, String> records = consumer.poll(100);
for (ConsumerRecord<String, String> record : records)
// print the offset,key and value for the consumer records.
System.out.printf("offset = %d, key = %s, value = %s\n",
record.offset(), record.key(), record.value());
return records;
}
Most probably you're getting a List from the Kafka topic while your consumer expects a String, you need to amend consumer configuration to match the types which come from the topic.
Try out the following Groovy code which sends 3 messages to the test topic (if it doesn't exist you will need to create it) and reads them after this.
import org.apache.kafka.clients.consumer.ConsumerConfig
import org.apache.kafka.clients.consumer.KafkaConsumer
import org.apache.kafka.clients.producer.KafkaProducer
import org.apache.kafka.clients.producer.ProducerConfig
import org.apache.kafka.clients.producer.ProducerRecord
import org.apache.kafka.common.serialization.LongDeserializer
import org.apache.kafka.common.serialization.LongSerializer
import org.apache.kafka.common.serialization.StringDeserializer
import org.apache.kafka.common.serialization.StringSerializer
def BOOTSTRAP_SERVERS = 'localhost:9092'
def TOPIC = 'test'
Properties kafkaProps = new Properties()
kafkaProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS)
kafkaProps.put(ProducerConfig.CLIENT_ID_CONFIG, 'KafkaExampleProducer')
kafkaProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, LongSerializer.class.getName())
kafkaProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName())
kafkaProps.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS)
kafkaProps.put(ConsumerConfig.GROUP_ID_CONFIG, 'KafkaExampleConsumer')
kafkaProps.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, LongDeserializer.class.getName())
kafkaProps.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName())
def producer = new KafkaProducer<>(kafkaProps)
def consumer = new KafkaConsumer<>(kafkaProps)
1.upto(3) {
def record = new ProducerRecord<>(TOPIC, it as long, 'Hello from JMeter ' + it)
producer.send(record)
log.info('Sent record(key=' + record.key() + 'value=' + record.value() + ')')
}
consumer.subscribe(Collections.singletonList(TOPIC))
final int giveUp = 100
int noRecordsCount = 0
while (true) {
def consumerRecords = consumer.poll(1000)
if (consumerRecords.count() == 0) {
noRecordsCount++
if (noRecordsCount > giveUp) break
else continue
}
consumerRecords.each { record ->
log.info('Received Record:(' + record.key() + ', ' + record.value() + ')')
}
consumer.commitAsync()
}
consumer.close()
You should see output like:
Once done you should be able to use the above code as a basis for your own Kafka messages consumption testing. See Apache Kafka - How to Load Test with JMeter article for more information on Kafka load testing with JMeter.
I'm using Hawtio to browse my ActiveMQ queues. I'd also like to be able to edit a JMS message before resending it to another queue.
I don't see how I can edit a message in Hawtio, but that's fine, I guess this is not really legal to modify a message directly in the broker.
Instead, I though I would copy the message body and send a new message with the body modified. Now, the problem I'm facing is that I can only see the first 255 chars of the message body. How can I see the entire ActiveMQ message in hawtio? Not just the first 255 characters.
Hawtio uses to browse the queue the JMX interface. It calls the browse() method on the queue. Which returns the messages as CompositedData[].
When a ActiveMQBytesMessage is converted (check class org.apache.activemq.broker.jmx.OpenTypeSupport.ByteMessageOpenTypeFactory) two fields are added BodyLength and BodyPreview. The fields return the following data.
BodyLength - the length of JMS message body
BodyPreview - the first 255 bytes of the JMS message body (the length which is hardcoded, as Claus Ibsen already said in his answer ;-) )
Check in class org.apache.activemq.broker.jmx.OpenTypeSupport.ByteMessageOpenTypeFactory the method Map<String, Object> getFields(Object o).
Hawtio uses the field BodyPreview to display the message, for non text messages.
Check in Hawtio the file hawtio-web/src/main/webapp/app/activemq/js/browse.ts
function createBodyText(message) {
if (message.Text) {
...
} else if (message.BodyPreview) {
...
if (code === 1 || code === 2) {
// bytes and text
var len = message.BodyPreview.length;
var lenTxt = "" + textArr.length;
body = "bytes:\n" + bytesData + "\n\ntext:\n" + textData;
message.textMode = "bytes (" + len + " bytes) and text (" + lenTxt + " chars)";
} else {
// bytes only
var len = message.BodyPreview.length;
body = bytesData;
message.textMode = "bytes (" + len + " bytes)";
}
...
} else {
message.textMode = "unsupported";
...
If you want to change it you either have to change it in ActiveMQ or in Hawtio.
A lengthy and verbose example to demonstrate the explanation.
import static java.lang.System.out;
import java.lang.management.ManagementFactory;
import java.util.Enumeration;
import java.util.concurrent.TimeUnit;
import javax.jms.BytesMessage;
import javax.jms.Connection;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.QueueBrowser;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.management.MBeanServer;
import javax.management.MBeanServerInvocationHandler;
import javax.management.ObjectName;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeType;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.jmx.QueueViewMBean;
import org.apache.activemq.command.ActiveMQBytesMessage;
import org.apache.activemq.command.ActiveMQTextMessage;
public class BodyPreviewExample {
public static void main(String[] args) throws Exception {
String password = "password";
String user = "user";
String queueName = "TEST_QUEUE";
String brokerUrl = "tcp://localhost:61616";
BrokerService broker = BrokerFactory.createBroker("broker:"+brokerUrl);
broker.start();
broker.waitUntilStarted();
Connection conn = new ActiveMQConnectionFactory(brokerUrl)
.createConnection(user, password);
conn.start();
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue producerQueue = session.createQueue(queueName);
MessageProducer producer = session.createProducer(producerQueue);
// create a dummy message
StringBuilder sb = new StringBuilder(1000);
for (int i = 0; i < 100; i++) {
sb.append(">CAFEBABE<");
}
// create and send a JMSBytesMessage
BytesMessage bytesMsg = session.createBytesMessage();
bytesMsg.writeBytes(sb.toString().getBytes());
producer.send(bytesMsg);
// create and send a JMSTextMessage
TextMessage textMsg = session.createTextMessage();
textMsg.setText(sb.toString());
producer.send(textMsg);
producer.close();
out.printf("%nmessage info via session browser%n");
String format = "%-20s = %s%n";
Queue consumerQueue = session.createQueue(queueName);
QueueBrowser browser = session.createBrowser(consumerQueue);
for (Enumeration p = browser.getEnumeration(); p.hasMoreElements();) {
out.println();
Object next = p.nextElement();
if (next instanceof ActiveMQBytesMessage) {
ActiveMQBytesMessage amq = (ActiveMQBytesMessage) next;
out.printf(format, "JMSMessageID", amq.getJMSMessageID());
out.printf(format, "JMSDestination", amq.getJMSDestination());
out.printf(format, "JMSXMimeType", amq.getJMSXMimeType());
out.printf(format, "BodyLength", amq.getBodyLength());
} else if (next instanceof ActiveMQTextMessage) {
ActiveMQTextMessage amq = (ActiveMQTextMessage) next;
out.printf(format, "JMSMessageID", amq.getJMSMessageID());
out.printf(format, "JMSDestination", amq.getJMSDestination());
out.printf(format, "JMSXMimeType", amq.getJMSXMimeType());
out.printf(format, "text.length", amq.getText().length());
} else {
out.printf("unhandled message type: %s%n", next.getClass());
}
}
session.close();
conn.close();
// access the queue via JMX
out.printf("%nmessage info via JMX browse operation%n");
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
ObjectName name = new ObjectName("org.apache.activemq:type=Broker"
+ ",brokerName=localhost"
+ ",destinationType=Queue"
+ ",destinationName=" + queueName);
QueueViewMBean queue
= MBeanServerInvocationHandler.newProxyInstance(mbeanServer,
name, QueueViewMBean.class, true);
CompositeData[] browse = queue.browse();
for (CompositeData compositeData : browse) {
out.println();
CompositeType compositeType = compositeData.getCompositeType();
out.printf(format, "CompositeType", compositeType.getTypeName());
out.printf(format,"JMSMessageID",compositeData.get("JMSMessageID"));
if (compositeData.containsKey("BodyLength")) {
// body length of the ActiveMQBytesMessage
Long bodyLength = (Long) compositeData.get("BodyLength");
out.printf(format, "BodyLength", bodyLength);
// the content displayed by hawtio
Byte[] bodyPreview = (Byte[]) compositeData.get("BodyPreview");
out.printf(format, "size of BodyPreview", bodyPreview.length);
} else if (compositeData.containsKey("Text")) {
String text = (String) compositeData.get("Text");
out.printf(format, "Text.length()", text.length());
}
}
// uncomment if you want to check with e.g. JConsole
// TimeUnit.MINUTES.sleep(5);
broker.stop();
}
}
example output
message info via session browser
JMSMessageID = ID:hostname-50075-1467979678722-3:1:1:1:1
JMSDestination = queue://TEST_QUEUE
JMSXMimeType = jms/bytes-message
BodyLength = 1000
JMSMessageID = ID:hostname-50075-1467979678722-3:1:1:1:2
JMSDestination = queue://TEST_QUEUE
JMSXMimeType = jms/text-message
text.length = 1000
message info via JMX browse operation
CompositeType = org.apache.activemq.command.ActiveMQBytesMessage
JMSMessageID = ID:hostname-50075-1467979678722-3:1:1:1:1
BodyLength = 1000
size of BodyPreview = 255
CompositeType = org.apache.activemq.command.ActiveMQTextMessage
JMSMessageID = ID:hostname-50075-1467979678722-3:1:1:1:2
Text.length() = 1000
I think there is a hardcoded limitation in ActiveMQ when you query and browse the queues using the JMX API which is what hawtio uses. But cannot remember if its only 255 bytes or not higher.
Look in hawtio settings, there is maybe an ActiveMQ plugin setting to change the 255 chars, can't remember either ;)
I have made an ontology on Protege. it has . owl extension. I am trying to import this ontology in oracle 12c using jena. but model. Read method requires an rdf file. I am giving the code as well as error. Kindly help me in this case.
error
Exception in thread "main" com.hp.hpl.jena.shared.JenaException: java.lang.UnsatisfiedLinkError: no ocijdbc11 in java.library.path
at oracle.spatial.rdf.client.jena.Oracle.<init>(Oracle.java:207)
at test.TestClass.main(TestClass.java:26)
code package test;
import java.io.InputStream;
import com.hp.hpl.jena.rdf.model.*;
import oracle.spatial.rdf.client.jena.GraphOracleSem;
import oracle.spatial.rdf.client.jena.ModelOracleSem;
import oracle.spatial.rdf.client.jena.Oracle;
import oracle.spatial.rdf.client.jena.OracleUtils;
import com.hp.hpl.jena.graph.GraphUtil;
import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.util.FileManager;
public class TestJena{
public static void main(String[] args) throws Exception
{
//String szJdbcURL = args[0];
//String szUser = args[1];
//String szPasswd = args[2];
//String szModelName = args[3];
// in memory Jena Model
Model model = ModelFactory.createDefaultModel();
InputStream is = FileManager.get().open("E:/abcd.owl");
model.read(is, "", "RDF/XML");
is.close();
Oracle oracle = new Oracle("jdbc:oracle:oci8:#", "c##hr_admin","Hira123");
ModelOracleSem modelDest = ModelOracleSem.createOracleSemModel(oracle,"M1");
GraphOracleSem g = modelDest.getGraph();
g.dropApplicationTableIndex();
int method = 2; // try bulk loader
String tbs = "SYSAUX"; // can be customized
if (method == 0) {
System.out.println("start incremental");
modelDest.add(model);
System.out.println("end size " + modelDest.size());
}
else if (method == 1) {
System.out.println("start batch load");
g.getBulkUpdateHandler().addInBatch(
GraphUtil.findAll(model.getGraph()), tbs);
System.out.println("end size " + modelDest.size());
}
else {
System.out.println("start bulk load");
g.getBulkUpdateHandler().addInBulk(
GraphUtil.findAll(model.getGraph()), tbs);
System.out.println("end size " + modelDest.size());
}
g.rebuildApplicationTableIndex();
long lCount = g.getCount(Triple.ANY);
System.out.println("Asserted triples count: " + lCount);
model.close();
OracleUtils.dropSemanticModel(oracle, "M1");
oracle.dispose();
}
}
You can rename the file to RDF: under the assumption that the format you used for the ontology is RDF/XML (the default), all that is needed is changing the file extension.
Regarding the error you post, you are missing a binary library. You need to set java.library.path to point at the folder containing the library mentioned in the error.
See for example how to set java library path for processing for how to do this.