I am working a on project which should render SSRS reports in Java.
Below is the procedure that I have followed.
Installed Eclipse
Created a java project By setting Execution Environment Java SE 1.8
Created a proxy using wsimport
wsimport image
Added the references for the generated proxy
added classed
Written this code
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Holder;
import com.microsoft.schemas.sqlserver._2005._06._30.reporting.reportingservices.ArrayOfString;
import com.microsoft.schemas.sqlserver._2005._06._30.reporting.reportingservices.ArrayOfWarning;
import com.microsoft.schemas.sqlserver._2005._06._30.reporting.reportingservices.ExecutionHeader;
import com.microsoft.schemas.sqlserver._2005._06._30.reporting.reportingservices.ExecutionInfo;
import com.microsoft.schemas.sqlserver._2005._06._30.reporting.reportingservices.ReportExecutionService;
import com.microsoft.schemas.sqlserver._2005._06._30.reporting.reportingservices.ReportExecutionServiceSoap;
public class Render {
static {
java.net.Authenticator.setDefault(new java.net.Authenticator() {
#Override
protected java.net.PasswordAuthentication getPasswordAuthentication() {
return new java.net.PasswordAuthentication("username", "pwd".toCharArray());
}
});
}
public static void main(String[] args) {
String reportPath = "/Reporting/Customers" ;
String format = "HTML4.0";
String historyID = null;
String devInfo = "<DeviceInfo><Toolbar>False</Toolbar><HTMLFragment>True</HTMLFragment></DeviceInfo>";
String executionID = null;
Holder<String> extension = null;
Holder<String> mimeType = null;
Holder<String> encoding = null;
Holder<ArrayOfWarning> warnings = null;
Holder<ArrayOfString> streamIDs = null;
Holder<byte[]> result = new Holder<byte[]>();
ReportExecutionService res = new ReportExecutionService();
ReportExecutionServiceSoap ress = res.getReportExecutionServiceSoap();
BindingProvider bp = (BindingProvider)ress;
bp.getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
ExecutionInfo execInfo = new ExecutionInfo();
execInfo = ress.loadReport(reportPath, historyID);
executionID = execInfo.getExecutionID();
bp.getRequestContext().put("sessionID", executionID);
ExecutionHeader eh = new ExecutionHeader();
eh.setExecutionID(executionID);
System.out.println(executionID);
ress.render(format, devInfo, result, extension, mimeType, encoding, warnings, streamIDs);
String resultString = new String(result.value);
}
}
When I am running this code , i am getting the below error.
Exception in thread "main" com.sun.xml.internal.ws.fault.ServerSOAPFaultException: Client received SOAP Fault from server: The session identifier is missing. A session identifier is required for this operation. ---> Microsoft.ReportingServices.Diagnostics.Utilities.MissingSessionIdException: The session identifier is missing. A session identifier is required for this operation. Please see the server log to find more detail regarding exact cause of the failure.
at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(Unknown Source)
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(Unknown Source)
at com.sun.xml.internal.ws.client.sei.StubHandler.readResponse(Unknown Source)
at com.sun.xml.internal.ws.db.DatabindingImpl.deserializeResponse(Unknown Source)
at com.sun.xml.internal.ws.db.DatabindingImpl.deserializeResponse(Unknown Source)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(Unknown Source)
at com.sun.proxy.$Proxy35.render(Unknown Source)
at Render.main(Render.java:50)
I am new to java, am I missing something ? I already set session id.
any help is appreciated.
Thanks in advance.
Related
I am building a swing application to download multiple files over the internet and save to a windows fileshare. I have used SwingWroker which internally uses the ExecutorService which internally queues them and downloads 10 at a time, but for some reason after downloading say 2 - 3 MB of file it stops and moves to next downloading file, They are downloaded in a batch of 10 as SwingWorker has fixed it in number of Threads for the Executor Service.
I have to write these files in a windows file share and I am using nio.FileChannels to do that. There are files ranging from 50-60 each weighing around 300MB - 500MB. The file links are located on a webpage to where I get to by login in using credentials on a login page(with a post request) over the internet before that I specify CookieHandler.setDefault(new CookieManager()) at the beginning and so it behaves like a browser to me.
Another observation is when I download them locally (not to a windows server share) they do work fine.
This is the code I am using
import java.io.File;
import java.io.FileOutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;
import javax.swing.SwingWorker;
public class DownloadProcess extends SwingWorker<Boolean, String> {
private String urlPath, filePath;
public DownloadProcess(String urlPath, String filePath){
this.urlPath = urlPath;
this.filePath = filePath;
}
#Override
protected Boolean doInBackground() {
boolean taskState = true;
URLConnection httpConn = null;
ReadableByteChannel readableByteChannel = null;
FileOutputStream fileOutputStream = null;
FileChannel fileOutputChannel = null;
try{
//String filePath = "\\\\fileshare.server\\xyz.txt";
//String urlPath = "http://example.com/anyBigFile.1GB.docx";
File localFile = new File(filePath);//File share
boolean itsThere = localFile!=null && localFile.exists();
long done = itsThere ? localFile.length() : 0;
URL url = new URL(urlPath);
httpConn = url.openConnection();
httpConn.setRequestProperty("Connection", "keep-alive");
if(itsThere) {
httpConn.setRequestProperty("Range","bytes="+done+"-");
}
readableByteChannel = Channels.newChannel(httpConn.getInputStream());
fileOutputStream = itsThere ? new FileOutputStream(filePath) : new FileOutputStream(filePath,true);
fileOutputChannel = fileOutputStream.getChannel();
for (long position = done, size = httpConn.getContentLength(); position < size && !isCancelled(); ) {
position += fileOutputChannel.transferFrom(readableByteChannel, position, 1 << 16);
}
//done
}catch(Exception e){
taskState = false;
e.printStackTrace();
}finally{
//close streams conns etc
}
return taskState;
}
}
This is the error stack trace that I get after 5 - 10 mins of download
/*
javax.net.ssl.SSLException: Connection has been shutdown: javax.net.ssl.SSLException: java.net.SocketException: Connection reset
at sun.security.ssl.SSLSocketImpl.checkEOF(Unknown Source)
at sun.security.ssl.AppInputStream.read(Unknown Source)
at java.io.BufferedInputStream.read1(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at sun.net.www.MeteredStream.read(Unknown Source)
at java.io.FilterInputStream.read(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(Unknown Source)
at java.nio.channels.Channels$ReadableByteChannelImpl.read(Unknown Source)
at com.objects.DownloadByteChannel.read(DownloadByteChannel.java:117)
at sun.nio.ch.FileChannelImpl.transferFromArbitraryChannel(Unknown Source)
at sun.nio.ch.FileChannelImpl.transferFrom(Unknown Source)
at com.core.DownloadTask.doInBackground(DownloadTask.java:154)
at com.core.DownloadTask.doInBackground(DownloadTask.java:59)
at com.util.ZSwingWorker$1.call(ZSwingWorker.java:286)
at java.util.concurrent.FutureTask.run(Unknown Source)
at com.util.ZSwingWorker.run(ZSwingWorker.java:325)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: javax.net.ssl.SSLException: java.net.SocketException: Connection reset
at sun.security.ssl.Alerts.getSSLException(Unknown Source)
at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
at sun.security.ssl.SSLSocketImpl.handleException(Unknown Source)
at sun.security.ssl.SSLSocketImpl.handleException(Unknown Source)
... 18 more
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at sun.security.ssl.InputRecord.readFully(Unknown Source)
at sun.security.ssl.InputRecord.read(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readDataRecord(Unknown Source)
... 18 more
*/
Usage:
public static void main(String[] args){
int counter = 1;
for(String url: urls){
new DownloadProcess(url,"\\\\fileshare.server\\xyz"+(counter++)+".txt").execute();
}
}
You are going to have to change your connection timeout serverside. I picked up a few links along the way if they are of any importance:
Modify Session Security settings
Lengthening salesforce session timeout
Hope this helps, good luck and let me know :)
Connection Reset means the remote side is closing the connection with a TCP RST (reset) packet. You need to find out what the remote side isn't liking and fix it.
If the remote side is Apache maybe you are running into the KeepAliveTimeout value. By default that is 5 seconds. It really sounds like you are running into some sort of configured limit on the remote side. When that happens the server is kicking you off with a reset.
I'm stuck facing problems with pegdown v1.4.2 while trying to implement custom ParserPlugin to a library I'm writing (Maven project, JDK 8):
CustomPlugin:
public class CustomHeadersParserPlugin extends Parser implements BlockPluginParser {
public CustomHeadersParserPlugin() {super(HtmlMdProc.MDP_SETTINGS, HtmlMdProc.PROCESSING_TIME_LIMIT, DefaultParseRunnerProvider);
}
public CustomHeadersParserPlugin(Integer options, Long maxParsingTimeInMillis) {
super(options, maxParsingTimeInMillis, DefaultParseRunnerProvider);
}
public CustomHeadersParserPlugin(Integer options, Long maxParsingTimeInMillis, ParseRunnerProvider parseRunnerProvider) {
super(options, maxParsingTimeInMillis, parseRunnerProvider);
}
public CustomHeadersParserPlugin(Integer options, Long maxParsingTimeInMillis, ParseRunnerProvider parseRunnerProvider, PegDownPlugins plugins) {
super(options, maxParsingTimeInMillis, parseRunnerProvider, plugins);
}
//************* CUSTOM RULES ***************
...
Pegdown Usage:
public class HtmlMdProc {
public static final int MDP_SETTINGS = Extensions.HARDWRAPS | Extensions.AUTOLINKS | Extensions.TABLES | Extensions.FENCED_CODE_BLOCKS;
public static final long PROCESSING_TIME_LIMIT = 5000l;
...
public HtmlMdProc markdown() {
PegDownPlugins pdp = PegDownPlugins.builder().withPlugin(CustomHeadersParserPlugin.class).build();
PegDownProcessor mdp = new PegDownProcessor(MDP_SETTINGS, PROCESSING_TIME_LIMIT, pdp);
RootNode rn = mdp.parseMarkdown(text.toCharArray());
String result = new CustomMarkdownToHtmlSerializer().toHtml(rn);
if (result != null)
this.text = result;
else
logger.debug("Could not process markdown in {} seconds", PROCESSING_TIME_LIMIT / 1000);
return this;
}
Test:
#Test
public void testmarkdownWithoutCode() {
String before = "Simple new line\nTest\n\nTest\nVot";
String expected = "<p>Simple new line<br />Test</p><p>Test<br />Vot</p>".replaceAll("\r", "");
HtmlMdProc textProc = new HtmlMdProc(before);
String result = textProc.markdown().text();
assertEquals(expected, result);
}
Testing Exeption:
java.lang.RuntimeException: Error creating extended parser class: null
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.parboiled.transform.AsmUtils.createClassReader(AsmUtils.java:56)
at org.parboiled.transform.ClassNodeInitializer.process(ClassNodeInitializer.java:62)
at org.parboiled.transform.ParserTransformer.extendParserClass(ParserTransformer.java:44)
at org.parboiled.transform.ParserTransformer.transformParser(ParserTransformer.java:38)
at org.parboiled.Parboiled.createParser(Parboiled.java:54)
at org.pegdown.plugins.PegDownPlugins$Builder.withPlugin(PegDownPlugins.java:113)
at com.myorg.html.services.HtmlMdProc.markdown(HtmlMdProc.java:317)
at com.myorg.html.services.HtmlMdProcTest.testmarkdownWithoutCode(HtmlMdProcTest.java:262)
Can I somehow bind my CustomHeadersParserPlugin avoiding spooky Reflections?
If not, tell me how to setup maven-bundle-plugin in pom.xml to make it work with pegdown v 1.4.2.
I found Issue with discussion Here, but I'm too novice to deal alone with Maven plugins and Reflections.
The only solution is to wait for This Issue to be closed, until I thing there is no luck with Pegdown and Java 8.
I am trying to read text contents of a webpage ( based on source ), but seem to be unable to make the connection. What could be the issue?
EDIT: updated stack trace
I ran this is debug mode and see the following:
JP_FetchWebPageHeader(Object).<init>()
Source not found
I was able to single setp in spite of the above error. is this a error message an issue?
I'm using eclipse on 64 bit windows and Java 1.7
The code is :
// **** Fetch web page or header
import java.io.*;
import java.net.*;
import java.util.Scanner;
public final class JP_FetchWebPageHeader {
/**
* #param aArgs
* <ul>
* <li> aArgs[0] : an HTTP URL
* <li> aArgs[1] : (header | content)
* </ul>
*/
public static void main(String...aArgs) throws MalformedURLException {
String url = aArgs[0];
String option = aArgs[1];
JP_FetchWebPageHeader fetcher = new JP_FetchWebPageHeader(url);
if (HEADER.equalsIgnoreCase(option)) {
log(fetcher.getPageHeader());
}else if (CONTENT.equalsIgnoreCase(option)) {
log(fetcher.getPageContent());
}else {
log("Unknown option.");
}
}
public JP_FetchWebPageHeader(URL aURL) {
if( ! HTTP.equals(aURL.getProtocol())) {
throw new IllegalArgumentException("URL isnt for HTTP protocol: " + aURL);
}
fURL = aURL;
}
public JP_FetchWebPageHeader(String aUrlName ) throws MalformedURLException {
this(new URL(aUrlName));
}
// Fetch the HTML content of the web page as simple text
public String getPageContent() {
String result = null;
URLConnection connection = null;
try {
connection = fURL.openConnection();
Scanner scanner = new Scanner(connection.getInputStream());
scanner.useDelimiter(END_OF_INPUT);
result = scanner.next();
} catch (IOException ex ) {
log("Cannot open connection to " + fURL.toString());
}
return result;
}
//Fetch HTML headers as simple text
public String getPageHeader() {
return null;
}
//PRIVATE
private URL fURL;
private static final String HTTP = "http";
private static final String HEADER = "header";
private static final String CONTENT = "content";
private static final String END_OF_INPUT = "\\Z";
private static final String NEWLINE = System.getProperty("line.separator");
private static void log(Object aObject){
System.out.println(aObject);
}
}
Arguments: http://www.google.com content
Result :
Cannot open connection to http://www.google.com
java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
null
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at JP_FetchWebPageHeader.getPageContent(JP_FetchWebPageHeader.java:54)
at JP_FetchWebPageHeader.main(JP_FetchWebPageHeader.java:30)
I needed to write a JavaAgent in a Lotus Notes 6.5 DB to access a web service. I used Axis Apache API for this purpose. I created A Java agent and added the jar files of axis in the agent by using Edit Project button.
Below is the agent code:
import lotus.domino.*;
import javax.xml.*;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
import java.net.URL;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
String endpoint = "http://ws.apache.org:5049/axis/services/echo";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint) );
call.setOperationName(new QName("http://soapinterop.org/", "echoString"));
String ret = (String) call.invoke( new Object[] { "Hello!" } );
System.out.println("Sent 'Hello!', got '" + ret + "'");
} catch(Exception e) {
e.printStackTrace();
}
}
}
And below is the exception thrown:
java.lang.ExceptionInInitializerError: org.apache.commons.discovery.DiscoveryException: No implementation defined for org.apache.commons.logging.LogFactory
at org.apache.commons.discovery.tools.SPInterface.newInstance(SPInterface.java:197)
at org.apache.commons.discovery.tools.DiscoverClass.newInstance(DiscoverClass.java:579)
at org.apache.commons.discovery.tools.DiscoverSingleton.find(DiscoverSingleton.java:418)
at org.apache.commons.discovery.tools.DiscoverSingleton.find(DiscoverSingleton.java:378)
at org.apache.axis.components.logger.LogFactory$1.run(LogFactory.java:84)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.axis.components.logger.LogFactory.getLogFactory(LogFactory.java:80)
at org.apache.axis.components.logger.LogFactory.<clinit>(LogFactory.java:72)
at org.apache.axis.configuration.EngineConfigurationFactoryFinder.<clinit>(EngineConfigurationFactoryFinder.java:94)
at org.apache.axis.client.Service.<init>(Service.java:111)
at JavaAgent.NotesMain(JavaAgent.java:17)
at lotus.domino.AgentBase.runNotes(Unknown Source)
at lotus.domino.NotesThread.run(NotesThread.java:218)
I thried to follow some links on the internet like, But i was not able to get exactly what it was asking to do. eg: http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/40d033fba3897f4d85256cd30034026a?OpenDocument
Any help will be great. All i wanted to do is write an agent so that i can access a web service, say temperature conversion web service on w3schools. http://www.w3schools.com/webservices/tempconvert.asmx?op=FahrenheitToCelsius
I googled with your error message and this is the first hit:
http://croarkin.blogspot.fi/2010/08/commons-logging-headaches-with-axis.html
It suggests using a commons-logging.properties file with:
org.apache.commons.logging.Log = org.apache.commons.logging.impl.Log4JLogger
org.apache.commons.logging.LogFactory = org.apache.commons.logging.impl.LogFactoryImpl
or putting this to your code:
#BeforeClass
public static void beforeClass() {
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger");
System.setProperty("org.apache.commons.logging.LogFactory", "org.apache.commons.logging.impl.LogFactoryImpl");
}
Probably you've already tried this because it's the first hit with google but just in case...
I am trying to read a pdf from a url without downloading and then i am trying to flatten it .
This is the code :
import java.io.FileOutputStream;
import com.lowagie.text.pdf.AcroFields;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;
public class FormFillAndMakeItFlattenPDF {
public static void main(String[] args) {
try {
PdfReader reader = new PdfReader("http://www.irs.gov/pub/irs-pdf/fw4.pdf");
PdfStamper stamp2 = new PdfStamper(reader, new FileOutputStream("C:\\Flattened.pdf"));
AcroFields form2 = stamp2.getAcroFields();
stamp2.setFormFlattening(true);
stamp2.close();
}
catch (Exception de) {
de.printStackTrace();
}
}
}
However, this is throwing an error/exception . This is the stacktrace :
java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:352)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:214)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:201)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:377)
at java.net.Socket.connect(Socket.java:530)
at java.net.Socket.connect(Socket.java:480)
at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:406)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:541)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:245)
at sun.net.www.http.HttpClient.New(HttpClient.java:318)
at sun.net.www.http.HttpClient.New(HttpClient.java:335)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:832)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:773)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:698)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1021)
at java.net.URL.openStream(URL.java:1009)
at com.lowagie.text.pdf.RandomAccessFileOrArray.<init>(Unknown Source)
at com.lowagie.text.pdf.RandomAccessFileOrArray.<init>(Unknown Source)
at com.lowagie.text.pdf.PRTokeniser.<init>(Unknown Source)
at com.lowagie.text.pdf.PdfReader.<init>(Unknown Source)
at com.lowagie.text.pdf.PdfReader.<init>(Unknown Source)
at FormFillAndMakeItFlattenPDF.main(FormFillAndMakeItFlattenPDF.java:18)
Can anybody tell me , what i am doing wrong here ?
If the problem happens because of proxy, call this at application startup.
System.setProperty("http.proxyHost", Config.PROXY_HOST);
System.setProperty("http.proxyPort", Config.PROXY_PORT);
where you change Config.X to your system values.
Note: for https you need to add similar lines with https.proxyHost and https.proxyPort
Your exact code works for me. I am using iText-4.2.0 (*) on Windows with Java 7.
Here is the code I ran, the test is green and "Flattened.pdf" is created correctly:
public class PdfTest {
#Test
public void testFlatten() throws Exception {
PdfReader reader = new PdfReader("http://www.irs.gov/pub/irs-pdf/fw4.pdf");
PdfStamper stamp2 = new PdfStamper(reader, new FileOutputStream("C:\\Users\\david\\Flattened.pdf"));
AcroFields form2 = stamp2.getAcroFields();
stamp2.setFormFlattening(true);
stamp2.close();
}
}
(*) https://github.com/ymasory/iText-4.2.0