| Method from org.apache.axis2.transport.http.ListingAgent Detail: |
public static void copy(InputStream stream,
OutputStream ostream) throws IOException {
IOUtils.copy(stream, ostream, false);
}
Copies the input stream to the output stream |
public String extractServiceName(String urlString) {
int n = urlString.indexOf(configContext.getServiceContextPath());
if (n != -1) {
String serviceName = urlString.substring(n + configContext.getServiceContextPath().length(),
urlString.length());
if (serviceName.length() > 0) {
if(serviceName.charAt(0)=='/"){
serviceName = serviceName.substring(1);
}
return serviceName;
}
}
return urlString.substring(urlString.lastIndexOf("/") + 1,
urlString.length());
}
|
public void handle(HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) throws IOException, ServletException {
initTransportListener(httpServletRequest);
String query = httpServletRequest.getQueryString();
if (query != null) {
if (query.indexOf("wsdl2") > 0 || query.indexOf("wsdl") > 0 ||
query.indexOf("xsd") > 0 || query.indexOf("policy") > 0) {
processListService(httpServletRequest, httpServletResponse);
} else {
super.handle(httpServletRequest, httpServletResponse);
}
} else {
super.handle(httpServletRequest, httpServletResponse);
}
}
|
protected void initTransportListener(HttpServletRequest httpServletRequest) {
// httpServletRequest.getLocalPort() , giving me a build error so I had to use the followin
String filePart;
try {
filePart = httpServletRequest.getRequestURL().toString();
} catch (Throwable t){
log.info("Old Servlet API (fallback to HttpServletRequest.getRequestURI) :" + t);
filePart = httpServletRequest.getRequestURI();
}
int ipindex = filePart.indexOf("//");
String ip;
if (ipindex >= 0) {
ip = filePart.substring(ipindex + 2, filePart.length());
int seperatorIndex = ip.indexOf(":");
int slashIndex = ip.indexOf("/");
String portstr;
if (seperatorIndex >= 0) {
portstr = ip.substring(seperatorIndex + 1, slashIndex);
} else {
portstr = "80";
}
try {
addTransportListener(httpServletRequest.getScheme(), Integer.parseInt(portstr));
} catch (NumberFormatException e) {
log.debug(e.toString(), e);
}
}
}
|
public void processExplicitSchemaAndWSDL(HttpServletRequest req,
HttpServletResponse res) throws IOException, ServletException {
HashMap services = configContext.getAxisConfiguration().getServices();
String filePart = req.getRequestURL().toString();
String schema = filePart.substring(filePart.lastIndexOf("/") + 1,
filePart.length());
if ((services != null) && !services.isEmpty()) {
Iterator i = services.values().iterator();
while (i.hasNext()) {
AxisService service = (AxisService) i.next();
InputStream stream = service.getClassLoader().getResourceAsStream("META-INF/" + schema);
if (stream != null) {
OutputStream out = res.getOutputStream();
res.setContentType("text/xml");
IOUtils.copy(stream, out, true);
return;
}
}
}
}
|
protected void processIndex(HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) throws IOException, ServletException {
processListServices(httpServletRequest, httpServletResponse);
}
|
protected void processListFaultyServices(HttpServletRequest req,
HttpServletResponse res) throws IOException, ServletException {
String serviceName = req.getParameter("serviceName");
if (serviceName != null) {
AxisService service = configContext.getAxisConfiguration().getService(serviceName);
try {
req.getSession().setAttribute(Constants.SINGLE_SERVICE, service);
} catch (Throwable t) {
log.info("Old Servlet API :" + t);
}
}
renderView(LIST_FAULTY_SERVICES_JSP_NAME, req, res);
}
|
public void processListService(HttpServletRequest req,
HttpServletResponse res) throws IOException, ServletException {
String url;
try {
url = req.getRequestURL().toString();
} catch (Throwable t) {
log.info("Old Servlet API (Fallback to HttpServletRequest.getRequestURI) :" + t);
url = req.getRequestURI();
}
String serviceName = extractServiceName(url);
HashMap services = configContext.getAxisConfiguration().getServices();
String query = req.getQueryString();
int wsdl2 = query.indexOf("wsdl2");
int wsdl = query.indexOf("wsdl");
int xsd = query.indexOf("xsd");
int policy = query.indexOf("policy");
if ((services != null) && !services.isEmpty()) {
Object serviceObj = services.get(serviceName);
if (serviceObj != null) {
AxisService axisService = (AxisService) serviceObj;
boolean isHttp = "http".equals(req.getScheme());
if (wsdl2 >= 0) {
res.setContentType("text/xml");
String ip = extractHostAndPort(url, isHttp);
String wsdlName = req.getParameter("wsdl2");
int ret = axisService.printWSDL2(res.getOutputStream(), ip, wsdlName);
if (ret == 0) {
res.sendRedirect("");
} else if (ret == -1) {
res.sendError(HttpServletResponse.SC_NOT_FOUND);
}
return;
} else if (wsdl >= 0) {
OutputStream out = res.getOutputStream();
res.setContentType("text/xml");
String ip = extractHostAndPort(url, isHttp);
String wsdlName = req.getParameter("wsdl");
if (wsdlName != null && wsdlName.length() >0) {
axisService.printUserWSDL(out, wsdlName);
out.flush();
out.close();
} else {
axisService.printWSDL(out, ip);
out.flush();
out.close();
}
return;
} else if (xsd >= 0) {
res.setContentType("text/xml");
int ret = axisService.printXSD(res.getOutputStream(), req.getParameter("xsd"));
if (ret == 0) {
//multiple schemas are present and the user specified
//no name - in this case we cannot possibly pump a schema
//so redirect to the service root
res.sendRedirect("");
} else if (ret == -1) {
res.sendError(HttpServletResponse.SC_NOT_FOUND);
}
return;
} else if (policy >= 0) {
ExternalPolicySerializer serializer = new ExternalPolicySerializer();
serializer.setAssertionsToFilter(configContext
.getAxisConfiguration().getLocalPolicyAssertions());
// check whether Id is set
String idParam = req.getParameter("id");
if (idParam != null) {
// Id is set
Policy targetPolicy = findPolicy(idParam, axisService);
if (targetPolicy != null) {
XMLStreamWriter writer;
try {
OutputStream out = res.getOutputStream();
writer = XMLOutputFactory.newInstance()
.createXMLStreamWriter(out);
res.setContentType("application/wspolicy+xml");
targetPolicy.serialize(writer);
writer.flush();
} catch (XMLStreamException e) {
throw new ServletException(
"Error occured when serializing the Policy",
e);
} catch (FactoryConfigurationError e) {
throw new ServletException(
"Error occured when serializing the Policy",
e);
}
} else {
OutputStream out = res.getOutputStream();
res.setContentType("text/html");
String outStr = "< b >No policy found for id="
+ idParam + "< /b >";
out.write(outStr.getBytes());
}
} else {
PolicyInclude policyInclude = axisService.getPolicyInclude();
Policy effecPolicy = policyInclude.getEffectivePolicy();
if (effecPolicy != null) {
XMLStreamWriter writer;
try {
OutputStream out = res.getOutputStream();
writer = XMLOutputFactory.newInstance()
.createXMLStreamWriter(out);
res.setContentType("application/wspolicy+xml");
effecPolicy.serialize(writer);
writer.flush();
} catch (XMLStreamException e) {
throw new ServletException(
"Error occured when serializing the Policy",
e);
} catch (FactoryConfigurationError e) {
throw new ServletException(
"Error occured when serializing the Policy",
e);
}
} else {
OutputStream out = res.getOutputStream();
res.setContentType("text/html");
String outStr = "< b >No effective policy for "
+ serviceName + " service< /b >";
out.write(outStr.getBytes());
}
}
return;
} else {
try {
req.getSession().setAttribute(Constants.SINGLE_SERVICE,
serviceObj);
} catch (Throwable t) {
log.info("Old Servlet API :" + t);
}
}
} else {
try {
req.getSession().setAttribute(Constants.SINGLE_SERVICE, null);
} catch (Throwable t){
log.info("Old Servlet API :" + t);
}
res.sendError(HttpServletResponse.SC_NOT_FOUND, url);
}
}
renderView(LIST_SINGLE_SERVICE_JSP_NAME, req, res);
}
|
protected void processListServices(HttpServletRequest req,
HttpServletResponse res) throws IOException, ServletException {
populateSessionInformation(req);
try {
req.getSession().setAttribute(Constants.ERROR_SERVICE_MAP,
configContext.getAxisConfiguration().getFaultyServices());
} catch (Throwable t){
log.info("Old Servlet API :" + t);
}
renderView(LIST_MULTIPLE_SERVICE_JSP_NAME, req, res);
}
|