Friday, August 24, 2018

Tomcat7 Manager GUI 401

When I try to access my home server from my laptop via domain.com/manager I get brought to the page that says "401 Unauthorized You are not authorized to view this page. If you have not changed any configuration files, please examine the file conf/tomcat-users.xml in your installation. That file must contain the credentials to let you use this webapp....". However, when I try to go the manager gui from the desktop computer that is hosting tomcat, it gives me the option to log in and everything works fine.

I have set up tomcat-users.xml to look like:



  
  
  

and I have made sure to force-reload and restart.... what am I missing?

Monday, August 20, 2018

GradlePublishPlugin: How to add classifier for raw publishing file?

I am publishing binary file to Apache Archiva repository. I can add classifier via web-interface, but when it comes to gradle maven publishing plugin usage, I can only add classifiers for jar artifacts.

I am trying to publish an executable, so I pass it as file

publishing {
publications {
    exe(MavenPublication) {
        groupId "${groupId}"
        artifactId "${artifactId}"
        version "${version}"

        artifact file("build/binaries/mainExecutable/release/main.exe")

        pom.setPackaging("exe")
    }
}

Everything works well, except classifier.

Sunday, August 19, 2018

ADO Command Timeout when Stored Procedure set to UPDATE or DELETE

The Stored Procedure

I have a stored procedure on SQL Server 2000. Depending on the @Action parameter the sproc will INSERT, UPDATE, or DELETE a record. It then checks for an error, commits the transaction, and returns 1. This works perfectly from SQL Query Analyzer.

CREATE PROCEDURE dbo.spWeb_GoodsInRequestProducts
@Action Int, -- 0 = Insert, 11 = Update, 2 = Delete
@GoodsInRequestRef Int,
@ProductRef Int,
@Qty Int = Null
AS
Set NoCount On

Declare @Error Int
Begin Transaction

If @Action = 0 Begin
    INSERT INTO dbo.tblGoodsInRequestProducts (
        GoodsInRequestRef,
        ProductRef,
        Qty
    ) VALUES (
        @GoodsInRequestRef,
        @ProductRef,
        @Qty )

End

If @Action = 1 Begin
    UPDATE  dbo.tblGoodsInRequestProducts
    SET     Qty = @Qty    
    WHERE   GoodsInRequestRef = @GoodsInRequestRef
    AND     ProductRef = @ProductRef

End

If @Action = 2 Begin
    DELETE FROM dbo.tblGoodsInRequestProducts
    WHERE   GoodsInRequestRef = @GoodsInRequestRef
    AND     ProductRef = @ProductRef

End

Set @Error = @@Error
If @Error = 0 Begin
    COMMIT Transaction
    SELECT 1
End
If @Error <> 0 Begin
    ROLLBACK Transaction
    SELECT 0
End

Set NoCount Off
GO

The ADO Command

Then on an asp classic vbscript web page I have an ado command that passes some parameters to and executes the sproc. This works fine if the @Action is set to 0 (INSERT record), but set to 1 (UPDATE) or 2 (DELETE) and the page times out.

Function GoodsInProduct()
    Dim objCmd
    Set objCmd = Server.CreateObject("ADODB.Command")
    objCmd.ActiveConnection = CONN
    objCmd.CommandType = adCmdStoredProc
    objCmd.CommandText = "dbo.spWeb_GoodsInRequestProducts"     
    objCmd.Parameters.Append objCmd.CreateParameter("@Action", adInteger, adParamInput, , 2)
    objCmd.Parameters.Append objCmd.CreateParameter("@GoodsInRequestRef", adInteger, adParamInput, , 1)
    objCmd.Parameters.Append objCmd.CreateParameter("@ProductRef", adInteger, adParamInput, , 10110)
    objCmd.Parameters.Append objCmd.CreateParameter("@Qty", adInteger, adParamInput, , 8)

    Dim objRS
    Set objRS = objCmd.Execute      
    GoodsInProduct = objRS(0)

    Set objRS = Nothing
    Set objCmd = Nothing
End Function

Response.Write GoodsInProduct

I also have a near identical sproc, called from a near identical ado command on the same page, that will insert, update, and delete without any fuss. Running SQL Profiler, I see the INSERT commands come through, but I never see the UPDATE or DELETE, the page just times out. As I have said, it all works perfectly in the SQL Query Analyzer.

Is anyone able to see what I am doing wrong? Even just an alternative or some way of improving the error checking so I can see where the error occurres.

Thank you.

Things Tried

I have just tried the bare minimum and still times out on the web page but works in SQLQA:

Dim strSQL
strSQL = "DELETE FROM dbo.tblGoodsInRequestProducts WHERE GoodsInRequestRef = 1 AND ProductRef = 10110"

Dim objConn
Set objConn = server.CreateObject("ADODB.Connection")
objConn.Open CONN
objConn.Execute (strSql)
objConn.Close
Set objConn = Nothing

Solved

SOLVED

For anyone in a similar situation: Remember to close SQL Enterprise Manager, SQL Query Analyzer, and SQL Profiler if you run into any problems.

I still don't fully understand the complex inner workings of SQL Server, but I had somehow caused a backlog of TRANSACTIONS that had not been committed. After closing the programs above, the transactions all completed and things worked as expected.

If anyone understands what I had done wrong then please let us all know so that others can stay clear of this happening.


Saturday, August 18, 2018

Tab-to-tab communication using BreezeJS and localStorage

I'm using BreezeJS and storing/restoring data in local storage. That's working great. The problem occurs when the user opens multiple tabs. Changes in each tab clobber each other. Changes should be synchronised between tabs.

NB: BreezeJS will take care of merging changes, I just need to deal with race conditions between tabs.

var stashName = 'stash_everything';

window.setInterval(function () {
    var exportData = manager.exportEntities();
    window.localStorage.setItem(stashName, exportData);
}, 5000);

addEvent(window, 'storage', function (event) {
  if (event.key == stashName) {
    var importData = window.localStorage.getItem(stashName);
    manager.importEntities(importData);
  }
});

I've tried listening to the 'storage' event, but I haven't been able to get it working successfully. I either still clobber changes, or get into an infinite loop.

The crux of the issue is that I'm just saving on a timer; if I only saved after user interaction, then I'd avoid (most) race conditions. There's no 'has the user changed anything since last time I asked you' call in breeze, though, as far as I can tell.

Does anyone have advice on how to approach this?

Solved

Hmm this doesn't seem like it is impervious to having problems for many reasons but the main one would be that you still won't prevent concurrent saves from each tab with different data sets. That being said, if you are comfortable with the fact the two caches could be out of sync just use some unique identifier -

Somewhere in your app on load -

var stashName = 'stash-everything-' + new Date().getTime();

window.setInterval(function () {
    var exportData = manager.exportEntities();
    window.localStorage.setItem(stashName, exportData);
}, 5000);

Now each tab would have a unique set of data to work with.