Está en la página 1de 13

PROYECTO

Hay que documentar con diagrama de clases y casos de USO

1. Decidir que utilizamos cualquiera de las tres base de datos y que webservice
2. Se generan cgi se publican y se quita el de C++
3. Con las bases de datos ya tienen que tener precargados los datos en tablas que dará el
ingeniero.
4. En cualquiera de esos formatos para cargar a postgress
5. En cuatro y cinco cualquiera de estos se genera y se carga la información a postgress
6.
7. Se carga la información a postgress de lo que se generó en el punto 4 y 5
8. Un browser que seleccione un PDF y despliegue el texto.

Diseño de interface

Investigar para implementar un OCR

• Quitar el C++
• Instalar C# en Linux

//Como convertir PDF a TEXT


import com.asprise.util.pdf.PDFReader;
import com.asprise.util.ocr.OCR;

PDFReader reader = new PDFReader(new File("my.pdf"));


reader.open(); // open the file.
int pages = reader.getNumberOfPages();

for(int i=0; i < pages; i++) {


BufferedImage img = reader.getPageAsImage(i);

// recognizes both characters and barcodes


String text = new OCR().recognizeAll(image);
System.out.println("Page " + i + ": " + text);
}

reader.close(); // finally, close the file.

CLIENTE DE PERL WEBSERVICE

https://docs.servicenow.com/bundle/geneva-servicenow-
platform/page/integrate/examples/concept/c_PerlWebServicesClientExamples.html

#!/usr/bin/perl -w

# declare usage of SOAP::Liteuse SOAP::Lite;

# specifying this subroutine, causes basic auth to use


# its credentials when challengedsub SOAP::Transport::HTTP::C
lient::get_basic_credentials{
# login as the itil userreturn'itil'=>'itil';}

# declare the SOAP endpoint heremy$soap= SOAP::Lite->proxy('h


ttps://myinstance.service-now.com/incident.do?SOAP');

# calling the insert functionmy$method= SOAP::Data->name('ins


ert')->attr({xmlns =>'http://www.service-now.com/'});

# create a new incident with the following short_description


and categorymy@params=( SOAP::Data->name(short_description =>
'This is an example short description'));push(@params, SOAP::
Data->name(category =>'Hardware'));

# invoke the SOAP callmy$result=$soap->call($method=>@params)


;

# print any SOAP faults that get returned


print_fault($result);# print the SOAP response that get retur
n
print_result($result);

# convenient subroutine for printing all resultssub print_res


ult {my($result)=@_;

if($result->body&&$result->body->{'insertResponse'}){my%key
Hash=%{$result->body->{'insertResponse'}};foreachmy$k(keys%ke
yHash){print"name=$k value=$keyHash{$k}\n";}}}

# convenient subroutine for printing all SOAP faultssub print


_fault {my($result)=@_;

if($result->fault){print"faultcode=".$result->fault->{'faul
tcode'}."\n";print"faultstring=".$result->fault->{'faultstrin
g'}."\n";print"detail=".$result->fault->{'detail'}."\n";}}

SERVIDOR
https://www.perlmonks.org/?node_id=1078567
#!/usr/bin/perl
{
package MyWebServer;

use HTTP::Server::Simple::CGI;
use base qw(HTTP::Server::Simple::CGI);

my %dispatch = (
'/bla' => \&resp_bla,
);

sub handle_request {
my $self = shift;
my $cgi = shift;

my $path = $cgi->path_info();
my $handler = $dispatch{$path};

if (ref($handler) eq "CODE") {
print "HTTP/1.0 200 OK\r\n";
$handler->($cgi);

} else {
print "HTTP/1.0 404 Not found\r\n";
print $cgi->header,
$cgi->start_html('Not found'),
$cgi->h1('Not found'),
$cgi->end_html;
}
}

sub resp_bla {
my $cgi = shift; # CGI.pm object
return if !ref $cgi;

print $cgi->header("text/plain"),
(rand(10) < 5) # pick a random number and see if it is less
+ than 5...
? 1 : 0; #...and print 1 if it is, or 0 if it isn't.

# start the server on port 8080


# access me at http://localhost:8080/bla
my $pid = MyWebServer->new(8080)->background();
print "Use 'kill $pid' to stop server.\n";
[download]

EN PYTON The code for the rest server is very simple:

http://www.dreamsyssoft.com/python-scripting-tutorial/create-simple-rest-web-service-with-
python.php

Create a simple REST web service with


Python
This is a quick tutorial on how to create a simple
RESTful web service using python.

The rest service uses web.py to create a server and


it will have two URLs, one for accessing all users and
one for accessing individual users:

http://localhost: 8080/users
http://localhost: 8080/users/{id}

#!/usr/bin/env python
import web
import xml.etree.ElementTree as ET

tree = ET.parse('user_data.xml')
root = tree.getroot()
urls = (
'/users', 'list_users' ,
'/users/(.*)' , 'get_user'
)

app = web.application(urls, globals())

class list_users:
def GET(self):
output = 'users:[';
for child in root:
print 'child', child.tag, child.attrib
output += str(child.attrib) + ','
output += ']';
return output

class get_user:
def GET(self, user):
for child in root:
if child.attrib['id'] == user:
return str(child.attrib)

if __name__ == "__main__":
app.run()

EN C# WEBSERVICE

https://rdi0r.wordpress.com/2013/02/24/consumir-webservice-c/

SERVER

Dentro del namespace WebService1 tendrá algo como ésto:

/// <summary>

/// Summary description for Service1

/// </summary>

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET
AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{

[WebMethod]
public string HelloWorld()
{
return "Hello World";
}

CLIENTE

El método HelloWorld le he cambiado el nombre y su contenido por esto:

[WebMethod]

//Venerando al glorioso Bob Sponge

public double SquarePants(double a, double b)

return Math.Pow(a, b);


}

WEBSERVER EN JAVA

SERVER

https://medium.com/@ssaurel/create-a-simple-http-web-server-in-java-3fc12b29d5fd

import
java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;
import java.util.StringTokenizer;

// The tutorial can be found just here on the SSaurel's Blog


:
// https://www.ssaurel.com/blog/create-a-simple-http-web-
server-in-java
// Each Client Connection will be managed in a dedicated
Thread
public class JavaHTTPServer implements Runnable{

static final File WEB_ROOT = new File(".");


static final String DEFAULT_FILE = "index.html";
static final String FILE_NOT_FOUND = "404.html";
static final String METHOD_NOT_SUPPORTED =
"not_supported.html";
// port to listen connection
static final int PORT = 8080;

// verbose mode
static final boolean verbose = true;

// Client Connection via Socket Class


private Socket connect;

public JavaHTTPServer(Socket c) {
connect = c;
}

public static void main(String[] args) {


try {
ServerSocket serverConnect = new
ServerSocket(PORT);
System.out.println("Server
started.\nListening for connections on port : " + PORT + "
...\n");

// we listen until user halts server


execution
while (true) {
JavaHTTPServer myServer = new
JavaHTTPServer(serverConnect.accept());

if (verbose) {

System.out.println("Connecton opened. (" + new Date()


+ ")");
}
// create dedicated thread to
manage the client connection
Thread thread = new
Thread(myServer);
thread.start();
}

} catch (IOException e) {
System.err.println("Server Connection
error : " + e.getMessage());
}
}

@Override
public void run() {
// we manage our particular client connection
BufferedReader in = null; PrintWriter out =
null; BufferedOutputStream dataOut = null;
String fileRequested = null;

try {
// we read characters from the client
via input stream on the socket
in = new BufferedReader(new
InputStreamReader(connect.getInputStream()));
// we get character output stream to
client (for headers)
out = new
PrintWriter(connect.getOutputStream());
// get binary output stream to client
(for requested data)
dataOut = new
BufferedOutputStream(connect.getOutputStream());

// get first line of the request from


the client
String input = in.readLine();
// we parse the request with a string
tokenizer
StringTokenizer parse = new
StringTokenizer(input);
String method =
parse.nextToken().toUpperCase(); // we get the HTTP method
of the client
// we get file requested
fileRequested =
parse.nextToken().toLowerCase();

// we support only GET and HEAD


methods, we check
if (!method.equals("GET") &&
!method.equals("HEAD")) {
if (verbose) {
System.out.println("501
Not Implemented : " + method + " method.");
}

// we return the not supported


file to the client
File file = new File(WEB_ROOT,
METHOD_NOT_SUPPORTED);
int fileLength = (int)
file.length();
String contentMimeType =
"text/html";
//read content to return to
client
byte[] fileData =
readFileData(file, fileLength);

// we send HTTP Headers with


data to client
out.println("HTTP/1.1 501 Not
Implemented");
out.println("Server: Java HTTP
Server from SSaurel : 1.0");
out.println("Date: " + new
Date());
out.println("Content-type: " +
contentMimeType);
out.println("Content-length: "
+ fileLength);
out.println(); // blank line
between headers and content, very important !
out.flush(); // flush character
output stream buffer
// file
dataOut.write(fileData, 0,
fileLength);
dataOut.flush();

} else {
// GET or HEAD method
if
(fileRequested.endsWith("/")) {
fileRequested +=
DEFAULT_FILE;
}

File file = new File(WEB_ROOT,


fileRequested);
int fileLength = (int)
file.length();
String content =
getContentType(fileRequested);

if (method.equals("GET")) { //
GET method so we return content
byte[] fileData =
readFileData(file, fileLength);

// send HTTP Headers


out.println("HTTP/1.1
200 OK");
out.println("Server:
Java HTTP Server from SSaurel : 1.0");
out.println("Date: " +
new Date());
out.println("Content-
type: " + content);
out.println("Content-
length: " + fileLength);
out.println(); // blank
line between headers and content, very important !
out.flush(); // flush
character output stream buffer
dataOut.write(fileData,
0, fileLength);
dataOut.flush();
}

if (verbose) {
System.out.println("File
" + fileRequested + " of type " + content + " returned");
}

} catch (FileNotFoundException fnfe) {


try {
fileNotFound(out, dataOut,
fileRequested);
} catch (IOException ioe) {
System.err.println("Error with
file not found exception : " + ioe.getMessage());
}

} catch (IOException ioe) {


System.err.println("Server error : " +
ioe);
} finally {
try {
in.close();
out.close();
dataOut.close();
connect.close(); // we close
socket connection
} catch (Exception e) {
System.err.println("Error
closing stream : " + e.getMessage());
}

if (verbose) {
System.out.println("Connection
closed.\n");
}
}
}

private byte[] readFileData(File file, int


fileLength) throws IOException {
FileInputStream fileIn = null;
byte[] fileData = new byte[fileLength];

try {
fileIn = new FileInputStream(file);
fileIn.read(fileData);
} finally {
if (fileIn != null)
fileIn.close();
}

return fileData;
}

// return supported MIME Types


private String getContentType(String fileRequested) {
if (fileRequested.endsWith(".htm") ||
fileRequested.endsWith(".html"))
return "text/html";
else
return "text/plain";
}

private void fileNotFound(PrintWriter out,


OutputStream dataOut, String fileRequested) throws
IOException {
File file = new File(WEB_ROOT,
FILE_NOT_FOUND);
int fileLength = (int) file.length();
String content = "text/html";
byte[] fileData = readFileData(file,
fileLength);

out.println("HTTP/1.1 404 File Not Found");


out.println("Server: Java HTTP Server from
SSaurel : 1.0");
out.println("Date: " + new Date());
out.println("Content-type: " + content);
out.println("Content-length: " + fileLength);
out.println(); // blank line between headers
and content, very important !
out.flush(); // flush character output stream
buffer

dataOut.write(fileData, 0, fileLength);
dataOut.flush();

if (verbose) {
System.out.println("File " +
fileRequested + " not found");
}
}

}
view rawJavaHTTPServer.java hosted with ❤ by GitHub

CLIENTE

También podría gustarte