I have tried the following jsp file in both IDEs. It is working good in NetBeans, but it is not working in Eclipse. The program is to get the time from a NTP server.
Code is as follows
<%--
Document : GetNTP
Created on : May 21, 2013, 2:21:29 PM
Author : Maximin
--%>
<%#page import="java.net.InetAddress"%>
<%#page import="java.text.SimpleDateFormat"%>
<%#page import ="java.util.Date"%>
<%#page import="org.apache.commons.net.ntp.NTPUDPClient"%>
<%#page import="org.apache.commons.net.ntp.TimeInfo"%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1><%
String TIME_SERVER = "time.nist.gov";
NTPUDPClient timeClient = new NTPUDPClient();
InetAddress inetAddress = InetAddress.getByName(TIME_SERVER);
TimeInfo timeInfo = timeClient.getTime(inetAddress);
long returnTime = timeInfo.getReturnTime();
Date time = new Date(returnTime);
SimpleDateFormat sdf= new SimpleDateFormat("dd-MM-yyyy");
out.println(sdf.format(time));
%></h1>
</body>
</html>
When i run this in eclipse I get as
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 17 in the generated java file
Only a type can be imported. org.apache.commons.net.ntp.NTPUDPClient resolves to a package
An error occurred at line: 18 in the generated java file
Only a type can be imported. org.apache.commons.net.ntp.TimeInfo resolves to a package
An error occurred at line: 18 in the jsp file: /GetTime.jsp
NTPUDPClient cannot be resolved to a type
15: <body>
16: <h1><%
17: String TIME_SERVER = "time.nist.gov";
18: NTPUDPClient timeClient = new NTPUDPClient();
19: InetAddress inetAddress = InetAddress.getByName(TIME_SERVER);
20: TimeInfo timeInfo = timeClient.getTime(inetAddress);
21: long returnTime = timeInfo.getReturnTime();
Why is it so?
What should I do to make it run on Eclipse?
Worked for me:
"Right click on your project and choose Properties (it's at the bottom...probably). Deployment Assembly is one of the pages. If the jar with the NTP classes is not in WebContent/WEB-INF/lib or otherwise on the server, make sure it is on this page."
Answered by nitind
Related
I tried to use donut chart from primefaces cause I used primefaces but the chart won't working.
So this is my XHTML
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
template="/WEB-INF/templates/new-dashbord-landing-page.xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<ui:define name="postMetadata">
</ui:define>
<ui:define name="content">
<div class="chart-donut">
<p:donutChart model="#{bean.donutModel}"/>
</div>
</ui:define>
</ui:composition>
for p:donutChart in my case I cannot use it, I don't know why
and this is my java
import org.apache.poi.ss.usermodel.charts.ChartData;
import org.primefaces.model.chart.DonutChartModel;
import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;
public class Bean {
private DonutChartModel donutModel;
#PostConstruct
public void init() {
donutModel = new DonutChartModel();
ChartData data = new ChartData();
DonutChartDataSet dataSet = new DonutChartDataSet();
List<Number> values = new ArrayList<>();
values.add(300);
values.add(50);
values.add(100);
dataSet.setData(values);
List<String> bgColors = new ArrayList<>();
bgColors.add("rgb(255, 99, 132)");
bgColors.add("rgb(54, 162, 235)");
bgColors.add("rgb(255, 205, 86)");
dataSet.setBackgroundColor(bgColors);
data.addChartDataSet(dataSet);
List<String> labels = new ArrayList<>();
labels.add("Red");
labels.add("Blue");
labels.add("Yellow");
data.setLabels(labels);
donutModel.setData(data);
}
public DonutChartModel getDonutModel() {
return donutModel;
}
}
and I use the same code like on primefaces documentation. I just want use the chart :(
The problem is the import for DonutChartModel. You're picking up the older version used for p:chart components. For the Charts.js based components the correct package name is:
org.primefaces.model.charts.donut.DonutChartModel
Slightly off topic, the bean also needs annotating. e.g. #Named and #RequestScoped.
EDITED :
I edited my swagger path. But i am getting below error now.
[main] INFO io.swagger.parser.Swagger20Parser - reading from https://SWAGGERFILE/api
[main] INFO io.swagger.parser.Swagger20Parser - reading from https://SWAGGERFILE/api
Exception in thread "main" java.lang.RuntimeException: missing swagger input or config!
at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:764)
at io.swagger.codegen.cmd.Generate.run(Generate.java:299)
at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)
Below is the command i am using in mac to generate dart package
java -jar /Users/PATH/modules/swagger-codegen-cli/src/main/target/swagger-codegen-cli.jar generate -i https://SWAGGERFILE/api-docs/#/ -l dart -o /Users/PATH/STORE/DART/PACKAGE
It works fine for
java -jar /Users/PATH/modules/swagger-codegen-cli/src/main/target/swagger-codegen-cli.jar generate -i http://petstore.swagger.io/v2/swagger.json -l dart -o /Users/PATH/STORE/DART/PACKAGE
Below is the error i am getting :
[main] INFO io.swagger.parser.Swagger20Parser - reading from https://SWAGGERFILE/api-docs/#/
[main] WARN io.swagger.parser.util.DeserializationUtils - Error snake-parsing yaml content
io.swagger.parser.util.DeserializationUtils$SnakeException: Exception safe-checking yaml content (maxDepth 2000)
at io.swagger.parser.util.DeserializationUtils$CustomSnakeYamlConstructor.getSingleData(DeserializationUtils.java:300)
at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:525)
at org.yaml.snakeyaml.Yaml.load(Yaml.java:438)
at io.swagger.parser.util.DeserializationUtils.readYamlTree(DeserializationUtils.java:137)
at io.swagger.parser.Swagger20Parser.deserializeYaml(Swagger20Parser.java:83)
at io.swagger.parser.Swagger20Parser.convertToSwagger(Swagger20Parser.java:125)
at io.swagger.parser.Swagger20Parser.read(Swagger20Parser.java:109)
at io.swagger.parser.SwaggerParser.read(SwaggerParser.java:69)
at io.swagger.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:437)
at io.swagger.codegen.cmd.Generate.run(Generate.java:297)
at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)
Caused by: mapping values are not allowed here
in 'string', line 14, column 17:
box-sizing: border-box;
^
at org.yaml.snakeyaml.scanner.ScannerImpl.fetchValue(ScannerImpl.java:869)
at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:358)
at org.yaml.snakeyaml.scanner.ScannerImpl.peekToken(ScannerImpl.java:250)
at org.yaml.snakeyaml.parser.ParserImpl$ParseDocumentEnd.produce(ParserImpl.java:253)
at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:158)
at org.yaml.snakeyaml.parser.ParserImpl.getEvent(ParserImpl.java:168)
at org.yaml.snakeyaml.composer.Composer.getNode(Composer.java:87)
at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:108)
at io.swagger.parser.util.DeserializationUtils$CustomSnakeYamlConstructor.getSingleData(DeserializationUtils.java:279)
... 10 more
[main] INFO io.swagger.parser.Swagger20Parser - reading from https://production.user-api.api.findnemo.in/api-docs/#/
[main] WARN io.swagger.parser.util.DeserializationUtils - Error snake-parsing yaml content
io.swagger.parser.util.DeserializationUtils$SnakeException: Exception safe-checking yaml content (maxDepth 2000)
at io.swagger.parser.util.DeserializationUtils$CustomSnakeYamlConstructor.getSingleData(DeserializationUtils.java:300)
at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:525)
at org.yaml.snakeyaml.Yaml.load(Yaml.java:438)
at io.swagger.parser.util.DeserializationUtils.readYamlTree(DeserializationUtils.java:137)
at io.swagger.parser.Swagger20Parser.deserializeYaml(Swagger20Parser.java:83)
at io.swagger.parser.Swagger20Parser.convertToSwagger(Swagger20Parser.java:125)
at io.swagger.parser.Swagger20Parser.read(Swagger20Parser.java:109)
at io.swagger.parser.SwaggerParser.read(SwaggerParser.java:83)
at io.swagger.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:437)
at io.swagger.codegen.cmd.Generate.run(Generate.java:297)
at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)
Caused by: mapping values are not allowed here
in 'string', line 14, column 17:
box-sizing: border-box;
^
at org.yaml.snakeyaml.scanner.ScannerImpl.fetchValue(ScannerImpl.java:869)
at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:358)
at org.yaml.snakeyaml.scanner.ScannerImpl.peekToken(ScannerImpl.java:250)
at org.yaml.snakeyaml.parser.ParserImpl$ParseDocumentEnd.produce(ParserImpl.java:253)
at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:158)
at org.yaml.snakeyaml.parser.ParserImpl.getEvent(ParserImpl.java:168)
at org.yaml.snakeyaml.composer.Composer.getNode(Composer.java:87)
at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:108)
at io.swagger.parser.util.DeserializationUtils$CustomSnakeYamlConstructor.getSingleData(DeserializationUtils.java:279)
... 10 more
[main] ERROR io.swagger.parser.SwaggerCompatConverter - failed to read resource listing
com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
at [Source: (String)"
<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Swagger UI</title>
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" >
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" /><link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
<style>
html
{
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}"[truncated 2632 chars]; line: 2, column: 2]
at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1840)
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:712)
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:637)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._handleOddValue(ReaderBasedJsonParser.java:1917)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:773)
at com.fasterxml.jackson.databind.ObjectMapper._readTreeAndClose(ObjectMapper.java:4231)
at com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:2711)
at io.swagger.parser.SwaggerCompatConverter.readResourceListing(SwaggerCompatConverter.java:194)
at io.swagger.parser.SwaggerCompatConverter.read(SwaggerCompatConverter.java:123)
at io.swagger.parser.SwaggerParser.read(SwaggerParser.java:83)
at io.swagger.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:437)
at io.swagger.codegen.cmd.Generate.run(Generate.java:297)
at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)
Exception in thread "main" java.lang.RuntimeException: missing swagger input or config!
at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:764)
at io.swagger.codegen.cmd.Generate.run(Generate.java:299)
at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)
shwetadodiya#shwetas-MBP swagger-codegen-master % java -jar /Users/shwetadodiya/Documents/FlutterProjects/Swagger/swagger-codegen-master/modules/swagger-codegen-cli/src/main/target/swagger-codegen-cli.jar generate -i https://production.user-api.api.findnemo.in/api-docs/#/ -l dart -o /Users/shwetadodiya/Documents/FlutterProjects/Swagger/SwaggerCode
[main] INFO io.swagger.parser.Swagger20Parser - reading from https://production.user-api.api.findnemo.in/api-docs/#/
[main] WARN io.swagger.parser.util.DeserializationUtils - Error snake-parsing yaml content
io.swagger.parser.util.DeserializationUtils$SnakeException: Exception safe-checking yaml content (maxDepth 2000)
at io.swagger.parser.util.DeserializationUtils$CustomSnakeYamlConstructor.getSingleData(DeserializationUtils.java:300)
at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:525)
at org.yaml.snakeyaml.Yaml.load(Yaml.java:438)
at io.swagger.parser.util.DeserializationUtils.readYamlTree(DeserializationUtils.java:137)
at io.swagger.parser.Swagger20Parser.deserializeYaml(Swagger20Parser.java:83)
at io.swagger.parser.Swagger20Parser.convertToSwagger(Swagger20Parser.java:125)
at io.swagger.parser.Swagger20Parser.read(Swagger20Parser.java:109)
at io.swagger.parser.SwaggerParser.read(SwaggerParser.java:69)
at io.swagger.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:437)
at io.swagger.codegen.cmd.Generate.run(Generate.java:297)
at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)
Caused by: mapping values are not allowed here
in 'string', line 14, column 17:
box-sizing: border-box;
^
at org.yaml.snakeyaml.scanner.ScannerImpl.fetchValue(ScannerImpl.java:869)
at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:358)
at org.yaml.snakeyaml.scanner.ScannerImpl.peekToken(ScannerImpl.java:250)
at org.yaml.snakeyaml.parser.ParserImpl$ParseDocumentEnd.produce(ParserImpl.java:253)
at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:158)
at org.yaml.snakeyaml.parser.ParserImpl.getEvent(ParserImpl.java:168)
at org.yaml.snakeyaml.composer.Composer.getNode(Composer.java:87)
at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:108)
at io.swagger.parser.util.DeserializationUtils$CustomSnakeYamlConstructor.getSingleData(DeserializationUtils.java:279)
... 10 more
[main] INFO io.swagger.parser.Swagger20Parser - reading from https://production.user-api.api.findnemo.in/api-docs/#/
[main] WARN io.swagger.parser.util.DeserializationUtils - Error snake-parsing yaml content
io.swagger.parser.util.DeserializationUtils$SnakeException: Exception safe-checking yaml content (maxDepth 2000)
at io.swagger.parser.util.DeserializationUtils$CustomSnakeYamlConstructor.getSingleData(DeserializationUtils.java:300)
at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:525)
at org.yaml.snakeyaml.Yaml.load(Yaml.java:438)
at io.swagger.parser.util.DeserializationUtils.readYamlTree(DeserializationUtils.java:137)
at io.swagger.parser.Swagger20Parser.deserializeYaml(Swagger20Parser.java:83)
at io.swagger.parser.Swagger20Parser.convertToSwagger(Swagger20Parser.java:125)
at io.swagger.parser.Swagger20Parser.read(Swagger20Parser.java:109)
at io.swagger.parser.SwaggerParser.read(SwaggerParser.java:83)
at io.swagger.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:437)
at io.swagger.codegen.cmd.Generate.run(Generate.java:297)
at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)
Caused by: mapping values are not allowed here
in 'string', line 14, column 17:
box-sizing: border-box;
^
at org.yaml.snakeyaml.scanner.ScannerImpl.fetchValue(ScannerImpl.java:869)
at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:358)
at org.yaml.snakeyaml.scanner.ScannerImpl.peekToken(ScannerImpl.java:250)
at org.yaml.snakeyaml.parser.ParserImpl$ParseDocumentEnd.produce(ParserImpl.java:253)
at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:158)
at org.yaml.snakeyaml.parser.ParserImpl.getEvent(ParserImpl.java:168)
at org.yaml.snakeyaml.composer.Composer.getNode(Composer.java:87)
at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:108)
at io.swagger.parser.util.DeserializationUtils$CustomSnakeYamlConstructor.getSingleData(DeserializationUtils.java:279)
... 10 more
[main] ERROR io.swagger.parser.SwaggerCompatConverter - failed to read resource listing
com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
at [Source: (String)"
<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Swagger UI</title>
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" >
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" /><link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
<style>
html
{
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}"[truncated 2632 chars]; line: 2, column: 2]
at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1840)
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:712)
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:637)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._handleOddValue(ReaderBasedJsonParser.java:1917)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:773)
at com.fasterxml.jackson.databind.ObjectMapper._readTreeAndClose(ObjectMapper.java:4231)
at com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:2711)
at io.swagger.parser.SwaggerCompatConverter.readResourceListing(SwaggerCompatConverter.java:194)
at io.swagger.parser.SwaggerCompatConverter.read(SwaggerCompatConverter.java:123)
at io.swagger.parser.SwaggerParser.read(SwaggerParser.java:83)
at io.swagger.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:437)
at io.swagger.codegen.cmd.Generate.run(Generate.java:297)
at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)
Exception in thread "main" java.lang.RuntimeException: missing swagger input or config!
at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:764)
at io.swagger.codegen.cmd.Generate.run(Generate.java:299)
at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)
The -i parameter expects the path to the OpenAPI YAML/JSON file. It looks like https://SWAGGERFILE/api-docs/#/ points to an HTML page (e.g. Swagger UI) and not the actual OpenAPI YAML/JSON file.
If you use Swagger UI, here's how you can get the YAML/JSON file link:
How to export a Swagger JSON/YAML file from Swagger UI?
I'm trying to inject a service into the component via #Reference annotation in Adobe CQ5, but after deployment it always returns null to me instead of service instance.
#Component(immediate = true)
#Service(value = GoodbyeWorldService.class)
public class GoodbyeWorldService {
#Reference
protected Scheduler scheduler;
private final static Logger LOGGER = LoggerFactory.getLogger(GoodbyeWorldService.class);
public void get() {
LOGGER.info("Scheduler is " + this.scheduler);
}
}
The JSP:
<%# include file="/apps/cqblueprints-example/components/global.jspx" %>
<jsp:directive.page contentType="text/html" pageEncoding="UTF-8"/>
<jsp:useBean id="goodbye" class="com.cqblueprints.example.services.GoodbyeWorldService" scope="page" />
<% goodbye.get(); %>
In the log I get:
2014-04-02 12:24:09.999 INFO [com.cqblueprints.example.services.GoodbyeWorldService] Scheduler is null
I've tested other simple print methods from this bean. They are working like charm.
What am I missing?
In order to have #Reference fields injected by the OSGi, you can't treat your service as a Java bean. Use SlingScriptHelper available as the sling object in the JSP files to get the service in a proper way:
<% GoodbyeWorldService service = sling.getService(GoodbyeWorldService.class); %>
<%= service.get() %>
Full example:
<%#page session="false" import="your.package.GoodbyeWorldService"
%><%#taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0"
%><sling:defineObjects/><%
GoodbyeWorldService service = sling.getService(GoodbyeWorldService.class);
%><%= service.get() %>
The problem is solved! I have just updated the version of maven-scr-plugin from 1.7.4 to 1.9.0 and it started to work! Now I am retrieving my instances via #Reference annotations and I see my service in "Services" and "Components" tabs in Felix OSGi Console. Thanks to all who replied here!
Can any one help me in setting [ Doctype and xml:lang="en" ] while creating XML using JDOM?
The xml:lang attribute can be set on any Element with the following:
public static void main(String[] args) throws IOException {
Element root = new Element("root");
DocType dtype = new DocType(root.getName());
Document doc = new Document(root, dtype);
root.setAttribute("lang", "en", Namespace.XML_NAMESPACE);
new XMLOutputter(Format.getPrettyFormat()).output(doc, System.out);
}
Here I have also created a DocType, but it is pretty empty. You can change it to suite your needs by reading the documentation
The code above produces:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE root>
<root xml:lang="en" />
Im trying to insert a keyspace into cassandra using hector and the SchemaManipulation example given from the hector wiki.
package net.zanity.live;
import java.util.Arrays;
import java.util.List;
import me.prettyprint.cassandra.model.BasicColumnDefinition;
import me.prettyprint.cassandra.model.BasicColumnFamilyDefinition;
import me.prettyprint.cassandra.serializers.StringSerializer;
import me.prettyprint.cassandra.service.ThriftCfDef;
import me.prettyprint.hector.api.Cluster;
import me.prettyprint.hector.api.ddl.*;
import me.prettyprint.hector.api.exceptions.HectorException;
import me.prettyprint.hector.api.factory.HFactory;
/**
*
* #author zznate
*
*/
public class SchemaManipulation {
private static final String DYN_KEYSPACE = "YOUWantToSeeThis";
private static final String DYN_CF = "DynamicCf";
private static final String CF_SUPER = "SuperCf";
private static StringSerializer stringSerializer = StringSerializer.get();
public static void main(String[] args) throws Exception {
Cluster cluster = HFactory.getOrCreateCluster("TestCluster", "localhost:9160");
try {
if ( cluster.describeKeyspace(DYN_KEYSPACE) != null ) {
cluster.dropKeyspace(DYN_KEYSPACE);
}
BasicColumnDefinition columnDefinition = new BasicColumnDefinition();
columnDefinition.setName(stringSerializer.toByteBuffer("birthdate"));
columnDefinition.setIndexName("birthdate_idx");
columnDefinition.setIndexType(ColumnIndexType.KEYS);
columnDefinition.setValidationClass(ComparatorType.LONGTYPE.getClassName());
BasicColumnFamilyDefinition columnFamilyDefinition = new BasicColumnFamilyDefinition();
columnFamilyDefinition.setKeyspaceName(DYN_KEYSPACE);
columnFamilyDefinition.setName(DYN_CF);
columnFamilyDefinition.addColumnDefinition(columnDefinition);
BasicColumnFamilyDefinition superCfDefinition = new BasicColumnFamilyDefinition();
superCfDefinition.setKeyspaceName(DYN_KEYSPACE);
superCfDefinition.setName(CF_SUPER);
superCfDefinition.setColumnType(ColumnType.SUPER);
ColumnFamilyDefinition cfDefStandard = new ThriftCfDef(columnFamilyDefinition);
ColumnFamilyDefinition cfDefSuper = new ThriftCfDef(superCfDefinition);
KeyspaceDefinition keyspaceDefinition =
HFactory.createKeyspaceDefinition(DYN_KEYSPACE, "org.apache.cassandra.locator.SimpleStrategy",
1, Arrays.asList(cfDefStandard, cfDefSuper));
cluster.addKeyspace(keyspaceDefinition);
// insert some data
List<KeyspaceDefinition> keyspaces = cluster.describeKeyspaces();
for (KeyspaceDefinition kd : keyspaces) {
if ( kd.getName().equals(DYN_KEYSPACE) ) {
System.out.println("Name: " +kd.getName());
System.out.println("RF: " +kd.getReplicationFactor());
System.out.println("strategy class: " +kd.getStrategyClass());
List<ColumnFamilyDefinition> cfDefs = kd.getCfDefs();
for (ColumnFamilyDefinition def : cfDefs) {
System.out.println(" CF Type: " +def.getColumnType());
System.out.println(" CF Name: " +def.getName());
System.out.println(" CF Metadata: " +def.getColumnMetadata());
}
}
}
} catch (HectorException he) {
he.printStackTrace();
}
cluster.getConnectionManager().shutdown();
}
}
The jsp code:
<%#page language="java" import="net.zanity.live.*" contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>GlassFish JSP Page</title>
</head>
<body>
<% out.println("CAKrE"); Test test = new Test(); out.println("sting displayed here: " + test.Testt()); %>
After this text loads the cassandra schema test will run and prolly crash the webapp
<% SchemaManipulation cI = new SchemaManipulation(); SchemaManipulation.main(new String [0]); %>
</body>
</html>
Im running this code in Eclipse 3.7.1 Indigo and the code when executed as a java application works and inserts into cassandra, but when i run it on the server it does not.
Cassandra is running on its default port as a local host and glasfish is also running on a local host on port 8080.
I think the issue is im not placing the hector jars in the correct place, the hector jars are already added to the buildpath but im not sure if that has added them to the server as well.
Any help would be appreciated as I'm failing to find useful documentation for cassandra.
EDIT: i have added the jar's to the server that was not the problem, issue is still unresolved.
Stack Trace of errors:
WARNING: StandardWrapperValve[jsp]: PWC1406: Servlet.service() for servlet jsp threw exception
java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at me.prettyprint.cassandra.service.AbstractCluster.<init>(AbstractCluster.java:44)
at me.prettyprint.cassandra.service.ThriftCluster.<init>(ThriftCluster.java:21)
at me.prettyprint.hector.api.factory.HFactory.createCluster(HFactory.java:192)
at me.prettyprint.hector.api.factory.HFactory.getOrCreateCluster(HFactory.java:139)
at me.prettyprint.hector.api.factory.HFactory.getOrCreateCluster(HFactory.java:128)
at net.zanity.live.SchemaManipulation.main(SchemaManipulation.java:36)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:61)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:403)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:492)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:378)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1534)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:326)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:227)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:170)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:822)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:719)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1013)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
I think you just forgot to add also the slf4j jar.
That should solve the problem.
In fact the stack trace says it cannot find the class org.slf4j.LoggerFactory which is included in the slf4j jar.
This jar is needed for hector, and indeed hector rises the exception.