Package com.dgwave.osrs.jaxb

Examples of com.dgwave.osrs.jaxb.OPSEnvelope


  }

  public OsrsResponse sendReceive(OsrsRequest request) throws OsrsException {

    String ret = sendReceive(getString(request));
    OPSEnvelope resp = createEnvelope(ret);
    OsrsResponse response = orf.createResponse(request, resp);
      return response;
  }
View Full Code Here


      throw new OsrsException("Sending post got exception ", ex);
    }
  }

  protected OPSEnvelope createEnvelope(String ret) throws OsrsException {
    OPSEnvelope opsEnvelope = null;
    try {

          InputSource inputSource = new InputSource(new StringReader(ret));
          SAXSource source = new SAXSource(xmlReader, inputSource);     
      Unmarshaller u = jc.createUnmarshaller();
View Full Code Here

    return opsEnvelope;
  }

  protected OPSEnvelope getEmptyEnvelope() throws OsrsException {
    initJaxb();
    OPSEnvelope opsEnvelope = null;

      opsEnvelope = oj.createOPSEnvelope();
      Header header = oj.createHeader();
      header.setVersion(this.version);
      opsEnvelope.setHeader(header);
     
      DataBlock dBlock = oj.createDataBlock();
     
      Body body = oj.createBody();
      body.setDataBlock(dBlock);
     
      opsEnvelope.setBody(body);
      return opsEnvelope;
  }
View Full Code Here

      throw new OsrsException("JAXB Error", e);
    }
  }
 
  protected String getString(OsrsRequest request) throws OsrsException {
    OPSEnvelope envelope = getEmptyEnvelope();
    Map<String, Object> attrs = request.getAttributes();

    Item pro = oj.createItem();
    pro.setKey("protocol");
    pro.setStringValue(this.protocol);
    Item obj = oj.createItem();
    obj.setKey("object");
    obj.setStringValue(request.getObject());
    Item act = oj.createItem();
    act.setKey("action");
    act.setStringValue(request.getAction());
    Item att = oj.createItem();
    att.setKey("attributes");
    att.addDtAssoc(processAttrs(attrs));
   
    DtAssoc c = oj.createDtAssoc();
    c.addItem(pro);
    c.addItem(act);
    c.addItem(obj);
    c.addItem(att);
    ((List<Object>)envelope.getBody().getDataBlock()
      .getDtAass()).add(c);

   
    try {
    Marshaller m = jc.createMarshaller();
View Full Code Here

  @Test
  public void testCreateOPSEnvelope() {
    try {
      JAXBContext jc = JAXBContext.newInstance("com.dgwave.osrs.jaxb");
      ObjectFactory objFactory = new ObjectFactory();
      OPSEnvelope opsEnvelope = objFactory.createOPSEnvelope();
      Header header = objFactory.createHeader();
      header.setVersion("0.9");
      opsEnvelope.setHeader(header);
     
      Item domain = objFactory.createItem();
      domain.setKey("domain");
      domain.setStringValue("dgwave.com");
     
      DtAssoc attrs = objFactory.createDtAssoc();
      attrs.addItem(domain);
      Item attributes = objFactory.createItem();
      attributes.setKey("attributes");
      attributes.addDtAssoc(attrs);
     
     
      Item protocol = objFactory.createItem();
      protocol.setKey("protocol");
      protocol.setStringValue("XCP");
      Item action = objFactory.createItem();
      action.setKey("action");
      action.setStringValue("belongs_to_rsp");
      Item obj = objFactory.createItem();
      obj.setKey("object");
      obj.setStringValue("domain");
     
      DtAssoc top = objFactory.createDtAssoc();
      top.addItem(protocol);
      top.addItem(action);
      top.addItem(obj);
      top.addItem(attributes);
     
      DataBlock dBlock = objFactory.createDataBlock();
      dBlock.addDtAssoc(top);
     
      Body body = objFactory.createBody();
      body.setDataBlock(dBlock);
     
      opsEnvelope.setBody(body);
     
      Marshaller m = jc.createMarshaller();
      m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
      m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
      m.setProperty("com.sun.xml.internal.bind.xmlHeaders",
View Full Code Here

"</dt_assoc>" +
"</data_block>" +
"</body>" +
"</OPS_envelope>";
   
    OPSEnvelope opsEnvelope = null;
    try {
      JAXBContext jc = JAXBContext.newInstance("com.dgwave.osrs.jaxb");
      Unmarshaller u = jc.createUnmarshaller();
      opsEnvelope = (OPSEnvelope)u.unmarshal(new StringReader(xml));
    } catch (Exception e) {
View Full Code Here

 
 
  @Test
  public void testGetEmptyEnvelope() {
    try {
      OPSEnvelope evp  = client.getEmptyEnvelope();
      assertNotNull(evp);
      assertEquals("Version", "0.9", evp.getHeader().getVersion());
     
    } catch (OsrsException e) {
      e.printStackTrace();
      fail ("Error while creating empty envelope");
    }
View Full Code Here

      "<item key=\"response_code\">200</item>\n" +
      "</dt_assoc>\n" +
      "</data_block>\n" +
      "</body>\n" +
      "</OPS_envelope>\n";
      OPSEnvelope evp  = client.createEnvelope(sampleResponse);
      assertNotNull(evp);
      assertEquals("Version ", "0.9", evp.getHeader().getVersion());
      Item item = (Item)((DtAssoc)evp.getBody().getDataBlock().getDtAass().get(0)).getDtAassi().get(5);
      assertEquals("Simple ", "is_success", item.getKey());
      assertNotNull(item.getStringValue());
      assertEquals("Value ", "1", item.getStringValue());
     
    } catch (OsrsException e) {
View Full Code Here

TOP

Related Classes of com.dgwave.osrs.jaxb.OPSEnvelope

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.