How to obtain Real-time ECReports(xml) from NotificationURI?

Questions about using and running the Rifidi Edge Server

Moderators: Matt, kyle

Post Reply
ww100hh
Posts: 16
Joined: Thu Aug 26, 2010 3:23 am
Organization: cvi

How to obtain Real-time ECReports(xml) from NotificationURI?

Post by ww100hh » Thu Aug 26, 2010 3:40 am

My English is poor,Sorry.
I am a new rifidi user.I couldn't find any application example which introduce how to obtain Real-time ECReports(xml) and deal with those xml from subscribe NotificationURI,so I couldn't write application code.I don't known which shape the ECReports xml file is . Do you have application examples?

ww100hh
Posts: 16
Joined: Thu Aug 26, 2010 3:23 am
Organization: cvi

How to obtain Real-time ECReports(xml) from NotificationURI?

Post by ww100hh » Thu Aug 26, 2010 3:45 am

I couldn't find any application example about how to obtain Real-time ECReports(xml) from NotificationURI and how to deal with it? I don't know which shape the ECReports xml are.Do you have examples?

kyle
Posts: 220
Joined: Tue Apr 22, 2008 10:12 pm
Name: Kyle
Organization: Pramari
Location: Hartford, CT
Contact:

Re: How to obtain Real-time ECReports(xml) from NotificationURI?

Post by kyle » Mon Aug 30, 2010 1:29 pm

The only client we have built is the workbench. You can find the sourcecode here: https://svn.rifidi.org/svn/rep-edge/rif ... cspecview/

I think you need to pass in your ip and port in a string like this "127.0.0.1:1000" to subscribe. The Edge server will then send back XML strings to that IP and port.

ww100hh
Posts: 16
Joined: Thu Aug 26, 2010 3:23 am
Organization: cvi

Re: How to obtain Real-time ECReports(xml) from NotificationURI?

Post by ww100hh » Wed Sep 01, 2010 3:19 am

Thank you very much.After reading source code you have given link, I know the client application must use socketserver thread now.
But I get into new trouble. See my code below.
ALEService service = new ALEService("http://localhost:8081/ALELRService?wsdl", new QName("urn:epcglobal:ale:wsdl:1", "ALEService"));
ALEServicePortType aleServicePort = service.getALEServicePort();
ECSpec myECSpec = readECSpec("file:///D:/myApp/myECSpec.xml");
Define parms = new Define();
parms.setSpec(myECSpec);
parms.setSpecName("myECSpec");
aleServicePort.define(parms);

Right? Now I have a ECSpec xml file which name is myECSpec.xml. It is saved on D dish of my machine.How to convert this file name to ECSpec object ? I want to do this in readECSpec method.How to program?

kyle
Posts: 220
Joined: Tue Apr 22, 2008 10:12 pm
Name: Kyle
Organization: Pramari
Location: Hartford, CT
Contact:

Re: How to obtain Real-time ECReports(xml) from NotificationURI?

Post by kyle » Thu Sep 02, 2010 3:57 pm

Which web service framework are you using? I think we used CXF for the client. This would be a question to ask of the web service framework. There is probably a way to handle it using an xml framework like JAXB, but I'm not really sure.

ww100hh
Posts: 16
Joined: Thu Aug 26, 2010 3:23 am
Organization: cvi

Re: How to obtain Real-time ECReports(xml) from NotificationURI?

Post by ww100hh » Fri Sep 03, 2010 3:28 am

Thank you!
Yes.use JAXB indeed.Your workbench source use it also.
My example application has been finished writing. See my code below.

package com.cvicse.edgeserver;

import java.io.IOException;
import java.io.FileReader;

import java.net.URL;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.namespace.QName;

import org.rifidi.edge.epcglobal.ale.api.read.data.ECReports;
import org.rifidi.edge.epcglobal.ale.api.read.data.ECSpec;
import org.rifidi.edge.epcglobal.ale.api.read.ws.ALEService;
import org.rifidi.edge.epcglobal.ale.api.read.ws.ALEServicePortType;
import org.rifidi.edge.epcglobal.ale.api.read.ws.Immediate;

public class ALEDemo
{
public static void main(String[] args)
{

try
{
URL url = new URL("http://localhost:8081/ALEService?wsdl");
System.out.println("Target ALE Service: " + url.toString());

ALEService service = new ALEService(url, new QName("urn:epcglobal:ale:wsdl:1", "ALEService"));
ALEServicePortType aleServicePort = service.getALEServicePort();

String ecSpecFilename = "D:\\myECSpec.xml";

ECSpec myECSpec = readECSpec(ecSpecFilename);

Immediate parms = new Immediate();
parms.setSpec(myECSpec);
ECReports reports = aleServicePort.immediate( parms);

printECReports(reports) ;

}
catch (Exception e)
{
System.out.println("ERROR: " + e.getMessage());
e.printStackTrace();
}
}

private static ECSpec readECSpec(String ecSpecFilename)
throws IOException
{
ECSpec ecSpec = new ECSpec();
try {
//JAXBContext jc = JAXBContext.newInstance("org.rifidi.edge.epcglobal.ale.api.read.data");
//JAXBContext jc = JAXBContext.newInstance("org.rifidi.edge.epcglobal.ale.api.read.data");
JAXBContext jc = JAXBContext.newInstance(ECSpec.class);
FileReader fileReader = new FileReader(ecSpecFilename);
Unmarshaller umarsh = jc.createUnmarshaller();
ecSpec = (ECSpec) umarsh.unmarshal(fileReader);
} catch (JAXBException e) {
e.printStackTrace();
}
return ecSpec;
}


private static void printECReports(ECReports ecReports)
throws IOException
{
System.out.println("Received the following ECReports:\n");
System.out.println("InitiationCondition:" + ecReports.getInitiationCondition());
System.out.println("TotalMilliseconds:" + ecReports.getTotalMilliseconds());
}

}


But I get a exception when running it.
ERROR: javax.xml.bind.JAXBElement cannot be cast to org.rifidi.edge.epcglobal.ale.api.read.data.ECSpec
java.lang.ClassCastException: javax.xml.bind.JAXBElement cannot be cast to org.rifidi.edge.epcglobal.ale.api.read.data.ECSpec
at com.cvicse.edgeserver.ALEDemo.readECSpec(ALEDemo.java:356)
at com.cvicse.edgeserver.ALEDemo.main(ALEDemo.java:116)


I have spend a lot of time to debug it by change the configuration of JAXBContext and Unmarshaller object.But still get that exception.I was dizzy.
Can you help me?

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests