Apache POI cannot create XMLSlideShow object - java

I am using an old version of Apache POI (3.8) on my Domino server. I want to create some presentation files so I started with a basic sample code:
package org.quintessens.poi;
import java.io.IOException;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFSlideLayout;
import org.apache.poi.xslf.usermodel.XSLFSlideMaster;
public class Presentation {
public void createXSLF() throws IOException{
System.out.println("createXSLF()");
//create an empty presentation
XMLSlideShow ppt = new XMLSlideShow();
System.out.println("Available slide layouts:");
//getting the list of all slide masters
for(XSLFSlideMaster master : ppt.getSlideMasters()){
//getting the list of the layouts in each slide master
for(XSLFSlideLayout layout : master.getSlideLayouts()){
//getting the list of available slides
System.out.println(layout.getType());
}
}
}
}
I have registered the class as a managed bean as followed:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config>
<managed-bean>
<managed-bean-name>Prez</managed-bean-name>
<managed-bean-class>org.quintessens.poi.Presentation</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
</faces-config>
I added a button on my XPage to call it:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:button value="XSLF" id="button1">
<xp:eventHandler event="onclick" submit="true" refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:Prez.createXSLF()}]]></xp:this.action>
</xp:eventHandler>
</xp:button>
</xp:view>
When I run the code I get an error 500 message.
If I check my log I read:
2016-09-21 20:50:27 HTTP JVM: createXSLF() 2016-09-21 20:50:27
HTTP JVM: CLFAD0211E: Exception thrown. For more detailed information,
please consult error-log-0.xml located in C:/Program
Files/IBM/Domino/data/domino/workspace/logs 2016-09-21 20:50:27 HTTP
JVM: CLFAD0246E: Exception occurred servicing request for:
/apps/quintessens/ApachePO.nsf/test.xsp - HTTP Code: 500. For more
detailed information, please consult error-log-0.xml located in
C:/Program Files/IBM/Domino/data/domino/workspace/logs
Sadly, the error log does not tell me much:
2016-09-21T20:50:26.872+02:00 ALLVARLIG CLFAD0211E: Exception thrown
2016-09-21T20:50:26.875+02:00 ALLVARLIG CLFAD0246E: Exception occurred
servicing request for: /apps/quintessens/ApachePO.nsf/test.xsp - HTTP
Code: 500
I tried to use the HSLF usermodel which goes well but which I do not want to use.
What should I do?

Related

Webservice method with login shows a java error

I need help to consume a method of a webservice but I have not been successful.
The method:
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Header>
<LoginInfo xmlns="http://tempuri.org/">
<Username>[string?]</Username>
<Password>[string?]</Password>
<Company>[string?]</Company>
</LoginInfo>
</Header>
<Body>
<GetCarsInfoNew xmlns="http://tempuri.org/">
<DeviceID>[string?]</DeviceID>
</GetCarsInfoNew>
</Body>
This is the code:
if(wbs.Autenticacion()){
System.out.println("Conectado como "+wbs.login.getUsername());
System.out.println( wbs.port.getCarsInfoNew("xxxxxxx"));
}
This is the error:
Exception in thread "main" com.sun.xml.internal.ws.fault.ServerSOAPFaultException: Client received SOAP Fault from server: Server was unable to process request. ---> Object reference not set to an instance of an object. Please see the server log to find more detail regarding exact cause of the failure.

Using MailGun on AppEngine Java

I'm trying to get the libraries needed to send mail on AppEngine.
The docs (https://cloud.google.com/appengine/docs/standard/java/mail/mailgun) state that these need to be added if using Maven:
jersey-core
1.19.4
jersey-client
1.19.4
jersey-multipart
1.19.4
Adding them however, results in an error message in Eclipse.
The type javax.ws.rs.ext.RuntimeDelegate$HeaderDelegate cannot be
resolved. It is indirectly referenced from required .class files
That can be resolved by adding javax.ws.rs-api-2.0.1, but using that jar seems problematic.
Appengine is throwing an error:
Caused by: java.lang.ExceptionInInitializerError
... 44 more
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: org.glassfish.jersey.internal.RuntimeDelegateImpl
at com.sun.jersey.core.header.MediaTypes.<clinit>(MediaTypes.java:65)
... 62 more
Caused by: java.lang.ClassNotFoundException: org.glassfish.jersey.internal.RuntimeDelegateImpl
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at com.google.apphosting.runtime.ApplicationClassLoader.findClass(ApplicationClassLoader.java:45)
In a thread here though that error org.glassfish.jersey.internal.RuntimeDelegateImpl NOT FOUND is said to be solvable by removing javax.ws.rs-api-2.0
Other suggestions include using jersey2, but that requires additional configuration I believe and the AppEngine docs don't show how to do that.
How can I send mail on Appengine using Mailgun???
I solved it by using Jersey 2.27 (JAX-RS 2.1 / Jersey 2.26+) available as a download from https://jersey.github.io/download.html
I needed the following jars:
hk2-api-2.5.0-b32.jar
hk2-locator-2.5.0-b42.jar
hk2-utils-2.5.0-b32.jar
javax.inject-1.jar
javax.inject-2.5.0-b42.jar
jersey-client.jar
jersey-common.jar
jersey-guava-2.26-b03.jar (from Jersey 2.25.1)
jersey-media-jaxb.jar
javax.ws.rs-api-2.1.jar
And modified the AppEngine sample to use Jersey 2.26+ as below:
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Form;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
public static void sendSimpleMessage(String recipient) {
Client clientMail = ClientBuilder.newBuilder().build();
clientMail.register(HttpAuthenticationFeature.basic("api", MAILGUN_API_KEY));
WebTarget targetMail = clientMail.target("https://api.mailgun.net/v3/" + MAILGUN_DOMAIN_NAME + "/messages");
Form formData = new Form();
formData.param("from", "Mailgun Sandbox <"+DOMAIN_MAIL_ADDRESS+">");
formData.param("to", recipient);
formData.param("subject", "Simple Mailgun Example");
formData.param("text", "Plaintext content");
Response response = targetMail.request().post(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED_TYPE));
System.out.println("Mail sent : " + response);
}
The MAILGUN_API_KEY is available from MailGun. MAILGUN_DOMAIN_NAME is my custom domain and DOMAIN_MAIL_ADDRESS is the address I wish to send from.
Note: I have guava-gwt and gauva on my classpath too, so perhaps it was the addition of jersey-guava that did the trick. Actually, jersey-gauva was only in jaxrs-ri-2.25.1 and not in jaxrs-ri-2.27 (JAX-RS 2.1 / Jersey 2.26+). It was definitely needed though.

Issue with generating excel sheets in a web application

While working in a web application I have some issues with generating the excel sheet based on the result. This excel sheet data should be independent for each request. As of now I have implemented in the following way:
Created a xml file for excel configuration
spring-excel-views.xml
<bean id="excelView" class="com.test.service.excelService"
I have configure this xml in the servlet configuration file
<bean class="xmlReolver> //Mentioned clearly in the code but not here
<property name="location>
<value>bin/spring-excel-views.xml</value>
</property>
</bean>
Now I have controller class as well as an Utility class
UtiilityClass: computes the results and send back to the Controller
Controller: model.addAttribute("result", result); //Assuming result is coming for Utility class
Now in excelService.java coded as follows:
class ExcelService implements AbstractExcelView{
#overridden
protected void buildExcelDocument(Map model,HttpServletRequest req, HTTPServletResponse res){
Map m = model.getResults("results"); // Picking this from Controller
for(Map.Entry<Integer,String> entry: m.entrySet()){ -->Exception is throwing
//excel sheet logiic
}
//iteration logic ----> Exception thrown here
}
}
Here sometimes excel sheet is generating successfully and sometimes it is throwing Nullpointerexception before starting the iteration. Also this excel data is overriding with some other requests data. Displayed result is good but I'm having the problem with the excel sheet data.
Help me out to resolve this issue.
Exception Stack trace
Exception Report:
type Exception report
message Request processing failed; nested exception is java.lang.NullPointerException
description: The server encountered an internal error that prevented it from fulfilling this request.
exception:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.
org. springframework. web. servlet. FrameworkServlet . processRequest (FrarneworkServlet. java: 932)
org.springframework.web.servlet.FrameworkServlet.doGet(Frameworkservlet.java:816)
javax.servlet.http.HttpServlet.service (HttpServlet.java: 620)
org.springframework.web.servlet.FrameworkServlet.service (FrameworkServlet.java:801)
javax.servlet.http.Httpservlet.service(Httpservlet.java:727)
root cause
java.lang.NullPointerException
com. hello. services.ExcelService.buildExcelDocument (Excelservice.java:34)
org. springframework.web.servlet.view.document.AbstractExcelView.renderMergedoutputModel (AbstractE
org.springfranework.web.servlet.view.AbstractView.render (AbstractView.java:264)
org.springframework.web.servlet.DispatcherServlet.render (Dispatcherservlet.java: 1208)
org. springframework . web . serviet . DispatcherServlet . processDispatchResult (DispatcherServlet . java: 1208
org. springframework. web. servlet . DispatcherServlet . doDispatch (DispatcherServlet . java: 939)
org. springframework.web.servlet.DispatcherServlet.doService (DispatcherServlet.java:856)
org. springframework.web.servlet.FrameworkServlet.processRequest (FrameworkServlet.java: 920)
org. springframework.web.servlet.FrameworkServlet.doGet (FrameeworkServlet.java:816)
javax.servlet.http.Httpservlet.service(Httpservlet.java: 620)
org.springframework.web.servlet.FrameworkServlet.service (FraneworkServlet.java:801)
javax.servlet.http.HttpServlet.service(Httpservlet.java:727)
As you pointed out that exception is throwing in the below line
for(Map.Entry entry: m.entrySet()){ -->Exception is throwing
You are getting this exception because model.getResults("results") is returning null.Thus your m is assigned null and doing m.entrySet() this on null reference is throwing null pointer exception.
So you'll have to figure out why model.getResults("results") is returning null and fix it. If there can occur situation where there will be no excel sheet generated and model.getResults("results") will return nulll. Then you'll have to provide appropriate checking in your code.Below is a checking but it may not be sufficient as you may to handle some more stuffs.
if(m!=null){
for(Map.Entry<Integer,String> entry: m.entrySet()){ -->Exception is throwing
//excel sheet logiic
}
//iteration logic ----> Exception thrown here
}
Regarding you question about Thread safe it completely depends how you have designed your class and using it which is very difficult to answer just by looking at the few lines. However this may not be an issue of Thread safe.

Can't send SMS; getting 500 error in Java/Scala Google Voice API

I've got this code:
val voice = new Voice("<un>", "<pw>")
voice.login()
// The ID isn't specced well in the source code, not sure what it needs to be
voice.sendSMS("<number>", "hello", "343434")
I'm getting this error thrown in the browser (Play 2.0):
Server returned HTTP response code: 500 for URL: https://www.google.com/voice/b/0/sms/send/]
The stacktrace is:
[info] play - Application started (Dev)
[info] application - index:
https://www.google.com/accounts/ClientLogin - OK
Logged in to Google - Auth token received
https://www.google.com/voice/b/0/settings/tab/phones - OK
https://www.google.com/voice/b/0 - OK
Successfully Received rnr_se.
smsdata: id=hello&phoneNumber=XXXXXXXX&conversationId=343434&text=hello&_rnr_se=XXXXXXXXXXXXXXX
[error] application -
! #6an08o8h8 - Internal server error, for request [GET /smsTest] ->
play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[IOException: Server returned HTTP response code: 500 for URL: https://www.google.com/voice/b/0/sms/send/]]
at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:134) [play_2.9.1.jar:2.0.1]
at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:115) [play_2.9.1.jar:2.0.1]
at akka.actor.Actor$class.apply(Actor.scala:311) [akka-actor.jar:2.0.1]
at play.core.ActionInvoker.apply(Invoker.scala:113) [play_2.9.1.jar:2.0.1]
at akka.actor.ActorCell.invoke(ActorCell.scala:619) [akka-actor.jar:2.0.1]
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:196) [akka-actor.jar:2.0.1]
Caused by: java.io.IOException: Server returned HTTP response code: 500 for URL: https://www.google.com/voice/b/0/sms/send/
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1436) ~[na:1.6.0_31]
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:234) ~[na:1.6]
at com.techventus.server.voice.Voice.sendSMS(Voice.java:1669) ~[google-voice-java-1.14.jar:na]
at controllers.Application$$anonfun$smsTest$1.apply(Application.scala:47) ~[classes/:na]
at controllers.Application$$anonfun$smsTest$1.apply(Application.scala:45) ~[classes/:na]
at play.api.mvc.Action$$anon$1.apply(Action.scala:170) ~[play_2.9.1.jar:2.0.1]
[info] Compiling 1 Scala source to /Users/franklovecchio/Desktop/dev/applications-voip/target/scala-2.9.1/classes...
I'm using the latest jar.
Is there anybody that can send an SMS currently?
Try using JSON Spray which is built on top of Akka. you would need the following imports among many others:
import java.io._;
import java.net.InetAddress;
import java.util.Properties;
import java.util.Date;
import javax.mail._;
import javax.mail.internet._;
import javax.activation._;
import cc.spray.json._
Basically the pseudocode or algorithm is identical to what you would have for an implementation in Java, only you would be coding in Scala.
Twitter's finagle is a good backbone for your server requests and responses.

Java Client for WCF on HTTPS

I can't figure out how to proceed for the next scenario.
I have a WCF service up and running with security like this:
<binding name="SSLBinding">
<security mode="Transport">
<transport clientCredentialType="None"/>
<!--<message clientCredentialType="UserName"/>-->
</security>
</binding>
I was able to make a dummy ceritificate in the IIS 5.0, so this WCF can be exposed on HTTPS.
Finally using a .Net client I can communicate with the Service, something like this:
private void randomMethod
{
//This is necesary, cause the certificate isnĀ“t valid
ServicePointManager.ServerCertificateValidationCallback =
new RemoteCertificateValidationCallback(IgnoreCertificateErrorHandler);
RefHTTPS.GestionesServiceClient service = new RefHTTPS.GestionesServiceClient();
richTextBox1.Text = service.version();
}
public static bool IgnoreCertificateErrorHandler(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
}
ISSUE: When I try to do this on a Java client I get Exceptions.
Someone has been able to do something like this, I need some guidance here.
I read a lot of posts on the web, but nothing works for me.
Edit (merged from additional content from OP, was posted as a question and flagged):
This is the full config (it has a config tag, but isn't showing):
<?xml version="1.0"?>
<system.web>
<compilation debug="true">
</compilation>
</system.web>
<system.serviceModel>
<bindings>
<binding name="SSLBinding">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</bindings>
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="https://x.x.x.x"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
<services>
<service behaviorConfiguration="WSGestiones.GestionesServiceBehavior" name="WSGestiones.GestionesService">
<endpoint address="https://x.x.x.x/GestionesWS/GestionesService.svc"
binding="basicHttpBinding" bindingConfiguration="SSLBinding" contract="WSGestiones.IGestionesService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="https://x.x.x.x/GestionesWS/GestionesService.svc/mex"
binding="mexHttpsBinding" contract="IMetadataExchange">
<identity>
<dns value="IPADDRESS" />
</identity>
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WSGestiones.GestionesServiceBehavior">
<serviceMetadata httpsGetEnabled="true" httpsGetUrl="https://x.x.x.x/GestionesWS/GestionesService.svc" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
I was able to add the certificate to the trusted list of my PC, I also added to the JDK or wherever in Java.
Some of my errors was:
Exception in thread "main" javax.xml.ws.WebServiceException: Cannot find 'https://x.x.x.x/GestionesWS/GestionesService.svc?wsdl' wsdl. Place the resource correctly in the classpath.
HTTP transport error: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Exception in thread "main" com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport error: javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative names present
Exception in thread "main" com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport error: java.net.SocketException: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl)
Exception in thread "main" com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport error: java.io.IOException: HTTPS hostname wrong: should be <x.x.x.x>
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: An error occurred when verifying security for the message.
Exception in thread "main" com.sun.xml.internal.ws.client.ClientTransportException: The server sent HTTP status code 401: Access Denied
Every time I hit an error, searched online and "fixed", a new one appears....in my 5th day of "fixes" I say "this is an infinite loop".
So....instead of trying to fix the errors, I was thinking of "fixing the logic".
I was also trying to connect to a server with a self-signed certificate for a service endpoint via Netbeans. When I tried to make a new connection object, I came across this runtime exception:
javax.xml.ws.WebServiceException: java.io.IOException: HTTPS hostname wrong: should be <hostname as in the certificate>
And I finally found a section about this exception in Metro's documentation. The code they provide unfortunately looks like it's intended only to be a temporary solution, but at least it looks like you can get around this issue.
I modified the code they provided by creating a static method that I call at the top of my main method where I always 'verify' the site I connect to for my service:
private static void overrideDefaultHostnameVerifier() {
//WORKAROUND. TO BE REMOVED.
javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(
new javax.net.ssl.HostnameVerifier() {
#Override
public boolean verify(String hostname, javax.net.ssl.SSLSession sslSession) {
return true;
}
});
}
The true solution to this problem looks to be getting a real issued certificate on the server hosting the service endpoint.

Categories