Inserting into cassandra using hector on Glassfish 3.1 - eclipse

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.

Related

Why Primefaces donutChart is not working?

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.

Talend - The import org.apache cannot be resolved

I've created a custom Talend component, which at certain step connects to an external Http service. For that, I'm using org.apache.commons.httpclient through javajet imports. I've seen the modules already exist in the Modules view. Nevertheless, when running a job the console outputs:
Execution failed : Failed to generate code.
[----------
1. ERROR in /Users/frb/Downloads/TOS_DI-20160510_1709-V6.2.0/workspace/.JETEmitters/src/org/talend/designer/codegen/translators/ngsi/orion/TOrionAppendBeginJava.java (at line 14)
import org.apache.commons.httpclient.*;
^^^^^^^^^^
The import org.apache cannot be resolved
----------
2. ERROR in /Users/frb/Downloads/TOS_DI-20160510_1709-V6.2.0/workspace/.JETEmitters/src/org/talend/designer/codegen/translators/ngsi/orion/TOrionAppendBeginJava.java (at line 15)
import org.apache.commons.httpclient.methods.*;
^^^^^^^^^^
The import org.apache cannot be resolved
----------
3. ERROR in /Users/frb/Downloads/TOS_DI-20160510_1709-V6.2.0/workspace/.JETEmitters/src/org/talend/designer/codegen/translators/ngsi/orion/TOrionAppendBeginJava.java (at line 16)
import org.apache.commons.httpclient.params.HttpMethodParams;;
^^^^^^^^^^
The import org.apache cannot be resolved
----------
3 problems (3 errors)
]
Any hints about how to fix this issue? My Talend version is 6.2.0.
EDIT 1
This is my begin code:
<%# jet
imports="
org.talend.core.model.process.INode
org.talend.core.model.process.ElementParameterParser
org.talend.core.model.metadata.IMetadataTable
org.talend.core.model.metadata.IMetadataColumn
org.talend.core.model.process.IConnection
org.talend.core.model.process.IConnectionCategory
org.talend.designer.codegen.config.CodeGeneratorArgument
org.talend.core.model.metadata.types.JavaTypesManager
org.talend.core.model.metadata.types.JavaType
java.util.List
java.util.Map
org.apache.commons.httpclient.*
org.apache.commons.httpclient.methods.*
org.apache.commons.httpclient.params.HttpMethodParams
"
%>
<%
// Get the CID
CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
INode node = (INode)codeGenArgument.getArgument();
String cid = node.getUniqueName();
// Get the component parameters
String orionEndpoint = ElementParameterParser.getValue(node, "__ORION_ENDPOINT__");
String authEndpoint = ElementParameterParser.getValue(node, "__AUTH_ENDPOINT__");
String authUsername = ElementParameterParser.getValue(node, "__AUTH_USERNAME__");
String authPassword = ElementParameterParser.getValue(node, "__AUTH_PASSWORD__");
String entityIdField = ElementParameterParser.getValue(node, "__ENTITY_ID_FIELD__");
String entityTypeField = ElementParameterParser.getValue(node, "__ENTITY_TYPE_FIELD__");
String defaultEntityType = ElementParameterParser.getValue(node, "__DEFAULT_ENTITY_TYPE__");
String ignoredFilds = ElementParameterParser.getValue(node, "__IGNORED_FIELDS__");
%>
System.out.println("I am the begin section");
HttpClient client = new HttpClient();
PostMethod method = new PostMethod(<%=authEndpoint%>);
method.setRequestHeader(new Header("Content-Type", "application/json"));
method.setRequestBody("{\"username\":\"" + <%=authUsername%> + "\",\"password\":\"" + <%=authPassword%> + "\"}");
try {
int statusCode = client.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: " + method.getStatusLine());
} // if
byte[] responseBody = method.getResponseBody();
System.out.println(new String(responseBody));
} catch (HttpException e) {
System.err.println("Fatal protocol violation: " + e.getMessage());
e.printStackTrace();
} catch (IOException e) {
System.err.println("Fatal transport error: " + e.getMessage());
e.printStackTrace();
} finally {
method.releaseConnection();
} // try
EDIT 2
I've added the following to my Component Descriptor file:
<IMPORTS>
<IMPORT
NAME="commons-httpclient"
MODULE="commons-httpclient-3.1.jar"
REQUIRED="true"
/>
</IMPORTS>
Now, in the modules view I'm able to see the following:
Sadly, the component outputs the same errors.
EDIT 3
After removing the imports and using fully qualified names, as suggested by #Balazs Gunics, the code seems to be generated. Nevertheless, some other errors related to commons-httpclient arise at running time:
Starting job job_tOrionAppend at 08:20 21/06/2016.
[statistics] connecting to socket on port 3916
[statistics] connected
I am the begin section
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.apache.commons.httpclient.HttpClient.<clinit>(HttpClient.java:66)
at iotp_talend_connectors.job_torionappend_0_1.job_tOrionAppend.tMysqlInput_1Process(job_tOrionAppend.java:854)
at iotp_talend_connectors.job_torionappend_0_1.job_tOrionAppend.tMysqlConnection_1Process(job_tOrionAppend.java:422)
at iotp_talend_connectors.job_torionappend_0_1.job_tOrionAppend.runJobInTOS(job_tOrionAppend.java:1355)
at iotp_talend_connectors.job_torionappend_0_1.job_tOrionAppend.main(job_tOrionAppend.java:1212)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
[statistics] disconnected
[statistics] disconnected
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 5 more
Job job_tOrionAppend ended at 08:20 21/06/2016. [exit code=1]
So in the begin.javajet code of yours the following code will only import these libraries for the code generation itself. But you need them to the generated code.
Generating java using java makes it hard to oversee this.
<%# jet
imports="
org.apache.commons.httpclient.*
org.apache.commons.httpclient.methods.*
org.apache.commons.httpclient.params.HttpMethodParams
So what you need is to have these imports added to the generated code. Well that is not really possible :( https://www.talendforge.org/forum/viewtopic.php?id=3670 To do that you need to modify the xml descriptor for your component.
So your imports are right. All you have to do is make sure you use the fully qualified names. I.e.: This piece of code:
System.out.println("I am the begin section");
HttpClient client = new HttpClient();
PostMethod method = new PostMethod(<%=authEndpoint%>);
Have to be rewritten to look like this:
System.out.println("I am the begin section");
org.apache.commons.httpclient.HttpClient client =
new org.apache.commons.httpclient.HttpClient();
org.apache.commons.httpclient.methods.PostMethod method =
new org.apache.commons.httpclient.methods.PostMethod(<%=authEndpoint%>);
Yes, it would be way more elegant if we could import the classes and use them.

Adobe CQ: Injecting services via #Reference returns null

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!

Code is Working Properly in NetBeans but not in Eclipse

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

iText ClassNotFound Exception

I'm using iText library to work with Acrobat Forms. The servlet compiled without any errors. I imported the external jar files of iText. After compiling, i packaged and prepared an executable .war file (Main.war) and pasted it in the deploy folder of jboss. However, on executing, i get a ClassNotFoundException Error.
Here's the stack trace
java.lang.ClassNotFoundException: com.itextpdf.text.DocumentException from BaseClassLoader#955d1c{VFSClassLoaderPolicy#13ed0e{name=vfszip:/E:/jboss-5.0.1.GA/server/default/deploy/Main.war/ domain=Clas
sLoaderDomain#1074641{name=vfszip:/E:/jboss-5.0.1.GA/server/default/deploy/Main.war/ parentPolicy=AFTER_BUT_JAVA_BEFORE parent=ClassLoaderDomain#dc9766{DefaultDomain}} roots=[MemoryContextHandler#3161
723[path= context=vfsmemory://5c4o12z-o9ytfs-grndwcq5-1-grndwom8-1y real=vfsmemory://5c4o12z-o9ytfs-grndwcq5-1-grndwom8-1y], ZipEntryHandler#22421558[path=Main.war/WEB-INF/classes context=file:/E:/jbo
ss-5.0.1.GA/server/default/deploy/ real=file:/E:/jboss-5.0.1.GA/server/default/deploy/Main.war/WEB-INF/classes]] delegates=null exported=[] <IMPORT-ALL>NON_EMPTY}}
at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:422)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
at java.lang.Class.getConstructor0(Class.java:2699)
at java.lang.Class.newInstance0(Class.java:326)
at java.lang.Class.newInstance(Class.java:308)
at org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:258)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1006)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:777)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:601)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
And here's my servlet code -
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.AcroFields;
import com.itextpdf.text.pdf.FdfReader;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import java.io.*;
import java.net.*;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Main extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
response.setContentType("application/pdf");
try{
FdfReader FDF = new FdfReader(request.getInputStream());
System.out.println("*************Recieved inputStream***********");
InputStream is = request.getInputStream();
PdfReader reader = new PdfReader(is, null);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfStamper stamper = new PdfStamper(reader, baos);
AcroFields fields = stamper.getAcroFields();
fields.setFields(FDF);
stamper.setFormFlattening(true);
stamper.close();
OutputStream os = response.getOutputStream();
baos.writeTo(os);
os.flush();
}
catch (DocumentException DE)
{
throw new IOException(DE.getMessage());
}
}
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
Can anyone tell me what's the problem????? Its urgent please..
Sameer
Looks like a DocumentException would be thrown, but the corresponding class can not be found by JBoss.
Are you sure that the iText .jar gets packaged with your webapp? Maybe have a look at the .WAR file you're deploying and check if the iText library is in there...
If not (or you don't want to) make sure to put it in the JBoss' lib folder. in /jboss-as/lib/ or /jboss-as/server/default/lib/.
Edit:
Your JAR should end up having a structure that looks about like this
.
|-- index.html
|-- META-INF
| `-- MANIFEST.MF
|
`-- WEB-INF
|-- classes
| `-- <your code is here>
|
`-- lib
`-- <here are your packaged .jar files>
[Mind, this is simplified and does not show all the files...]