Giter VIP home page Giter VIP logo

netstoragekit-java's Introduction

NetStorageKit (for Java)

Important

Akamai does not maintain or regulate this package. While it can be incorporated to assist you in API use, Akamai Technical Support will not offer assistance and Akamai cannot be held liable if issues arise from its use.

Overview

This library assists in the interaction with Akamai's NetStorage CMS API. The following CMS API Specs are available:

Project organization

  • /src - project sources
  • /test - junit test cases
  • /build - build and output libraries
  • /doc - javadoc for class libraries
  • /lib - 3rd party dependency libraries (Currenly only necessary for running unit tests)
  • /example - an example app that utilizes the NetStorageKit

Install

  • Compile the sources from /src into build/classes.
  • An ant build.xml is also provided for ease of use. Common commands are: ant compile, ant jar and ant test
  • A maven pom.xml is also provided for ease of use. To install: mvn install
  • Both IntelliJ and Eclipse project files are available
  • the destination jar file is located in build/jar

Getting Started

  • Create an instance of the NetStorage object by passing in the host, username and key
  • Issue a command to NetStorage by calling the appropriate method from the NetStorage object

For example, to delete a file:

import com.akamai.netstorage.NetStorage;
import com.akamai.netstorage.DefaultCredential;

DefaultCredential credential = new DefaultCredential("example.akamaihd.net","id of your upload account", "apiKey of upload account");

NetStorage ns = new NetStorage(credential);
ns.delete("/[CP Code]/example.zip");

Other methods return an InputStream. For example, to retrieve a directory listing:

import com.akamai.netstorage.NetStorage;
import com.akamai.netstorage.DefaultCredential;
DefaultCredential credential = new DefaultCredential("example.akamaihd.net","id of your upload account", "apiKey of upload account");
NetStorage ns = new NetStorage(credential);

try (InputStream result = ns.dir("/[CP code]/1234")) {
 // TODO: consume InputStream
}

Finally, when uploading a File object can be sent or an open InputStream wll be used

import com.akamai.netstorage.NetStorage;
import com.akamai.netstorage.DefaultCredential;
DefaultCredential credential = new DefaultCredential("example.akamaihd.net","id of your upload account", "apiKey of upload account");
NetStorage ns = new NetStorage(credential);
try (InputStream result = ns.upload("/[CP code]/1234/example.zip", new File("../workingdir/srcfile.zip"))) {
 // TODO: consume InputStream
}

Sample application (CMS)

  • A sample application has been created that can take command line parameters.
java -classpath build/classes CMS -a dir -u user1 -k 1234abcd example.akamaihd.net/1234

netstoragekit-java's People

Contributors

aausch avatar akalcosmin avatar avxban avatar colinbendell avatar dariusk avatar davidbarnabasjacob avatar johneke-akamai avatar mmaville avatar njdoyle avatar rcalendi avatar vladonemo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

netstoragekit-java's Issues

I am trying to access contents from Directory & subdiretory

Hi Team - As the API gives /dir to list down all contents within the same directory. Can you create another method which will list down all contents within a directory along with its sub-directory contents recursively. I Please let me know your thoughts.

UnknownHostException when using Credential Hostname with path

Hello,

I am using the SDK for uploading to netstorage through an API Manager with an URL such as this one:

devUrl.apim.company.com/netstorage

( The APIM is configured to redirect to an akamai URL(myhostname.akamaihd.net). )
This URL is used as the hostname when constructing the Credential object, however it seems like the path(/netstorage) is kept when calling Netstorage, since I am getting UnknownHostExceptions.
Directly calling the HTTP API without the SDK with the above URL works without any issues.

Thanks in advance

Add API Interface

Currently, in order to use this API, you have to communicate with a concrete class, NetStorage. For testing purposes, it'd be easier to use an interface so that we can mock it.

Allow for setting additional action parameters for stat action

It's currently not possible to set the desired encoding for the stat action when using NetStorage.java. Suggesting adding a new stat method to NetStorage.java with an additional parameter Map<String, String> additionalParams (same as for the dir action).

Issues with spaces in filenames with NetStorageKit-3.6.6.jar library

Seeing the following error when the filename contains a space:

Exception in thread "main" com.akamai.netstorage.NetStorageException: com.akamai.netstorage.NetStorageException: Communication Error
at com.akamai.netstorage.NetStorage.execute(NetStorage.java:71)
at com.akamai.netstorage.NetStorage.upload(NetStorage.java:258)
at com.akamai.netstorage.NetStorage.upload(NetStorage.java:287)
at com.akamai.netstorage.NetStorage.upload(NetStorage.java:265)
at ns.uploadToAkamai(ns.java:33)
at ns.doIt(ns.java:38)
at ns.main(ns.java:19)
Caused by: com.akamai.netstorage.NetStorageException: Communication Error
at com.akamai.netstorage.NetStorageCMSv35Signer.execute(NetStorageCMSv35Signer.java:359)
at com.akamai.netstorage.NetStorageCMSv35Signer.execute(NetStorageCMSv35Signer.java:364)
at com.akamai.netstorage.NetStorage.execute(NetStorage.java:68)
... 6 more
Caused by: com.akamai.netstorage.NetStorageException: Unexpected Response from Server: 400 Bad Request
{null=[HTTP/1.1 400 Bad Request], Cache-Control=[max-age=0, no-cache, no-store], Server=[Apache], Connection=[close], Pragma=[no-cache], Expires=[Thu, 16 Aug 2018 21:51:34 GMT], Date=[Thu, 16 Aug 2018 21:51:34 GMT], Content-Type=[text/html; charset=iso-8859-1]}
at com.akamai.netstorage.NetStorageCMSv35Signer.validate(NetStorageCMSv35Signer.java:281)
at com.akamai.netstorage.NetStorageCMSv35Signer.execute(NetStorageCMSv35Signer.java:348)
... 8 more
%

Use SSL by default

CMS example is using constructor setting useSSL to false.
Default value should be always true, to prevent stealing of user name and password during insecure communication.

Now: public NetStorage(String hostname, String username, String key) {
        this(hostname, username, key, false);
    }

Should be:

public NetStorage(String hostname, String username, String key) {
        this(hostname, username, key, true);
    }

Optimizing the upload speed

As per https://developer.akamai.com/learn/NetStorage/NetStorage.html
“Third, you can properly partition your upload job, and open multiple parallel upload connections, to increase your aggregated throughput. Once your content is uploaded, it’s replicated quickly to another geographic location, and readily available from another part of the world.”

Can somebody suggest if there is any API available on this regard?

Some compiler error shows up when I import this project into eclipse

in com.akamai.netstorage.DefaultCredential
require getName and and getKey have @OverRide
in com.akamai.netstorage.NetStorageCMSv35Signer
require couple methods have @OverRide
in com.akamai.netstorage.Utils
readIniSection method, need to put Scanner into try also, otherwise you have memory leak for the unclosed resource

Also there is no lib folder for this project, need to find hamcrest-core-1.3.jar by myself

Please add proxy support

Please add support for a configurable proxy. I've changed my local code to use a hard-coded proxy, but it would be good to have an option to pass it in via a constructor.

Netstorage HTTP API | CPCode

Hi @colinbendell ,

I was try the NetStorageKit-Java library to upload an image. Since this library assists in the interaction with Akamai's NetStorage CMS API and all the API actions require CPCode.

  1. How do we pass CP code to an action while using this library?

  2. In the readme file we have a command
    java -classpath build/classes CMS -a dir -u user1 -k 1234abcd example.akamaihd.net/1234
    Is 1234(for example) after Netstorage HTTP API domain the CP Code ?

Thanks,
Radha Krishna N

Communication Error when upload file object to netstorage

We have multiple threads to upload files simultaneously to netstorage from two different hosts.
Most of the time it performs well, but sometimes it will throw Communication Error.

Is there any enhancement related to it in the TODO list?

  • TODO: support rebinding on IO communication errors (eg: connection reset)
    --
      | * TODO: support async IO
      | * TODO: support multiplexing of uploads
      | * TODO: optimize and adapt throughput based on connection latency
      | * TODO: support HTTP trailers for late SHA256 validation

Caused by: com.akamai.netstorage.NetStorageException: Communication Error
at com.akamai.netstorage.NetStorageCMSv35Signer.execute(NetStorageCMSv35Signer.java:359) ~[NetStorageKit-3.6.6.jar:?]
at com.akamai.netstorage.NetStorageCMSv35Signer.execute(NetStorageCMSv35Signer.java:364) ~[NetStorageKit-3.6.6.jar:?]
at com.akamai.netstorage.NetStorage.execute(NetStorage.java:68) ~[NetStorageKit-3.6.6.jar:?]
... 141 more
Caused by: java.net.SocketException: Socket closed
at java.net.SocketInputStream.socketRead0(Native Method) ~[?:1.8.0_232]
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) ~[?:1.8.0_232]
at java.net.SocketInputStream.read(SocketInputStream.java:171) ~[?:1.8.0_232]
at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[?:1.8.0_232]
at sun.security.ssl.InputRecord.readFully(InputRecord.java:465) ~[?:1.8.0_232]
at sun.security.ssl.InputRecord.read(InputRecord.java:503) ~[?:1.8.0_232]
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:975) ~[?:1.8.0_232]
at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:933) ~[?:1.8.0_232]
at sun.security.ssl.AppInputStream.read(AppInputStream.java:105) ~[?:1.8.0_232]
at java.io.BufferedInputStream.fill(BufferedInputStream.java:246) ~[?:1.8.0_232]
at java.io.BufferedInputStream.read1(BufferedInputStream.java:286) ~[?:1.8.0_232]
at java.io.BufferedInputStream.read(BufferedInputStream.java:345) ~[?:1.8.0_232]
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:735) ~[?:1.8.0_232]
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:678) ~[?:1.8.0_232]
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1593) ~[?:1.8.0_232]
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1498) ~[?:1.8.0_232]
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480) ~[?:1.8.0_232]
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:352) ~[?:1.8.0_232]
at com.akamai.netstorage.NetStorageCMSv35Signer.validate(NetStorageCMSv35Signer.java:270) ~[NetStorageKit-3.6.6.jar:?]
at com.akamai.netstorage.NetStorageCMSv35Signer.execute(NetStorageCMSv35Signer.java:348) ~[NetStorageKit-3.6.6.jar:?]
at com.akamai.netstorage.NetStorageCMSv35Signer.execute(NetStorageCMSv35Signer.java:364) ~[NetStorageKit-3.6.6.jar:?]
at com.akamai.netstorage.NetStorage.execute(NetStorage.java:68) ~[NetStorageKit-3.6.6.jar:?]

Use Proper Encapsulation

In the NetStorage class, you have:

public String hostName;
public String username;
public String key;
public Boolean useSSL;

This, along with the fact that there is no interface, provides a nightmare for when you want to share this thing in your application with other folks. These fields can be modified by anyone.

proxy per connection

Can you please add support for proxy per connection.

I know we can set proxy at jvm level through

System.setProperty("https.proxyHost","localhost");

System.setProperty("https.proxyPort","8080");

but for this we have to synchronise all the threads. set and unset proxy for every connection(when connecting to other services)
this will lead to bottleneck of traffic.

so support for proxy per connection level would be much appreciated.

Use Standard Maven Versioning...

Typically, Maven projects do not have a non-SNAPSHOT version in their pom.xml file. When you cut a release, you remove the "-SNAPSHOT" and create a tag for that release. Using the maven-release-plugin makes this very simple:

https://maven.apache.org/maven-release/maven-release-plugin/

Also, uploading this jar file to Maven Central would make using this API so much easier (there's another issue open for this already). Right now, we have to build and deploy this to our own Nexus server.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.