I am developing an Amazon Associate web service (AAWS) P using their WSDL. For this I am using Tomcat version 6 and jdk 1.6 in Eclipse 3.3. The project is set up as a dynamic web project and uses Axis2.
I can run my application from home but not from within the University via a proxy server. AAWS API uses SOAP previously I have used REST from within the university and used basic authentication, the REST app ran okay, see below the code for this (details changed for security)
**************************
**********
**********
**********
**********
**********
**********
**********
**********
**********
**********
***
public class SimpleAuthenticator extends Authenticator {
private String username;
private String password;
public SimpleAuthenticator(String
username, String password) {
this.username = username;
this.password = password;
}
public PasswordAuthentication getPasswordAuthentication(
) {
return new PasswordAuthentication(use
rname, password.toCharArray());
}
}
//below calls above:
try {
//Set up Authenticator
System.setProperty( "proxySet", "true" );
System.setProperty("http.p
roxyHost",
"proxyhost");
System.setProperty("http.p
roxyPort",
"8080");
Authenticator.setDefault(n
ew SimpleAuthenticator("usern
amer",
"password"));
} catch (Exception e) {
e.printStackTrace();
}
**************************
**********
**********
**********
**********
**********
**********
**********
**********
**********
**********
I The REST calls worked fine - however when using the Amazon API I get the error below
**************************
**********
**********
**********
**********
**********
**********
**********
**********
**********
Retrieving document at '
http://ecs.amazonaws.com/AWSECommerceService/UK/AWSECommerceService.wsdl'.
[INFO] Building AxisService from wsdl:
http://ecs.amazonaws.com/AWSECommerceService/UK/AWSECommerceService.wsdl[INFO] Unable to sendViaPost to url[
http://soap.amazon.co.uk/onca/soap?Service=AWSECommerceService]org.apache.axis2.AxisFault
: Transport error: 501 Error: Not Implemented
at org.apache.axis2.transport
.http.HTTP
Sender.han
dleRespons
e(HTTPSend
er.java:29
8)
at org.apache.axis2.transport
.http.HTTP
Sender.sen
dViaPost(H
TTPSender.
java:192)
at org.apache.axis2.transport
.http.HTTP
Sender.sen
d(HTTPSend
er.java:77
)
at org.apache.axis2.transport
.http.Comm
onsHTTPTra
nsportSend
er.writeMe
ssageWithC
ommons(Com
monsHTTPTr
ansportSen
der.java:3
27)
at org.apache.axis2.transport
.http.Comm
onsHTTPTra
nsportSend
er.invoke(
CommonsHTT
PTransport
Sender.jav
a:206)
at org.apache.axis2.engine.Ax
isEngine.s
end(AxisEn
gine.java:
396)
at org.apache.axis2.descripti
on.OutInAx
isOperatio
nClient.se
nd(OutInAx
isOperatio
n.java:374
)
at org.apache.axis2.descripti
on.OutInAx
isOperatio
nClient.ex
ecuteImpl(
OutInAxisO
peration.j
ava:211)
at org.apache.axis2.client.Op
erationCli
ent.execut
e(Operatio
nClient.ja
va:163)
at org.apache.axis2.jaxws.cor
e.controll
er.AxisInv
ocationCon
troller.ex
ecute(Axis
Invocation
Controller
.java:570)
at org.apache.axis2.jaxws.cor
e.controll
er.AxisInv
ocationCon
troller.do
Invoke(Axi
sInvocatio
nControlle
r.java:110
)
at org.apache.axis2.jaxws.cor
e.controll
er.Invocat
ionControl
ler.invoke
(Invocatio
nControlle
r.java:105
)
at org.apache.axis2.jaxws.cli
ent.proxy.
JAXWSProxy
Handler.in
vokeSEIMet
hod(JAXWSP
roxyHandle
r.java:271
)
at org.apache.axis2.jaxws.cli
ent.proxy.
JAXWSProxy
Handler.in
voke(JAXWS
ProxyHandl
er.java:14
1)
at $Proxy10.itemSearch(Unknow
n Source)
at servlet.MPCServlet.itemSea
rch(MPCSer
vlet.java:
293)
at servlet.MPCServlet.doPost(
MPCServlet
.java:143)
at javax.servlet.http.HttpSer
vlet.servi
ce(HttpSer
vlet.java:
710)
at javax.servlet.http.HttpSer
vlet.servi
ce(HttpSer
vlet.java:
803)
at org.apache.catalina.core.A
pplication
FilterChai
n.internal
DoFilter(A
pplication
FilterChai
n.java:290
)
at org.apache.catalina.core.A
pplication
FilterChai
n.doFilter
(Applicati
onFilterCh
ain.java:2
06)
at org.apache.catalina.core.S
tandardWra
pperValve.
invoke(Sta
ndardWrapp
erValve.ja
va:233)
at org.apache.catalina.core.S
tandardCon
textValve.
invoke(Sta
ndardConte
xtValve.ja
va:175)
at org.apache.catalina.authen
ticator.Au
thenticato
rBase.invo
ke(Authent
icatorBase
.java:433)
at org.apache.catalina.core.S
tandardHos
tValve.inv
oke(Standa
rdHostValv
e.java:128
)
at org.apache.catalina.valves
.ErrorRepo
rtValve.in
voke(Error
ReportValv
e.java:102
)
at org.apache.catalina.core.S
tandardEng
ineValve.i
nvoke(Stan
dardEngine
Valve.java
:109)
at org.apache.catalina.connec
tor.Coyote
Adapter.se
rvice(Coyo
teAdapter.
java:263)
at org.apache.coyote.http11.H
ttp11Proce
ssor.proce
ss(Http11P
rocessor.j
ava:844)
at org.apache.coyote.http11.H
ttp11Proto
col$Http11
Connection
Handler.pr
ocess(Http
11Protocol
.java:584)
at org.apache.tomcat.util.net
.JIoEndpoi
nt$Worker.
run(JIoEnd
point.java
:447)
at java.lang.Thread.run(Threa
d.java:595
)
20-Apr-2008 09:25:53 org.apache.catalina.core.S
tandardWra
pperValve invoke
**************************
**********
**********
**********
**********
**********
**********
**********
**********
*********
I have also included the code for the main calling method in this itemsearch:
**************************
**********
**********
**********
**********
**********
**********
**********
**********
*********
private void itemSearch(HttpServletRequ
est request,
HttpServletResponse response) {
PrintWriter out = null;
try {
out = response.getWriter();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String keyWord = request.getParameter("keyw
ord");
String url = request.getParameter("url"
);
Vector<SearchItem> vect = new Vector<SearchItem>();
// Set the service:
try{
this.service = new AWSECommerceService();
// Set the service port:
AWSECommerceServicePortTyp
e port = service.getAWSECommerceSer
vicePort()
;
// Get the operation object:
ItemSearchRequest itemRequest = new ItemSearchRequest();
// Fill in the request object:
itemRequest.setSearchIndex
(url);
itemRequest.setKeywords(ke
yWord);
ItemSearch ItemElement = new ItemSearch();
ItemElement.setAWSAccessKe
yId("Acces
skeyID");
ItemElement.getRequest().a
dd(itemReq
uest);
ItemElement.setAssociateTa
g("Associa
teTag");
// Call the Web service operation and store the response
// in the response object:
ItemSearchResponse amazonResponse = port
.itemSearch(ItemElement);
OperationRequest operationRequest = amazonResponse.getOperatio
nRequest()
;
if (operationRequest != null) {
BigInteger totalpages = null;
for (Items itemList : amazonResponse.getItems())
{
Request requestElement = itemList.getRequest();
if (requestElement != null) {
totalpages = itemList.getTotalPages();
}
for (Item item : itemList.getItem()) {
out.println("Product Name: "
+ item.getItemAttributes().g
etTitle() + " " +
item.getASIN());
String title = item.getItemAttributes().g
etTitle();
Price price = item.getItemAttributes().g
etListPric
e();
//String listPrice = price.getFormattedPrice();
String listPrice = "";
String manufacturer = item.getItemAttributes().g
etManufact
urer();
SearchItem searchItem = new SearchItem(title,manufactu
rer,listPr
ice);
vect.add(searchItem);
}
}
}
}
finally{
}
request.setAttribute("stuf
f", vect);
requestDespatch(request, response, "itemsearchresult.jsp");
}
**************************
**********
**********
**********
**********
**********
**********
**********
**********
*******
I have tried numerous solutions to this problem.
1st solution - adding the following to axis.xml within the transport sender section:
<ProxyHost>wwwcache.csd.ab
dn.ac.uk</
ProxyHost>
<ProxyPort>8080</ProxyPort
>
<ProxyUser>ccorner</ProxyU
ser>
<ProxyPassword>WYHAFApa</P
roxyPasswo
rd>
2nd solution
Attempted to authenticate and set up the proxy properties in the code
Options options = new Options();
HttpTransportProperties.Pr
oxyPropert
ies pp = new HttpTransportProperties.Pr
oxyPropert
ies();
pp.setProxyName("proxyname
");
pp.setProxyPort(8080);
pp.setUserName("username")
;
pp.setPassWord("password")
;
HttpTransportProperties.Au
thenticato
r auth = new HttpTransportProperties.Au
thenticato
r();
auth.setPassword("password
");
auth.setUsername("username
");
auth.setHost("proxyname");
auth.setPort(8080);
options.setProperty(HTTPCo
nstants.PR
OXY, pp);
options.setProperty(HTTPCo
nstants.AU
THENTICATE
,auth );
After this I tried commenting out the simple authenticator code and just using solution 2
Can you help in this please.
Thanks
Clive Corner
Start Free Trial