Giter Club home page Giter Club logo

jxapi's People

Contributors

alexeypolyakov avatar creighton avatar itsnotyou avatar ljwolford avatar pauliejes avatar rneatrour avatar wegrata avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jxapi's Issues

Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 - When posting new Statement

Guys,

I am trying to use jxapi with OpenLrs- which is an open source LRS written in Java. So when I try to Post a single statement (or multiple statements for that matter), it returns Json response as Jsonarray. For eg:
For a post statement below:

{
  "actor": {
    "name": "Sally Glider",
    "mbox": "mailto:[email protected]"
  },
  "verb": {
    "id": "http://adlnet.gov/expapi/verbs/experienced",
    "display": { "en-US": "experienced" }
  },
  "object": {
    "id": "http://example.com/activities/solo-hang-gliding",
    "definition": {
      "name": { "en-US": "Solo Hang Gliding" }
    }
  }
}

OpenLrs' response is:

[
  "c250f7a5-859b-4080-a8cb-0972fa76b25d"
]

Now this throws an error:
Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2

in the class-StatementClient in the function:

public String postStatement(Statement statement)

at line:
JsonArray jsonResult = gson.fromJson(result, JsonArray.class);

I even tried to convert the response to Jsonarray at the source- Openlrs before returning, but it still throws the same error.

Could someone tell me what's the expected response? In the specification, there is no hint given except that it says the POST should return an array of id, which as I see it, the Openlrs does follow suit? Could anyone please help me? Thanks

NPE in Group.serialize() when no members are set in statement

I'm sending a XAPI statement with a team specified in the context.

According to the spec, a Group does not need to contain its memberlist (ico identified groups at least) :
https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Data.md#2422-when-the-actor-objecttype-is-group

So I'm sending something as for example :

  "team": {
   "objectType": "Group",
   "name": "AR2",
   "account": {
    "name": "123",
    "homePage": "https://www.example.com/groups/"
   }
  }

This is parsed by jxapi in a Group instance with uninitialized member collection (i.e. null).

When for whatever reason you want to serialize the received statement again, Group.serialize() throws an NPE.
The related code is:

public JsonElement serialize() {
		JsonObject obj = (JsonObject) super.serialize();
		JsonArray members = new JsonArray();
		for (Agent agent : this.member) {
			members.add(agent.serialize());
		}
		obj.add("member", members);
		return obj;
	}

There's no null check on this.member, contrary to eg the code in gov.adlnet.xapi.model.Context.serialize().

addFilter is not working properly

Hi , I have used the code given by you below. addFilter seemed to be working, but when I tested with some random value as filter, it is fetching other statements (which does not fall in Filter). Please check the code by posting many statements and try to apply filter.
public void testGetStatement() throws FileNotFoundException, IOException {
Properties p = new Properties();
p.load(new FileReader(new File("../jxapi/src/test/java/config/config.properties")));
lrs_uri = p.getProperty("lrs_uri");
username = p.getProperty("username");
password = p.getProperty("password");
mbox = p.getProperty("mbox");

    StatementClient client = new StatementClient(lrs_uri, username, password);
    
    Statement stmnt = new Statement(new Agent("test", mbox), 
            new Verb("http://example.com/tested"), 
            new Activity("http://example.com/" + UUID.randomUUID().toString()));
    
    HashMap<String, JsonElement> extension = new HashMap<String, JsonElement>();
    String room100key = "http://example.com/class_room_100";
    extension.put(room100key,  new JsonPrimitive("Math"));
    String room110key = "http://example.com/class_room_110";
    extension.put(room110key,  new JsonPrimitive("Science"));
    String room120key = "http://example.com/class_room_120";
    extension.put(room120key,  new JsonPrimitive("History"));
    Context context = new Context();
    context.setExtensions(extension);
    
    stmnt.setContext(context);
    client.putStatement(stmnt, stmnt.getId());
    
    client.addFilter(room120key, extension.get(room120key).getAsString()).getStatements();
}

}

Help to use jxapi

Hi dear, thanks for share your code.
I'm approaching now for the first time to xapi contents.
I am still not entirely clear what is the complete process for xapi contents.
I'm developing a LMS.
With your code is possible to upload a file (audio, video, word, power point, pdf) and download it in xapi format?
if yes, how can I do it?
what is the xapi format? a zip file?
Then, how can I extract the orginal content to and show it in an iframe?
I hope that you can help me.
Best regards
Bye Attilio

Exception handling loses HTTP errors

The exception handling (or rather, printing) code in BaseClient.issueGet() and BaseClient.issueDelete() invariably ends up throwing IOExceptions, obscuring the actual exception that occurred.

Sequence of events looks something like:

  • readFromConnection gets response code higher than 400
  • readFromConnection constructs StringBuilder with message from connection
  • readFromConnection's finally block closes the InputStreamReader
    • Closing an InputStreamReader closes the underlying stream.
  • readFromConnection throws newly constructed IOException with helpful message
  • issueGet (or issueDelete) catches the IOException
  • issueGet tries to read from the connection's error stream (which is already closed)
  • issueGet throws new IOException with no information except "stream is closed"

how to add in maven project

Sir,

Previously i have added jar and used. Now I have Maven project. for that i want to add dependency. Could you please provide me with the detail.

java.io.IOException: stream is closed

I'm trying to get statements from an LRS with the following code:

ArrayList<Statement> statements = new ArrayList<>();
Actor actor = new Agent(null, "mailto:[email protected]");

StatementClient client = new StatementClient(
        "https://my.lrs.com/TCAPI/statements",
        "lrs_username",
        "lrs_password").filterByActor(actor);

StatementResult results = client.getStatements();
statements.addAll(results.getStatements());
while (results.hasMore()) {
    results = client.getStatements(results.getMore());
    statements.addAll(results.getStatements());
}

When executing this code I get the following error:

java.io.IOException: stream is closed
    at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.ensureOpen(HttpURLConnection.java:3308)
    at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:3333)
    at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
    at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
    at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
    at java.io.InputStreamReader.read(InputStreamReader.java:184)
    at java.io.BufferedReader.fill(BufferedReader.java:161)
    at java.io.BufferedReader.readLine(BufferedReader.java:324)
    at java.io.BufferedReader.readLine(BufferedReader.java:389)
    at gov.adlnet.xapi.client.BaseClient.issueGet(BaseClient.java:212)
    at gov.adlnet.xapi.client.StatementClient.getStatements(StatementClient.java:156)

Maven repository

I'd like to use jxapi in a project, is it uploaded to any Maven repository? I saw the project is configured to deploy to Sonatype, but I'm unable to find it there. Thanks!

unable to add multiple values in extension in Object

HashMap<String, JsonElement> ext = new HashMap<>(); JsonElement je=new JsonPrimitive("location"));
ext.put(LOCATION,je);
ad.setExtensions(ext);
activity.setDefinition(ad);
statement.setObject(activity);

if I try to add one more value like classroom and classname to extension. I am getting error. Cant we add two or more values to extension? If we have some more values to be added to extension, then how can we add?

addFilter is not working

client.addFilter('context.extensions.yourExtension', 'customExtensionValue').getStatements(); I get the error, addFilter has private access in StatementClient. I am unable to use this functionality

Having an OSGi-ready jar available for jxapi?

OSGi is a popular and proven framework for developing and running modular Java applications.
Gradually more and more libraries add OSGi metadata in their MANIFEST files.

jxapi does not deliver this yet. So I'm working (in-house for the moment) on getting an OSGi-ready package built.

Is there an interest by others to have this available "officially" from this repo for instance?
I could then try to submit a pull request for this.

Dependencies include Servlet class

According to Servlet Spec 3.0 it is not allowed to include a servlet class in a web app. jxapi has a dependency on javax.servlet (see org.eclipse.jetty.orbit/javax.servlet/3.0.0.v201112011016) which is a problem when using jxapi in a web app.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.