Using MultiValued Map with Glassfish jersey jar - glassfish

We've upgraded to Glass fish Jersey from Sun Jersey. We've following piece of code which is not working with glassfish jar and earlier was working with sun jar.
MultivaluedMap<String, String> args = new MultivaluedMapImpl();
args.add("local", sharedDrivePath);
args.add("nas", nasPath);
args.add("controlNo", controlNumber);
ImageBean eReportImageBean = new ImageBean();
response = resource.path("getImage").queryParam(args).accept(MediaType.APPLICATION_XML)
.get(ClientResponse.class);
ImageBean = response.readEntity(ImageBean.class);
Here MultivaluedMapImpl is not available with glassfish jersey and also queryparam(string, string) is not supported with Webtarget resource.
Please help with a feasilble solution on this.
ImageBean ImageBean = new EReportImageBean();
response = resource.path("getImage").queryParam("local",sharedPath).queryParam("as",asPath).queryParam("No", Number).request(MediaType.APPLICATION_XML).get(ClientResponse.class);
ImageBean = response.readEntity(ImageBean.class);
Now I'm getting below exception:
javax.ws.rs.client.ResponseProcessingException: org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyReader not found for media type=application/xml, type=class org.glassfish.jersey.client.ClientResponse, genericType=class org.glassfish.jersey.client.ClientResponse.
Please help

Related

EJB2.1 lookup issue in JBoss EAP 7.2.8

We have migrated our application from Weblogic to JBoss EAP 7.2.8 and now we are facing issue in JNDI lookup of remote interface.
Configuration in ejb-jar.xml:
<session>
<ejb-name>BeanSL</ejb-name>
<home>com.project.ejb.BeanSLHome</home>
<remote>com.project.ejb.BeanSLIF</remote>
<ejb-class>com.project.ejb.BeanSL</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
server.log entry in Jboss for EJB registration of above mentioned class:
java:global/ear/jarWithEJB/BeanSL!com.project.ejb.BeanSLIF
java:app/dbdocejb/BeanSL!com.project.ejb.BeanSLIF
java:module/BeanSL!com.project.ejb.BeanSLIF
java:jboss/exported/ear/jarWithEJB/BeanSL!com.project.ejb.BeanSLIF
java:global/ear/jarWithEJB/BeanSL!com.project.ejb.BeanSLHome
java:app/dbdocejb/BeanSL!com.project.ejb.BeanSLHome
java:module/BeanSL!com.project.ejb.BeanSLHome
java:jboss/exported/ear/jarWithEJB/BeanSL!com.project.ejb.BeanSLHome
Remote Interface: BeanSLIF
Home Interface: BeanSLHome
Class implementing Remote Interface: BeanSL
BeanSLIF beanSLIf = null ;
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, “org.wildfly.naming.client.WildFlyInitialContextFactory”);
p.put( Context.PROVIDER_URL, “http-remoting://localhost:8090” );
p.put(Context.SECURITY_PRINCIPAL, “jbossUser”);
p.put(Context.SECURITY_CREDENTIALS, “jbossPassword”);
p.put("jboss.naming.client.ejb.context", "true");
ctx = new InitialContext( p );
beanSLIf = (BeanSLIF) ctx.lookup(“ejb:/ear/jarWithEJB/BeanSL!com.project.ejb.BeanSLIF”);
On inspecting the above lookup code(cx.lookup(ejb:/...) code I am getting below ‘Proxy’:
Proxy for remote EJB StatelessEJBLocator for "/ear/jarWithEJB/BeanSL", view is interface com.project.ejb.BeanSLIF, affinity is None
And this further leads to:
com.sun.proxy.$Proxy39 cannot be cast to com.project.ejb.BeanSLIF
Any help would be really appreciated. Thanks in advance.

View pdf in JPanel

How to view the pdf in JPanel using PDfBox??
I have the Source Code Like below.
try {
PDDocument inputPDF = PDDocument.load(FilePath);
List<PDPage> AllPages = inputPDF.getDocumentCatalog().getAllPages();
inputPDF.close();
PDPage TestPage = (PDPage)AllPages.get(0);
PDFPagePanel pdfPanel = new PDFPagePanel();
pdfPanel.setPage(TestPage);
pnlRiwayatStatus.add(pdfPanel);
}
catch(Exception e){
Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, e);
}
But thus source code NoClassDefFoundError
The missing class is mentioned in a comment:
java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
This shows that you don't have the Apache Commons Logging jar in your class path.
According to the PDFBox web site, though, it is a required dependency:
Minimum Requirements
PDFBox has the following basic dependencies:
Java 6
commons-logging
Commons Logging is a generic wrapper around different logging frameworks, so you’ll either need to also use a logging library like log4j or let commons-logging fall back to the standard java.util.logging API included in the Java platform.
You should consider using Apache Maven for automatic dependency resolution.

Regiser JacksonJsonProvider in Websphere liberty profile

I am trying to call a REST service from an EJB hoping to utilize Jackson's
#JsonIgnoreProperties(ignoreUnknown = true)
The following does the trick in wlp v8.5.5.9
Client client = ClientBuilder.newClient().register(JacksonJsonProvider.class);
The same code produces a NullPointerException in the wlp v16.0.0.2
Caused by: java.lang.NullPointerException
at org.apache.cxf.jaxrs.impl.tl.ThreadLocalProviders.getContextResolver(ThreadLocalProviders.java:50)
at org.codehaus.jackson.jaxrs.JacksonJsonProvider.locateMapper(JacksonJsonProvider.java:634)
at org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:413)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBodyReader(JAXRSUtils.java:1356)
at org.apache.cxf.jaxrs.impl.ResponseImpl.doReadEntity(ResponseImpl.java:438)
... 98 more
I have found a discussions triggered by the same problems in v8.5.5.9, but I am not sure how it could help me. As I noted I have no troubles with the code in the v8.5.5.9
Another discussion was related to the Jackson v2.x. Initially I used Jackson v1.9.13, but I have tried to switch to the newest Jeckson 2.8.0 version and apply the offered solution. The same outcome: application works in wlp 8.5.5.9 and produces the same error in v16.0.0.2.
Any ideas?
Update:
the problem could be avoided by extending the JacksonJsonProvider class and explicitly providing object mapper
public class MyJacksonJsonProvider extends JacksonJsonProvider {
public MyJacksonJsonProvider() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setVisibilityChecker(objectMapper.getVisibilityChecker().withFieldVisibility(JsonAutoDetect.Visibility.ANY));
objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
setMapper(objectMapper);
}
}
and then registering it in the client
Client client = ClientBuilder.newClient().register(MyJacksonJsonProvider.class);
However it would be nice to understand if it is a bug or a feature.

Connecting to Mule's JMX output from Java

What is the standard way to connect to Mules JMX output through a standard java program,
I'm trying something like this but looking at the source of Mules SimplePasswordJmxAuthenticator, I need to supply auth tokens to mule so perhaps there is a better lib to use for sending jmx requests?
url1 = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1198/server");
JMXConnector jmxc = JMXConnectorFactory.connect(url1);
I'm not familiar with the details of Mule's JMX server, but here's how you could add credentials to your code snippet:
url1 = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1198/server");
String[] credentials = new String[]{"myusername", "mypassword"};
Map<String, Object> env = new HashMap<String, Object>(1);
env.put(javax.management.remote.JMXConnector.CREDENTIALS, credentials);
JMXConnector jmxc = JMXConnectorFactory.connect(url1, env);
That's the standard JMXRemoting way of doing it. Perhaps it will work for you.

BundleTransformer.Core throwing implementation exception

I'm trying to use BundleTransformer.Core and BundleTransformer.Less, however I've run into the following exception when trying to setup MVC4 bundles using the recommended code:
Method 'OrderFiles' in type 'BundleTransformer.Core.Orderers.NullOrderer' does not have an implementation.
That exception is thrown on registering the following:
public static void RegisterBundles(BundleCollection bundles)
{
var cssTransformer = new CssTransformer();
var jsTransformer = new JsTransformer();
var nullOrderer = new NullOrderer();
var commonStylesBundle = new Bundle("~/Bundles/CommonStyles");
commonStylesBundle.Include("~/Styles/V3/functions.less",
"~/Styles/V3/helpers.less",
"~/Styles/V3/media-queries.less",
"~/Styles/V3/normalize.less",
"~/Styles/V3/print.less",
"~/Styles/V3/style.less");
commonStylesBundle.Transforms.Add(cssTransformer);
commonStylesBundle.Orderer = nullOrderer;
bundles.Add(commonStylesBundle);
}
I have tried both the latest versions of BundleTransformer.Core and the immediate prior version.
It seems that you have installed preview version of the Microsoft ASP.NET Web Optimization Framework (1.1.0 Alpha1 or 1.1.0 Beta1). At the moment, the Bundle Transformer supports only RTM-version of the Microsoft ASP.NET Web Optimization Framework (version 1.0.0). I recommend that you roll back to RTM-version.