Running jrxlm report with Jasper Server - java

I have created jrxml report by iReport. Then I have run it with JasperServer and it work perfectly. I have generate pdf report by this URL:
http://localhost:8081/jasperserver/flow.html/flowFile/my_report.pdf
It works well but when I tried to refresh the page I get this error:
An id is required to lookup a FlowDefinition
Also when I try to call this REST service in JasperServer client application I get this error:
com.sun.jersey.api.client.UniformInterfaceException: Client response status: 500
This is the Java client application to call the REST service:
public final static String serverUrl = "http://localhost:8081/jasperserver/flow.html/flowFile/my_report.xls";
public final static String serverUser = "jasperadmin";
public final static String serverPassword = "jasperadmin";
static File outPutDir= new File(System.getProperty("java.io.tmpdir"));
public static void main(String[] args) {
try {
Report report = new Report();
report.setUrl("/reports/samples/Employees");
report.setOutputFolder(outPutDir.getAbsolutePath());
JasperserverRestClient client = JasperserverRestClient.getInstance(serverUrl, serverUser, serverPassword);
File reportFile = client.getReportAsFile(report);
} catch (Exception e) {
e.printStackTrace();
}
}

flowId
When calling flow.html you must provide an action, which is put into the flowId. JasperServer is using the flow.html to provide an interface which can be accessed over the URL. For example if calling a report this would be:
_flowId=viewReportFlow
Also the report and parameters have to be provided. So with this in mind the URL could look like this:
http://localhost:8081/jasperserver/flow.html?_flowId=viewReportFlow&reportUnit=/reports/samples/Employees&j_username=the_user&j_password=secret&output=pdf
Server error
When connecting to the server, this URL is used
http://localhost:8081/jasperserver/flow.html/flowFile/my_report.xls
This is not the server URL used by JasperserverRestClient. The server URL should look like this:
http://localhost:8081/jasperserver
NOTE: flow.html is for accessing JasperServer without logging into the UI. It is not an application path where you should put your reports.

Related

How to set various parameters for Java RMI based communication?

While performing a client-server communication with various forums, I am unable to perform Remote-object's lookup on the client machine.
The errors which I receive are ConnectIOException(NoRouteToHostException), and sometimes ConnectException and sometimes someother.
This is not what I want to ask. But, the main concern is how should I setup client platform and server platform --- talking about networking details --- this is what I doubt interferes with my connection.
My questions :-
How should I edit my /etc/hosts file on both client-side and server-side? Server's IP- 192.168.1.8 & Client's IP-192.168.1.100. Means, should I add the system name in both the files:
192.168.1.8 SERVER-1 # on the server side
192.168.1.100 CLIENT-1 # on the client side
Should I edit like this? Can this be one of the possible concerns? I just want to remove any doubts left over to perform the rmi-communication!
Also, I am also setting Server's hostname property using System.setProperty("java.rmi.server.hostname",192.168.1.8); on the server side. Should I do the same on the client-side too?
I've read about setting classpath while running the java program on both server-side as well as the client-side. I did this too,but,again the same exceptions. No difference at all. I've read that since Java update 6u45, classpaths aren't necessary to include! Please throw some light on this too...
If I am missing something, Please enlighten about the same too. A brief idea/link to resources are most preferred.
You don't need any of this unless you have a problem. The most usual problem is the one described in the RMI FAQ #A.1, and editing the hosts file of the server or setting java.rmi.server.hostname in the server JVM is the solution to that.
'No route to host' is a network connectivity problem, not an RMI problem, and not one you'll solve with code or system property settings.
Setting the classpath has nothing to do with network problems.
Here is server example of which transfers an concrete class. This class must be exist in server and client classpath with same structure
Message:
public class MyMessage implements Serializable {
private static final long serialVersionUID = -696658756914311143L;
public String Title;
public String Body;
public MyMessage(String strTitle) {
Title = strTitle;
Body = "";
}
public MyMessage() {
Title = "";
Body = "";
}
}
And here is the server code that gets an message and returns another message:
public class SimpleServer {
public String ServerName;
ServerRemoteObject mRemoteObject;
public SimpleServer(String pServerName) {
ServerName = pServerName;
}
public void bindYourself() {
try {
mRemoteObject = new ServerRemoteObject(this);
java.rmi.registry.Registry iRegistry = LocateRegistry.getRegistry(RegistryContstants.RMIPort);
iRegistry.rebind(RegistryContstants.CMName, mRemoteObject);
} catch (Exception e) {
e.printStackTrace();
mRemoteObject = null;
}
}
public MyMessage handleEvent(MyMessage mMessage) {
MyMessage iMessage = new MyMessage();
iMessage.Body = "Response body";
iMessage.Title = "Response title";
return iMessage;
}
public static void main(String[] server) {
SimpleServer iServer = new SimpleServer("SERVER1");
iServer.bindYourself();
while (true) {
try {
Thread.sleep(10000);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
and here is the remote interface of server remote object:
public interface ISimpleServer extends java.rmi.Remote{
public MyMessage doaction(MyMessage message) throws java.rmi.RemoteException;
}
all you need is adding MyMessage class both in server and client classpath.

Tesseract implementing a web service to trigger OCR actions

I am trying to implement a web service which triggers OCR actions of the server side.
Client code:
...
sy = belgeArsivle(testServisIstegi, ab);
...
private static ServisYaniti belgeArsivle(com.ocr.ws.ServiceRequest serviceRequest,com.ocr.ws.Document document) {
com.ocr.ws.ServiceRequest service = new com.ocr.ws.OCRArsivWSService();
com.ocr.ws.OCRArsivWS port = service.getOCRArsivWSPort();
return port.docArchive(serviceRequest, document);
}
When I run the code on the server side there is no problem. But whenever I call the web service method from the client I got this error code:
Exception: javax.xml.ws.soap.SOAPFaultException: Unable to load library 'libtesseract302': The specified module could not be found.
The working server-side code is:
public static void main(String[] args) {
// TODO code application logic here
File imageFile = new File("...OCR\\testTurWithBarcodeScanned.png");
Tesseract instance = Tesseract.getInstance();
try {
String lang = "tur";
instance.setLanguage(lang);
String result = instance.doOCR(imageFile);
System.out.println(result);
// write in a file
try {
File file = new File("...MyOutputWithBarcode.txt");
BufferedWriter out = new BufferedWriter(new FileWriter(file));
out.write(result);
out.close();
} catch (IOException ex) {
}
} catch (TesseractException ep) {
System.err.println(ep.getMessage());
}
}
I know that this error code is about Tesseract libraries. I put the corresponding .dll files (liblept168 and libtesseract302) under the client project's folder, added corresponding libraries (jna, jai_imageio, ghost4j_0.3.1), did neccessary changes in classpath but still getting this error.
I run a test code on the server side, it works fine. But the client side code is not working. Do I need to make some extra adjustment on the client side to run this web service?
I found out that the actual problem was with the Tomcat Server. I had to put the jar files to the Tomcat's Sources under Properties, than voila!

MockWebServer's takeRequest() method takes long to response or hangs

I'm using MockWebServer library in my Android JUnit tests. I'm testing an SDK that makes calls to a server. So I'm using MockWebServer to override these server URLs and capture what the SDK is sending to make assertions on it.
The problem that I'm running into is that if I try to do server.takeRequest() and assign it to a new RecordedRequest variable, the test hangs up on the second server.takeRequest() and sometimes, even on the first one -- if I run it on an emulator it hangs on the first server.takeRequest() method but if I run it on my physical Android device, it freezes on the second server.takeRequest() method.
public void testSomething() {
final MockWebServer server = new MockWebServer();
try {
server.play();
server.enqueue(new MockResponse().setBody("")
.setResponseCode(HttpURLConnection.HTTP_INTERNAL_ERROR));
server.enqueue(new MockResponse().setBody("")
.setResponseCode(HttpURLConnection.HTTP_OK));
server.enqueue(new MockResponse().setBody("")
.setResponseCode(HttpURLConnection.HTTP_OK));
URL url = server.getUrl("/");
// This internal method overrides some of the hardcoded URLs
// within the SDK that I'm testing.
Util.overrideUrls(url.toString())
// Do some server calls via the SDK utilizing the mock server url.
RecordedRequest requestFor500 = server.takeRequest();
// Do some assertions with 'requestFor500'
// Do some more server calls via the SDK utilizing the mock server url.
/*
* This is the part where the JUnit test hangs or seems to go into
* an infinite loop and never recovers
*/
RecordedRequest requestAfter500Before200 = server.takeRequest();
} catch {
...
}
}
Am I doing something wrong or is this some type of bug with MockWebServer?
Add timeout to MockWebServer so that it does not hang
server.takeRequest(1, TimeUnit.SECONDS);
There seems to be a problem with MockWebServer's dispatch queue, which freezes for some reason when serving responses which are not 200 or 302. I have solved this by providing a custom dispatcher:
MockWebServer server = ...;
final MockResponse response = new MockResponse().setResponseCode(401);
server.setDispatcher(new Dispatcher() {
#Override
public MockResponse dispatch(RecordedRequest request)
throws InterruptedException {
return response; // this could have been more sophisticated
}
});
Tested with MockWebServer 2.0.0

image corrupted by FileUpload

I need to make a HTTP server for recieving and sending images and text(less than 100 characters) to the client. I am planning to use JSON or Google Protocol Buffer.
I studied the "HttpUploadServer" example in the Netty 4.0.6 package.
Then, I deleted everything in the handler except things dealing with multipart POST requests.
Here's the part where I am struggling with.
private void writeHttpData(InterfaceHttpData data) {
FileUpload fileUpload = (FileUpload)data;
try {
File file = fileUpload.getFile();
file.renameTo(new File("C:\\savedFiles\\"+file.getName()));
} catch (IOException e) {
e.printStackTrace();
}
}
When I call getFile(), it gives me a corrupted file. I've tested it with zip files, and images(png, jpeg).
(BTW. I am using Postman add-on to test the server, so wrong headers are not my problem)
Is there a way to make this right?
Found an answer on Github
Change
private static final HttpDataFactory factory = new DefaultHttpDataFactory(DefaultHttpDataFactory.MINSIZE);
to
private static final HttpDataFactory factory = new DefaultHttpDataFactory(false);
or
private static final HttpDataFactory factory = new DefaultHttpDataFactory(true);
for me setting it true worked!

Following Jersey Tutorial

I am trying to follow the first part of jersey tutorial using Grizzly as the web container. I am just at the "Hello World!" part and trying to run my code. This is the main of the web services that I am trying to deploy.
public class Main {
public static void main(String [] args) throws IOException {
final String baseUri = "http://localhost:9998";
final Map<String, String > initParams = new HashMap<String, String>();
initParams.put("com.sun.jersey.config.property.packages", "com.sun.ws.rest.samples.helloworld.resources");
System.out.println("Starting grizzly");
SelectorThread threadSelector = GrizzlyWebContainerFactory.create(baseUri,initParams);
System.out.println(String.format("Jersey app started with WADL available at %sapplication.wadl Try out %shelloworld. Hit enter to stop it...", baseUri, baseUri));
System.in.read();
threadSelector.stopEndpoint();
System.exit(0);
}
}
When I run this, I always get
Exception in thread "main" java.lang.IllegalArgumentException: The URI path, of the URI http://localhost:9998, must be present
at com.sun.jersey.api.container.grizzly.GrizzlyWebContainerFactory.create(GrizzlyWebContainerFactory.java:236)
at com.sun.jersey.api.container.grizzly.GrizzlyWebContainerFactory.create(GrizzlyWebContainerFactory.java:138)
at com.sun.jersey.api.container.grizzly.GrizzlyWebContainerFactory.create(GrizzlyWebContainerFactory.java:105)
at Main.main(Main.java:29)
Does anyone know what is happening? I have made sure that my packages are all correct. I do not know how to configure grizzly and just trying to learn how to use Jersey
final String baseUri = "http://localhost:9998/";
Note the / on the end; you're missing it.

Categories

Resources