NullPointerException: wtf?

ok, aggiungi un metodo. nullpointerexception.
come? dove? quando? perchè?
boh. ma intanto NullPointerException. AAARGHH

Signed-off-by: Luca Fulchir <luca@fulchir.it>
parent 56b26307
......@@ -10,7 +10,7 @@ java:
- mkdir -p ${BUILDDIR} 2>/dev/null
${JAVAC} -cp ${JOLIEDIR}/jolie.jar -d ${BUILDDIR} jolie/net/utils/URLEncoder.java
${JAVAC} -cp ${JOLIEDIR}/jolie.jar:${JARDIR}/commons-codec-1.6.jar -d ${BUILDDIR} jolie/net/utils/Hmac.java
${JAVAC} -cp ${JOLIEDIR}/jolie.jar:${JARDIR}/httpcore-4.2.2.jar:${JARDIR}/httpclient-4.2.3.jar:${JARDIR}/commons-io-2.4.jar -d ${BUILDDIR} jolie/net/utils/genericHTTP.java
${JAVAC} -cp ${JOLIEDIR}/jolie.jar:${JARDIR}/httpcore-4.2.2.jar:${JARDIR}/httpclient-4.2.3.jar:${JARDIR}/commons-io-2.4.jar:${JARDIR}/commons-codec-1.6.jar -d ${BUILDDIR} jolie/net/utils/genericHTTP.java
cd ${BUILDDIR} && jar cvf ${PACKAGE_NAME} ./jolie/net/utils/*class && cd ${CWD}
......
......@@ -22,7 +22,8 @@ type OAuth1Token: void {
interface OAuth1Interface {
RequestResponse:
RequestToken (OAuth1Init) (OAuth1Token)
RequestToken (OAuth1Init) (OAuth1Token) throws wrong_answer,
getReferral (OAuth1Token) (string)
}
outputPort OAuth1 {
......
......@@ -9,7 +9,22 @@ inputPort OAuth1 {
}
main {
RequestToken (where) (token) {
[getReferral (info) (output) {
http_data.URI = info.location_authorize;
http_data.headers[0].name = "userAgent";
http_data.headers[0].value = "Jolie-OAuth";
http_data.query[0].name = "oauth_token";
http_data.query[0].value = info.token;
http_data.query[1].name = "oauth_callback";
http_data.query[1].value = "";
http_data.method = "GET";
sendRequest@genericHTTP (http_data) (output)
}] {nullProcess}
[RequestToken (where) (token) {
http_data.URI = where.location_request;
toUpperCase@StringUtils (where.method) (http_data.method);
......@@ -25,7 +40,7 @@ RequestToken (where) (token) {
answer.word = "&";
indexOf@StringUtils (answer) (index);
undef(answer.word);
// UNDOCOMENTED: what if we can not find the string??
// TODO: UNDOCOMENTED: what if we can not find the string??
answer.begin = 0;
answer.end = index;
......@@ -77,6 +92,6 @@ RequestToken (where) (token) {
throw (wrong_answer)
}
}
}
}]{nullProcess}
}
......@@ -8,7 +8,7 @@ main
// data needed for the connection: where to connect, how and who we are
data.location_request = "https://api.dropbox.com/1/oauth/request_token";
data.location_authorize = "https://api.dropbox.com/1/oauth/authorize";
data.location_authorize = "https://www.dropbox.com/1/oauth/authorize";
data.location_access = "https://api.dropbox.com/1/oauth/access_token";
data.method = "post";
data.consumer_key = "27250pnzil7tmhx";
......@@ -18,7 +18,10 @@ main
RequestToken@OAuth1 (data) (answer);
println@Console (answer.token)();
println@Console (answer.token_secret)()
println@Console (answer.token_secret)();
getReferral@OAuth1 (answer) (referr);
println@Console (">>>>" + referr)()
}
......@@ -12,7 +12,7 @@ inputPort OAuth1Data{
}
main {
DataRequestToken (where) (postString)
[DataRequestToken (where) (postString)
{
scope (error_handler) {
install( Hmac_fault =>
......@@ -73,7 +73,8 @@ scope (error_handler) {
postString = postString +
"oauth_callback=\"" + where.callback + "\","
}
}]{nullProcess}
}
}
......@@ -27,10 +27,10 @@ type HTTPpair: void {
type HTTPRequest:void {
.URI :string
.method :string
.userAgent? :string
.parameters* :HTTPpair
.cookies? :string
.headers* :HTTPpair
.query* :HTTPpair
}
type HTTPResponse:void {
......
......@@ -24,12 +24,14 @@ package jolie.net.utils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.commons.io.IOUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.apache.commons.io.IOUtils;
import org.apache.commons.codec.net.URLCodec;
import java.util.ArrayList;
import java.util.List;
import jolie.runtime.JavaService;
......@@ -54,23 +56,89 @@ public static String sendRequest (Value req) throws FaultException {
private static String sendGet (HttpClient httpclient, Value req)
throws FaultException
{
return new String("Not implemented");
boolean notFirst = false;
String query = new String("");
try {
URLCodec codec = new URLCodec("UTF8");
if (req.hasChildren("query")) {
for (Value pair : req.getChildren("query")) {
String name = codec.encode(
pair.getFirstChild("name").strValue(), "UTF8");
String value = codec.encode(
pair.getFirstChild("value").strValue(),
"UTF8");
if (notFirst) {
query += "&";
}
query += name + "=" + value;
notFirst = true;
}
}
HttpGet httpget;
if (query.isEmpty()) {
httpget = new HttpGet(req.getFirstChild("URI")
.strValue());
} else {
httpget = new HttpGet(req.getFirstChild("URI")
.strValue() + "?" + query);
}
if (req.hasChildren("headers")) {
for (Value entry : req.getChildren("headers")) {
// add every header
httpget.addHeader(entry.getFirstChild("name")
.strValue(),
entry.getFirstChild("value")
.strValue());
}
}
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
return IOUtils.toString(entity.getContent(), "UTF-8");
} catch (Exception e) {
throw new FaultException(e.getMessage());
}
}
private static String sendPost (HttpClient httpclient, Value req)
throws FaultException
{
HttpPost httppost = new HttpPost(req.getFirstChild("URI").strValue());
if (req.hasChildren("headers")) {
for (Value entry : req.getChildren("headers")) {
// add every header
httppost.addHeader(
entry.getFirstChild("name").strValue(),
entry.getFirstChild("value").strValue());
boolean notFirst = false;
String query = new String("");
try {
URLCodec codec = new URLCodec("UTF8");
if (req.hasChildren("query")) {
for (Value pair : req.getChildren("query")) {
String name = codec.encode(
pair.getFirstChild("name").strValue(), "UTF8");
String value = codec.encode(
pair.getFirstChild("value").strValue(),
"UTF8");
if (notFirst) {
query += "&";
}
query += name + "=" + value;
notFirst = true;
}
}
HttpPost httppost;
if (query.isEmpty()) {
httppost = new HttpPost(req.getFirstChild("URI")
.strValue());
} else {
httppost = new HttpPost(req.getFirstChild("URI")
.strValue() + "?" + query);
}
if (req.hasChildren("headers")) {
for (Value entry : req.getChildren("headers")) {
// add every header
httppost.addHeader(entry.getFirstChild("name")
.strValue(),
entry.getFirstChild("value")
.strValue());
}
}
}
try {
if (req.hasChildren("parameters")) {
for (Value pair : req.getChildren("parameters")) {
List<NameValuePair> postParams =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment