Example usage for java.util UUID fromString

List of usage examples for java.util UUID fromString

Introduction

In this page you can find the example usage for java.util UUID fromString.

Prototype

public static UUID fromString(String name) 

Source Link

Document

Creates a UUID from the string standard representation as described in the #toString method.

Usage

From source file:net.sourceforge.msscodefactory.cffreeswitch.v2_4.CFFreeSwitchXMsgRqstHandler.CFFreeSwitchXMsgRqstSecSessionReadBySecUserIdxHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    CFFreeSwitchXMsgSchemaMessageFormatter schemaFormatter = null;
    try {//from ww  w . jav  a2s. c  o  m
        // Common XML Attributes
        String attrId = null;
        String attrSecUserId = null;
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("RqstSecSessionReadBySecUserIdx");

        CFFreeSwitchXMsgRqstHandler xmsgRqstHandler = (CFFreeSwitchXMsgRqstHandler) getParser();
        if (xmsgRqstHandler == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser()");
        }

        schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();

        ICFFreeSwitchSchemaObj schemaObj = xmsgRqstHandler.getSchemaObj();
        if (schemaObj == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser().getSchemaObj()");
        }

        // Extract Attributes
        numAttrs = attrs.getLength();
        for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
            attrLocalName = attrs.getLocalName(idxAttr);
            if (attrLocalName.equals("Id")) {
                if (attrId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("SecUserId")) {
                if (attrSecUserId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrSecUserId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("schemaLocation")) {
                // ignored
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(),
                        S_ProcName, getParser().getLocationInfo(), attrLocalName);
            }
        }

        // Ensure that required attributes have values
        if ((attrSecUserId == null) || (attrSecUserId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "SecUserId");
        }

        // Save named attributes to context
        CFLibXmlCoreContext curContext = getParser().getCurContext();
        // Convert string attributes to native Java types
        // and apply the converted attributes to the editBuff.

        UUID natSecUserId;
        natSecUserId = UUID.fromString(attrSecUserId);

        // Read the objects
        List<ICFSecuritySecSessionObj> list = schemaObj.getSecSessionTableObj()
                .readSecSessionBySecUserIdx(natSecUserId);
        String responseOpening = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFFreeSwitchXMsgSecSessionMessageFormatter.formatSecSessionRspnListOpenTag();
        xmsgRqstHandler.appendResponse(responseOpening);
        Iterator<ICFSecuritySecSessionObj> iter = list.iterator();
        ICFSecuritySecSessionObj cur;
        String subxml;
        while (iter.hasNext()) {
            cur = iter.next();
            subxml = CFFreeSwitchXMsgSecSessionMessageFormatter.formatSecSessionRspnDerivedRec("\n\t\t",
                    cur.getSecSessionBuff());
            xmsgRqstHandler.appendResponse(subxml);
        }
        String responseClosing = "\n" + "\t"
                + CFFreeSwitchXMsgSecSessionMessageFormatter.formatSecSessionRspnListCloseTag()
                + schemaFormatter.formatRspnXmlPostamble();
        xmsgRqstHandler.appendResponse(responseClosing);
    } catch (RuntimeException e) {
        CFFreeSwitchXMsgRqstHandler xmsgRqstHandler = ((CFFreeSwitchXMsgRqstHandler) getParser());
        schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();
        String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFFreeSwitchXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + schemaFormatter.formatRspnXmlPostamble();
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    } catch (Error e) {
        CFFreeSwitchXMsgRqstHandler xmsgRqstHandler = ((CFFreeSwitchXMsgRqstHandler) getParser());
        schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();
        String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFFreeSwitchXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + schemaFormatter.formatRspnXmlPostamble();
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    }
}

From source file:net.sourceforge.msscodefactory.cffreeswitch.v2_4.CFFreeSwitchXMsgRqstHandler.CFFreeSwitchXMsgRqstSecGroupMemberReadByUserIdxHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    CFFreeSwitchXMsgSchemaMessageFormatter schemaFormatter = null;
    try {/*  w w w  .  ja v  a 2  s.  c  o m*/
        // Common XML Attributes
        String attrId = null;
        String attrSecUserId = null;
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("RqstSecGroupMemberReadByUserIdx");

        CFFreeSwitchXMsgRqstHandler xmsgRqstHandler = (CFFreeSwitchXMsgRqstHandler) getParser();
        if (xmsgRqstHandler == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser()");
        }

        schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();

        ICFFreeSwitchSchemaObj schemaObj = xmsgRqstHandler.getSchemaObj();
        if (schemaObj == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser().getSchemaObj()");
        }

        // Extract Attributes
        numAttrs = attrs.getLength();
        for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
            attrLocalName = attrs.getLocalName(idxAttr);
            if (attrLocalName.equals("Id")) {
                if (attrId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("SecUserId")) {
                if (attrSecUserId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrSecUserId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("schemaLocation")) {
                // ignored
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(),
                        S_ProcName, getParser().getLocationInfo(), attrLocalName);
            }
        }

        // Ensure that required attributes have values
        if ((attrSecUserId == null) || (attrSecUserId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "SecUserId");
        }

        // Save named attributes to context
        CFLibXmlCoreContext curContext = getParser().getCurContext();
        // Convert string attributes to native Java types
        // and apply the converted attributes to the editBuff.

        UUID natSecUserId;
        natSecUserId = UUID.fromString(attrSecUserId);

        // Read the objects
        List<ICFSecuritySecGroupMemberObj> list = schemaObj.getSecGroupMemberTableObj()
                .readSecGroupMemberByUserIdx(natSecUserId);
        String responseOpening = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFFreeSwitchXMsgSecGroupMemberMessageFormatter.formatSecGroupMemberRspnListOpenTag();
        xmsgRqstHandler.appendResponse(responseOpening);
        Iterator<ICFSecuritySecGroupMemberObj> iter = list.iterator();
        ICFSecuritySecGroupMemberObj cur;
        String subxml;
        while (iter.hasNext()) {
            cur = iter.next();
            subxml = CFFreeSwitchXMsgSecGroupMemberMessageFormatter.formatSecGroupMemberRspnDerivedRec("\n\t\t",
                    cur.getSecGroupMemberBuff());
            xmsgRqstHandler.appendResponse(subxml);
        }
        String responseClosing = "\n" + "\t"
                + CFFreeSwitchXMsgSecGroupMemberMessageFormatter.formatSecGroupMemberRspnListCloseTag()
                + schemaFormatter.formatRspnXmlPostamble();
        xmsgRqstHandler.appendResponse(responseClosing);
    } catch (RuntimeException e) {
        CFFreeSwitchXMsgRqstHandler xmsgRqstHandler = ((CFFreeSwitchXMsgRqstHandler) getParser());
        schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();
        String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFFreeSwitchXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + schemaFormatter.formatRspnXmlPostamble();
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    } catch (Error e) {
        CFFreeSwitchXMsgRqstHandler xmsgRqstHandler = ((CFFreeSwitchXMsgRqstHandler) getParser());
        schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();
        String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFFreeSwitchXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + schemaFormatter.formatRspnXmlPostamble();
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    }
}

From source file:net.sourceforge.msscodefactory.cffreeswitch.v2_4.CFFreeSwitchXMsgRqstHandler.CFFreeSwitchXMsgRqstTSecGroupMemberReadByUserIdxHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    CFFreeSwitchXMsgSchemaMessageFormatter schemaFormatter = null;
    try {/*from  ww  w .j a va 2  s.  c o  m*/
        // Common XML Attributes
        String attrId = null;
        String attrSecUserId = null;
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("RqstTSecGroupMemberReadByUserIdx");

        CFFreeSwitchXMsgRqstHandler xmsgRqstHandler = (CFFreeSwitchXMsgRqstHandler) getParser();
        if (xmsgRqstHandler == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser()");
        }

        schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();

        ICFFreeSwitchSchemaObj schemaObj = xmsgRqstHandler.getSchemaObj();
        if (schemaObj == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser().getSchemaObj()");
        }

        // Extract Attributes
        numAttrs = attrs.getLength();
        for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
            attrLocalName = attrs.getLocalName(idxAttr);
            if (attrLocalName.equals("Id")) {
                if (attrId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("SecUserId")) {
                if (attrSecUserId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrSecUserId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("schemaLocation")) {
                // ignored
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(),
                        S_ProcName, getParser().getLocationInfo(), attrLocalName);
            }
        }

        // Ensure that required attributes have values
        if ((attrSecUserId == null) || (attrSecUserId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "SecUserId");
        }

        // Save named attributes to context
        CFLibXmlCoreContext curContext = getParser().getCurContext();
        // Convert string attributes to native Java types
        // and apply the converted attributes to the editBuff.

        UUID natSecUserId;
        natSecUserId = UUID.fromString(attrSecUserId);

        // Read the objects
        List<ICFSecurityTSecGroupMemberObj> list = schemaObj.getTSecGroupMemberTableObj()
                .readTSecGroupMemberByUserIdx(natSecUserId);
        String responseOpening = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFFreeSwitchXMsgTSecGroupMemberMessageFormatter.formatTSecGroupMemberRspnListOpenTag();
        xmsgRqstHandler.appendResponse(responseOpening);
        Iterator<ICFSecurityTSecGroupMemberObj> iter = list.iterator();
        ICFSecurityTSecGroupMemberObj cur;
        String subxml;
        while (iter.hasNext()) {
            cur = iter.next();
            subxml = CFFreeSwitchXMsgTSecGroupMemberMessageFormatter
                    .formatTSecGroupMemberRspnDerivedRec("\n\t\t", cur.getTSecGroupMemberBuff());
            xmsgRqstHandler.appendResponse(subxml);
        }
        String responseClosing = "\n" + "\t"
                + CFFreeSwitchXMsgTSecGroupMemberMessageFormatter.formatTSecGroupMemberRspnListCloseTag()
                + schemaFormatter.formatRspnXmlPostamble();
        xmsgRqstHandler.appendResponse(responseClosing);
    } catch (RuntimeException e) {
        CFFreeSwitchXMsgRqstHandler xmsgRqstHandler = ((CFFreeSwitchXMsgRqstHandler) getParser());
        schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();
        String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFFreeSwitchXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + schemaFormatter.formatRspnXmlPostamble();
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    } catch (Error e) {
        CFFreeSwitchXMsgRqstHandler xmsgRqstHandler = ((CFFreeSwitchXMsgRqstHandler) getParser());
        schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();
        String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFFreeSwitchXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + schemaFormatter.formatRspnXmlPostamble();
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    }
}

From source file:org.noorganization.instalist.server.api.UnitResourceTest.java

@Test
public void testGetUnits() throws Exception {
    String url = "/groups/%d/units";

    Response notAuthorizedResponse = target(String.format(url, mGroup.getId())).request().get();
    assertEquals(401, notAuthorizedResponse.getStatus());

    Response wrongAuthResponse = target(String.format(url, mGroup.getId())).request()
            .header(HttpHeaders.AUTHORIZATION, "X-Token wrongauth").get();
    assertEquals(401, wrongAuthResponse.getStatus());

    Response wrongGroupResponse = target(String.format(url, mNAGroup.getId())).request()
            .header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken).get();
    assertEquals(401, wrongGroupResponse.getStatus());

    Response okResponse1 = target(String.format(url, mGroup.getId())).request()
            .header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken).get();
    assertEquals(200, okResponse1.getStatus());
    UnitInfo[] allUnitInfo = okResponse1.readEntity(UnitInfo[].class);
    assertEquals(2, allUnitInfo.length);
    for (UnitInfo current : allUnitInfo) {
        if (mUnit.getUUID().equals(UUID.fromString(current.getUUID()))) {
            assertEquals("unit1", current.getName());
            assertEquals(mUnit.getUpdated(), current.getLastChanged().toInstant());
            assertFalse(current.getDeleted());
        } else if (mDeletedUnit.getUUID().equals(UUID.fromString(current.getUUID()))) {
            assertNull(current.getName());
            assertEquals(mDeletedUnit.getUpdated(), current.getLastChanged().toInstant());
            assertTrue(current.getDeleted());
        } else/*from  w  ww . j  av  a  2 s  .  com*/
            fail("Unexpected unit.");
    }

    Thread.sleep(1000);
    mManager.getTransaction().begin();
    mUnit.setUpdated(Instant.now());
    mManager.getTransaction().commit();
    Response okResponse2 = target(String.format(url, mGroup.getId()))
            .queryParam("changedsince", ISO8601Utils.format(new Date(System.currentTimeMillis() - 500), true))
            .request().header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken).get();
    assertEquals(200, okResponse2.getStatus());
    UnitInfo[] oneUnitInfo = okResponse2.readEntity(UnitInfo[].class);
    assertEquals(1, oneUnitInfo.length);
    assertEquals(mUnit.getUUID(), UUID.fromString(oneUnitInfo[0].getUUID()));
    assertEquals("unit1", oneUnitInfo[0].getName());
    assertFalse(oneUnitInfo[0].getDeleted());
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskXMsgRqstHandler.CFAsteriskXMsgRqstLogOutHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    CFAsteriskXMsgSchemaMessageFormatter schemaFormatter = null;
    try {/* w ww. j ava  2  s  .com*/
        // Common XML Attributes
        String attrId = null;
        // Request Attributes
        String attrSecSessionId = null;
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("RqstLogOut");

        CFAsteriskXMsgRqstHandler xmsgRqstHandler = (CFAsteriskXMsgRqstHandler) getParser();
        if (xmsgRqstHandler == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser()");
        }

        schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();

        ICFAsteriskSchemaObj schemaObj = xmsgRqstHandler.getSchemaObj();
        if (schemaObj == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser().getSchemaObj()");
        }

        // Extract Attributes
        numAttrs = attrs.getLength();
        for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
            attrLocalName = attrs.getLocalName(idxAttr);
            if (attrLocalName.equals("Id")) {
                if (attrId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("SecSessionId")) {
                if (attrSecSessionId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrSecSessionId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("schemaLocation")) {
                // ignored
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(),
                        S_ProcName, getParser().getLocationInfo(), attrLocalName);
            }
        }

        // Ensure that required attributes have values
        if ((attrSecSessionId == null) || (attrSecSessionId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "SecSessionId");
        }

        UUID secSessionId = UUID.fromString(attrSecSessionId);
        if (secSessionId == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "converted-secSessionId");
        }
        if (schemaObj.getAuthorization() == null) {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Already disconnected from the database");
        }
        ICFSecuritySecSessionObj secSession = schemaObj.getSecSession();
        if (secSession == null) {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Security session does not exist for this schema");
        }
        if (!secSessionId.equals(secSession.getRequiredSecSessionId())) {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Security session id does not match the one established by this schema");
        }
        if (secSession.getOptionalFinish() == null) {
            schemaObj.rollback();
            schemaObj.beginTransaction();
            ICFSecuritySecSessionEditObj editSecSession = secSession.beginEdit();
            editSecSession.setOptionalFinish(Calendar.getInstance());
            editSecSession.update();
            editSecSession.endEdit();
            schemaObj.commit();
        }
        schemaObj.disconnect(false);
        schemaObj.setAuthorization(null);
        String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFAsteriskXMsgSchemaMessageFormatter.formatRspnLoggedOut("\n\t\t\t", secSessionId) + "\n"
                + schemaFormatter.formatRspnXmlPostamble();
        ((CFAsteriskXMsgRqstHandler) getParser()).appendResponse(response);
    } catch (RuntimeException e) {
        CFAsteriskXMsgRqstHandler xmsgRqstHandler = ((CFAsteriskXMsgRqstHandler) getParser());
        schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();
        String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFAsteriskXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + schemaFormatter.formatRspnXmlPostamble();
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    } catch (Error e) {
        CFAsteriskXMsgRqstHandler xmsgRqstHandler = ((CFAsteriskXMsgRqstHandler) getParser());
        schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();
        String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFAsteriskXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + schemaFormatter.formatRspnXmlPostamble();
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    }
}

From source file:org.noorganization.instalist.server.api.RecipeResourceTest.java

@Test
public void testGetRecipes() throws Exception {
    String url = "/groups/%d/recipes";

    Response notAuthorizedResponse = target(String.format(url, mGroup.getId())).request().get();
    assertEquals(401, notAuthorizedResponse.getStatus());

    Response wrongAuthResponse = target(String.format(url, mGroup.getId())).request()
            .header(HttpHeaders.AUTHORIZATION, "X-Token wrongauth").get();
    assertEquals(401, wrongAuthResponse.getStatus());

    Response wrongGroupResponse = target(String.format(url, mNAGroup.getId())).request()
            .header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken).get();
    assertEquals(401, wrongGroupResponse.getStatus());

    Response okResponse1 = target(String.format(url, mGroup.getId())).request()
            .header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken).get();
    assertEquals(200, okResponse1.getStatus());
    RecipeInfo[] allRecipeInfo = okResponse1.readEntity(RecipeInfo[].class);
    assertEquals(2, allRecipeInfo.length);
    for (RecipeInfo current : allRecipeInfo) {
        if (mRecipe.getUUID().equals(UUID.fromString(current.getUUID()))) {
            assertEquals("recipe1", current.getName());
            assertEquals(mRecipe.getUpdated(), current.getLastChanged().toInstant());
            assertFalse(current.getDeleted());
        } else if (mDeletedRecipe.getUUID().equals(UUID.fromString(current.getUUID()))) {
            assertNull(current.getName());
            assertEquals(mDeletedRecipe.getUpdated(), current.getLastChanged().toInstant());
            assertTrue(current.getDeleted());
        } else/*from w ww  .  jav  a 2s  .co  m*/
            fail("Unexpected recipe.");
    }

    Thread.sleep(200);
    mManager.getTransaction().begin();
    mRecipe.setUpdated(Instant.now());
    mManager.getTransaction().commit();
    Response okResponse2 = target(String.format(url, mGroup.getId()))
            .queryParam("changedsince", ISO8601Utils.format(new Date(System.currentTimeMillis() - 100), true))
            .request().header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken).get();
    assertEquals(200, okResponse2.getStatus());
    RecipeInfo[] oneRecipeInfo = okResponse2.readEntity(RecipeInfo[].class);
    assertEquals(1, oneRecipeInfo.length);
    assertEquals(mRecipe.getUUID(), UUID.fromString(oneRecipeInfo[0].getUUID()));
    assertEquals("recipe1", oneRecipeInfo[0].getName());
    assertFalse(oneRecipeInfo[0].getDeleted());
}

From source file:com.dynatrace.cf.servicebroker.catalog.Service.java

Service addAllPlans(/*@Value("${RUXIT_PLANS}")*/ Map<String, DynatracePlan> dynatracePlans)
        throws ParseException {

    for (DynatracePlan dynatrace_plan : dynatracePlans.values()) {
        String dynatracePlanId = dynatrace_plan.getPlanId();
        String dynatracePlanName = dynatrace_plan.getName();

        plan().id(UUID.fromString(dynatracePlanId)).name(dynatracePlanName)
                .description("Service plan for " + dynatracePlanName).metadata()
                .bullets("JVM Performance analysis", "Browser End User Monitoring",
                        "Database call response time & throughput", "Performance data AI access",
                        "Synthetics Monitoring", "Software Analytics")
                .displayName(dynatracePlanName.toUpperCase()).cost().amount("usd", 0.0).unit("MONTHLY").and()
                .and().free(true);/*from www  .j  a v a  2  s.  c  o m*/
    }
    return this;
}

From source file:net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrmXMsgRqstHandler.CFCrmXMsgRqstSecSessionReadByFinishIdxHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    try {/*from  w  w  w. j a v  a2  s  . com*/
        // Common XML Attributes
        String attrId = null;
        String attrSecUserId = null;
        String attrFinish = null;
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("RqstSecSessionReadByFinishIdx");

        CFCrmXMsgRqstHandler xmsgRqstHandler = (CFCrmXMsgRqstHandler) getParser();
        if (xmsgRqstHandler == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser()");
        }

        ICFCrmSchemaObj schemaObj = xmsgRqstHandler.getSchemaObj();
        if (schemaObj == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser().getSchemaObj()");
        }

        // Extract Attributes
        numAttrs = attrs.getLength();
        for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
            attrLocalName = attrs.getLocalName(idxAttr);
            if (attrLocalName.equals("Id")) {
                if (attrId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("SecUserId")) {
                if (attrSecUserId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrSecUserId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("Finish")) {
                if (attrFinish != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrFinish = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("schemaLocation")) {
                // ignored
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(),
                        S_ProcName, getParser().getLocationInfo(), attrLocalName);
            }
        }

        // Ensure that required attributes have values
        if ((attrSecUserId == null) || (attrSecUserId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "SecUserId");
        }

        // Save named attributes to context
        CFLibXmlCoreContext curContext = getParser().getCurContext();
        // Convert string attributes to native Java types
        // and apply the converted attributes to the editBuff.

        UUID natSecUserId;
        natSecUserId = UUID.fromString(attrSecUserId);

        Calendar natFinish;
        try {
            natFinish = CFLibXmlUtil.parseTimestamp(attrFinish);
        } catch (RuntimeException e) {
            throw CFLib.getDefaultExceptionFactory().newInvalidArgumentException(getClass(), S_ProcName, 0,
                    "Finish", attrFinish, e);
        }

        // Read the objects
        List<ICFCrmSecSessionObj> list = schemaObj.getSecSessionTableObj()
                .readSecSessionByFinishIdx(natSecUserId, natFinish);
        String responseOpening = CFCrmXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFCrmXMsgSecSessionMessageFormatter.formatSecSessionRspnListOpenTag();
        xmsgRqstHandler.appendResponse(responseOpening);
        Iterator<ICFCrmSecSessionObj> iter = list.iterator();
        ICFCrmSecSessionObj cur;
        String subxml;
        while (iter.hasNext()) {
            cur = iter.next();
            subxml = CFCrmXMsgSecSessionMessageFormatter.formatSecSessionRspnDerivedRec("\n\t\t",
                    cur.getSecSessionBuff());
            xmsgRqstHandler.appendResponse(subxml);
        }
        String responseClosing = "\n" + "\t"
                + CFCrmXMsgSecSessionMessageFormatter.formatSecSessionRspnListCloseTag()
                + CFCrmXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
        xmsgRqstHandler.appendResponse(responseClosing);
    } catch (RuntimeException e) {
        String response = CFCrmXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFCrmXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + CFCrmXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
        CFCrmXMsgRqstHandler xmsgRqstHandler = ((CFCrmXMsgRqstHandler) getParser());
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    } catch (Error e) {
        String response = CFCrmXMsgSchemaMessageFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFCrmXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + CFCrmXMsgSchemaMessageFormatter.formatRspnXmlPostamble();
        CFCrmXMsgRqstHandler xmsgRqstHandler = ((CFCrmXMsgRqstHandler) getParser());
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    }
}

From source file:net.sourceforge.msscodefactory.cffreeswitch.v2_4.CFFreeSwitchXMsgRqstHandler.CFFreeSwitchXMsgRqstLogOutHandler.java

public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
    CFFreeSwitchXMsgSchemaMessageFormatter schemaFormatter = null;
    try {//from   ww  w.  j a  v  a 2s .c  o  m
        // Common XML Attributes
        String attrId = null;
        // Request Attributes
        String attrSecSessionId = null;
        // Attribute Extraction
        String attrLocalName;
        int numAttrs;
        int idxAttr;
        final String S_ProcName = "startElement";
        final String S_LocalName = "LocalName";

        assert qName.equals("RqstLogOut");

        CFFreeSwitchXMsgRqstHandler xmsgRqstHandler = (CFFreeSwitchXMsgRqstHandler) getParser();
        if (xmsgRqstHandler == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser()");
        }

        schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();

        ICFFreeSwitchSchemaObj schemaObj = xmsgRqstHandler.getSchemaObj();
        if (schemaObj == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "getParser().getSchemaObj()");
        }

        // Extract Attributes
        numAttrs = attrs.getLength();
        for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
            attrLocalName = attrs.getLocalName(idxAttr);
            if (attrLocalName.equals("Id")) {
                if (attrId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("SecSessionId")) {
                if (attrSecSessionId != null) {
                    throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                            S_ProcName, S_LocalName, attrLocalName);
                }
                attrSecSessionId = attrs.getValue(idxAttr);
            } else if (attrLocalName.equals("schemaLocation")) {
                // ignored
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(),
                        S_ProcName, getParser().getLocationInfo(), attrLocalName);
            }
        }

        // Ensure that required attributes have values
        if ((attrSecSessionId == null) || (attrSecSessionId.length() <= 0)) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "SecSessionId");
        }

        UUID secSessionId = UUID.fromString(attrSecSessionId);
        if (secSessionId == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "converted-secSessionId");
        }
        if (schemaObj.getAuthorization() == null) {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Already disconnected from the database");
        }
        ICFSecuritySecSessionObj secSession = schemaObj.getSecSession();
        if (secSession == null) {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Security session does not exist for this schema");
        }
        if (!secSessionId.equals(secSession.getRequiredSecSessionId())) {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Security session id does not match the one established by this schema");
        }
        if (secSession.getOptionalFinish() == null) {
            schemaObj.rollback();
            schemaObj.beginTransaction();
            ICFSecuritySecSessionEditObj editSecSession = secSession.beginEdit();
            editSecSession.setOptionalFinish(Calendar.getInstance());
            editSecSession.update();
            editSecSession.endEdit();
            schemaObj.commit();
        }
        schemaObj.disconnect(false);
        schemaObj.setAuthorization(null);
        String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFFreeSwitchXMsgSchemaMessageFormatter.formatRspnLoggedOut("\n\t\t\t", secSessionId) + "\n"
                + schemaFormatter.formatRspnXmlPostamble();
        ((CFFreeSwitchXMsgRqstHandler) getParser()).appendResponse(response);
    } catch (RuntimeException e) {
        CFFreeSwitchXMsgRqstHandler xmsgRqstHandler = ((CFFreeSwitchXMsgRqstHandler) getParser());
        schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();
        String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFFreeSwitchXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + schemaFormatter.formatRspnXmlPostamble();
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    } catch (Error e) {
        CFFreeSwitchXMsgRqstHandler xmsgRqstHandler = ((CFFreeSwitchXMsgRqstHandler) getParser());
        schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();
        String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t"
                + CFFreeSwitchXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n"
                + schemaFormatter.formatRspnXmlPostamble();
        xmsgRqstHandler.resetResponse();
        xmsgRqstHandler.appendResponse(response);
        xmsgRqstHandler.setCaughtException(true);
    }
}