I'm using json4s to parse json string, the code is running good locally, but when I put it into the production server, it throws NoSuchMethodError. My code as follows please:
import scala.util.parsing.json.JSON
import scala.util.matching.Regex
import org.json4s._
import org.json4s.JsonDSL._
import org.json4s.native.JsonMethods._
import org.json4s.JsonInput
def getIndexMap(vtStr: String): Map[String, Any] = {
implicit val formats = DefaultFormats
import org.json4s.native.JsonMethods
import JsonMethods._
var json = JsonMethods.parse(StringInput(vtStr), false, true) // the exception thrown here
}
The stacktrace please:
WARN scheduler.TaskSetManager: Lost task 0.0 in stage 3.0 (TID 79, avh007.av.pan.local): java.lang.NoSuchMethodError: scala.runtime.ObjectRef.create(Ljava/lang/Object;)Lscala/runtime/ObjectRef;
at org.json4s.native.JsonParser$$anonfun$1.apply(JsonParser.scala:145)
at org.json4s.native.JsonParser$$anonfun$1.apply(JsonParser.scala:143)
at org.json4s.native.JsonParser$.parse(JsonParser.scala:131)
at org.json4s.native.JsonParser$.parse(JsonParser.scala:71)
at org.json4s.native.JsonParser$.parse(JsonParser.scala:66)
at org.json4s.native.JsonMethods$class.parse(JsonMethods.scala:11)
at org.json4s.native.JsonMethods$.parse(JsonMethods.scala:63)
at com.panw.spark.PanavParser$.getIndexMap(PanavParser.scala:84)
at com.panw.spark.PanavStreamScala2$$anonfun$main$2$$anonfun$apply$1$$anonfun$apply$2.apply(PanavStreamScala2.scala:184)
at com.panw.spark.PanavStreamScala2$$anonfun$main$2$$anonfun$apply$1$$anonfun$apply$2.apply(PanavStreamScala2.scala:163)
at scala.collection.Iterator$class.foreach(Iterator.scala:727)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
at com.panw.spark.PanavStreamScala2$$anonfun$main$2$$anonfun$apply$1.apply(PanavStreamScala2.scala:163)
at com.panw.spark.PanavStreamScala2$$anonfun$main$2$$anonfun$apply$1.apply(PanavStreamScala2.scala:140)
at org.apache.spark.rdd.RDD$$anonfun$foreachPartition$1.apply(RDD.scala:806)
at org.apache.spark.rdd.RDD$$anonfun$foreachPartition$1.apply(RDD.scala:806)
at org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:1498)
at org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:1498)
at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:61)
at org.apache.spark.scheduler.Task.run(Task.scala:64)
at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:203)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Related
Given this simple Jax-RS class:
package com.company.app;
import java.net.URI;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.RedirectionException;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
#Path("/")
public class MyResource {
#GET
#Path("/")
public Response root() {
throw new RedirectionException(Status.TEMPORARY_REDIRECT, URI.create("/index.html"));
}
//...
}
In quarkus (using the resteasy extension) when I execute this rest-assured test:
#Test
public void testRootRedirect() {
RestAssuredConfig config = new RestAssuredConfig().redirect(new RedirectConfig().followRedirects(false));
given()
.config(config)
.when()
.get("/")
.then()
.statusCode(307)
.header("location", endsWith("/index.html"));
}
The test is green, but I see this stacktrace in the logs:
Oct 01, 2020 8:04:07 AM org.jboss.resteasy.core.ExceptionHandler handleWebApplicationException
ERROR: RESTEASY002010: Failed to execute
javax.ws.rs.RedirectionException: HTTP 307 Temporary Redirect
at com.unblu.qa.artifacts.PageResource.root(PageResource.java:30)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:167)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:130)
at org.jboss.resteasy.core.ResourceMethodInvoker.internalInvokeOnTarget(ResourceMethodInvoker.java:638)
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTargetAfterFilter(ResourceMethodInvoker.java:504)
at org.jboss.resteasy.core.ResourceMethodInvoker.lambda$invokeOnTarget$2(ResourceMethodInvoker.java:454)
at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:456)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:417)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:391)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:68)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:488)
at org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:259)
at org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:160)
at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
at org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:163)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:245)
at io.quarkus.resteasy.runtime.standalone.RequestDispatcher.service(RequestDispatcher.java:73)
at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.dispatch(VertxRequestHandler.java:132)
at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.access$000(VertxRequestHandler.java:37)
at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler$1.run(VertxRequestHandler.java:94)
at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:2046)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1578)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1452)
at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
at java.base/java.lang.Thread.run(Thread.java:834)
at org.jboss.threads.JBossThread.run(JBossThread.java:479)
Is this stacktrace really a problem? The test is green…
How can I prevent this?
I am working on a Spark Application and I want to create a rest API in Django, below is my code
from django.shortcuts import render
from django.http import Http404
from rest_framework.views import APIView
from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework import status
from django.http import JsonResponse
from django.core import serializers
from django.conf import settings
import json
from pyspark import SparkContext, SparkConf, SQLContext
sc = SparkContext()
sql = SQLContext(sc)
df = Sql.read.format("jdbc").options(
url = "jdbc:mysql://127.0.0.1:3306/demo",
driver = "com.mysql.cj.jdbc.Driver",
dbtable = "tablename",
user = "xyz",
password = "abc"
).load()
totalrecords = df.count()
# Create your views here.
#api_view(["GET"])
def Demo(self):
try:
a = str(totalrecords)
return JsonResponse(a,safe=False)
except ValueError as e:
return Response(e.args[0],status.HTTP_400_BAD_REQUEST)
I want to know how will I run this code, as I have directly tried "python manage.py runserver" which is not working, so how to run this spark and django with django api and spark-submit with all required spark jar file?
To run this code you have to use spark submit only,
spark-submit --jars mysql.jar manage.py runserver 0.0.0.0:8000
or
spark-submit manage.py runserver
i use sopaUI 5.0.0 with libraries:
btf 1.2
jackson-annotations-2.0.1
jackson-core-2.8.1
jackson-coreutils-1.8
json-schema-core-1.2.5
json-schema-validator-2.2.6
I try do this code:
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
import com.github.fge.jsonschema.core.report.ProcessingReport
import com.github.fge.jsonschema.main.JsonSchema
import com.github.fge.jsonschema.main.JsonSchemaFactory
def response = testRunner.testCase.getTestStepByName("getClientByID").getPropertyValue("response")
ObjectMapper mapper = new ObjectMapper()
JsonNode invoiceJSON = mapper.readTree(response)
JsonNode invoiceSchemaJSON = mapper.readTree(new File("C:\\test\\resources\\schems\\client-card-rs.json"))
log.info( invoiceSchemaJSON)
JsonSchemaFactory factory = JsonSchemaFactory.byDefault()
JsonSchema invoiceSchema = factory.getJsonSchema(invoiceSchemaJSON)
if (invoiceSchema.validInstance(invoiceJSON)) log.info("Response Validated!")
else {
testRunner.fail(invoiceSchema.validate(invoiceJSON).toString())
}
But script crash with error at line:
JsonSchemaFactory factory = JsonSchemaFactory.byDefault()
First,issued error:
"write_bigdecimal_as_plain"
Later
java.lang.NoClassDefFoundError: Could not initialize class com.github.fge.jsonschema.SchemaVersion
SoapUI error log:
2016-09-11 15:39:49,202 ERROR [errorlog] java.lang.NoClassDefFoundError: Could not initialize class com.github.fge.jsonschema.SchemaVersion
java.lang.NoClassDefFoundError: Could not initialize class com.github.fge.jsonschema.SchemaVersion
at com.github.fge.jsonschema.core.load.configuration.LoadingConfigurationBuilder.<init>(LoadingConfigurationBuilder.java:117)
at com.github.fge.jsonschema.core.load.configuration.LoadingConfiguration.byDefault(LoadingConfiguration.java:151)
at com.github.fge.jsonschema.main.JsonSchemaFactoryBuilder.<init>(JsonSchemaFactoryBuilder.java:67)
at com.github.fge.jsonschema.main.JsonSchemaFactory.newBuilder(JsonSchemaFactory.java:123)
at com.github.fge.jsonschema.main.JsonSchemaFactory.byDefault(JsonSchemaFactory.java:113)
at com.github.fge.jsonschema.main.JsonSchemaFactory$byDefault.call(Unknown Source)
at Script6.run(Script6.groovy:20)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:100)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:154)
at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:277)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Help pls.
The only solution that worked for me was using the json-schema-validator-2.2.8-lib.jar from com.github.java-json-tools (https://mvnrepository.com/artifact/com.github.java-json-tools/json-schema-validator/2.2.8) instead of com.github.fge (which supported the project till its 2.2.6 version). It is important to use the package of libs provided instead of collecting all the relevant dependencies manually. Somehow it doesn't want to work correctly.
I am using SoapUI 5.2.1 on Docker container built on top of an OpenJDK 8 image.
I have a very simple Java app using JAX-RS, running on WLP 8.5.5.8. When I post JSON that is a composite structure I get this error:
[ERROR ] Error occurred during error handling, give up! Invalid type
of value. Type: [java.util.LinkedHashMap] with value: [{d=e}] [ERROR
] SRVE0777E: Exception thrown by application class
'org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage:116'
java.lang.RuntimeException: org.apache.cxf.interceptor.Fault: Invalid
type of value. Type: [java.util.LinkedHashMap] with value: [{d=e}]
at
org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:116)
at [internal classes] Caused by: org.apache.cxf.interceptor.Fault:
Invalid type of value. Type: [java.util.LinkedHashMap] with value:
[{d=e}] at
org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:76)
... 1 more Caused by: java.lang.IllegalArgumentException: Invalid
type of value. Type: [java.util.LinkedHashMap] with value: [{d=e}]
at com.ibm.json.java.JSONObject.put(JSONObject.java:241) ... 1 more
When I do a POST on the resource and the json object contains a property that is either a json array or a json object, the exception is thrown before the function is reached
Example JSON that causes this (if I remove the "c" property it works fine):
{
"a": "b",
"c": {
"d": "e"
}
}
The same error is thrown if "c" is an array:
{
"a": "b",
"c": [
{"d": "e"},
{"d": "f"},
{"d": "g"}
]
}
I have not added any libs of my own, all is what is included in WLP. If I run this example on WLP 8.5.5.3 it works fine. Any ideas what I am missing because I find it hard to believe that this simple sample expose a defect?
This is my resource:
RootResouce.java
package com.sample;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import com.ibm.json.java.JSONObject;
#Path("/hello")
public class RootResource {
#POST
#Consumes(MediaType.APPLICATION_JSON)
#Produces(MediaType.APPLICATION_JSON)
public Response postTest(JSONObject json) {
return Response.ok(json).build();
}
}
This is my app:
package com.sample;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.core.Application;
public class MyApp extends Application {
#Override
public Set<Class<?>> getClasses() {
Set<Class<?>> s = new HashSet<Class<?>>();
s.add(RootResource.class);
return s;
}
}
This is my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<servlet>
<description>Simple Test service</description>
<display-name>sample</display-name>
<servlet-name>sample</servlet-name>
<servlet-class>com.ibm.websphere.jaxrs.server.IBMRestServlet</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.sample.MyApp</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<enabled>true</enabled>
<async-supported>false</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>sample</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<display-name>SimpleTest</display-name>
</web-app>
Looking a little further with the code provided, I see this in the exception:
Caused by: java.lang.IllegalArgumentException: Invalid type of value. Type: [java.util.LinkedHashMap] with value: [{d=e}]
at com.ibm.json.java.JSONObject.put(JSONObject.java:241)
at org.codehaus.jackson.map.deser.MapDeserializer._readAndBind(MapDeserializer.java:244)
at org.codehaus.jackson.map.deser.MapDeserializer.deserialize(MapDeserializer.java:166)
at org.codehaus.jackson.map.deser.MapDeserializer.deserialize(MapDeserializer.java:24)
at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:1961)
at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:889)
at org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:410)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBodyReader(JAXRSUtils.java:1356)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBody(JAXRSUtils.java:1307)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameter(JAXRSUtils.java:847)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameters(JAXRSUtils.java:810)
at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:255)
at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:85)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307
Maybe the default json provider changed between jax-rs 1.1 and 2.0? Deserializing request data with Jackson into a json4j object is not going well. Setting the provider like this seems to allow it to work:
import com.ibm.websphere.jaxrs.providers.json4j.JSON4JArrayProvider;
import com.ibm.websphere.jaxrs.providers.json4j.JSON4JObjectProvider;
public class MyApp extends Application {
#Override
public Set<Class<?>> getClasses() {
Set<Class<?>> s = new HashSet<Class<?>>();
s.add(RootResource.class);
s.add(JSON4JObjectProvider.class);
s.add(JSON4JArrayProvider.class);
return s;
}
I am running one simple cucumber test.
While running I am getting the following error.
java.lang.reflect.InvocationTargetException
My Runner class is -
package com.my.automation;
import cucumber.junit.Cucumber;
import org.junit.runner.RunWith;
#RunWith(Cucumber.class)
#Cucumber.Options(format = {"html:target/cucumber-html","json:target/cucumber.json",
"junit:target/cucumber-junit/cukey-junit_results.xml"},
features = {"src/test/resources/com/my/automation/cuketest/CukeTest.feature"} )
public class RunTest {
}