Skip to content

Commit

Permalink
Update the model to use CDATA for URL, and introduce param tag
Browse files Browse the repository at this point in the history
  • Loading branch information
jbonofre committed Mar 26, 2012
1 parent 3a0324f commit 5ed966c
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.utils.URIUtils;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.DefaultHttpClient;
Expand Down Expand Up @@ -80,7 +81,6 @@ public void process(Exchange exchange) throws Exception {
} else {
request = new HttpGet(url);
}

if (mashup.getCookie() != null) {
LOGGER.trace("Looking for an existing cookie");
String cookieKey = (String) in.getHeader(mashup.getCookie().getKey());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,14 @@ public void digeste(InputStream inputStream) throws Exception {
digester.addSetNext("mashup/cookie", "setCookie");

digester.addObjectCreate("mashup/page", Page.class);
digester.addSetProperties("mashup/page");
digester.addSetProperties("mashup/page");
digester.addCallMethod("mashup/page/url", "setUrl", 0);
digester.addSetNext("mashup/page", "addPage");

digester.addObjectCreate("mashup/page/param", Param.class);
digester.addSetProperties("mashup/page/param");
digester.addSetNext("mashup/page/param", "addParam");

digester.addObjectCreate("mashup/page/extractor", Extractor.class);
digester.addSetProperties("mashup/page/extractor");
digester.addSetNext("mashup/page/extractor", "addExtractor");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
public class Page {

private String url;
private List<Param> params = new LinkedList<Param>();
private String method;
private int wait;
private List<Extractor> extractors = new LinkedList<Extractor>();
Expand All @@ -19,6 +20,18 @@ public void setUrl(String url) {
this.url = url;
}

public List<Param> getParams() {
return params;
}

public void setParams(List<Param> params) {
this.params = params;
}

public void addParam(Param param) {
this.params.add(param);
}

public List<Extractor> getExtractors() {
return extractors;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.apache.camel.processor.mashup.model;

public class Param {

private String name;
private String value;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ public void digeste() throws Exception {

// get the pages
List<Page> pages = mashup.getPages();
assertEquals(pages.size(), 3);
assertEquals(pages.size(), 4);

Page page1 = pages.get(0);
assertEquals("http://www.example.org/page1", page1.getUrl());
assertEquals("POST", page1.getMethod());

Page page2 = pages.get(1);
assertEquals("http://www.example.org/page2", page2.getUrl());
assertEquals(30, page2.getWait());

// get page2 extractor
List<Extractor> extractors = page2.getExtractors();
Expand Down Expand Up @@ -64,6 +65,14 @@ public void digeste() throws Exception {
Extractor errorHandlerExtractor = errorHandler.getExtractors().get(0);
assertEquals("my.class", errorHandlerExtractor.getClazz());

// get the page 4
Page page4 = pages.get(3);
assertEquals("http://www.example.org/page4", page4.getUrl());
assertEquals(2, page4.getParams().size());
Param param1 = page4.getParams().get(0);
assertEquals("param1", param1.getName());
assertEquals("value1", param1.getValue());

}

}
6 changes: 6 additions & 0 deletions processor/src/test/resources/model/valid.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,10 @@
</errorhandler>
</page>

<page>
<url><![CDATA[http://www.example.org/page4]]></url>
<param name="param1" value="value1"/>
<param name="param2" value="value2"/>
</page>

</mashup>

0 comments on commit 5ed966c

Please sign in to comment.