How to run jetty with https using sbt 0.7.7 - scala

I am using jetty 2.1.6 and sbt 0.7.7.
Currently my app is running on http, but I want to run with https
I tried following approach to run it with https :
http://wiki.eclipse.org/Jetty/Howto/Configure_SSL#Configuring_Jetty_for_SSL
Then i set below code in build.scala file.
override lazy val jettyInstance = new JettyRunner(customJettyConfiguration)
def customJettyConfiguration = {
val myLog = log
val myJettyClasspath = jettyClasspath
new CustomJettyConfiguration {
def war = "target/scala_2.8.0/tos.war"
def scanDirectories = Nil
def scanInterval = 0
def jettyClasspath = myJettyClasspath
def classpath = jettyRunClasspath
def classpathName = "test"
def log = myLog
override def jettyConfigurationXML =
<Configure id="Server" class="org.mortbay.jetty.Server">
<Call name="addConnector">
<Arg>
<New class="org.mortbay.jetty.security.SslSocketConnector">
<Set name="Port">443</Set>
<Set name="maxIdleTime">30000</Set>
<Set name="handshakeTimeout">2000</Set>
<Set name="keystore"><SystemProperty name="jetty.home" default=""/>/etc/xinetd.d/keystore</Set>
<Set name="password">password</Set>
<Set name="keyPassword">password</Set>
<Set name="truststore"><SystemProperty name="jetty.home" default=""/>/etc/xinetd.d/keystore</Set>
<Set name="trustPassword">password</Set>
<Set name="handshakeTimeout">2000</Set>
</New>
</Arg>
</Call>
<Call name="addConnector">
<Arg>
<New class="org.mortbay.jetty.nio.SelectChannelConnector">
<Set name="host"><SystemProperty name="jetty.host"/></Set>
<Set name="port"><SystemProperty name="jetty.port" default="8080"/></Set>
<Set name="maxIdleTime">30000</Set>
<Set name="Acceptors">2</Set>
<Set name="statsOn">false</Set>
<Set name="confidentialPort">443</Set>
<Set name="lowResourcesConnections">5000</Set>
<Set name="lowResourcesMaxIdleTime">5000</Set>
</New>
</Arg>
</Call>
</Configure>
}
}
But I did not get my work done.
Please let me know , if i am doing anything wrong.
EDIT
I am using 6.1.26 version of jetty.
Sorry, i mentioned it wrong earlier.
EDIT
Now I have successfully upgraded my jetty server to jetty-8.0.0.M3
Now i am getting below error when I am writing above code in my build.scala file :
java.lang.NoSuchMethodError: org.eclipse.jetty.xml.XmlConfiguration.configure(Ljava/lang/Object;)V
at sbt.jetty.LazyJettyRun7$$anonfun$3.apply(LazyJettyRun7.scala:96)
at sbt.jetty.LazyJettyRun7$$anonfun$3.apply(LazyJettyRun7.scala:95)
at scala.Iterator$class.foreach(Iterator.scala:414)
at scala.List$$anon$2.foreach(List.scala:598)
at scala.Iterable$class.foreach(Iterable.scala:256)
at scala.xml.NodeSeq.foreach(NodeSeq.scala:34)
at sbt.jetty.LazyJettyRun7$.apply(LazyJettyRun7.scala:95)
at sbt.JettyRunner.runJetty$1(WebApp.scala:49)
at sbt.JettyRunner.apply(WebApp.scala:58)
at sbt.WebScalaProject$$anonfun$jettyRunTask$1.apply(ScalaProject.scala:383)
at sbt.WebScalaProject$$anonfun$jettyRunTask$1.apply(ScalaProject.scala:383)
at sbt.TaskManager$Task.invoke(TaskManager.scala:62)
at sbt.impl.RunTask.doRun$1(RunTask.scala:77)
at sbt.impl.RunTask.runTask(RunTask.scala:85)
at sbt.impl.RunTask.run(RunTask.scala:32)
at sbt.impl.RunTask$.apply(RunTask.scala:17)
at sbt.impl.RunTask$.apply(RunTask.scala:16)
at sbt.Project$class.run(Project.scala:98)
at sbt.Project$class.act(Project.scala:129)
at sbt.BasicScalaProject.act(DefaultProject.scala:21)
at sbt.xMain$$anonfun$8.apply(Main.scala:530)
at sbt.xMain$$anonfun$8.apply(Main.scala:530)
at sbt.xMain.withAction(Main.scala:563)
at sbt.xMain.sbt$xMain$$handleAction(Main.scala:530)
at sbt.xMain.handleCommand(Main.scala:520)
at sbt.xMain.processAction(Main.scala:459)
at sbt.xMain.process$1(Main.scala:257)
at sbt.xMain$Continue$1.apply(Main.scala:132)
at sbt.xMain.run$1(Main.scala:136)
at sbt.xMain.processArguments(Main.scala:266)
at sbt.xMain.startProject(Main.scala:107)
at sbt.xMain.run(Main.scala:84)
at sbt.xMain.run0$1(Main.scala:35)
at sbt.xMain.run(Main.scala:42)
at xsbt.boot.Launch$.run(Launch.scala:55)
at xsbt.boot.Launch$$anonfun$explicit$1.apply(Launch.scala:45)
at xsbt.boot.Launch$.launch(Launch.scala:69)
at xsbt.boot.Launch$.apply(Launch.scala:16)
at xsbt.boot.Boot$.runImpl(Boot.scala:31)
at xsbt.boot.Boot$.main(Boot.scala:20)
at xsbt.boot.Boot.main(Boot.scala)
[info] == jetty-run ==
[error] Error running jetty-run: Error running Jetty: java.lang.NoSuchMethodError: org.eclipse.jetty.xml.XmlConfiguration.configure(Ljava/lang/Object;)V

0.7.7 is a a pretty old version of SBT. I understand you may have reasons not to upgrade, but if you can there is the xsbt-web-plugin SBT plugin that makes configuring SSL in Jetty super easy.

Related

Extending Modx modResource schema errors

I'm trying to extend the modx modresource object, but keep getting errors & I can't seem to figure out why. It is related to the schema (I think) but everything looks correct.
Schema:
<?xml version="1.0" encoding="UTF-8"?>
<model package="extresource" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" tablePrefix="modx_" version="1.0.0">
<object class="extResource" extends="modResource">
<composite alias="ResourceData" class="ResourceData" local="id" foreign="internalKey" cardinality="one" owner="local"/>
</object>
<object class="ResourceData" table="resource_data" extends="xPDOSimpleObject">
<field key="internalKey" dbtype="int" precision="11" phptype="integer" null="false" attributes="unsigned"/>
<field key="views" dbtype="int" precision="11" phptype="integer" null="true" />
<field key="starred" dbtype="int" precision="10" phptype="integer" null="false" />
<index alias="internalKey" name="internalKey" primary="false" unique="true" type="BTREE" >
<column key="internalKey" length="" collation="A" null="false" />
</index>
<aggregate alias="Resource" class="modResource" local="internalKey" foreign="id" cardinality="one" owner="foreign"/>
</object>
</model>
I'm testing it using:
$resource = $modx->getObject('modResource', 11112);
echo $resource->get('pagetitle'); //test I have the resource
$data = $resource->getOne('ResourceData');
The errors I get are:
Could not getOne: foreign key definition for alias ResourceData not
found. No foreign key definition for parentClass: modDocument using
relation alias: ResourceData
The table exists & has data, the package is registered in the modx extension packages. I've been over the schema many times & it looks right.
What is causing these errors?
You have to use the right object class in $modx->getObject. Otherwise you will get a modResource object, that does not know the extended object data and relationship.
$resource = $modx->getObject('extResource', 11112);
Does the resource you are loading have its class_key field set to extResource? That's needed for it to load the right resource object class.

Quartz delayed starting

I am running into an issue where quartz-service.xml (using quartz 1.8.6 with JBOSS 5.1.x) is deploying before the application that contains the class files to be run. Is there a way to delay the start of quartz?
My quartz-service.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<server>
<mbean code="org.quartz.ee.jmx.jboss.QuartzService" name="user:service=QuartzService,name=QuartzService">
<attribute name="JndiName">Quartz Scheduler</attribute>
<attribute name="Properties">
org.quartz.scheduler.instanceName = DefaultQuartzScheduler
org.quartz.scheduler.rmi.export = false
org.quartz.scheduler.rmi.proxy = false
org.quartz.scheduler.xaTransacted = false
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 5
org.quartz.threadPool.threadPriority = 4
org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
org.quartz.plugin.jobInitializer.class = org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin
org.quartz.plugin.jobInitializer.fileNames = D:/JBoss-5.1.0/quartz-config.xml
org.quartz.plugin.jobInitializer.failOnFileNotFound = true
org.quartz.plugin.jobInitializer.scanInterval = 120
org.quartz.plugin.jobInitializer.wrapInUserTransaction = false
</attribute>
</mbean>
</server>
In Spring, there is a property named startupDelay, for example:
<property name="startupDelay" value="10"/>
In java, you can call the method startDelayed() on the Scheduler instance, for example:
scheduler.startDelayed(10);
So you should find it out in JBOSS what the property is. Hope it helps.
Below parameter can be used in Spring with Quartz Schedular maven dependency where you can specify start delay in milliseconds
<property name="startDelay" value="60000" />

Integrate enunciate and ant for REST APIs document

I am encountering an error during integrating enunciate and ant for CXF REST service APIs project. Error exists in method getFeeItemsByCapID(). I try to find answer in source code, but without result. Who has any idea about the error? Thanks for your help. If you have any tips.
Ant Script
<path id="enunciate.classpath">
<fileset dir="${enunciate.home}/lib">
<include name="*.jar"/>
</fileset>
<!--include (optional) spring module-->
<fileset dir="${enunciate.home}/lib/modules/cxf">
<include name="*.jar"/>
</fileset>
<fileset dir="${java.home}">
<include name="lib/tools.jar"/>
</fileset>
</path>
<taskdef name="enunciate" classname="org.codehaus.enunciate.main.EnunciateTask">
<classpath refid="enunciate.classpath"/>
</taskdef>
<enunciate basedir="java/" configFile="enunciate.xml">
<include name="**/*.java"/>
<classpath refid="enunciate.classpath"/>
<export artifactId="war.file" destination="d:/myapp.war"/>
<javacArgument argument="-g"/>
</enunciate>
Enunciate.xml
<?xml version="1.0"?>
<enunciate label="test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://enunciate.codehaus.org/schemas/enunciate-1.26.xsd">
<namespaces>
<namespace id="api" uri="http://api.example.com/" />
<namespace id="link" uri="http://api.example.com/link" />
<namespace id="persona" uri="http://api.example.com/persona" />
</namespaces>
<modules>
<!-- Docs -->
<docs splashPackage="org.codehaus.enunciate.api" title="test" copyright="test.com"/>
<java-client disabled="false"/>
<amf disabled="true"/>
<c disabled="true"/>
<obj-c disabled="true"/>
<csharp disabled="true"/>
<spring-app disabled="false"/>
<cxf disabled="false"/>
<gwt disabled="true"/>
<jaxws-ri disabled="true"/>
<jersey disabled="true"/>
</modules>
Java Code
#GET
#RecordDetailSecurity(RecordDetailSectionType.FEE)
#Path("/{recordIds}/fees/")
#Produces(MediaType.APPLICATION_JSON)
#JsonView(Views.PublicView.class)
public ResponseModel getFeeItemsByCapID(#PathParam("recordIds") String recordIds,
#QueryParam("fields") #DefaultValue("") String fields) throws Exception
{
Exception:
java.lang.IllegalStateException: D:\AA7.2.0\main-dev\biz\modules\rest-apis\java\com\accela\restapis\jaxrs\agency\service\FeeWebService.java:76: the element 'value' must have a value specified.
at net.sf.jelly.apt.decorations.declaration.DecoratedAnnotationMirror.<init>(DecoratedAnnotationMirror.java:66)
at net.sf.jelly.apt.decorations.DeclarationDecorator.decorate(DeclarationDecorator.java:362)
at net.sf.jelly.apt.decorations.DeclarationDecorator.decorateAnnotationMirrors(DeclarationDecorator.java:113)
at net.sf.jelly.apt.decorations.declaration.DecoratedDeclaration.getAnnotationMirrors(DecoratedDeclaration.java:213)
at net.sf.jelly.apt.decorations.declaration.DecoratedDeclaration.getAnnotations(DecoratedDeclaration.java:195)
at net.sf.jelly.apt.decorations.declaration.DecoratedDeclaration.getAnnotation(DecoratedDeclaration.java:225)
at org.codehaus.enunciate.contract.jaxrs.ResourceMethod.<init>(ResourceMethod.java:130)
at org.codehaus.enunciate.contract.jaxrs.Resource.getResourceMethods(Resource.java:143)
at org.codehaus.enunciate.contract.jaxrs.Resource.<init>(Resource.java:69)
at org.codehaus.enunciate.contract.jaxrs.RootResource.<init>(RootResource.java:34)
at org.codehaus.enunciate.apt.EnunciateAnnotationProcessor.getRootModel(EnunciateAnnotationProcessor.java:214)
at org.codehaus.enunciate.apt.EnunciateAnnotationProcessor.process(EnunciateAnnotationProcessor.java:103)
at com.sun.mirror.apt.AnnotationProcessors$CompositeAnnotationProcessor.process(AnnotationProcessors.java:60)
at com.sun.tools.apt.comp.Apt.main(Apt.java:454)
at com.sun.tools.apt.main.JavaCompiler.compile(JavaCompiler.java:258)
at com.sun.tools.apt.main.Main.compile(Main.java:1102)
at com.sun.tools.apt.main.Main.compile(Main.java:964)
at com.sun.tools.apt.Main.processing(Main.java:95)
at com.sun.tools.apt.Main.process(Main.java:85)
at com.sun.tools.apt.Main.process(Main.java:67)
at org.codehaus.enunciate.main.Enunciate.invokeApt(Enunciate.java:777)
at org.codehaus.enunciate.main.Enunciate.doGenerate(Enunciate.java:366)
at org.codehaus.enunciate.main.Enunciate$Stepper.step(Enunciate.java:1735)
at org.codehaus.enunciate.main.Enunciate$Stepper.stepTo(Enunciate.java:1767)
at org.codehaus.enunciate.main.Enunciate.execute(Enunciate.java:174)
at org.codehaus.enunciate.main.EnunciateTask.execute(EnunciateTask.java:156)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:357)
at org.apache.tools.ant.Target.performTasks(Target.java:385)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
at org.apache.tools.ant.Main.runBuild(Main.java:758)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Source Code:
public DecoratedAnnotationMirror(AnnotationMirror delegate) {
if (delegate == null) {
throw new IllegalArgumentException("A delegate must be provided.");
}
this.delegate = delegate;
AnnotationType annotationType = delegate.getAnnotationType();
Collection<AnnotationTypeElementDeclaration> allElements = annotationType.getDeclaration() != null? annotationType.getDeclaration().getMethods() : Collections.<AnnotationTypeElementDeclaration>emptyList();
Map<AnnotationTypeElementDeclaration, AnnotationValue> elementValues = getElementValues();
put("annotationType", annotationType);
put("position", delegate.getPosition());
put("elementValues", elementValues);
allElementValues = new HashMap<String, Object>();
for (AnnotationTypeElementDeclaration element : allElements) {
if (elementValues.containsKey(element)) {
Object value = elementValues.get(element).getValue();
allElementValues.put(element.getSimpleName(), value);
put(element.getSimpleName(), value);
}
else {
AnnotationValue defaultValue = element.getDefaultValue();
if (defaultValue == null) {
throw new IllegalStateException(delegate.getPosition() + ": the element '" + element.getSimpleName() + "' must have a value specified.");
}
I have found root cause in my Customized Annotation. It seems because the annotation without default value. When I removed the customized annotation of method or append default value in annotation definition. the exception will be gone. But the annotation accept an enumeration, in business logic the annotation without default value. We always need to set enum value for using. But, why annotation always need default value? Anybody know the reason?
#Target( {ElementType.TYPE, ElementType.METHOD})
#Retention(RetentionPolicy.RUNTIME)
public #interface RecordDetailSecurity
{
RecordDetailSectionType value(); //append default value such as "default RecordDetailSectionType.ADDITIONAL_INFORMATION;"
}
#RecordDetailSecurity(RecordDetailSectionType.FEE)
public ResponseModel getFeeItemsByCapID(#PathParam("recordIds") String recordIds,
#QueryParam("fields") #DefaultValue("") String fields) throws Exception
About annotation default value error, I have created a sample project to try again. It works well. Now, I need to change my original opinion. It's my fault. :)
Firstly, my project compiling is successful without enunciate ant target before. However the enumeration "RecordDetailSectionType " belongs to another jar actually.
I didn't include the jar in to enunciate class path, so enunciate cannot to recognize the customized annotation type value. Sorry for the misunderstanding.

Is there a way to make fusion chart's funnel display zero values?

I'm using fusion charts' funnel mode to display some sums which may or may not be 0, grouped into different cathegories. I'm also displaying the number of terms that goes into each sum (for example: $1000, 3 accounts). I want the funnel to display a slice even if its value is 0 and have it displayed like $0, x accounts to give the user information on how many accounts there are in every cathegory even if the final sum is 0.
Xml for the fusioncharts object:
$strXML = "
<chart showhovercap='1' showNames='1' showValues='1' numberSuffix=' lei' decimalPrecision='0' decimalSeparator=',' thousandSeparator='.' formatNumber='1' isSliced='1' slicingDistance='5' bgColor='f5f5f5'>
<set link='".$url1."' name='Negociere' value='".$negociere."' color='FD0006' hoverText='".$nr_negociere.$text_negociere."' />
<set link='".$url2."' name='Ofertare' value='".$oferta."' color='FF4100' hoverText='".$nr_oferta.$text_oferta."' />
<set link='".$url3."' name='Analiza' value='".$analiza."' color='FF8900' hoverText='".$nr_analiza.$text_analiza."' />
<set link='".$url4."' name='Abordare' value='".$abordare."' color='086FA1' hoverText='".$nr_abordare.$text_abordare."' />
<set link='".$url5."' name='Prospectare' value='".$prospectare."' color='00B25C' hoverText='".$nr_prospectare.$text_prospectare."' />
</chart>
";
Could you please try by setting "streamlinedData" attribute to "0" in the element of your XML data?
Ref. Code:
<chart showhovercap='1' showNames='1' showValues='1' numberSuffix='$' decimalPrecision='0' decimalSeparator=',' thousandSeparator='.' formatNumber='1' isSliced='1' slicingDistance='5' bgColor='f5f5f5' streamlinedData='0'>
<set label="Negociere,3 accounts" value="0"/>
<set label="Ofertare, 5 accounts" value="0"/>
<set label="Analiza, 2 accounts" value="1"/>
<set label="Abordare, 1 accounts" value="0"/>
<set label="Prospectare, 2 accounts" value="0"/>
</chart>

Soap in Groovy - keep getting NoSuchMethodError

Newbie question:
I'm new to groovy & soap , so I might be missing out on something here:
I'm trying to communicate with a very basic web service :
import groovy.net.soap.SoapClient
...
def proxy = new SoapClient("http://soapclient.com/xml/soapresponder.wsdl")
res = proxy.Method1("ABC", "123");
println (res);
It seems the connection works , but when I try to invoke "Method1(..)" , I keep getting
Exception in thread "main" java.lang.NoSuchMethodError: org.codehaus.groovy.runtime.InvokerHelper.getInstance()Lorg/codehaus/groovy/runtime/Invoker;
at groovy.net.soap.SoapClient.invokeMethod(Unknown Source)
This is the relevant part of the WSDL:
<message name="Method1">
<part name="bstrParam1" type="xsd:string"/>
<part name="bstrParam2" type="xsd:string"/>
</message>
−
<message name="Method1Response">
<part name="bstrReturn" type="xsd:string"/>
</message>
−
<portType name="SoapResponderPortType">
−
<operation name="Method1" parameterOrder="bstrparam1 bstrparam2 return">
<input message="tns:Method1"/>
<output message="tns:Method1Response"/>
</operation>
</portType>
What am I doing wrong?
The help page for Groovy Soap says it has been deprecated (on Mar 03, 2008), so probably hasn't had any love for quite a while :-/
It recommends to use GroovyWS, and that page says that this should work:
#Grab(group='org.codehaus.groovy.modules', module='groovyws', version='0.5.2')
import groovyx.net.ws.WSClient
try {
proxy = new WSClient( "http://soapclient.com/xml/soapresponder.wsdl", this.class.classLoader)
proxy.initialize()
result = proxy.Method1("ABC", "123")
println res
}
catch( e ) {
e.printStackTrace()
}
However, when you run this, you get:
[snip]
Caused by: org.xml.sax.SAXParseException: Unexpected <schema> appears at line 0 column 0
at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.unexpectedX(NGCCRuntimeEx.java:488)
... 54 more
I can't see why this WSDL is wrong however... I'll keep looking
Well, it didn't resolve , but I did move to GroovyWS and after a little dependencies hell ,it worked. See here