working on it ...

Filters

Explore Public Snippets

Sort by

Found 617 snippets matching: "web service"

    public by fabio.nosenzo @ Amazon_AWS_Python_API  588165  5  8  -1

    Amazon S3 Aws - S3Connection object from python boto API

    This snippet is about the S3Connection object provided by python boto package for Amazon AWS API. Here the __init__ method is listed with all its variables. The AWSAuthConnection object is initialized and it handles all the data for managing requests and response from Amazon AWS service. Path: [boto/s3/connection.py] Learn more about S3Con
    import boto.utils
    from boto.connection import AWSAuthConnection
    
    class S3Connection(AWSAuthConnection):
        DefaultHost = boto.config.get('s3', 'host', 's3.amazonaws.com')
        DefaultCallingFormat = boto.config.get('s3', 'calling_format', 'boto.s3.connection.SubdomainCallingFormat')
        QueryString = 'Signature=%s&Expires=%d&AWSAccessKeyId=%s'
    
        def __init__(self, aws_access_key_id=None, aws_secret_access_key=None,
                     is_secure=True, port=None, proxy=None, proxy_port=None,
                     proxy_user=None, proxy_pass=None,
                     host=DefaultHost, debug=0, https_connection_factory=None,
                     calling_format=DefaultCallingFormat, path='/',
                     provider='aws', bucket_class=Bucket, security_token=None,
                     suppress_consec_slashes=True, anon=False,
                     validate_certs=None):
            if isinstance(calling_format, str):
                calling_format=boto.utils.find_class(calling_format)()
            self.calling_format = calling_format
            self.bucket_class = bucket_class
            self.anon = anon
            AWSAuthConnection.__init__(self, host,
                    aws_access_key_id, aws_secret_access_key,
                    is_secure, port, proxy, proxy_port, proxy_user, proxy_pass,
                    debug=debug, https_connection_factory=https_connection_factory,
                    path=path, provider=provider, security_token=security_token,
                    suppress_consec_slashes=suppress_consec_slashes,
                    validate_certs=validate_certs)

    public by cghersi  468641  7  8  2

    Load a SOAP endpoint with Apache CXF using JMS transport provided by Apache ActiveMQ

    This is an example on how to load a SOAP web service in order to be able to invoke its methods via JMS transport
    private JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    public MyInterface loadEndPoint() {
    	//try to load from local, if available:
    	boolean loadOK = false;
    	MyInterface result = null;
    	try {
    		Class<?> c = Class.forName("MyImplClass");
    		Method fact = c.getMethod("get");
    		result = (MyInterface) fact.invoke(null);
    		loadOK = true;
    	} catch (ClassNotFoundException e) {
    		log.info("Cannot find MyImplClass, redirecting to  remote access...", e);		
    	} catch (Exception e) {
    		log.warn("Error searching MyImplClass, , redirecting to remote access. Exception is " + e, e);
    	}
    		
    	//load remote endpoint:
    	if (!loadOK) {
    		//detect transport protocol for web services:
    		String brokerAddr = "127.0.0.1"; //the right broker address
    		String queueName = "MyQueueName";
    		String address = "jms:jndi:dynamicQueues/" + queueName + "?jndiInitialContextFactory=org.apache.activemq.jndi.ActiveMQInitialContextFactory&jndiConnectionFactoryName=ConnectionFactory&jndiURL=" + brokerAddr;
    
    		log.info("Connecting to " + address);
    		String connString = "tcp://" + brokerAddr + ":61616";
    		ActiveMQConnectionFactory connFactory = new ActiveMQConnectionFactory("Myusername", "Mypassword", connString);
    
    		SoapBindingConfiguration conf = new SoapBindingConfiguration();
    		//MTOM not supported! .net does not interoperate with cxf mtom impl.
    //		conf.setMtomEnabled(true);
    		conf.setVersion(Soap12.getInstance());
    		factory.setBindingConfig(conf);
    
    		factory.setServiceClass(MyInterface.class);
    		factory.setAddress(address);
    		factory.getFeatures().add(new WSAddressingFeature());
    		factory.getFeatures().add(getJMSConfigFeature(queueName, connFactory, 10000)));
    		Object resObj = factory.create();
    		if ((resObj != null) && (resObj instanceof MyInterface))
    			result = (MyInterface) resObj;
    		}
    
    		return result;
    	}
    }
    
    public static JMSConfigFeature getJMSConfigFeature(String queueName, ActiveMQConnectionFactory connectionFactory, Long receiveTimeout) {
    	JMSConfigFeature jmsConfigFeature = new JMSConfigFeature();
    	JMSConfiguration jmsConfig = new JMSConfiguration();
    	jmsConfig.setUseJms11(true);
    	jmsConfig.setTargetDestination(queueName);
    	jmsConfig.setConnectionFactory(connectionFactory);
    	if (receiveTimeout != null)
    		jmsConfig.setReceiveTimeout(receiveTimeout);
    	jmsConfigFeature.setJmsConfig(jmsConfig);
    	return jmsConfigFeature;
    }

    public by lbottaro @ Amazon_AWS_Python_API  304434  0  8  0

    Amazon S3 Aws - How to download a file from a bucket to a target directory

    This code shows how to download a file from an existing bucket invoking the boto python API, saving to a target directory. You need to specify the filename and path where to save the data. [How to create a bucket](http://www.snip2code.com/Snippet/4892/Amazon-Aws-S3---Creating-a-bucket-in-pyt) [How to upload a file to a bucket](http://www.sn
    # This downloads the object foobar.pdf and saves it in /home/luca/documents/
    
    key = bucket.get_key('foobar.pdf')
    key.get_contents_to_filename('/home/luca/documents/foobar.pdf')

    public by dave83  2730  0  6  3

    JAX-RS web service using Path annotation

    This simple code shows how to implement a JAX-RS rest web service. @Path annotation is used to bind URI pattern to a specific method. The web service path '/path' is the main root. On a GET request to URI '/path' the method getUser() will be invoked. On a GET request to URI '/path/test' the method getTest() will be invoked. In this simple j
    import javax.ws.*;
     
    @Path("/path")
    public class WebRestService {
     
    	@GET
    	public Response getUser() {
     
    		return Response.status(200).entity("get User is called").build();
     
    	}
     
    	@GET
    	@Path("/test")
    	public Response getTest() {
     
    		return Response.status(200).entity("get Test is called").build();
     
    	}
    }

    public by lbottaro @ Amazon_AWS_Python_API  10726  32  8  0

    Amazon S3 Aws - Change an object's acl using boto API

    This code shows how to change the access rights on a file uploaded on S3 storage. This example sets the object foo_bar.txt to be publicly readable, and secret.txt to be private. Supported acl values defined in boto.gs.acl.py. CannedACLStrings = ['private', 'public-read', 'project-private', 'public-read-write', 'authenticated-read', 'buc
    # Public ACL example
    # Here you get the key reference for file foo_bar.txt
    foo_bar_key = bucket.get_key('foo_bar.txt')
    # This set the foo_bar file publicly readable
    foo_bar_key.set_canned_acl('public-read')
    
    # Private ACL example
    # Here you get the key reference for file secret.txt
    secret_key = bucket.get_key('secret.txt')
    # This set the secret.txt file as private
    secret_key.set_canned_acl('private')

    public by lbottaro @ Amazon_AWS_Python_API  6432  19  8  1

    Amazon S3 Aws - How to delete a bucket using boto API

    This example shows how to remove a bucket invoking python API provided by boto. Important note: the bucket must be empty.
    import boto
    import boto.s3.connection
    access_key = '<aws access key>'
    secret_key = '<aws secret key>'
    
    # This code initialize the Amazon S3 connection to your account
    conn = boto.connect_s3(
            aws_access_key_id = access_key,
            aws_secret_access_key = secret_key)
    
    # Iteration through all available buckets stored into S3
    # Name and creation date are listed
    for bucket in conn.get_all_buckets():
            print "{name}\t{created}".format(
                    name = bucket.name,
                    created = bucket.creation_date,
            )
            # Remove the bucket
            conn.delete_bucket(bucket.name)

    public by lbottaro @ Amazon_AWS_Python_API  6270  3  8  0

    Amazon S3 Aws - How to get content information for a given bucket using boto python api

    This snippet shows how to iterate through your own Amazon S3 buckets and list the available content.
    import boto
    import boto.s3.connection
    access_key = '<aws access key>'
    secret_key = '<aws secret key>'
    
    # This code initialize the Amazon S3 connection to your account
    conn = boto.connect_s3(
            aws_access_key_id = access_key,
            aws_secret_access_key = secret_key)
    
    # Iteration through all available buckets stored into S3
    # Name and creation date are listed
    for bucket in conn.get_all_buckets():
            print "{name}\t{created}".format(
                    name = bucket.name,
                    created = bucket.creation_date,
            )
            # For each bucket get all data content put into the bucket
            for key in bucket.list():
                    # Get name, size and date
                    print "{name}\t{size}\t{modified}".format(
                            name = key.name,
                            size = key.size,
                            modified = key.last_modified,
                            )

    public by lbottaro @ Amazon_AWS_Python_API  6135  1  8  1

    Amazon S3 Aws - get_bucket method in boto python API

    This example shows how to get a single key from a bucket and then write that key to a file.
    from boto.s3.connection import S3Connection
    from boto.s3.key import Key
    
    # Get connection using Amazon secret and access keys
    conn = S3Connection('<aws secret key>', '<aws access key>')
    
    # Get the bucket with name 'bucketname'
    bucket = conn.get_bucket('bucketname')
    
    # Get the key reference to file 'picture.jpg'
    key = bucket.get_key("picture.jpg")
    
    # Open file in write mode
    fp = open ("picture.jpg", "w")
    
    # Set the reference to file
    key.get_file (fp)

    public by lbottaro @ Amazon_AWS_Python_API  5977  1  8  1

    Amazon S3 Aws - Generate signed object download URLs

    This python code generates signed URL to download a private file from Amazon S3 storage, invoking boto API. Note that this generates a signed download URL for secret_plans.txt that will work for 1 hour (3600 seconds). Signed download URLs will work for the time period even if the object is private (when the time period is up, the URL will stop w
    # Get the private key reference to secret_plans.txt file
    plans_key = bucket.get_key('secret_plans.txt')
    # Generate a signed URL, timer is set to 1 hour
    plans_url = plans_key.generate_url(3600, query_auth=True, force_http=True)
    print plans_url

    public by lbottaro @ Amazon_AWS_Python_API  5467  5  8  1

    Amazon S3 Aws - Generate unsigned object download URLs

    This python code generates unsigned URL to download a public file from Amazon S3 storage. Note that unsigned URL can be generated for object with public acl.
    # Create an unsigned download URL for hello.txt. 
    # Requirements:
    # file hello.txt is public by setting its ACL 
    
    # Get hello.txt file key from bucket
    hello_key = bucket.get_key('hello.txt')
    # Create the unsigned URL
    hello_url = hello_key.generate_url(0, query_auth=False, force_http=True)
    print hello_url
    
    • Public Snippets
    • Channels Snippets