private void correctionButton_Click(object sender, System.EventArgs e)
        {
            if (false == ValidatePublisher())
            {
                return;
            }

            try
            {
                ConnectionManager.BeginTransaction();

                //
                // Deserialize into a change record object
                //
                StringReader reader = new StringReader(correctionTextBox.Text);

                ChangeRecordCorrection changeRecordCorrection = ( ChangeRecordCorrection )correctionSerializer.Deserialize(reader);

                //
                // Validate what we created.
                //
                SchemaCollection.Validate(changeRecordCorrection);

                //
                // Create a new change record to hold the correction.
                //
                ChangeRecord changeRecord = new ChangeRecord(changeRecordCorrection);
                changeRecord.Process();
                ConnectionManager.Commit();

                //
                // If we made it this far, we were able to process the correction
                //
                MessageBox.Show("Correction processed!");

                //
                // Refresh our display.
                //
                ShowChangeRecord();
            }
            catch (Exception exception)
            {
                ConnectionManager.Abort();

                MessageBox.Show("An exception occurred when trying to process the correction:\r\n\r\n" + exception.ToString());
            }
        }
        private void Validate(SoapMessage message)
        {
            Debug.Enter();

            StreamReader srdr = new StreamReader(message.Stream, System.Text.Encoding.UTF8);

#if DEBUG
            Debug.Write(SeverityType.Verbose, CategoryType.None, srdr.ReadToEnd());
            message.Stream.Seek(0, System.IO.SeekOrigin.Begin);
#endif
            //
            // Validate incoming XML, ValidateStream will rewind stream when finished
            // so I don't have to.
            //
            SchemaCollection.Validate(message.Stream);

            Debug.Leave();
        }
        public override void ProcessMessage(SoapMessage message)
        {
            try
            {
                switch (message.Stage)
                {
                case SoapMessageStage.BeforeDeserialize:
                    //
                    // Check to see if the server has been manually stopped.
                    //
                    if (0 == Config.GetInt("Run", 1))
                    {
                        DispositionReport.ThrowFinal(new UDDIException(ErrorType.E_busy, "UDDI_ERROR_BUSY_SERVICENOTAVAILABLE"));

                        //
                        // DispositionReport.ThrowFinal will close the HTTP stream so there is no point going on in this method
                        //
                        return;
                    }

                    try
                    {
                        //
                        // Validate against the UDDI schemas
                        //
                        SchemaCollection.Validate(oldStream);
                    }
                    catch (Exception e)
                    {
                        DispositionReport.ThrowFinal(new UDDIException(ErrorType.E_fatalError, "UDDI_ERROR_FATALERROR_SCHEMAVALIDATIONFAILED", e.Message));

                        //
                        // DispositionReport.ThrowFinal will close the HTTP stream so there is no point going on in this method
                        //
                        return;
                    }

                    //
                    // Make sure we only have 1 UDDI request in the SOAP body.  This method will also set the versionMajor
                    // member.
                    //
                    CheckForSingleRequest(oldStream);

                    //
                    // If this is a v1 message, we'll first map it to the v2
                    // namespace so that it can be processed by the new
                    // library.
                    //
                    if (1 == Context.ApiVersionMajor || 2 == Context.ApiVersionMajor)
                    {
                        TextReader reader = new StreamReader(oldStream);
                        TextWriter writer = new StreamWriter(newStream, new System.Text.UTF8Encoding(false));
                        string     xml    = reader.ReadToEnd();

                        if (1 == Context.ApiVersionMajor)
                        {
                            xml = xml.Replace("=\"urn:uddi-org:api\"", "=\"urn:uddi-org:api_v2\"");
                            xml = xml.Replace("='urn:uddi-org:api'", "=\"urn:uddi-org:api_v2\"");
                        }
                        writer.Write(xml);
                        writer.Flush();

                        newStream.Position = 0;
                    }

                    break;

                case SoapMessageStage.AfterDeserialize:
                    //
                    // After the message is deserialized is the earliest place where we
                    // have access to our SOAP headers.
                    //
                    CheckSOAPHeaders(message);

                    //
                    // Now that the message has been deserialized, make
                    // sure that the generic and xmlns attributes agree.
                    //
                    IMessage obj = message.GetInParameterValue(0) as IMessage;
                    if (null != obj)
                    {
                        //
                        // We only need to do this if the deserialized object supports IMessage
                        //
                        string expected = Context.ApiVersionMajor + ".0";
                        string actual   = obj.Generic.Trim();

                        if (expected != actual)
                        {
                            throw new UDDIException(ErrorType.E_unrecognizedVersion, "UDDI_ERROR_UNKNOWNVERSION_GENERICNAMESPACEMISMATCH");
                        }
                    }

                    break;

                case SoapMessageStage.BeforeSerialize:
                    break;

                case SoapMessageStage.AfterSerialize:

                    //
                    // There may have been exceptions thrown during serialization.
                    //
                    if (null != message.Exception &&
                        (null == message.Exception.Detail ||
                         0 == message.Exception.Detail.ChildNodes.Count))
                    {
                        DispositionReport.ThrowFinal(new UDDIException(ErrorType.E_fatalError, "UDDI_ERROR_FATALERROR_FAILEDDESERIALIZATION"));

                        //
                        // DispositionReport.ThrowFinal will close the HTTP stream so there is no point going on in this method
                        //
                        return;
                    }

                    //
                    // If the original request was v1, then we'll need to
                    // remap the output to use the v1 namespace.
                    //
                    if (1 == Context.ApiVersionMajor || 2 == Context.ApiVersionMajor)
                    {
                        newStream.Position = 0;

                        TextReader reader = new StreamReader(newStream);
                        TextWriter writer = new StreamWriter(oldStream, new System.Text.UTF8Encoding(false));

                        string xml = reader.ReadToEnd();

                        //
                        // We don't have to use the same 'loose' replacement as we did on the incoming request
                        // because our response will be serialized such that the default namespace is our UDDI
                        // namespace.
                        //

                        if (1 == Context.ApiVersionMajor)
                        {
                            xml = xml.Replace("xmlns=\"urn:uddi-org:api_v2\"", "xmlns=\"urn:uddi-org:api\"");
                            xml = xml.Replace("generic=\"2.0\"", "generic=\"1.0\"");
                        }
                        writer.Write(xml);
                        writer.Flush();
                    }

                    break;

                default:
                    throw new UDDIException(ErrorType.E_fatalError, "UDDI_ERROR_FATALERROR_UNKNOWNEXTSTAGE");
                }
            }
            catch (Exception e)
            {
                DispositionReport.Throw(e);
            }
        }
Exemple #4
0
        public static void ImportRCF()
        {
            FileStream rcfStream = File.Open(rcfFile, FileMode.Open, FileAccess.Read, FileShare.Read);

            try
            {
                //
                // Validate the RCF file.
                //
                SchemaCollection.Validate(rcfStream);

                //
                //
                // Open our RCF file, it has already been checked to make sure it exists.
                //
                XmlTextReader rcfReader = new XmlTextReader(rcfStream);

                while (true == rcfReader.Read() && false == rcfReader.EOF)
                {
                    if (rcfReader.Name.Equals("operator") && rcfReader.NamespaceURI.Equals(UDDI.Replication.Constants.Namespace))
                    {
                        //
                        // For each operator node, we want the following information.  These are all
                        // mandatory elements, so if any were missing we should not have passed schema
                        // validation.
                        //
                        //	operatorNodeID (this is the operatorKey)
                        //  operatorStatus
                        //  soapReplicationUrl
                        //  certificate
                        //  operatorCustodyName (operatorName)
                        //

                        //
                        // Note that contacts are currently being ignored.  This is because we are not sending
                        // the businessKey for the operator.  Since we store contacts based on businessKey (actually businessID)
                        // we do not have a way of storing contacts.  IN 70 says that the operatorNodeID should actually be this
                        // businessKey, so once we decide to implement this, we'll process contacts.
                        //

                        X509Certificate certificate        = null;
                        string          operatorKey        = null;
                        string          operatorName       = null;
                        string          soapReplicationUrl = null;
                        int             operatorStatus     = 0;
                        string          localOperatorKey   = Config.GetString("OperatorKey").ToLower();

                        do
                        {
                            switch (rcfReader.Name)
                            {
                            case "operatorNodeID":
                            {
                                operatorKey = rcfReader.ReadElementString();
                                break;
                            }

                            case "operatorCustodyName":
                            {
                                operatorName = rcfReader.ReadElementString();
                                break;
                            }

                            case "operatorStatus":
                            {
                                operatorStatus = OperatorStatus2ID(rcfReader.ReadElementString());
                                break;
                            }

                            case "soapReplicationURL":
                            {
                                soapReplicationUrl = rcfReader.ReadElementString();
                                break;
                            }

                            case "certificate":
                            {
                                //
                                // Read our data in 1024 byte chunks.  Keep an array list of these
                                // chunks.
                                //
                                int       bytesRead = 0;
                                int       chunkSize = 1024;
                                ArrayList chunks    = new ArrayList();

                                do
                                {
                                    byte[] data = new byte[chunkSize];
                                    bytesRead = rcfReader.ReadBase64(data, 0, chunkSize);

                                    if (bytesRead > 0)
                                    {
                                        chunks.Add(data);
                                    }
                                }while(bytesRead != 0);

                                //
                                // Allocate a buffer to hold all of our chunks.
                                //
                                byte[] certificateData = new byte[chunks.Count * chunkSize];

                                //
                                // Copy each chunk into our buffer.  This buffer is our certificate.
                                //
                                int index = 0;
                                foreach (byte[] chunkData in chunks)
                                {
                                    Array.Copy(chunkData, 0, certificateData, index, chunkData.Length);
                                    index += chunkData.Length;
                                }

                                //
                                // Create a certificate from our byte data.
                                //
                                certificate = new X509Certificate(certificateData);
                                break;
                            }
                            }
                        }while(true == rcfReader.Read() && false == rcfReader.EOF && false == rcfReader.Name.Equals("operator"));

                        //
                        // Make sure we identify the local operator.
                        //
                        if (false == operatorKey.ToLower().Equals(localOperatorKey))
                        {
                            //
                            // Import this operator
                            //
                            SaveOperatorInfo(operatorKey, operatorName, soapReplicationUrl, operatorStatus, certificate);
                            Console.WriteLine("Successfully imported {0}.", operatorName);
                        }
                        else
                        {
                            SaveOperatorInfo(null, operatorName, soapReplicationUrl, operatorStatus, certificate);
                            Console.WriteLine("Successfully update the local operator.");
                        }
                    }
                }
            }
            catch (XmlException xmlException)
            {
                Console.WriteLine("Exception processing the RCF: ");
                Console.WriteLine("\t");
                Console.WriteLine(xmlException.ToString());
            }
            catch (XmlSchemaException schemaException)
            {
                Console.WriteLine("The RCF did not pass schema validation: ");
                Console.WriteLine("\t");
                Console.WriteLine(schemaException.ToString());
            }
            finally
            {
                rcfStream.Close();
            }
        }