Why jboss uses deprecated DOMSerializerImpl org.apache.xerces 2.12.0.SP03 - deployment

I've got an issue while deploing with putting key value into the infinispan cache some object
ISPN000559: Cannot marshall 'class org.infinispan.marshall.protostream.impl.MarshallableUserObject': org.w3c.dom.ls.LSException
from the stacktrace I see that it calls org.apache.xerces#2.12.0.SP03//org.apache.xml.serialize.DOMSerializerImpl.writeToString(DOMSerializerImpl.java:518) from the deprecated class, but as I understand it should use xalan serializer 2.7.2 instead
when I trying to serialize it from our app, it uses the correct serializer using this code from xercesImpl-2.12.2 CoreDomImplementationImpl.java
public LSSerializer createLSSerializer() {
try {
Class serializerClass = ObjectFactory.findProviderClass(
"org.apache.xml.serializer.dom3.LSSerializerImpl",
ObjectFactory.findClassLoader(), true);
return (LSSerializer) serializerClass.newInstance();
}
catch (Exception e) {}
// Fall back to Xerces' deprecated serializer if
// the Xalan based serializer is unavailable.
return new DOMSerializerImpl();
}
we call it like this
public static #Null
String documentToString(#Null Document document) {
if (document == null) {
return null;
}
DOMImplementationLS domImplementation = (DOMImplementationLS) document.getImplementation();
LSSerializer lsSerializer = domImplementation.createLSSerializer();
String result = lsSerializer.writeToString(document);
return result;
}
please help me to understand why incorrect serializer is used while deploy and how to fix it;
needed library xalan-2.7.2 is present in WEB-INF\lib\
orgWildflyVersion = '26.1.2.Final'
infinispanVersion = '13.0.10.Final'

Related

strange behavior of HystrixCommand

The project uses SpringBoot(2.3.4) and SpringCloud(Hoxton.SR8).
There are three classes: BillController, BillService(interface) and BillServiceImpl (implements BillService), BillController calls function getBillList declared in BillService.
In BillServiceImpl, there are two method, one is getBillList, the other is simulateUnstableService, getBillList calls simulateUnstableService, and in simulateUnstableService just a long sleep(2000).
The strange thing is that if I annoate getBillList with HystrixCommand, then it works as I expect. But if I move HystrixCommand to annoate simulateUnstableService, then there is no break which means timeout does not trigger Circuit Breaker.
#Service
public class BillServiceImpl implements BillService {
#Override
// have effact
#HystrixCommand(
commandProperties = {
#HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "1500")
}
)
public List<Bill> getBillList(long userId) {
return simulateUnstableService(userId);
}
// no effact
// #HystrixCommand(
// commandProperties = {
// #HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "1500")
// }
// )
public List<Bill> simulateUnstableService(long userId) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return new ArrayList<>();
}
}
And more, if I just copy simulateUnstableService method content to getBillList, and annoate getBillList with HystrixCommand, the breaker also works.
Why?
Excellent question.
Hystrix uses AOP to wrap the method being called and deliver the Circuit Braking functionality. There is actually an aspect class HystrixCommandAspect.java which defines the around advice used to achieve this.
Now, AOPs don't exactly work if you call a method from within a class. See this answer for more clarity- Spring AOP not working for method call inside another method
When the circuit breaks the fallback method is called. We need to mention fallback method inside the hystrix command. The fallback method has the same signature as the method being annotated by hystrix.
Is simulateUnstableService your fallback method?
#HystrixCommand(fallbackMethod='yourFallbackMethod'
commandProperties = {
#HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "1500")
}
)
public List<Bill> getBillList(long userId) {
return simulateUnstableService(userId);
}
Also, it is good practice to add the hystrix command properties inside the application.properties file instead of providing along with the annotation.

Fixing the pointcut definition error while defining an aspect for tracing the RabbitMQ send

The opentracing instrumentation for spring-rabbitmq doesn't have an aspect defined for tracing the org.springframework.amqp.rabbit.core.RabbitTemplate#send. Here is the link of the code: RabbitMqSendTracingAspect.java
I tried implementing it and got some serious errors while defining a pointcut.
Here is my code for the same:
#Aspect
#Configuration
public class AmqpSendTracingAspect {
private final Tracer tracer;
public AmqpSendTracingAspect(Tracer tracer) {
this.tracer = tracer;
}
#Around(value = "execution(* org.springframework.amqp.core.AmqpTemplate.send(..)) " +
"&& args(exchange,routingKey, message)",
argNames = "pjp,exchange,routingKey,message")
public Object traceAmqpSend(ProceedingJoinPoint pjp,
String exchange, String routingKey, Message message) throws Throwable {
final Object[] args = pjp.getArgs();
System.out.println("Aspect RUnning");
final MessageProperties messageProperties = message.getMessageProperties();
Scope scope = AmqpTracingUtils.buildSendSpan(tracer, messageProperties);
tracer.inject(
scope.span().context(),
Format.Builtin.TEXT_MAP,
new AmqpInjectAdapter(messageProperties));
AmqpSpanDecorator spanDecorator = new AmqpSpanDecorator();
spanDecorator.onSend(messageProperties, exchange, routingKey, scope.span());
args[2] = message;
try {
return pjp.proceed(args);
} catch (Exception ex) {
spanDecorator.onError(ex, scope.span());
throw ex;
} finally {
scope.close();
}
}
}
I am getting the following errors from CglibAopProxy framework even when I annotated with #EnableAspectJAutoProxy(proxyTargetClass = false)
Unable to proxy interface-implementing method [public final void org.springframework.amqp.rabbit.core.RabbitTemplate.start()] because it is marked as final: Consider using interface-based JDK proxies instead!
Unable to proxy interface-implementing method [public final void org.springframework.amqp.rabbit.core.RabbitTemplate.stop()] because it is marked as final: Consider using interface-based JDK proxies instead!
Please help me out!
It's not an error. the code producing that message is like this:
if (implementsInterface(method, ifcs)) {
logger.info("Unable to proxy interface-implementing method [" + method + "] because " +
"it is marked as final: Consider using interface-based JDK proxies instead!");
}
So, it is an info and it fully doesn't stop your application to work afterward. Just a pointer that RabbitTemplate.start() method is not going to be proxied, which definitely should not be. So, you are good so far.
I think since you use Spring Cloud, you are not able to override the AOP config with that #EnableAspectJAutoProxy therefore it always uses CglibAopProxy.
I would just ignore that info. Would be better do not such a logging level for framework categories.

Finding What the Android Facebook SDK Version Is

How do I find out the version of the current SDK is installed or referenced by my application? I have looked through the class files and the manifest but there is no reference as to what version it is.
Thanks in advance.
You have FacebookSdkVersion class with the current version: https://github.com/facebook/facebook-android-sdk/blob/master/facebook/src/com/facebook/FacebookSdkVersion.java
final class FacebookSdkVersion {
public static final String BUILD = "3.5.2";
public static final String MIGRATION_BUNDLE = "fbsdk:20130708";
}
Since this class is without modifier and you can't access it from your package, use a reflection.
This will return you the sdk version:
private String getFacebookSDKVersion()
{
String sdkVersion = null;
ClassLoader classLoader = getClass().getClassLoader();
Class<?> cls;
try
{
cls = classLoader.loadClass("com.facebook.FacebookSdkVersion");
Field field = cls.getField("BUILD");
sdkVersion = String.valueOf(field.get(null));
}
catch (ClassNotFoundException e)
{
// error
}
catch (NoSuchFieldException e)
{
// error
}
catch (IllegalArgumentException e)
{
// error
}
catch (IllegalAccessException e)
{
// error
}
return sdkVersion;
}
The most easy way:
1.- Go to your AndroidManifest.xml
2.- Look at your Bottom Navigation View, there is two tabs: Text and Merged Manifest, click on the last one.
3.- On the right side will appear the Manifest Sources, there it is: for example i have this: facebook-android-sdk:4.20.0 manifest.
I know its a bit old, but i searched this in march of 2017 and there is no an easy answer like this.
There is a public API:
import com.facebook.Settings;
Settings.getSdkVersion()
"Gets the current version of the Facebook SDK for Android as a string."
I don't recommend using reflection to access the package class - they may change that in the future and break your code, but this public API should be considered stable.
Late to answer but I found one more class while trying #sromku's answer.
There is one class called FacebookSdk: import com.facebook.FacebookSdk;
It exposes 2 useful methods which we can try:
getGraphApiVersion()
getSdkVersion()

Issues with Restful Jersey and JSON

I have a strange issue and didn't find any information about it at all.
Having a simple POJO like (simplified..)
#XmlRootElement
public class Bill {
List<Position> positions
.. getter/setter
}
#XmlRootElement
public class Position {
.. some simple properties with getters/setters
}
I am unable to call a RESTful Service using instances of these classes. I'm getting real weird errors I don't really understand.
org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.List out of START_OBJECT token
The funny thing is, when I just test serialization/deserialization using Jackson Object mapper directly, it works as expected!
ObjectMapper mapper = new ...
mapper.writeValue(stringWriter, bill);
mapper.readValue(stringWriter.toString(), Bill.class);
This works perfectly. So I guess the POJO itself is OK and Jackson is able to handle the JSON-String.
Calling the RESTful service using the same Bill instance fails with the error mentioned above. I see it is using Jackson as well, here is part of stack trace:
at org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:160)
at org.codehaus.jackson.map.deser.StdDeserializationContext.mappingException(StdDeserializationContext.java:198)
at org.codehaus.jackson.map.deser.CollectionDeserializer.deserialize(CollectionDeserializer.java:103)
at org.codehaus.jackson.map.deser.CollectionDeserializer.deserialize(CollectionDeserializer.java:93)
at org.codehaus.jackson.map.deser.CollectionDeserializer.deserialize(CollectionDeserializer.java:25)
at org.codehaus.jackson.map.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:230)
And here is how the RESTful Application is configured:
#javax.ws.rs.ApplicationPath("rest")
public class ApplicationConfig extends Application {
public Set<Class<?>> getClasses() {
return getRestResourceClasses();
}
/**
* Do not modify this method. It is automatically generated by NetBeans REST support.
*/
private Set<Class<?>> getRestResourceClasses() {
Set<Class<?>> resources = new java.util.HashSet<Class<?>>();
resources.add(rest.RestAPI.class);
// following code can be used to customize Jersey 1.x JSON provider:
try {
Class jacksonProvider = Class.forName("org.codehaus.jackson.jaxrs.JacksonJsonProvider");
resources.add(jacksonProvider);
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
return resources;
}
}
Do you have any idea what I'm missing?
I generated the service and the client with NetBeans. Oh and it works when I use XML instead of JSON.
Any help would be very much appreciated.
I'm sorry but after hours of testing and debugging I finally found the cause of the problem.
Still I would be very interested why this is?
Commenting out the following code did the trick:
// following code can be used to customize Jersey 1.x JSON provider:
try {
Class jacksonProvider = Class.forName("org.codehaus.jackson.jaxrs.JacksonJsonProvider");
resources.add(jacksonProvider);
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE, null, ex);
}

How to deal with IResourceStreamWriter API change in Wicket 1.5?

In Wicket 1.4, I had a custom AbstractResourceStreamWriter (used in a custom kind of Link for streaming a file that gets generated on the fly):
private AbstractResourceStreamWriter resourceStreamWriter() {
return new AbstractResourceStreamWriter() {
#Override
public void write(OutputStream output) {
try {
reportService.generateReport(output, report);
} catch (ReportGenerationException e) {
// ...
}
}
#Override
public String getContentType() {
return CONTENT_TYPES.get(report.getOutputType());
}
};
}
In Wicket 1.5, the IResourceStreamWriter interface has been changed so that the method gets a Response instead of OutputStream. It is somewhat confusing that the IResourceStreamWriter javadocs still talk about OutputStream:
Special IResourceStream implementation that a Resource can return when
it directly wants to write to an output stream instead of return the
IResourceStream.getInputStream()
...
Implement this method to write the resource data directly the the
given OutputStream.
Anyway, I don't see a quick way of getting an OutputStream from the Response.
Given that I have a method (the call generateReport(output, report) in above code) which expects an OutputStream to write into, what's the simplest way to make this work again?
What about
ByteArrayOutputStream baos = new ByteArrayOutputStream();
reportService.generateReport(baos, report);
response.write(baos.toByteArray());
or something similar?
There is a org.apache.wicket.request.Response#getOutputStream(). But again I'm not sure this is the same as in 1.4.x. In 1.5 this will buffer what you write in the output stream. Where the javadoc says it shouldn't be buffered.