Translate

Wednesday, November 4, 2015

MS SQL Error Log Files

Yes, there are backup application log files and they can be very helpful in figuring out the cause of a backup failure. In my case I was getting the "Backup BACKUP failed to complete the command BACKUP DATABASE database_name. Check the backup application log for detailed messages.", "Backup Error: 3041, Severity: 16, State: 1" error like the following:

Checking the log file, which on my server is located in the "SQL\MSSQL12.MSSQLSERVER\MSSQL\Log" folder, I get the following:

Thursday, October 8, 2015

Java - Search for AD Groups and List Group Attributes

Added the ability to search for AD groups and get a Group's Attributes to my LDAP class:

 /**
  * 
  * @param groupName The name of the AD group.
  * @return The AD attributes for the group or null if error.
  * @throws NamingException
  */
    public Attributes getADGroupAttributes(String groupName) throws NamingException {
     this.userName = null;
        String searchFilter = "(&(objectClass=group)(cn=" + groupName + "))";
        SearchControls searchControls = new SearchControls();
        searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
        NamingEnumeration  results = ctx.search("dc=MYDOMAIN,dc=LOCAL", searchFilter, searchControls);
        SearchResult searchResult = null;
        if(results.hasMoreElements()) {
             searchResult = (SearchResult) results.nextElement();
            //make sure there is not another item available, there should be only 1 match
            if(results.hasMoreElements()) {
                this.strRes = "Matched multiple groups for the group name: " + groupName;
                return null;
            }
        }
        else{
            this.strRes = "No groups found";
            return null;         
        }
        return searchResult.getAttributes();  
    } 
 
    /**
     * 
     * @param groupName The group name to search for. Can use wild cards.
     * @return A comma delimited list of the AD group names
     * @throws NamingException
     */
    public String searchforADGroup(String groupName) throws NamingException {
     this.userName = null;
        String searchFilter = "(&(objectClass=group)(cn=" + groupName + "))";
        SearchControls searchControls = new SearchControls();
        searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
        NamingEnumeration  results = ctx.search("dc=MYDOMAIN,dc=LOCAL", searchFilter, searchControls);
        SearchResult searchResult = null;
        String strGroups = "";
        if(results!= null) {
         try {
    while(results.hasMore()) {
     searchResult = (SearchResult) results.nextElement();
     strGroups = strGroups + searchResult.getAttributes().get("cn") + ",";
    }
   } catch (Exception e) {

   }
        }
        else{
            this.strRes = "No groups found";
            return null;         
        }
        return strGroups;  
    } 

Wednesday, October 7, 2015

JQUERY - Object doesn't support property or method 'addEventListener' Error

Working on the new site and it works on my laptop for IE but loading from the site in IE it would come up was frozen. Nothing worked. Using the developer tools in IE I saw that I was getting the "Object doesn't support property or method 'addEventListener'" error in jquery. Added the following in the header of the JSP page fixed the problem:

 <meta http-equiv="X-UA-Compatible" content="IE=edge;" />

Thanks To

Tuesday, October 6, 2015

Java - Secure LDAP - simple bind failed: internews.local:636 Error

This took me a while to fix because I had to get the right certificates to install in the Java certificate store on the new server. I finally found the "cer" files on one of the domain controllers, copied the files to the new server, and then used the Java keytool utility to import the certificates into the Java certificate store.
Some tips:
Use "keytool.exe" located the the Java bin folder to import the certificates.
Import the certificates into the "cacerts" file located in the security folder under "jre\lib\security".

Monday, October 5, 2015

Tomcat - CertificateFile must be defined when using SSL with APR error

Setting Tomcat to use SSL and I was getting the "Connector attribute SSLCertificateFile must be defined when using SSL with APR" error. Had to disable APR in server.xml as follows:


  <!--
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  -->

Tomcat - Cannot Start Tomcat Service

I'm setting up a new server with Java Server 1.8 and Tomcat 8. Went to install Tomcat as a service on a Windows Server 2008 box and the install finished with an error but the Tomcat Service was there as a Windows Service. When I tried to start the service I would get an error message. The event log showed an error with Event ID 7024. The Tomcat commons-daemon log showed "[2015-10-04 07:18:16] [error] [12756] Failed creating java". What I needed to do is tell Tomcat the location of the "jvm.dll" file. I ran the tomcat8w utility located in the Tomcat bin folder and set the location on the Java tab:

Wednesday, September 16, 2015

SharePoint 2013 - Cannot Delete or Save Documents

Working on the new SharePoint 2013 and we were running into different issues. Could not save or delete documents and we received the following "Unexpected response from server. The status code..." error when replying on a list/discussion.
Looked like a permissions or authentication problem to me. Doing a trace after a save or delete I saw that it was cycling between the HTTP request and redirect to login. Changing the authentication settings on the site in IIS fixed the problems.

SharePoint - Set Trusted Root Certificate

The SharePoint sight was not displaying, there was just a blank page and no errors. I looked at the log using the ULS Viewer and found an error message "An operation failed because the following certificate has validation errors...". To fix the problem I had to add my SSL certificate as a Trusted Certificate using the Certificate Manager Snap-in in the MMC. This site has a simple explanation on how to do it.

Monday, September 14, 2015

SharePoint - Map Missing AD Attribute to User Profile Property

There are a few Active Directory Attributes that are not listed on the "Add User Profile Property" page. To add a missing attribute you have to first add a user profile property that uses any attribute from the attribute list and then modify the entry using the SharePoint Management Shell. You need to run the Management Shell with a user account that will have right permissions or you will run into errors.
The following is an example of the script:

# Richrd Golebiowski
# January 12, 2012
# Run in Sharepoint Managemnt Shell as SP_Farm
$url = "http://myssp:1000" #URL of your Central Admin site.
$spsProperty = "PostOfficeBox” #Internal name of the SharePoint user profile property
$fimProperty = "postOfficeBox” #Name of the attribute in FIM/LDAP source
$connectionName = “Ad Primary Connection” #Name of the SharePoint synchronization connection

$site = Get-SPSite $url

if ($site)
{Write-Host “Successfully obtained site reference!”}
else
{Write-Host “Failed to obtain site reference”}

$serviceContext = Get-SPServiceContext($site)

if ($serviceContext)
{Write-Host “Successfully obtained service context!”}
else
{Write-Host “Failed to obtain service context”}
$upManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileConfigManager($serviceContext)

if ($upManager)
{Write-Host “Successfully obtained user profile manager!”}
else
{Write-Host “Failed to obtain user profile manager”}
$synchConnection = $upManager.ConnectionManager[$connectionName]

if ($synchConnection)
{Write-Host “Successfully obtained synchronization connection!”}
else
{Write-Host “Failed to obtain user synchronization connection!”}

Write-Host “Adding the attribute mapping…”
$synchConnection.PropertyMapping.AddNewMapping([Microsoft.Office.Server.UserProfiles.ProfileType]::User, $spsProperty, $fimProperty)
Write-Host “Done!”

I tried running the script with my personal admin account instead of the farm account and ran into a lot of errors. The most interesting was executing "new-object Microsoft.Office.Server.UserProfiles.UserProfileConfigManager($serviceContext)" would set "$upManager" and then show "Successfully obtained user profile manager!" but the ConnectionManager would be empty and I would get a "Cannot index into a null array." error when executing "$synchConnection = $upManager.ConnectionManager[$connectionName]"

Wednesday, September 9, 2015

Spring - Using @Async to execute methods asynchronously

I have a long running database update that was added to a web application. Didn't seem right to have a method running for so long with the final result being a "Success!" message on the web page and no feedback to the client in the meantime so I made the method run asynchronously using Spring @EnableAsync and @Async. You can get my Eclipse test web application at Git Project.

Wednesday, September 2, 2015

Unit4 Agresso - Re-queue IntellAgent Events

Due to a network problem that affect SMTP we had a few IntellAgent Events that timed out. So the e-mails associated with them did not get sent. I figured out a script that would re-queue the events so that the e-mails would get sent.
My script:

begin tran
INSERT INTO [dbo].[ainqueue]
   ([alert_user_id]
   ,[destination]
   ,[error_count]
   ,[event_id]
   ,[instance_id]
   ,[last_update]
   ,[output_id]
   ,[output_seq]
   ,[output_type]
   ,[result]
   ,[sort_order]
   ,[status]
   ,[user_id])
SELECT [alert_user_id]
  ,[destination]
  ,0
  ,[event_id]
  ,[instance_id]
  ,[last_update]
  ,[output_id]
  ,[output_seq]
  ,[output_type]
  ,''
  ,[sort_order]
  ,'N'
  ,[user_id]
  FROM [dbo].[ainlog]
  where  error_count = 5 AND last_update > '8/31/2015'
  delete  FROM [dbo].[ainlog]
  where  error_count = 5 AND last_update > '8/31/2015'
  commit tran

The script copies the event information from the event log table, ainlog, to the event queue table, ainqueue and then deletes the records from the log table. The events need to be deleted from the log table so that the log for the events that we just queued up get recorded when they are executed. If yo do not delete the log records the new log record will not get written because of a constraint on the table and this will prevent the queue record from being deleted which will cause the event to be ecxecuted again and anothere e-mail sent the next time the server process runs.

Note: Your TSQL from clause will need to be set to select the correct records in your particular situation.

Saturday, August 29, 2015

Java - Authenicate against Active Directory

It turns out it's very easy using JNDI to authenticate someone against Active Directory.

/**
 * Authenticate against AD
 * @param username The user name
 * @param password The password
 * @return True if authenticate
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public boolean authenicate(String username, String password){
 boolean bRes = true;
 ResourceBundle rsBun = ResourceBundle.getBundle("LDAP_Res");
 Hashtable env = new Hashtable();
 env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
 //Use the secure connection
 env.put(Context.PROVIDER_URL, rsBun.getString("urls"));
 //Add the domain name if the user name does not contain it
 if (username.indexOf(rsBun.getString("domain")) == -1){
  username = rsBun.getString("domain") + "\\" + username;
 }
 env.put(Context.SECURITY_PRINCIPAL, username); 
 env.put(Context.SECURITY_CREDENTIALS, password); 
 try {
  LdapContext ctx = new InitialLdapContext(env,null);
  ctx.close();
 } catch (NamingException e) {
  bRes = false;
 } 
 return bRes;
}

Saturday, August 15, 2015

Java - Using web socket for push notifications

I was working on a small web application that had a long running server process and I thought it would be good to send a progress notification back to the user. The client is identified on the server by their session.

The controller:

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Iterator;
import java.util.Map.Entry;
import javax.servlet.http.HttpSession;
import javax.websocket.EndpointConfig;
import javax.websocket.OnClose;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;


@ServerEndpoint(value = "/mainwebsock", 
        configurator = GetHttpSessionConfigurator.class)
public class MainControllerWebSocket {
 private static Map mSessions = new HashMap();
 
 @OnMessage
 public void onMessage(String message, Session session) throws IOException,
   InterruptedException {
  System.out.println("User input: " + message);
  session.getBasicRemote().sendText("Hello world Mr. " + message);
  // Sending message to client each 1 second
  for (int i = 0; i <= 6; i++) {
   session.getBasicRemote().sendText(i + " Message from server");
   Thread.sleep(1000);

  }
 }
 
 public static void sendMessage(String message, String strSessionID){
  try {
   @SuppressWarnings("resource")
   Session mySes = mSessions.get(strSessionID);
   if (mySes != null && mySes.isOpen()) mySes.getBasicRemote().sendText(message);
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }

    @OnOpen
    public void open(Session session, EndpointConfig config) {
     HttpSession httpSession = (HttpSession) config.getUserProperties().get(HttpSession.class.getName());
        mSessions.put(httpSession.getId(), session);
        System.out.println("Client connected on session: " + httpSession.getId());
    }

 @SuppressWarnings("rawtypes")
 @OnClose
 public void onClose(Session session) {
  for (Iterator iter = mSessions.entrySet().iterator(); iter.hasNext();) {
     @SuppressWarnings("unchecked")
   Map.Entry  e = (Entry) iter.next();
     if (e.getValue().getId() == session.getId() ) {
      iter.remove();
     }}
  System.out.println("Connection closed");
 }
}


The session configurator:

import javax.servlet.http.HttpSession;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;

public class GetHttpSessionConfigurator extends ServerEndpointConfig.Configurator
{
    @Override
    public void modifyHandshake(ServerEndpointConfig config, 
                                HandshakeRequest request, 
                                HandshakeResponse response)
    {
        HttpSession httpSession = (HttpSession)request.getHttpSession();
        config.getUserProperties().put(HttpSession.class.getName(),httpSession);
    }
}

The JavaScript:

var webSocket = null;

function connect() {
 var wsURI = 'ws://' + window.location.host + '/INagresso/mainwebsock';
 console.log("Connecting");
 webSocket = new WebSocket(wsURI);
 
 webSocket.onerror = function(event) {
  displayMessage(event.data);
 };
 
 webSocket.onopen = function(event) {
  displayMessage("Connection open.");
 };
 
 webSocket.onmessage = function(event) {
  displayMessage(event.data);
 };
 
}


function displayMessage(data) {
document.getElementById('main_content').innerHTML += '
' + data; } function disconnect() { if (webSocket !== null) { webSocket.close(); webSocket = null; } displayMessage("WebSocket closed."); } //Button click handler function createADAcccount(){ if (webSocket == null) {connect();} $('div#main_content').empty(); $('li#value_input').html('<h1>Create AD Accounts</h1>'); $("div#main_content").load('${pageContext.request.contextPath}/testCreateAccountsAD'); }

In any server process when we want to send a message to the web client we call:

//strMessage is the message we want to send 
//and mySession.getId() is the HttpSession Id
MainControllerWebSocket.sendMessage(strMessage, mySession.getId());
Git Project

SharePoint 2013 - Start or Stop Search

Starting search using the Services Control Manager in Windows will cause problems with your SharePoint Server. The search service should be started or stopped using SharePoint Central Administration or Power Shell. When I used the Services Control Manager to start the Search Host Controller Service I would get the following error:

The Execute method of job definition Microsoft.Office.Server.Search.Administration.CustomDictionaryDeploymentJobDefinition (ID 1371766a-f3a1-4d40-a1d9-7464c0b2b2cb)
threw an exception. More information is included below.
and this in the SharePoint Log:

TCP error code 10061: No connection could be made because the target machine actively refused it 10.10.40.160:808
After this error the search service would be stopped by SharePoint and show as disabled in the Services Control Manager in Windows.

Thursday, August 13, 2015

SharePoint 2013 - Search Crawl Index Reset Error

I was working on the getting search set up and the crawl was not working. Doing a "Index Rest" would eventually time out and when I looked at the error using the ULS Viewer I found "Application error when access /_admin/search/searchreset.aspx, Error=No connection could be made because the target machine actively refused it." In my case the problems were caused by the "SharePoint Search Host Controller" service being disabled.

Tuesday, August 11, 2015

SharePoint 2013 Site Settings URL

Working on migrating our SharePoint from 2010 to 2013. I did the upgrade of the content database but then I couldn't get to the site settings because of a file not found exception. What I found I could do is go directly to the settings URL "http://xxx/_layouts/15/settings.aspx". Once there I went to "Master page" under "Look and Feel" changed the Site Master Page and System Master Page to one of the standard pages.

Wednesday, March 4, 2015

Unit4 Agresso - No mail system profile exists error

Some of the Mail Integration settings in Agresso Management Console were corrupted, displaying a message stating that "No mail system profile exists":

The fix was to individualy disable and then enable the server processes:

Sunday, February 22, 2015

Spring MVC - Basic Project

I've been learning Spring MVC and created a basic Spring project in Eclipse.
You can find the project here on Github.