Perlscript in Java nachbauen?

Status
Nicht offen für weitere Antworten.
G

Guest

Gast
Guten Morgen zusammen,

ist es irgendwie möglich ein Perlscript in Java nachzubauen?

Das in Perl geschriebene Script bewerkstelligt einen Zugriff auf einen Webservice, zu der keine WSDL-Datei existiert.
Wenn man in der Kommandokonsole folgendes eingibt, erhält man einen Zugriff auf Bugzilla:

Code:
meinPerlscript --uri [url]http://MeineURLZuDemScript[/url] -bugid 5555

Anschließend erhält man die Daten zu dem Bug.

Hier der Code des Scripts:

Code:
#!/usr/bin/perl -w
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the “License”); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at [url]http://www.mozilla.org/MPL/[/url]
#
# Software distributed under the License is distributed on an “AS
# IS” basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is the Bugzilla Bug Tracking System.
#
# Contributor(s): Marc Schumann <wurblzap@gmail.com>
#                 Mads Bondo Dydensborg <mbd@dbc.dk>

=head1 NAME

bz_webservice_demo.pl - Show how to talk to Bugzilla via XMLRPC

=head1 SYNOPSIS

C<bz_webservice_demo.pl [options]>

C<bz_webservice_demo.pl --help> for detailed help

=cut

use strict;
use Getopt::Long;
use Pod::Usage;
use File::Basename qw(dirname);
use File::Spec;
use HTTP::Cookies;
use XMLRPC::Lite;
use LWP::Protocol::https::Socket;

# If you want, say “use Bugzilla::WebService::Constants” here to get access
# to Bugzilla's web service error code constants.
# If you do this, remember to issue a “use lib” pointing to your Bugzilla
# installation directory, too.

my $help;
my $Bugzilla_uri;
my $Bugzilla_login;
my $Bugzilla_password;
my $Bugzilla_remember;
my $bug_id;
my $product_name;
my $create_file_name;
my $legal_field_values;

GetOptions('help|h|?'       => \$help,
           'uri=s'          => \$Bugzilla_uri,
           'login:s'        => \$Bugzilla_login,
           'password=s'     => \$Bugzilla_password,
           'rememberlogin!' => \$Bugzilla_remember,
           'bug_id:s'       => \$bug_id,
           'product_name:s' => \$product_name,
           'create:s'       => \$create_file_name,
           'field:s'        => \$legal_field_values
          ) or pod2usage({'-verbose' => 0, '-exitval' => 1});

=head1 OPTIONS

=over

=item --help, -h, -?

Print a short help message and exit.

=item --uri

URI to Bugzilla's C<xmlrpc.cgi> script, along the lines of
C<http://your.bugzilla.installation/path/to/bugzilla/xmlrpc.cgi>.

=item --login

Bugzilla login name. Specify this together with B<--password> in order to log in.

Specify this without a value in order to log out.

=item --password

Bugzilla password. Specify this together with B<--login> in order to log in.

=item --rememberlogin

Gives access to Bugzilla's “Bugzilla_remember” option.
Specify this option while logging in to do the same thing as ticking the
C<Bugzilla_remember> box on Bugilla's log in form.
Don't specify this option to do the same thing as unchecking the box.

See Bugzilla's rememberlogin parameter for details.

=item --bug_id

Pass a bug ID to have C<bz_webservice_demo.pl> do some bug-related test calls.

=item --product_name

Pass a product name to have C<bz_webservice_demo.pl> do some product-related
test calls.

=item --create

Specify a file that contains settings for the creating of a new bug.

=item --field

Pass a field name to get legal values for this field. It must be either a
global select field (such as bug_status, resolution, rep_platform, op_sys,
priority, bug_severity) or a custom select field.

=back

=head1 DESCRIPTION

=cut

pod2usage({'-verbose' => 1, '-exitval' => 0}) if $help;
_syntaxhelp('URI unspecified') unless $Bugzilla_uri;

# We will use this variable for SOAP call results.
my $soapresult;

# We will use this variable for function call results.
my $result;

# Open our cookie jar. We save it into a file so that we may re-use cookies
# to avoid the need of logging in every time. You're encouraged, but not
# required, to do this in your applications, too.
# Cookies are only saved if Bugzilla's rememberlogin parameter is set to one of
#    - on
#    - defaulton (and you didn't pass 0 as third parameter to User.login)
#    - defaultoff (and you passed 1 as third parameter to User.login)
my $cookie_jar =
    new HTTP::Cookies('file' => File::Spec->catdir(dirname($0), 'cookies.txt'),
                      'autosave' => 1);

=head2 Initialization

Using the XMLRPC::Lite class, you set up a proxy, as shown in this script.
Bugzilla's XMLRPC URI ends in C<xmlrpc.cgi>, so your URI looks along the lines
of C<http://your.bugzilla.installation/path/to/bugzilla/xmlrpc.cgi>.

=cut

my $proxy = XMLRPC::Lite->proxy($Bugzilla_uri,
                                'cookie_jar' => $cookie_jar);

=head2 Checking Bugzilla's version

To make sure the Bugzilla you're connecting to supports the methods you wish to
call, you may want to compare the result of C<Bugzilla.version> to the
minimum required version your application needs.

=cut

$soapresult = $proxy->call('Bugzilla.version');
_die_on_fault($soapresult);
print 'Connecting to a Bugzilla of version ' . $soapresult->result()->{version} . ".\n";

=head2 Checking Bugzilla's timezone

To make sure that you understand the dates and times that Bugzilla returns to you, you may want to call C<Bugzilla.timezone>.

=cut

$soapresult = $proxy->call('Bugzilla.timezone');
_die_on_fault($soapresult);
print 'Bugzilla\'s timezone is ' . $soapresult->result()->{timezone} . ".\n";

=head2 Logging In and Out

=head3 Using Bugzilla's Environment Authentication

Use a
C<http://login:password@your.bugzilla.installation/path/to/bugzilla/xmlrpc.cgi>
style URI.
You don't log out if you're using this kind of authentication.

=head3 Using Bugzilla's CGI Variable Authentication

Use the C<User.login> and C<User.logout> calls to log in and out, as shown
in this script.

The C<Bugzilla_remember> parameter is optional.
If omitted, Bugzilla's defaults apply (as specified by its C<rememberlogin>
parameter).

Bugzilla hands back cookies you'll need to pass along during your work calls.

=cut

if (defined($Bugzilla_login)) {
    if ($Bugzilla_login ne '') {
        # Log in.
        $soapresult = $proxy->call('User.login',
                                   { login => $Bugzilla_login, 
                                     password => $Bugzilla_password,
                                     remember => $Bugzilla_remember } );
        _die_on_fault($soapresult);
        print "Login successful.\n";
    }
    else {
        # Log out.
        $soapresult = $proxy->call('User.logout');
        _die_on_fault($soapresult);
        print "Logout successful.\n";
    }
}

=head2 Retrieving Bug Information

Call C<Bug.get_bug> with the ID of the bug you want to know more of.
The call will return a C<Bugzilla::Bug> object.

=cut

if ($bug_id) {
    $soapresult = $proxy->call('Bug.get_bugs', { ids => [$bug_id] });
    _die_on_fault($soapresult);
    $result = $soapresult->result;
    my $bug = $result->{bugs}->[0];
    foreach my $field (keys(%$bug)) {
        my $value = $bug->{$field};
        if (ref($value) eq 'HASH') {
            foreach (keys %$value) {
                print "$_: " . $value->{$_} . "\n";
            }
        }
        else {
            print "$field: $value\n";
        }
    }
}

=head2 Retrieving Product Information

Call C<Product.get_product> with the name of the product you want to know more
of.
The call will return a C<Bugzilla::Product> object.

=cut

if ($product_name) {
    $soapresult = $proxy->call('Product.get_product', $product_name);
    _die_on_fault($soapresult);
    $result = $soapresult->result;

    if (ref($result) eq 'HASH') {
        foreach (keys(%$result)) {
            print "$_: $$result{$_}\n";
        }
    }
    else {
        print "$result\n";
    }
}

=head2 Creating A Bug

Call C<Bug.create> with the settings read from the file indicated on
the command line. The file must contain a valid anonymous hash to use 
as argument for the call to C<Bug.create>.
The call will return a hash with a bug id for the newly created bug.

=cut

if ($create_file_name) {
    $soapresult = $proxy->call('Bug.create', do "$create_file_name" );
    _die_on_fault($soapresult);
    $result = $soapresult->result;

    if (ref($result) eq 'HASH') {
        foreach (keys(%$result)) {
            print "$_: $$result{$_}\n";
        }
    }
    else {
        print "$result\n";
    }

}

=head2 Getting Legal Field Values

Call C<Bug.legal_values> with the name of the field (including custom
select fields). The call will return a reference to an array with the
list of legal values for this field.

=cut

if ($legal_field_values) {
    $soapresult = $proxy->call('Bug.legal_values', {field => $legal_field_values} );
    _die_on_fault($soapresult);
    $result = $soapresult->result;

    print join("\n", @{$result->{values}}) . "\n";
}


=head1 NOTES

=head2 Character Set Encoding

Make sure that your application either uses the same character set
encoding as Bugzilla does, or that it converts correspondingly when using the
web service API.
By default, Bugzilla uses UTF-8 as its character set encoding.

=head2 Format For Create File

The create format file is a piece of Perl code, that should look something like
this:

    {
        product     => "TestProduct", 
        component   => "TestComponent",
        summary     => "TestBug - created from bz_webservice_demo.pl",
        version     => "unspecified",
        description => "This is a description of the bug... hohoho",
        op_sys      => "All",
        platform    => "All",	
        priority    => "P4",
        severity    => "normal"
    };

=head1 SEE ALSO

There are code comments in C<bz_webservice_demo.pl> which might be of further
help to you.

=cut

sub _die_on_fault {
    my $soapresult = shift;

    if ($soapresult->fault) {
        my ($package, $filename, $line) = caller;
        die $soapresult->faultcode . ' ' . $soapresult->faultstring .
            " in SOAP call near $filename line $line.\n";
    }
}

sub _syntaxhelp {
    my $msg = shift;

    print "Error: $msg\n";
    pod2usage({'-verbose' => 0, '-exitval' => 1});
}

Blos wie ist dies in Java möglich?
 
G

Guest

Gast
Anonymous hat gesagt.:
Code:
meinPerlscript --uri [url]http://MeineURLZuDemScript[/url] -bugid 5555

Muss heißen:

Code:
meinPerlscript --uri [url]http://MeineURLZuBugzilla[/url] -bugid 5555
 

musiKk

Top Contributor
Warum sollte es nicht moeglich sein? Perl ist turingvollstaendig, Java ist es, man kann mit beiden Sprachen alles machen.

Nur wird dir hier sicher niemand auf das Script umschreiben, da das doch mit ein wenig Arbeit verbunden ist. An und fuer sich wird da ja nur ein Keks gebastelt und per XMLRPC oder son SOAP-Zeugs (was ja eigentlich nicht das Gleiche ist, aber beide Bezeichner tauchen hier auf) an den Server geschickt, der eine entsprechende Antwort liefert.
 
G

Guest

Gast
Das ist mir schon bewusst, dass niemand hier das auf Java umschreibt. Mir fehlt nur bisher ein Ansatz. In der ersten Version wird noch nicht einmal ein Cookie gefordert. Lediglich sollte man in der Lage sein einen Bug auslesen zu können.
Ich weiß auch, dass man das mithilfe von XMLRPC realisieren kann.

Habe ich dann eine sogenannte "Bug-Klasse", die den Bug repräsentiert und eine Klasse, die eine Anfrage an einen Bug schickt? Darüber bin ich nicht im Klaren.
 

musiKk

Top Contributor
Mir ist nicht ganz klar, wo die Frage ist. Welche Klassen du erstellst, ist ganz deine Sache. Wenn du dich an dem Perl-Script orientieren willst, dann muesst du alles in eine grosse Methode schreiben, da das Script rein prozedural geschrieben wurde (mit Ausnahme der verwendeten Perl-Module).

Ich wuerde es aber durchaus so machen: Also eine Klasse, die den Bug-Abfrager repraesentiert und Bug-Objekte zurueckliefert. Aber das ist reine Geschmackssache.
 
Status
Nicht offen für weitere Antworten.
Ähnliche Java Themen
  Titel Forum Antworten Datum
J Probleme mit drucken aus Java Java Basics - Anfänger-Themen 3
Gokul Java chart library suggestion for web application? Java Basics - Anfänger-Themen 2
D wie kann ich gcc aus einer .java datei heraus aufrufen? Java Basics - Anfänger-Themen 2
S Text Formatierung in Java Java Basics - Anfänger-Themen 2
B Erste Schritte yaml parsen in Java Java Basics - Anfänger-Themen 19
C Methoden Umlaute in Java Java Basics - Anfänger-Themen 18
W Java-PRogramm liest als EXE-File Nicht USB, jedoch aus NetBeans Java Basics - Anfänger-Themen 45
W Methoden java map ersatz für c++map Java Basics - Anfänger-Themen 3
M Erste Schritte Java Primzahltester Java Basics - Anfänger-Themen 4
A csv Reader für Java? Java Basics - Anfänger-Themen 27
K Java - Enums Java Basics - Anfänger-Themen 30
tomzen Java Unterstützung für exel dateien installieren. Java Basics - Anfänger-Themen 2
Rookar java.lang.NoClassDefFoundError: org/json/JSONException Java Basics - Anfänger-Themen 2
Rookar Mit Button andere java öffnen Java Basics - Anfänger-Themen 4
F Java Object to Hashmap ? Java Basics - Anfänger-Themen 6
I Backend in Java und Ansicht von Dateien in statische HTML Seiten? Java Basics - Anfänger-Themen 15
R Input/Output Verwendung des Euro-Zeichens in Java Java Basics - Anfänger-Themen 7
I Push Nachrichten von JAVA EE App an Mobile App Java Basics - Anfänger-Themen 3
H .java Dateien in Eclipse einbinden und ausführen Java Basics - Anfänger-Themen 1
onlyxlia Schlüsselworte Was meint man mit "einen Typ" in Java erstellen? Java Basics - Anfänger-Themen 2
O Java Kara geschweifte Klammern Java Basics - Anfänger-Themen 2
G Mausrad logitech kann links und rechts klick wie in java abragen. Java Basics - Anfänger-Themen 15
XWing Java Klssenproblem Java Basics - Anfänger-Themen 4
R Umgebungsvariable java -cp gibt immer Java-Hilfe... Java Basics - Anfänger-Themen 3
farbenlos Csv Datei in Java einlesen Java Basics - Anfänger-Themen 18
F TableModelListener: java.lang.ArrayIndexOutOfBoundsException: 132 Java Basics - Anfänger-Themen 3
G Java 8 - Support-Ende Java Basics - Anfänger-Themen 7
T Java Weihnachtsbaum + Rahmen Java Basics - Anfänger-Themen 1
N Will mit Java anfangen Java Basics - Anfänger-Themen 13
Ü Java Array - Buchstaben als Zahlen ausgeben Java Basics - Anfänger-Themen 22
M Java Iterator Verständnisfrage Java Basics - Anfänger-Themen 6
M Java Mail Programm Java Basics - Anfänger-Themen 4
Sniper1000 Java 391 für Windows Java Basics - Anfänger-Themen 37
G Java long- in int-Variable umwandeln Java Basics - Anfänger-Themen 6
JaZuDemNo Java im Studium Java Basics - Anfänger-Themen 7
E Java Programm zur anzeige, ob Winter- oder Sommerzeit herrscht Java Basics - Anfänger-Themen 62
I QR code in Java selber generieren Java Basics - Anfänger-Themen 5
V Java-Ausnahmebehandlung: Behandlung geprüfter Ausnahmen Java Basics - Anfänger-Themen 1
krgewb Java Streams Java Basics - Anfänger-Themen 10
A Überwältigt von der komplexen Java Welt Java Basics - Anfänger-Themen 29
O Mehrfachvererbung auf Spezifikations- und Implementierungsebene in Java. Interfaces Java Basics - Anfänger-Themen 19
John_Sace Homogene Realisierung von Generics in Java ? Java Basics - Anfänger-Themen 19
P Meldung aus Java-Klasse in Thread an aufrufende Klasse Java Basics - Anfänger-Themen 1
R mit Java API arbeiten Java Basics - Anfänger-Themen 9
P JDK installieren Probleme bei der Java-Installation Java Basics - Anfänger-Themen 8
S Java: Wie sortiere ich eine ArrayList benutzerdefinierter Objekte nach einem bestimmten Attribut? Java Basics - Anfänger-Themen 2
Timo12345 JNLP File mit Java öffnen Java Basics - Anfänger-Themen 2
S Video Editierung mit Java.._ Java Basics - Anfänger-Themen 2
F Einstelungen in Java - CursorBlinkRate Java Basics - Anfänger-Themen 10
A PHP $_POST["name"] in Java Java Basics - Anfänger-Themen 3
vivansai21 Is there a oneliner to create a SortedSet filled with one or multiple elements in Java? Java Basics - Anfänger-Themen 9
Athro-Hiro Weißes Bild in Java erstellen Java Basics - Anfänger-Themen 3
Arjunreddy Can someone please tell me how to use a debugger in BlueJ(a Java environment) Java Basics - Anfänger-Themen 1
M Java assoziationen (UML) Java Basics - Anfänger-Themen 8
H Excel-Tabellen mit Java erstellen Java Basics - Anfänger-Themen 4
Simon16 Java ArrayListe von einer Klasse sortieren Java Basics - Anfänger-Themen 2
P Wie kann ich in meinem Java Programm etwas dauerhaft speichern? Java Basics - Anfänger-Themen 5
H Nutzt Eclipse alle CPU-Threads beim Ausführen von Java-Programmen? Java Basics - Anfänger-Themen 4
xXGrowGuruXx Java einstieg, leichte sache 0 verstanden Java Basics - Anfänger-Themen 7
A java.sql.SQLException: Data type mismatch. Java Basics - Anfänger-Themen 1
H Java-Programm zur Ausgabe von Zuständen Java Basics - Anfänger-Themen 80
N Java Spiel Figur auf dem Hintergrundbild bewegen. Java Basics - Anfänger-Themen 11
G Kann Java-Programm nicht als jar aufrufen, auch als EXE nicht Java Basics - Anfänger-Themen 19
N Java Taschenrechner hat Jemand vlt einen Tipp dafür wie ich jetzt die buttons verbinden kann und das Ergebnis auf dem textfield anzeigen lassen kann Java Basics - Anfänger-Themen 13
A Lerngruppe Java Java Basics - Anfänger-Themen 2
G Help me in the Java Program Java Basics - Anfänger-Themen 2
L Java- Vererbung Java Basics - Anfänger-Themen 4
LimDul Suche Java Stream Tutorial Java Basics - Anfänger-Themen 2
_so_far_away_ Ich möchte Java lernen Java Basics - Anfänger-Themen 11
benny1993 Java Programm erstellen für ein Fußball-Turnier Java Basics - Anfänger-Themen 3
M Datentypen While-Schleife eine Java Methode erstellen Java Basics - Anfänger-Themen 3
V Bild per Java Script austauschen Java Basics - Anfänger-Themen 7
MoxMorris this Keyword in Java Java Basics - Anfänger-Themen 14
D Wie kann man in Java nach Arrays auf Duplikate prüfen Java Basics - Anfänger-Themen 12
wolei JAVA Zeitdifferenz feststellen. Java Basics - Anfänger-Themen 4
DiyarcanZeren Rekursion in Java Java Basics - Anfänger-Themen 5
wolei Java generic interface in a generic class Java Basics - Anfänger-Themen 6
monsterherz Ablauf der Erstellung eines Java Programmes Java Basics - Anfänger-Themen 17
monsterherz Circle.java:5: error: <identifier> expected Java Basics - Anfänger-Themen 2
julian-fr Wie kann ich am besten Java lernen? Java Basics - Anfänger-Themen 17
A Java-Properties und -RessourceBundles Java Basics - Anfänger-Themen 5
lrnz22 Java-Basics-Aufgabe Java Basics - Anfänger-Themen 8
R Java kann nicht installiert werden Java Basics - Anfänger-Themen 8
marcelnedza Finde meinen Fehler in einer Methode nicht, Java Karol Java Basics - Anfänger-Themen 15
G In ein java Dokument Ton einbinden Java Basics - Anfänger-Themen 1
C was heisst es wenn java ']' erwartet ? Java Basics - Anfänger-Themen 2
KeinJavaFreak Erste Schritte Programm "Java(TM) Platform SE binary " nicht vorhanden Java Basics - Anfänger-Themen 1
KeinJavaFreak Erste Schritte Java "Executable Jar File" nicht vorhanden Java Basics - Anfänger-Themen 1
melisax Java 2D-Array Tabelle Java Basics - Anfänger-Themen 4
melisax Java Array Wert an bestimmtem Index angeben Java Basics - Anfänger-Themen 14
J Java Testklasse Java Basics - Anfänger-Themen 5
P Java Selenium . Parameterized.Parameters erzeugt eine Fehlermeldung Java Basics - Anfänger-Themen 14
W Java-Code mit Array Java Basics - Anfänger-Themen 14
W Java-Code Java Basics - Anfänger-Themen 2
P BeforeEach AfterEach werden nicht ausgeführt. Java / Selenium Java Basics - Anfänger-Themen 4
A Wie führe ich eine Batch-Datei von meiner Java-Anwendung aus? Java Basics - Anfänger-Themen 18
W Java code- TicTac toe Java Basics - Anfänger-Themen 51
Ostkreuz Java Docs Java Basics - Anfänger-Themen 9
R Java boolean Unterschied " == " und " = " Java Basics - Anfänger-Themen 3
D Java Programm mit Batch-Datei starten Java Basics - Anfänger-Themen 32

Ähnliche Java Themen


Oben