Example usage for org.apache.commons.codec.binary StringUtils newStringUtf8

List of usage examples for org.apache.commons.codec.binary StringUtils newStringUtf8

Introduction

In this page you can find the example usage for org.apache.commons.codec.binary StringUtils newStringUtf8.

Prototype

public static String newStringUtf8(final byte[] bytes) 

Source Link

Document

Constructs a new String by decoding the specified array of bytes using the UTF-8 charset.

Usage

From source file:com.smartitengineering.cms.spi.impl.content.PythonGeneratorTest.java

@Test
public void testPythonRepGeneration() throws IOException {
    TypeRepresentationGenerator generator = new PythonRepresentationGenerator();
    final RepresentationTemplate template = mockery.mock(RepresentationTemplate.class);
    WorkspaceAPIImpl impl = new WorkspaceAPIImpl() {

        @Override//from   ww  w.  j  ava  2  s  .c o  m
        public RepresentationTemplate getRepresentationTemplate(WorkspaceId id, String name) {
            return template;
        }
    };
    impl.setRepresentationGenerators(Collections.singletonMap(TemplateType.JASPER, generator));
    RepresentationProvider provider = new RepresentationProviderImpl();
    final WorkspaceAPI api = impl;
    registerBeanFactory(api);
    final Content content = mockery.mock(Content.class);
    final Field field = mockery.mock(Field.class);
    final FieldValue value = mockery.mock(FieldValue.class);
    final ContentType type = mockery.mock(ContentType.class);
    final Map<String, RepresentationDef> reps = mockery.mock(Map.class, "repMap");
    final RepresentationDef def = mockery.mock(RepresentationDef.class);
    mockery.checking(new Expectations() {

        {
            exactly(1).of(template).getTemplateType();
            will(returnValue(TemplateType.JASPER));
            exactly(1).of(template).getTemplate();
            will(returnValue(IOUtils.toByteArray(
                    getClass().getClassLoader().getResourceAsStream("scripts/python/test-script.py"))));
            exactly(1).of(value).getValue();
            will(returnValue(CONTENT));
            exactly(1).of(field).getValue();
            will(returnValue(value));
            exactly(1).of(content).getField(this.<String>with(Expectations.<String>anything()));
            will(returnValue(field));
            exactly(1).of(content).getContentDefinition();
            will(returnValue(type));
            final ContentId contentId = mockery.mock(ContentId.class);
            exactly(2).of(content).getContentId();
            will(returnValue(contentId));
            final WorkspaceId wId = mockery.mock(WorkspaceId.class);
            exactly(1).of(contentId).getWorkspaceId();
            will(returnValue(wId));
            exactly(2).of(type).getRepresentationDefs();
            will(returnValue(reps));
            exactly(2).of(reps).get(with(REP_NAME));
            will(returnValue(def));
            exactly(1).of(def).getParameters();
            will(returnValue(Collections.emptyMap()));
            exactly(1).of(def).getMIMEType();
            will(returnValue(GroovyGeneratorTest.MIME_TYPE));
            final ResourceUri rUri = mockery.mock(ResourceUri.class);
            exactly(1).of(def).getResourceUri();
            will(returnValue(rUri));
            exactly(1).of(rUri).getValue();
            will(returnValue("iUri"));
        }
    });
    Representation representation = provider.getRepresentation(REP_NAME, type, content);
    Assert.assertNotNull(representation);
    Assert.assertEquals(REP_NAME, representation.getName());
    Assert.assertEquals(CONTENT, StringUtils.newStringUtf8(representation.getRepresentation()));
    Assert.assertEquals(GroovyGeneratorTest.MIME_TYPE, representation.getMimeType());
    mockery.assertIsSatisfied();
}

From source file:com.smartitengineering.cms.spi.impl.content.RubyGeneratorTest.java

@Test
public void testRubyRepGeneration() throws IOException {
    TypeRepresentationGenerator generator = new RubyRepresentationGenerator();
    final RepresentationTemplate template = mockery.mock(RepresentationTemplate.class);
    WorkspaceAPIImpl impl = new WorkspaceAPIImpl() {

        @Override//from   w w  w.  j a  v a  2s .  co  m
        public RepresentationTemplate getRepresentationTemplate(WorkspaceId id, String name) {
            return template;
        }
    };
    impl.setRepresentationGenerators(Collections.singletonMap(TemplateType.RUBY, generator));
    RepresentationProvider provider = new RepresentationProviderImpl();
    final WorkspaceAPI api = impl;
    registerBeanFactory(api);
    final Content content = mockery.mock(Content.class);
    final Field field = mockery.mock(Field.class);
    final FieldValue value = mockery.mock(FieldValue.class);
    final ContentType type = mockery.mock(ContentType.class);
    final Map<String, RepresentationDef> reps = mockery.mock(Map.class, "repMap");
    final RepresentationDef def = mockery.mock(RepresentationDef.class);
    final Map<String, Field> fieldMap = mockery.mock(Map.class);
    mockery.checking(new Expectations() {

        {
            exactly(1).of(template).getTemplateType();
            will(returnValue(TemplateType.RUBY));
            exactly(1).of(template).getTemplate();
            will(returnValue(IOUtils.toByteArray(
                    getClass().getClassLoader().getResourceAsStream("scripts/ruby/test-script.rb"))));
            exactly(1).of(template).getName();
            will(returnValue(REP_NAME));
            exactly(1).of(value).getValue();
            will(returnValue(CONTENT));
            exactly(1).of(field).getValue();
            will(returnValue(value));
            exactly(1).of(fieldMap).get(with(Expectations.<String>anything()));
            will(returnValue(field));
            exactly(1).of(content).getFields();
            will(returnValue(fieldMap));
            exactly(1).of(content).getContentDefinition();
            will(returnValue(type));
            final ContentId contentId = mockery.mock(ContentId.class);
            exactly(2).of(content).getContentId();
            will(returnValue(contentId));
            final WorkspaceId wId = mockery.mock(WorkspaceId.class);
            exactly(1).of(contentId).getWorkspaceId();
            will(returnValue(wId));
            exactly(2).of(type).getRepresentationDefs();
            will(returnValue(reps));
            exactly(2).of(reps).get(with(REP_NAME));
            will(returnValue(def));
            exactly(1).of(def).getParameters();
            will(returnValue(Collections.emptyMap()));
            exactly(1).of(def).getMIMEType();
            will(returnValue(GroovyGeneratorTest.MIME_TYPE));
            final ResourceUri rUri = mockery.mock(ResourceUri.class);
            exactly(1).of(def).getResourceUri();
            will(returnValue(rUri));
            exactly(1).of(rUri).getValue();
            will(returnValue("iUri"));
        }
    });
    Representation representation = provider.getRepresentation(REP_NAME, type, content);
    Assert.assertEquals(REP_NAME, representation.getName());
    Assert.assertEquals(CONTENT, StringUtils.newStringUtf8(representation.getRepresentation()));
    Assert.assertEquals(GroovyGeneratorTest.MIME_TYPE, representation.getMimeType());
}

From source file:com.smartitengineering.cms.spi.impl.content.JavascriptGeneratorTest.java

@Test
public void testJavascriptRepGeneration() throws IOException {
    TypeRepresentationGenerator generator = new JavascriptRepresentationGenerator();
    final RepresentationTemplate template = mockery.mock(RepresentationTemplate.class);
    WorkspaceAPIImpl impl = new WorkspaceAPIImpl() {

        @Override//from   w  ww . j a va 2  s  . c o m
        public RepresentationTemplate getRepresentationTemplate(WorkspaceId id, String name) {
            return template;
        }
    };
    impl.setRepresentationGenerators(Collections.singletonMap(TemplateType.JAVASCRIPT, generator));
    RepresentationProvider provider = new RepresentationProviderImpl();
    final WorkspaceAPI api = impl;
    registerBeanFactory(api);
    final Content content = mockery.mock(Content.class);
    final Field field = mockery.mock(Field.class);
    final FieldValue value = mockery.mock(FieldValue.class);
    final Map<String, Field> fieldMap = mockery.mock(Map.class);
    final ContentType type = mockery.mock(ContentType.class);
    final Map<String, RepresentationDef> reps = mockery.mock(Map.class, "repMap");
    final RepresentationDef def = mockery.mock(RepresentationDef.class);
    mockery.checking(new Expectations() {

        {
            exactly(1).of(template).getTemplateType();
            will(returnValue(TemplateType.JAVASCRIPT));
            exactly(1).of(template).getTemplate();
            will(returnValue(IOUtils.toByteArray(
                    getClass().getClassLoader().getResourceAsStream("scripts/js/test-script.js"))));
            exactly(1).of(template).getName();
            will(returnValue(REP_NAME));
            exactly(1).of(value).getValue();
            will(returnValue(CONTENT));
            exactly(1).of(field).getValue();
            will(returnValue(value));
            exactly(1).of(fieldMap).get(with(Expectations.<String>anything()));
            will(returnValue(field));
            exactly(1).of(content).getFields();
            will(returnValue(fieldMap));
            exactly(1).of(content).getContentDefinition();
            will(returnValue(type));
            final ContentId contentId = mockery.mock(ContentId.class);
            exactly(2).of(content).getContentId();
            will(returnValue(contentId));
            final WorkspaceId wId = mockery.mock(WorkspaceId.class);
            exactly(1).of(contentId).getWorkspaceId();
            will(returnValue(wId));
            exactly(2).of(type).getRepresentationDefs();
            will(returnValue(reps));
            exactly(2).of(reps).get(with(REP_NAME));
            will(returnValue(def));
            exactly(1).of(def).getParameters();
            will(returnValue(Collections.emptyMap()));
            exactly(1).of(def).getMIMEType();
            will(returnValue(GroovyGeneratorTest.MIME_TYPE));
            final ResourceUri rUri = mockery.mock(ResourceUri.class);
            exactly(1).of(def).getResourceUri();
            will(returnValue(rUri));
            exactly(1).of(rUri).getValue();
            will(returnValue("iUri"));
        }
    });
    Assert.assertNotNull(SmartContentAPI.getInstance());
    Assert.assertNotNull(SmartContentAPI.getInstance().getContentLoader());
    Representation representation = provider.getRepresentation(REP_NAME, type, content);
    Assert.assertNotNull(representation);
    Assert.assertEquals(REP_NAME, representation.getName());
    Assert.assertEquals(CONTENT, StringUtils.newStringUtf8(representation.getRepresentation()));
    Assert.assertEquals(GroovyGeneratorTest.MIME_TYPE, representation.getMimeType());
}

From source file:es.uah.cc.ie.utils.DrushUpdater.java

/**
 * @param String
 */
private String decode(String s) {
    return StringUtils.newStringUtf8(Base64.decodeBase64(s));
}

From source file:codesample.AuthenticationSample.java

/*****************************************************************************************************************
 *
 * Get the encoded username required to authenticate user to BWS.
 *
 * @return Returns a string containing the encoded username if successful, and null otherwise.
 *
 *****************************************************************************************************************
 *//*from   w  ww  . j  a  v a2s .  c o  m*/
public static String getEncodedUserName(String username, Authenticator authenticator,
        CredentialType credentialType, String domain) throws WebServiceException {
    final String METHOD_NAME = "getEncodedUserName()";
    final String BWS_API_NAME = "_bwsUtil.getEncodedUsername()";
    logMessage("Entering %s", METHOD_NAME);
    String returnValue = null;

    GetEncodedUsernameRequest request = new GetEncodedUsernameRequest();
    request.setMetadata(REQUEST_METADATA);
    request.setUsername(username);
    request.setOrgUid(REQUEST_METADATA.getOrganizationUid());
    request.setAuthenticator(authenticator);

    request.setCredentialType(credentialType);
    request.setDomain(domain);

    GetEncodedUsernameResponse response = null;
    try {
        logRequest(BWS_API_NAME);
        response = _bwsUtil.getEncodedUsername(request);
        logResponse(BWS_API_NAME, response.getReturnStatus().getCode(), response.getMetadata());
    } catch (WebServiceException e) {
        // Log and re-throw exception.
        logMessage("Exiting %s with exception \"%s\"", METHOD_NAME, e.getMessage());
        throw e;
    }

    if (response.getReturnStatus().getCode().equals("SUCCESS")) {
        returnValue = response.getEncodedUsername();
    } else {
        logMessage("Error Message: \"%s\"", response.getReturnStatus().getMessage());
    }

    if (Base64.isBase64(returnValue)) {
        logMessage("Decoded value of encoded username \"%s\"",
                StringUtils.newStringUtf8(Base64.decodeBase64(returnValue)));
    } else {
        logMessage("Value of encoded username \"%s\"", returnValue);
    }
    logMessage("Exiting %s", METHOD_NAME);
    return returnValue;
}

From source file:com.smartitengineering.cms.spi.impl.content.GroovyGeneratorTest.java

@Test
public void testGroovyRepGeneration() throws IOException {
    TypeRepresentationGenerator generator = new GroovyRepresentationGenerator();
    final RepresentationTemplate template = mockery.mock(RepresentationTemplate.class);
    WorkspaceAPIImpl impl = new WorkspaceAPIImpl() {

        @Override/*from www .  j  a va 2s  . c  o m*/
        public RepresentationTemplate getRepresentationTemplate(WorkspaceId id, String name) {
            return template;
        }
    };
    impl.setRepresentationGenerators(Collections.singletonMap(TemplateType.GROOVY, generator));
    RepresentationProvider provider = new RepresentationProviderImpl();
    final WorkspaceAPI api = impl;
    registerBeanFactory(api);
    final Content content = mockery.mock(Content.class);
    final Field field = mockery.mock(Field.class);
    final FieldValue value = mockery.mock(FieldValue.class);
    final ContentType type = mockery.mock(ContentType.class);
    final Map<String, RepresentationDef> reps = mockery.mock(Map.class, "repMap");
    final RepresentationDef def = mockery.mock(RepresentationDef.class);
    mockery.checking(new Expectations() {

        {
            exactly(1).of(template).getTemplateType();
            will(returnValue(TemplateType.GROOVY));
            exactly(1).of(template).getTemplate();
            will(returnValue(IOUtils.toByteArray(getClass().getClassLoader()
                    .getResourceAsStream("scripts/groovy/GroovyTestRepresentationGenerator.groovy"))));
            exactly(1).of(template).getName();
            will(returnValue(REP_NAME));
            exactly(1).of(value).getValue();
            will(returnValue(CONTENT));
            exactly(1).of(field).getValue();
            will(returnValue(value));
            exactly(1).of(content).getField(this.<String>with(Expectations.<String>anything()));
            will(returnValue(field));
            exactly(1).of(content).getContentDefinition();
            will(returnValue(type));
            final ContentId contentId = mockery.mock(ContentId.class);
            exactly(2).of(content).getContentId();
            will(returnValue(contentId));
            final WorkspaceId wId = mockery.mock(WorkspaceId.class);
            exactly(1).of(contentId).getWorkspaceId();
            will(returnValue(wId));
            exactly(2).of(type).getRepresentationDefs();
            will(returnValue(reps));
            exactly(2).of(reps).get(with(REP_NAME));
            will(returnValue(def));
            exactly(1).of(def).getParameters();
            will(returnValue(Collections.emptyMap()));
            exactly(1).of(def).getMIMEType();
            will(returnValue(GroovyGeneratorTest.MIME_TYPE));
            final ResourceUri rUri = mockery.mock(ResourceUri.class);
            exactly(1).of(def).getResourceUri();
            will(returnValue(rUri));
            exactly(1).of(rUri).getValue();
            will(returnValue("iUri"));
        }
    });
    Representation representation = provider.getRepresentation(REP_NAME, type, content);
    Assert.assertNotNull(representation);
    Assert.assertEquals(REP_NAME, representation.getName());
    Assert.assertEquals(GroovyGeneratorTest.MIME_TYPE, representation.getMimeType());
    Assert.assertEquals(CONTENT, StringUtils.newStringUtf8(representation.getRepresentation()));
}

From source file:csiro.pidsvc.mappingstore.Manager.java

public Manager(HttpServletRequest request) throws NamingException, SQLException, IOException {
    this();// ww w  .  j  a va  2s  . c o  m

    // Try to retrieve authentication details using Java API.
    _authorizationName = request.getRemoteUser();

    // If it fails try to read 'authorization' HTTP header directly.
    if (_authorizationName == null) {
        String authHeader = request.getHeader("authorization");
        if (authHeader != null && !authHeader.isEmpty() && authHeader.startsWith("Basic")) {
            // Extract user name from basic authentication HTTP header.
            authHeader = authHeader.substring(authHeader.indexOf(' '));
            authHeader = StringUtils.newStringUtf8(Base64.decodeBase64(authHeader));
            _authorizationName = authHeader.substring(0, authHeader.indexOf(':'));
        }
    }
}

From source file:kr.debop4j.core.tools.StringTool.java

/**
 * ?? Base64 ? ?? ./*  w ww  .j  a  va 2s.  com*/
 *
 * @param input the input
 * @return the string
 */
public static String encodeBase64String(final byte[] input) {
    return StringUtils.newStringUtf8(encodeBase64(input));
}

From source file:com.bzcentre.dapiPush.DapiReceiver.java

@Override
public Object[] invoke(Map<String, Object> request) {
    NginxClojureRT.log.info(TAG + " is invoked...");
    String chk_token;//ww  w. j  av  a2 s.  c om
    String user_id;
    String invitations;
    String return_code = "";
    String dummy_header = "http://www.dummy.com/dummy?"; // full url for URLEncodedUtils
    String payload;
    String provider;
    MsgCounter msgCounter = new MsgCounter();
    @SuppressWarnings("unused")
    Integer isModerator;
    String query;
    String dapiToken = newBzToken(service_seed);
    int push_status = NGX_HTTP_FORBIDDEN;

    GsonBuilder gBuilder = new GsonBuilder();
    gBuilder.registerTypeAdapter(new TypeToken<Receipient>() {
    }.getType(), new ReceipientTypeAdapter());
    Gson g = gBuilder.disableHtmlEscaping().serializeNulls().create();
    List<String[]> undeliverables = new ArrayList<>();
    Set<String> deliverables = new HashSet<>();

    String msg = "";
    errMsg = null;

    String requestMethod;

    // Supported request map constants can be find in the MiniConstants file
    requestMethod = request.get(REQUEST_METHOD).toString();
    if (requestMethod.equals(GET) && request.containsKey(QUERY_STRING)) {
        try {
            msg = dummy_header + request.get(QUERY_STRING).toString();
        } catch (NullPointerException e) {
            errMsg = "NullPointerException" + e.getMessage();
        }
    } else if (requestMethod.equals(POST)) {
        if (request.containsKey(BODY)) {
            InputStream body = (InputStream) request.get(BODY);
            BufferedReader bReader = new BufferedReader(new InputStreamReader(body));
            StringBuilder sbfFileContents = new StringBuilder();
            //read file line by line
            try {
                while ((msg = bReader.readLine()) != null) {
                    sbfFileContents.append(msg);
                }
                msg = dummy_header + sbfFileContents.toString();
            } catch (IOException e) {
                errMsg = "IOException" + e.getMessage();
            } catch (NullPointerException e) {
                errMsg = "Null Content, Error :" + e.getMessage();
            }
        } else {
            errMsg = "NO BODY";
        }
    }

    if (errMsg != null) {
        NginxClojureRT.log.info(TAG + "http parse error:" + errMsg);
        return new Object[] { NGX_HTTP_BAD_REQUEST, ArrayMap.create(CONTENT_TYPE, "text/plain"), //headers map
                "{\"method\":\"" + requestMethod + " \", \"message\":\"" + errMsg + "\"}" //response body can be string, File or Array/Collection of string or File
        };
    }
    // invitations is a base64+URLencoded string
    try {
        NginxClojureRT.log.debug(TAG + "msg get from body:\n" + msg);

        final Map<String, Object> queryMap = convertQueryStringToMap(msg);
        PushNotificationResponse<SimpleApnsPushNotification> apnsProxyResponse;
        chk_token = queryMap.get("dapiToken").toString();
        user_id = queryMap.get("user_id").toString();

        invitations = queryMap.get("invitations").toString();
        invitations = StringUtils.newStringUtf8(Base64.decodeBase64(invitations));
        NginxClojureRT.log.debug(TAG + "after base64 decode:\n" + invitations);

        if (chk_token.equals(dapiToken)) { // Hoicoi Token validation
            List<Receipient> invitees;
            NginxClojureRT.log.info(TAG + "Parsing invitees from json..." + invitations);
            invitees = g.fromJson(invitations, new TypeToken<ArrayList<Receipient>>() {
            }.getType());

            NginxClojureRT.log.info(TAG + "user " + user_id + " is sending " + invitees.size()
                    + " push token(s) to user(s) " + g.toJson(invitees.get(0).getPayload().getAcme7()));
            // receipient={"fcm_token","apns_token","payload"}
            // payload class is as APNS message payload defined, FCM needs to map to it.
            msgCounter.countdown = invitees.size();
            NginxClojureRT.log.info(TAG + "msgCounter[countdown,apns,fcm]:" + msgCounter.list());
            for (Receipient receipient : invitees) {
                return_code = "";
                payload = g.toJson(receipient.getPayload());
                //                  isModerator= receipient.getIsMdr();

                // default state sent_request, ApnsProxy will validate the result and make state update
                if (receipient.getApns_Token() != null && !receipient.getApns_Token().isEmpty()
                        && payload != null) {
                    query = "INSERT INTO `notification_push_blacklist` (`provider`,`user_id`,`to_token`) VALUES ('apns',"
                            + receipient.getPayload().getAcme8() + ",'" + receipient.getApns_Token() + "')";
                    try {
                        stmt.executeUpdate(query);
                    } catch (SQLException e) {
                        if (e.getErrorCode() != 1062) { // code 1062=duplicate entry
                            NginxClojureRT.log.info(TAG + "apns query exception near line 186: "
                                    + e.getMessage() + " when\n" + query);
                        }
                    }

                    provider = "apns";
                    switch (inBlackList(receipient.getPayload().getAcme8(), receipient.getApns_Token())) {
                    case "sent_request":
                    case "false":

                        apnsProxyResponse = apnsProxy.apnsPush(receipient.getApns_Token(), payload);

                        if (apnsProxyResponse.isAccepted()) {
                            NginxClojureRT.log.info(TAG + "Pushing notification to user "
                                    + receipient.getPayload().getAcme8() + " through APNS.");

                            MessageProcessor.pushBlackList(receipient.getApns_Token(), "whiteList", null);
                            deliverables.add(receipient.getPayload().getAcme8());
                            push_status = (push_status == NGX_HTTP_FORBIDDEN ? NGX_HTTP_NO_CONTENT
                                    : push_status); //status 204
                            return_code = "apns_pushOK";
                            msgCounter.countdown--;
                            msgCounter.apns++;
                        } else {
                            String reason = apnsProxyResponse.getRejectionReason();
                            Date timestamp = apnsProxyResponse.getTokenInvalidationTimestamp();
                            push_status = NGX_HTTP_NOT_FOUND;

                            if (reason.equals("BadDeviceToken") || reason.equals("Unregistered")) {
                                MessageProcessor.pushBlackList(receipient.getApns_Token(), reason, timestamp);
                            } else {
                                MessageProcessor.pushBlackList(receipient.getApns_Token(), "whiteList", null);
                            }

                            String[] undeliverable = { provider, receipient.getApns_Token(),
                                    receipient.getPayload().getAcme8() };
                            undeliverables.add(undeliverable);
                            msgCounter.countdown--;
                        }
                        break;
                    case "inactive":
                        push_status = NGX_HTTP_NOT_FOUND;// status 404, to indicate that the user removes the app.
                        return_code = "Unregistered";
                        String[] undeliverable = { provider, receipient.getApns_Token(),
                                receipient.getPayload().getAcme8() };
                        undeliverables.add(undeliverable);
                        msgCounter.countdown--;
                        NginxClojureRT.log.info(TAG + "Already in blacklist:" + receipient.getApns_Token());
                        break;
                    default:
                        msgCounter.countdown--;
                        return_code = "apns_blacklist_null_exception";
                        NginxClojureRT.log.info(TAG + "APNS BlackList check return null!");
                        break;
                    }
                }

                if (receipient.getFcm_Token() != null && receipient.getFcm_Token().isEmpty()
                        && payload != null) {
                    //                     Timestamp timestamp = new Timestamp(System.currentTimeMillis());
                    query = "INSERT INTO `notification_push_blacklist` (`provider`,`user_id`,`to_token`) VALUES ('fcm',"
                            + receipient.getPayload().getAcme8() + ",'" + receipient.getFcm_Token() + "')";
                    try {
                        stmt.executeUpdate(query);
                    } catch (SQLException e) {
                        if (e.getClass().getName().equals("com.mysql.jdbc.CommunicationsException")) {
                            rebuildDBConnection("stmt", query);
                        }

                        if (e.getErrorCode() != 1062) { // code 1062=duplicate entry
                            NginxClojureRT.log.info(TAG + "odbc query exception near line 223 => Code:"
                                    + e.getErrorCode() + " : " + e.getMessage() + "\n" + query);
                        }
                    }

                    provider = "fcm";
                    String responseType = inBlackList(receipient.getPayload().getAcme8(),
                            receipient.getFcm_Token());
                    switch (responseType) {
                    case "sent_request":
                    case "false":
                        msgCounter.countdown--;
                        if (fcmProxy.fcmPush(receipient.getFcm_Token(), payload)) {
                            deliverables.add(receipient.getPayload().getAcme8());
                            push_status = (push_status == NGX_HTTP_FORBIDDEN ? NGX_HTTP_NO_CONTENT
                                    : push_status); //status 204
                            return_code = "fcm_pushOK";
                            msgCounter.fcm++;
                            break;
                        } else {
                            String response = inBlackList(receipient.getPayload().getAcme8(),
                                    receipient.getFcm_Token());
                            if (!response.equals("inactive")) {
                                NginxClojureRT.log.info("TAG"
                                        + "Some thing wrong with the fcmPush. Expecting inactive but ... ->"
                                        + response);
                                break;
                            } else {
                                msgCounter.countdown++; // if is inactive, continue inactive block, so add the counter back.
                            }
                        }
                    case "inactive":
                        push_status = NGX_HTTP_NOT_FOUND;// status 404, to indicate that the user removes the app.
                        return_code = "Unregistered";
                        String[] undeliverable = { provider, receipient.getFcm_Token(),
                                receipient.getPayload().getAcme8() };
                        undeliverables.add(undeliverable);
                        msgCounter.countdown--;
                        if (responseType.equals("inactive"))
                            NginxClojureRT.log.info(TAG + "Already in blacklist:" + receipient.getFcm_Token());
                        break;
                    default:
                        msgCounter.countdown--;
                        return_code = "fcm_blacklist_null_exception";
                        NginxClojureRT.log.info(TAG + "FCM BlackList nullException!");
                        break;
                    }
                }
                NginxClojureRT.log.info(TAG + "msgCounter[countdown,apns,fcm]:" + msgCounter.list());
                if (msgCounter.countdown == 0) {
                    NginxClojureRT.log.info(TAG + "There are " + (msgCounter.apns + msgCounter.fcm)
                            + " notification(s) ha(s)(ve) been successfully pushed to user(s) "
                            + g.toJson(deliverables) + " for => "
                            + invitees.get(0).getPayload().getAps().getAlert().getBody());
                    return wrapupPushResult(receipient.getPayload().getAcme8(), push_status, return_code,
                            deliverables, msgCounter, undeliverables);
                }
            }
        } else {
            return_code = "InvalidToken";
            errMsg = "HoiCoi Token is not valid<br>" + chk_token + "<br>" + dapiToken;
        }
    } catch (IllegalArgumentException | JsonParseException | IllegalStateException | NullPointerException
            | ClassCastException | URISyntaxException e) {
        return_code = e.getClass().getName();
        errMsg = e.getMessage();
        e.printStackTrace();
    }

    return new Object[] { NGX_HTTP_FORBIDDEN, ArrayMap.create(CONTENT_TYPE, "text/plain"), //headers map
            "{\"code\":\"" + (return_code.isEmpty() ? "future_not_response" : return_code)
                    + "\", \"message\":\"Should return from the Future response.\"}" //response body can be string, File or Array/Collection of string or File
    };
}

From source file:kr.debop4j.core.tools.StringTool.java

/**
 * Decode base 64 string.//w w w . j a va2  s  .com
 *
 * @param base64Data the base 64 data
 * @return the string
 */
public static String decodeBase64String(final byte[] base64Data) {
    return StringUtils.newStringUtf8(Base64.decodeBase64(base64Data));
}