Deploy report to JasperServer via SOAP API - java

I am looking for an example on deploying a report unit to JasperServer using it's SOAP Services, preferably with a java client.

I found a way to do that with JasperServer WebServices (Set of SOAP services for managing server and data on it).
So ... the unit of data used to communicate with the server is com.jaspersoft.jasperserver.api.metadata.xml.domain.impl.ResourceDescriptor... which represents a resource... implementation of client is the following com.jaspersoft.jasperserver.irplugin.wsclient.WSClient...
to make it a bit clearer here is the code :
public void publishImage() throws Exception {
ResourceDescriptor rd = new ResourceDescriptor();
rd.setName("coffeepicture");
rd.setLabel("Coffee picture from java");
rd.setResourceType(ResourceDescriptor.TYPE_IMAGE);
rd.setMainReport(true);
rd.setParentFolder("/Samples");
rd.setUriString(rd.getParentFolder() + rd.getName());
rd.setWsType(ResourceDescriptor.TYPE_IMAGE);
rd.setIsNew(true);
rd.setHasData(true);
File image = new File("/home/coffee.jpg");
client.addOrModifyResource(rd, image);
}
The code above shows how to upload an image to the server, to deploy a report you will need to create separate ResourceDescriptors for .jrxml file and datasource if any...
Regards!

Related

Dynamic web service client from wsdl

One of my system need to invoke SOAP based webservices. As of now, for every new webservices, I generate Java stubs from the provided WSDL file and redeploy the web application with new webservice consumer code. Is there a good approach to dynamically create a webservice client that can invoke the methods from the provided WSDL files? All I am expecting is
put the WSDL file in the location that can be accessed by the web application
invoke the Servlet with a keyword having the wsdl file name, and other params required for the webservice method.
Can the Apache CXF help in this? I read in a post, generating wsdl2java in the runtime and loading the classes, over a time, can exhaust the pemgen memory space.
You should look here : http://cxf.apache.org/docs/dynamic-clients.html
This is exactly that.
here an example:
ClientImpl client = (ClientImpl)doc.getClientFromWsdl("http://myurl:8080/DataCentersWS?wsdl");
String operationName = "getVirtualisationManagerUuid";
BindingOperationInfo op = doc.getOperation(client, operationName);
List<MessagePartInfo> messagesParts = op.getInput().getMessageParts();
Object[] params = new Object[messagesParts.size()];
/* feed yours params here (this feeding was heavy in my code */
Object[] res = client.invoke(op, params);
There is many other examples in the source distribution of cxf.

WCF Service is not getting the parameter supplied from java application while calling it

I have a WCF service deployed at a certain server.
I need to call it through the JAVA application, when i am checking the parameter for this OperationContract is being passed correctly from java side but when i am logging the parameter value in WCF service, it seems not to be received here.
We are using 'basicHttpBinding' only and the attributes set for the Service and OperationContracts are as follows :-
[ServiceContract]
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[XmlSerializerFormat(Style = OperationFormatStyle.Rpc, Use = OperationFormatUse.Encoded)]
public interface IMyService
{
[WebMethod]
[OperationContract(Action = #"http://tempuri.org/GetString")]
[WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Wrapped)]
string GetString(string strParameters);
}
Can any body check if this is correct or may suggest with all the steps so that a WCF can be accessed properly through JAVA application ?
For REST ful WCF, try using WEbHTTPBinding rather basic HTTP. REST WCF support WebHTTPBindings
WebInvoke attribute is not used for BasicHttpBinding (It is for webhttpBinding). You can take that out. One way to diagnose is open config in wcf config editor (SvcConfigEditor.exe). Enable tracing (search for enabling wcf tracing), make a request to service which will generate trace file. Check the log in Trace viewer (svtraceviewer.exe). You will find place where it is failing.

Java Web service that sends excel file to client

Hi friends i am new to web services, their is requirement in my project that a webservice should be created which does some database interaction process and business logic than it has to send an excel file to the requested client [file should be downloaded on to client meachine].
I know we can send attachment in both SOAP and RESTFULL. i want to know which is the best method to send excel file and how to send it sample code so that i can get idea.
I know web service communicate through xml i want to know that convert excel file to xml and send it to client from their client convert it again to excel is that method ok from both performance and efficient point of view.
Finally i want to know which is the best method to achieve it and sample code so that i can work on it.
Updated question
This is my web service method in project A
#Path("/todo")
public class TodoResource
{
#GET
#Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response getfile(){
File file =new File("D:\\Test.xls"); // Initialize this to the File path you want to serve.
return Response.ok(file, MediaType.APPLICATION_OCTET_STREAM).build();
}
}
This in project B where i created client
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
// TODO Auto-generated method stub
System.out.println(">>>>>>>>>>>>>>>>>Starting of Project Test Call >>>>>>>>>>>>>>>>>");
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service = client.resource(getBaseURI());
//Get Excel Download
System.out.println(":::::: The Application APPLICATION_OCTET_STREAM Response :::::: ");
System.out.println(service.path("rest").path("todo").accept(MediaType.APPLICATION_OCTET_STREAM).get(String.class));
System.out.println(">>>>>>>>>>>>>>>>>Ending of Project Test Call >>>>>>>>>>>>>>>>>");
}
private static URI getBaseURI() {
return UriBuilder.fromUri("http://localhost:8080/WebService_XML").build();
}
my requirement is the client will send some info like parameter 1,parameter 2 etc. based on that it will interact with database and a file will be created. and that file should be send to client.like on click call webservice process it send that file to client, browser download popup window will appear to save or open should appear. on click save save it.
Got The Solution check here
but what about client,can any client[.net, php etc] can access this.

Netty File Server

I have been browsing the examples on both an HTTP file server and an uploading server.
I am writting a file server that can do both: send and receive files. But I am not sure about how to merge the 2 pipelines.
Or maybe I need to modify them depending on the command (upload or get a file). Even when the docs state that a pipeline cannot be modified for a channel once stablished, I see the "port unification" example does modify it depending on the data.
Any help will be greatly appreciated.
It sounds like you need a HTTP server and differentiate between HTTP GET for downloading files to the client and POST to upload files to the server instead of differentiating the types with pipelines. Take a look at HttpStaticFileServerHandler for downloading files with GET requests. What you need to adapt are the first lines of messageReceived:
#Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
HttpRequest request = (HttpRequest) e.getMessage();
if (request.getMethod().equals(HttpMethod.POST)) {
// receive uploaded file
return;
}
if (request.getMethod() != GET) {
sendError(ctx, METHOD_NOT_ALLOWED);
return;
}
...
I think that you need to think of your app as 2 sub-apps in one.
The first sub-app being the file server. You will need to bootstrap and create a pipeline for that as per the Http file server example.
The second sub-app being the upload client. You will need to separately bootstrap and create pipeline for that as per the http client example.

Spring ws : how to access to the size of an AxiomAttachment

In order to get an attachment i have the following code in an endpoint :
#PayloadRoot(localPart = REQUEST_ELEMENT, namespace = MODELES_V1_0_URI)
#ResponsePayload
public Source saveFile(MessageContext argo) throws Exception {
(AxiomSoapMessage)MessageContextHolder.getMessageContext().getRequest();
AxiomSoapMessage request = (AxiomSoapMessage)argo.getRequest();
Attachment attachement= request.getAttachments().next();
But the attachment implements AxiomAttachment (i'm using AxiomSoapMessageFactory) and according to this class " Axiom does not support getting the size of attachments.".
How can i get the size of the attachement ?
Iv try to use this in order to be able to send big files (more than 10 mo) as an attachement to prevent an outofMemory (any better idea will be appreciate - i have already try the mtom spring sample but it doesnt work with heavy file (outOfMemory too) even by specifying the AxiomSoapMessageFactory).
Im open to any better solution (the spring ws mtom sample doesnt work..) for dealing with heavy file with spring ws
It's not really possible to get the size of a file before you save it off from the DataHandler. Think about it. MTOM is a technology to stream binary files to a web service. The question you've asked is akin to saying "How long is this telephone call going to last?" You can't know for sure until you've hung up the phone.

Categories

Resources