Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Stardust/Knowledge Base/Integration/UI/UIMashup/VB NET Example

Introduction

This example assumes that the reader is familiar with the use of the External Web Application type provided by Stardust. The example model referenced here may be downloaded from this location.

ASPX Page

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="ExtWebApp._Default"%>
<%@ import Namespace="System.Xml.XPath" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>External Web App Example</title>
    <script type="text/javascript" src="<%=ippPortalBaseUri %>/plugins/processportal/IppProcessPortal.js"></script>
</head>
<body>
    <form id="StudData" runat="server">
    <asp:Label Text="Profile"  runat="server" ID="StudProfile" 
        Font-Bold="True" Font-Names="Californian FB"/>
    <p>
        <asp:Label ID="lbl_LabelPersonId" runat="server"></asp:Label>
        <asp:TextBox id="txt_PersonId" runat="server" type="text"/></p>    
    <p>
        <asp:Label ID="lbl_LabelFirstName" runat="server"></asp:Label>
        <asp:TextBox id="txt_FirstName" runat="server" type="text"/></p>
    <p>
        <asp:Label ID="lbl_LabelLastName" runat="server"></asp:Label>
        <asp:TextBox id="txt_LastName" runat="server" type="text"/></p>
    <p>
        <asp:Label ID="lbl_LabelAge" runat="server"></asp:Label>
        <asp:TextBox id="txt_Age" runat="server" type="text"/></p>
 
    <asp:Label Text="Address"  runat="server" ID="StudAddress" 
        Font-Bold="True" Font-Names="Californian FB"/>
    <p>
        <asp:Label ID="lbl_LabelStreet1" runat="server"></asp:Label>
        <asp:TextBox id="txt_Street1" runat="server" type="text"/></p>
    <p>
        <asp:Label ID="lbl_LabelStreet2" runat="server"></asp:Label>
        <asp:TextBox id="txt_Street2" runat="server" type="text"/></p>    
    <p>
        <asp:Label ID="lbl_LabelCity" runat="server"></asp:Label>
        <asp:TextBox id="txt_City" runat="server" type="text"/></p>    
    <p>
        <asp:Label ID="lbl_LabelState" runat="server"></asp:Label>
        <asp:TextBox id="txt_State" runat="server" type="text"/></p>    
    <p>
        <asp:Label ID="lbl_LabelZip" runat="server"></asp:Label>
        <asp:TextBox id="txt_Zip" runat="server" type="text"/></p>    
    <p>
        <asp:Button ID="BtnSubmit" runat="server" Text="Submit"/>
    </p>
    </form>    
</body>
</html>

Code Behind Page

Imports System.Xml.XPath
Imports System.Xml
Imports System.Xml.XPath.XPathExpression
Imports System.Collections
Imports System.Text.ASCIIEncoding
Imports System.Net
Imports System.IO
 
Partial Public Class _Default
    Inherits System.Web.UI.Page
    Protected ippInteractionUri As String
    Protected ippPortalBaseUri As String
    Protected ippServicesBaseUri As String
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ippInteractionUri = HttpContext.Current.Request("ippInteractionUri")
        ippPortalBaseUri = HttpContext.Current.Request("ippPortalBaseUri")
        ippServicesBaseUri = HttpContext.Current.Request("ippServicesBaseUri")
        If Page.IsPostBack = False Then
            Try
                Dim xpathDoc = New XPathDocument(ippInteractionUri + "/inData")
                Dim xmlNav = xpathDoc.CreateNavigator()
                xmlNav.MoveToFirstChild()
                xmlNav.MoveToChild("parameter", "http://infinity.com/bpm/ws/v2009a/api")
                xmlNav.MoveToChild("xml", "http://infinity.com/bpm/ws/v2009a/api")
                xmlNav.MoveToFirstChild()
                Dim xmlNI = xmlNav.SelectChildren(XPathNodeType.Element, False)
                System.Diagnostics.Debug.WriteLine(xmlNI.Current.Name & " " & xmlNI.Current.Value)
                While xmlNI.Current.HasChildren
                    xmlNI.Current.MoveToFirstChild()
                    System.Diagnostics.Debug.WriteLine(xmlNI.Current.Name & " " & xmlNI.Current.Value)
                    Call Extract_FormParams(xmlNI.Current.Name, xmlNI.Current.Value)
                    While xmlNI.Current.MoveToNext
                        System.Diagnostics.Debug.WriteLine(xmlNI.Current.Name & " " & xmlNI.Current.Value)
                        Call Extract_FormParams(xmlNI.Current.Name, xmlNI.Current.Value)
                    End While
                End While
            Catch ex As XPathException
                System.Diagnostics.Debug.WriteLine("XMLException: " + ex.Message)
            Catch ex As Exception
                System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message)
            End Try
        End If
    End Sub
 
    Private Sub Extract_FormParams(ByVal formVar As String, ByVal formVal As String)
        Select Case formVar
            Case "Id"
                lbl_LabelPersonId.Text = formVar
                txt_PersonId.Text = formVal
            Case "FirstName"
                lbl_LabelFirstName.Text = formVar
                txt_FirstName.Text = formVal
            Case "LastName"
                lbl_LabelLastName.Text = formVar
                txt_LastName.Text = formVal
            Case "Age"
                lbl_LabelAge.Text = formVar
                txt_Age.Text = formVal
            Case "Street1"
                lbl_LabelStreet1.Text = formVar
                txt_Street1.Text = formVal
            Case "Street2"
                lbl_LabelStreet2.Text = formVar
                txt_Street2.Text = formVal
            Case "City"
                lbl_LabelCity.Text = formVar
                txt_City.Text = formVal
            Case "State"
                lbl_LabelState.Text = formVar
                txt_State.Text = formVal
            Case "Zip"
                lbl_LabelZip.Text = formVar
                txt_Zip.Text = formVal
        End Select
    End Sub
 
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles BtnSubmit.Click
        Dim Encoding = New System.Text.ASCIIEncoding
        Dim arr = Encoding.GetBytes(BuildResponseXML())
        Dim script = New String("")
        Dim request As HttpWebRequest = CType(HttpWebRequest.Create(ippInteractionUri & "/outData/Student2"), HttpWebRequest)
        request.Method = "PUT"
        request.ContentType = "application/xml"
        request.ContentLength = arr.Length
        request.KeepAlive = True
        Dim dataStream = request.GetRequestStream()
        dataStream.Write(arr, 0, arr.Length)
        dataStream.Close()
        Try
            Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
            If response.StatusCode = HttpStatusCode.Accepted Then
                script = "InfinityBpm.ProcessPortal.completeActivity();"
            End If
        Catch ex As WebException
            script = "alert('Exception occurred submitting data!');"
        End Try
        Page.ClientScript.RegisterClientScriptBlock(Page.GetType, "OnComplete", script.ToString, True)
    End Sub
 
    Private Function BuildResponseXML() As String
        Dim xmlString As String
        Dim stringWriter As New StringWriter()
        Dim xmlTextWriter As XmlTextWriter = New XmlTextWriter(stringWriter)
        xmlTextWriter.WriteStartElement("Student")
        xmlTextWriter.WriteElementString("Id", txt_PersonId.Text)
        xmlTextWriter.WriteElementString("FirstName", txt_FirstName.Text)
        xmlTextWriter.WriteElementString("LastName", txt_LastName.Text)
        xmlTextWriter.WriteElementString("Age", txt_Age.Text)
        xmlTextWriter.WriteStartElement("Address")
        xmlTextWriter.WriteElementString("Street1", txt_Street1.Text)
        xmlTextWriter.WriteElementString("Street2", txt_Street2.Text)
        xmlTextWriter.WriteElementString("City", txt_City.Text)
        xmlTextWriter.WriteElementString("State", txt_State.Text)
        xmlTextWriter.WriteElementString("Zip", txt_Zip.Text)
        xmlTextWriter.WriteEndElement()
        xmlTextWriter.WriteEndElement()
        xmlTextWriter.Flush()
        xmlString = stringWriter.ToString()
        stringWriter.Close()
        xmlTextWriter.Close()
        System.Diagnostics.Debug.WriteLine(xmlString)
        Return xmlString
    End Function
End Class

Note

The above example deals with reading and writing back SDT values  from the external application. When dealing with primitives like strings or integer values a few minor changes are required. The code snippet below illustrates how to write back an integer value:

  Dim request As HttpWebRequest = CType(HttpWebRequest.Create(ippInteractionUri & "/outData/int2"), HttpWebRequest)
  request.Method = "PUT"
  request.ContentType = "text/plain"
  request.KeepAlive = True
  Dim intString = Encoding.GetBytes(txt_int1.Text)
  Dim intStreamString = request.GetRequestStream()
  intStreamString.Write(intString, 0, intString.Length)
  intStreamString.Close()
  Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)

Copyright © Eclipse Foundation, Inc. All Rights Reserved.