Modified:
webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/HttpTransportProperties.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/HttpTransportProperties.java?rev=710158&r1=710157&r2=710158&view=diff
==============================================================================
---
webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/HttpTransportProperties.java
(original)
+++
webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/HttpTransportProperties.java
Mon Nov 3 13:07:13 2008
@@ -1,249 +1,249 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.axis2.transport.http;
-
-import org.apache.commons.httpclient.HttpVersion;
-import org.apache.commons.httpclient.auth.AuthPolicy;
-import org.apache.commons.httpclient.auth.AuthScope;
-
-import java.util.List;
-import java.util.Properties;
-
-/**
- * Utility bean for setting transport properties in runtime.
- */
-public class HttpTransportProperties {
- protected boolean chunked;
- protected HttpVersion httpVersion;
- protected String protocol;
-
- public HttpTransportProperties() {
- }
-
- public boolean getChunked() {
- return chunked;
- }
-
- public HttpVersion getHttpVersion() {
- return httpVersion;
- }
-
- public String getProtocol() {
- return protocol;
- }
-
- public void setChunked(boolean chunked) {
- this.chunked = chunked;
- }
-
- public void setHttpVersion(HttpVersion httpVerion) {
- this.httpVersion = httpVerion;
- }
-
- public void setProtocol(String protocol) {
- this.protocol = protocol;
- }
-
- public static class ProxyProperties {
- protected int proxyPort = -1;
- protected String domain = null;
- protected String passWord = null;
- protected String proxyHostName = null;
- protected String userName = null;
-
- public ProxyProperties() {
- }
-
- public String getDomain() {
- return domain;
- }
-
- public String getPassWord() {
- return passWord;
- }
-
- public String getProxyHostName() {
- return proxyHostName;
- }
-
- public int getProxyPort() {
- return proxyPort;
- }
-
- public String getUserName() {
- return userName;
- }
-
- public void setDomain(String domain) {
- this.domain = domain;
- }
-
- public void setPassWord(String passWord) {
- this.passWord = passWord;
- }
-
- public void setProxyName(String proxyHostName) {
- this.proxyHostName = proxyHostName;
- }
-
- public void setProxyPort(int proxyPort) {
- this.proxyPort = proxyPort;
- }
-
- public void setUserName(String userName) {
- this.userName = userName;
- }
- }
-
- /*
- This class is responsible for holding all the necessary information needed
for NTML, Digest
- and Basic Authentication. Authentication itself is handled by httpclient.
User doesn't need to
- warry about what authentication mechanism it uses. Axis2 uses httpclinet's
default authentication
- patterns.
- */
- public static class Authenticator {
- /*host that needed to be authenticated with*/
- private String host;
- /*port of the host that needed to be authenticated with*/
- private int port = AuthScope.ANY_PORT;
- /*Realm for authentication scope*/
- private String realm = AuthScope.ANY_REALM;
- /*Domain needed by NTCredentials for NT Domain*/
- private String domain;
- /*User for authenticate*/
- private String username;
- /*Password of the user for authenticate*/
- private String password;
- /* Switch to use preemptive authentication or not*/
- private boolean preemptive = false;
- /* if Authentication scheme needs retry just turn on the following
flag */
- private boolean allowedRetry = false;
- /* Changing the priorty or adding a custom AuthPolicy*/
- private List authSchemes;
-
- /* Default Auth Schems*/
- public static final String NTLM = AuthPolicy.NTLM;
- public static final String DIGEST = AuthPolicy.DIGEST;
- public static final String BASIC = AuthPolicy.BASIC;
-
- public String getHost() {
- return host;
- }
-
- public void setHost(String host) {
- this.host = host;
- }
-
- public int getPort() {
- return port;
- }
-
- public void setPort(int port) {
- this.port = port;
- }
-
- public String getRealm() {
- return realm;
- }
-
- public void setRealm(String realm) {
- this.realm = realm;
- }
-
- public String getUsername() {
- return username;
- }
-
- public void setUsername(String username) {
- this.username = username;
- }
-
- public String getPassword() {
- return password;
- }
-
- public void setPassword(String password) {
- this.password = password;
- }
-
- public void setPreemptiveAuthentication(boolean preemptive) {
- this.preemptive = preemptive;
- }
-
- public boolean getPreemptiveAuthentication() {
- return this.preemptive;
- }
-
- public String getDomain() {
- return domain;
- }
-
- public void setDomain(String domain) {
- this.domain = domain;
- }
-
- public void setAuthSchemes(List authSchemes) {
- this.authSchemes = authSchemes;
- }
-
- public List getAuthSchemes() {
- return this.authSchemes;
- }
-
- public void setAllowedRetry(boolean allowedRetry) {
- this.allowedRetry = allowedRetry;
- }
-
- public boolean isAllowedRetry() {
- return this.allowedRetry;
- }
- }
-
- /**
- * @deprecated
org.apache.axis2.transport.http.HttpTransportProperties.MailProperties has been
- * deprecated and user are encourage the use of java.util.Properties
instead.
- */
- public static class MailProperties {
- final Properties mailProperties = new Properties();
-
- private String password;
-
- public void addProperty(String key, String value) {
- mailProperties.put(key, value);
- }
-
- public void deleteProperty(String key) {
- mailProperties.remove(key);
- }
-
- public Properties getProperties() {
- return mailProperties;
- }
-
- public String getPassword() {
- return password;
- }
-
- public void setPassword(String password) {
- this.password = password;
- }
-
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axis2.transport.http;
+
+import org.apache.commons.httpclient.HttpVersion;
+import org.apache.commons.httpclient.auth.AuthPolicy;
+import org.apache.commons.httpclient.auth.AuthScope;
+
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * Utility bean for setting transport properties in runtime.
+ */
+public class HttpTransportProperties {
+ protected boolean chunked;
+ protected HttpVersion httpVersion;
+ protected String protocol;
+
+ public HttpTransportProperties() {
+ }
+
+ public boolean getChunked() {
+ return chunked;
+ }
+
+ public HttpVersion getHttpVersion() {
+ return httpVersion;
+ }
+
+ public String getProtocol() {
+ return protocol;
+ }
+
+ public void setChunked(boolean chunked) {
+ this.chunked = chunked;
+ }
+
+ public void setHttpVersion(HttpVersion httpVerion) {
+ this.httpVersion = httpVerion;
+ }
+
+ public void setProtocol(String protocol) {
+ this.protocol = protocol;
+ }
+
+ public static class ProxyProperties {
+ protected int proxyPort = -1;
+ protected String domain = null;
+ protected String passWord = null;
+ protected String proxyHostName = null;
+ protected String userName = null;
+
+ public ProxyProperties() {
+ }
+
+ public String getDomain() {
+ return domain;
+ }
+
+ public String getPassWord() {
+ return passWord;
+ }
+
+ public String getProxyHostName() {
+ return proxyHostName;
+ }
+
+ public int getProxyPort() {
+ return proxyPort;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setDomain(String domain) {
+ this.domain = domain;
+ }
+
+ public void setPassWord(String passWord) {
+ this.passWord = passWord;
+ }
+
+ public void setProxyName(String proxyHostName) {
+ this.proxyHostName = proxyHostName;
+ }
+
+ public void setProxyPort(int proxyPort) {
+ this.proxyPort = proxyPort;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+ }
+
+ /*
+ This class is responsible for holding all the necessary information needed
for NTML, Digest
+ and Basic Authentication. Authentication itself is handled by httpclient.
User doesn't need to
+ warry about what authentication mechanism it uses. Axis2 uses httpclinet's
default authentication
+ patterns.
+ */
+ public static class Authenticator {
+ /*host that needed to be authenticated with*/
+ private String host;
+ /*port of the host that needed to be authenticated with*/
+ private int port = AuthScope.ANY_PORT;
+ /*Realm for authentication scope*/
+ private String realm = AuthScope.ANY_REALM;
+ /*Domain needed by NTCredentials for NT Domain*/
+ private String domain;
+ /*User for authenticate*/
+ private String username;
+ /*Password of the user for authenticate*/
+ private String password;
+ /* Switch to use preemptive authentication or not*/
+ private boolean preemptive = false;
+ /* if Authentication scheme needs retry just turn on the following
flag */
+ private boolean allowedRetry = false;
+ /* Changing the priorty or adding a custom AuthPolicy*/
+ private List authSchemes;
+
+ /* Default Auth Schems*/
+ public static final String NTLM = AuthPolicy.NTLM;
+ public static final String DIGEST = AuthPolicy.DIGEST;
+ public static final String BASIC = AuthPolicy.BASIC;
+
+ public String getHost() {
+ return host;
+ }
+
+ public void setHost(String host) {
+ this.host = host;
+ }
+
+ public int getPort() {
+ return port;
+ }
+
+ public void setPort(int port) {
+ this.port = port;
+ }
+
+ public String getRealm() {
+ return realm;
+ }
+
+ public void setRealm(String realm) {
+ this.realm = realm;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public void setPreemptiveAuthentication(boolean preemptive) {
+ this.preemptive = preemptive;
+ }
+
+ public boolean getPreemptiveAuthentication() {
+ return this.preemptive;
+ }
+
+ public String getDomain() {
+ return domain;
+ }
+
+ public void setDomain(String domain) {
+ this.domain = domain;
+ }
+
+ public void setAuthSchemes(List authSchemes) {
+ this.authSchemes = authSchemes;
+ }
+
+ public List getAuthSchemes() {
+ return this.authSchemes;
+ }
+
+ public void setAllowedRetry(boolean allowedRetry) {
+ this.allowedRetry = allowedRetry;
+ }
+
+ public boolean isAllowedRetry() {
+ return this.allowedRetry;
+ }
+ }
+
+ /**
+ * @deprecated
org.apache.axis2.transport.http.HttpTransportProperties.MailProperties has been
+ * deprecated and user are encourage the use of java.util.Properties
instead.
+ */
+ public static class MailProperties {
+ final Properties mailProperties = new Properties();
+
+ private String password;
+
+ public void addProperty(String key, String value) {
+ mailProperties.put(key, value);
+ }
+
+ public void deleteProperty(String key) {
+ mailProperties.remove(key);
+ }
+
+ public Properties getProperties() {
+ return mailProperties;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ }
+}
Propchange:
webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/HttpTransportProperties.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/ListingAgent.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/ListingAgent.java?rev=710158&r1=710157&r2=710158&view=diff
==============================================================================
---
webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/ListingAgent.java
(original)
+++
webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/ListingAgent.java
Mon Nov 3 13:07:13 2008
@@ -1,463 +1,463 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-package org.apache.axis2.transport.http;
-
-import org.apache.axiom.attachments.utils.IOUtils;
-import org.apache.axis2.AxisFault;
-import org.apache.axis2.Constants;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.deployment.DeploymentConstants;
-import org.apache.axis2.description.AxisDescription;
-import org.apache.axis2.description.AxisService;
-import org.apache.axis2.description.PolicyInclude;
-import org.apache.axis2.description.TransportInDescription;
-import org.apache.axis2.util.ExternalPolicySerializer;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.neethi.Policy;
-import org.apache.neethi.PolicyRegistry;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.xml.stream.FactoryConfigurationError;
-import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-
-public class ListingAgent extends AbstractAgent {
-
- private static final Log log = LogFactory.getLog(ListingAgent.class);
-
- private static final String LIST_MULTIPLE_SERVICE_JSP_NAME =
- "listServices.jsp";
- private static final String LIST_SINGLE_SERVICE_JSP_NAME =
- "listSingleService.jsp";
- private static final String LIST_FAULTY_SERVICES_JSP_NAME =
"listFaultyService.jsp";
-
- public static final String RUNNING_PORT = "RUNNING_PORT";
-
- public ListingAgent(ConfigurationContext aConfigContext) {
- super(aConfigContext);
- }
-
- private void addTransportListener(String schema, int port) {
- try {
- TransportInDescription trsIn =
-
configContext.getAxisConfiguration().getTransportIn(schema);
- if (trsIn == null) {
- trsIn = new TransportInDescription(schema);
- CustomListener httspReceiver = new CustomListener(port,
schema);
- httspReceiver.init(configContext, trsIn);
- trsIn.setReceiver(httspReceiver);
- configContext.getListenerManager().addListener(trsIn, true);
- }
- } catch (AxisFault axisFault) {
- //
- }
- }
-
- 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);
- }
- }
- }
-
- 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);
- }
-
-
- protected void processIndex(HttpServletRequest httpServletRequest,
- HttpServletResponse httpServletResponse)
- throws IOException, ServletException {
- processListServices(httpServletRequest, httpServletResponse);
- }
-
- private String extractHostAndPort(String filePart, boolean isHttp) {
- int ipindex = filePart.indexOf("//");
- String ip = null;
- if (ipindex >= 0) {
- ip = filePart.substring(ipindex + 2, filePart.length());
- int seperatorIndex = ip.indexOf(":");
- int slashIndex = ip.indexOf("/");
- String port;
- if (seperatorIndex >= 0) {
- port = ip.substring(seperatorIndex + 1, slashIndex);
- ip = ip.substring(0, seperatorIndex);
- } else {
- ip = ip.substring(0, slashIndex);
- port = "80";
- }
- if (isHttp) {
- configContext.setProperty(RUNNING_PORT, port);
- }
- }
- return ip;
- }
-
- 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");
- copy(stream, out);
- out.flush();
- out.close();
- return;
- }
- }
- }
- }
-
- /**
- * Copies the input stream to the output stream
- *
- * @param stream the <code>InputStream</code>
- * @param ostream the <code>OutputStream</code>
- */
- public static void copy(InputStream stream, OutputStream ostream) throws
IOException {
- int nextValue = stream.read();
- while (-1 != nextValue) {
- ostream.write(nextValue);
- nextValue = stream.read();
- }
- }
-
- 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 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) {
- boolean isHttp = "http".equals(req.getScheme());
- if (wsdl2 >= 0) {
- res.setContentType("text/xml");
- String ip = extractHostAndPort(url, isHttp);
- String wsdlName = req.getParameter("wsdl2");
- if (wsdlName != null && wsdlName.length()>0) {
- InputStream in = ((AxisService)
serviceObj).getClassLoader()
-
.getResourceAsStream(DeploymentConstants.META_INF + "/" + wsdlName);
- if (in != null) {
- OutputStream out = res.getOutputStream();
- out.write(IOUtils.getStreamAsByteArray(in));
- out.flush();
- out.close();
- } else {
- res.sendError(HttpServletResponse.SC_NOT_FOUND);
- }
- } else {
- OutputStream out = res.getOutputStream();
- ((AxisService) serviceObj)
- .printWSDL2(out, ip);
- out.flush();
- out.close();
- }
- 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 axisServce = (AxisService) serviceObj;
- axisServce.printUserWSDL(out, wsdlName);
- out.flush();
- out.close();
- } else {
- ((AxisService) serviceObj).printWSDL(out, ip);
- out.flush();
- out.close();
- }
- return;
- } else if (xsd >= 0) {
- res.setContentType("text/xml");
- int ret = ((AxisService)
serviceObj).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) serviceObj);
-
- 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)
serviceObj).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 + " servcie</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);
- }
-
- private Policy findPolicy(String id, AxisDescription des) {
-
- List policyElements = des.getPolicyInclude().getPolicyElements();
- PolicyRegistry registry = des.getPolicyInclude().getPolicyRegistry();
-
- Object policyComponent;
-
- Policy policy = registry.lookup(id);
-
- if (policy != null) {
- return policy;
- }
-
- for (Iterator iterator = policyElements.iterator();
iterator.hasNext();) {
- policyComponent = iterator.next();
-
- if (policyComponent instanceof Policy) {
- // policy found for the id
-
- if (id.equals(((Policy) policyComponent).getId())) {
- return (Policy) policyComponent;
- }
- }
- }
-
- AxisDescription child;
-
- for (Iterator iterator = des.getChildren(); iterator.hasNext();) {
- child = (AxisDescription) iterator.next();
- policy = findPolicy(id, child);
-
- if (policy != null) {
- return policy;
- }
- }
-
- return null;
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.axis2.transport.http;
+
+import org.apache.axiom.attachments.utils.IOUtils;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.deployment.DeploymentConstants;
+import org.apache.axis2.description.AxisDescription;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.PolicyInclude;
+import org.apache.axis2.description.TransportInDescription;
+import org.apache.axis2.util.ExternalPolicySerializer;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.neethi.Policy;
+import org.apache.neethi.PolicyRegistry;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+public class ListingAgent extends AbstractAgent {
+
+ private static final Log log = LogFactory.getLog(ListingAgent.class);
+
+ private static final String LIST_MULTIPLE_SERVICE_JSP_NAME =
+ "listServices.jsp";
+ private static final String LIST_SINGLE_SERVICE_JSP_NAME =
+ "listSingleService.jsp";
+ private static final String LIST_FAULTY_SERVICES_JSP_NAME =
"listFaultyService.jsp";
+
+ public static final String RUNNING_PORT = "RUNNING_PORT";
+
+ public ListingAgent(ConfigurationContext aConfigContext) {
+ super(aConfigContext);
+ }
+
+ private void addTransportListener(String schema, int port) {
+ try {
+ TransportInDescription trsIn =
+
configContext.getAxisConfiguration().getTransportIn(schema);
+ if (trsIn == null) {
+ trsIn = new TransportInDescription(schema);
+ CustomListener httspReceiver = new CustomListener(port,
schema);
+ httspReceiver.init(configContext, trsIn);
+ trsIn.setReceiver(httspReceiver);
+ configContext.getListenerManager().addListener(trsIn, true);
+ }
+ } catch (AxisFault axisFault) {
+ //
+ }
+ }
+
+ 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);
+ }
+ }
+ }
+
+ 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);
+ }
+
+
+ protected void processIndex(HttpServletRequest httpServletRequest,
+ HttpServletResponse httpServletResponse)
+ throws IOException, ServletException {
+ processListServices(httpServletRequest, httpServletResponse);
+ }
+
+ private String extractHostAndPort(String filePart, boolean isHttp) {
+ int ipindex = filePart.indexOf("//");
+ String ip = null;
+ if (ipindex >= 0) {
+ ip = filePart.substring(ipindex + 2, filePart.length());
+ int seperatorIndex = ip.indexOf(":");
+ int slashIndex = ip.indexOf("/");
+ String port;
+ if (seperatorIndex >= 0) {
+ port = ip.substring(seperatorIndex + 1, slashIndex);
+ ip = ip.substring(0, seperatorIndex);
+ } else {
+ ip = ip.substring(0, slashIndex);
+ port = "80";
+ }
+ if (isHttp) {
+ configContext.setProperty(RUNNING_PORT, port);
+ }
+ }
+ return ip;
+ }
+
+ 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");
+ copy(stream, out);
+ out.flush();
+ out.close();
+ return;
+ }
+ }
+ }
+ }
+
+ /**
+ * Copies the input stream to the output stream
+ *
+ * @param stream the <code>InputStream</code>
+ * @param ostream the <code>OutputStream</code>
+ */
+ public static void copy(InputStream stream, OutputStream ostream) throws
IOException {
+ int nextValue = stream.read();
+ while (-1 != nextValue) {
+ ostream.write(nextValue);
+ nextValue = stream.read();
+ }
+ }
+
+ 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 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) {
+ boolean isHttp = "http".equals(req.getScheme());
+ if (wsdl2 >= 0) {
+ res.setContentType("text/xml");
+ String ip = extractHostAndPort(url, isHttp);
+ String wsdlName = req.getParameter("wsdl2");
+ if (wsdlName != null && wsdlName.length()>0) {
+ InputStream in = ((AxisService)
serviceObj).getClassLoader()
+
.getResourceAsStream(DeploymentConstants.META_INF + "/" + wsdlName);
+ if (in != null) {
+ OutputStream out = res.getOutputStream();
+ out.write(IOUtils.getStreamAsByteArray(in));
+ out.flush();
+ out.close();
+ } else {
+ res.sendError(HttpServletResponse.SC_NOT_FOUND);
+ }
+ } else {
+ OutputStream out = res.getOutputStream();
+ ((AxisService) serviceObj)
+ .printWSDL2(out, ip);
+ out.flush();
+ out.close();
+ }
+ 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 axisServce = (AxisService) serviceObj;
+ axisServce.printUserWSDL(out, wsdlName);
+ out.flush();
+ out.close();
+ } else {
+ ((AxisService) serviceObj).printWSDL(out, ip);
+ out.flush();
+ out.close();
+ }
+ return;
+ } else if (xsd >= 0) {
+ res.setContentType("text/xml");
+ int ret = ((AxisService)
serviceObj).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) serviceObj);
+
+ 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)
serviceObj).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 + " servcie</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);
+ }
+
+ private Policy findPolicy(String id, AxisDescription des) {
+
+ List policyElements = des.getPolicyInclude().getPolicyElements();
+ PolicyRegistry registry = des.getPolicyInclude().getPolicyRegistry();
+
+ Object policyComponent;
+
+ Policy policy = registry.lookup(id);
+
+ if (policy != null) {
+ return policy;
+ }
+
+ for (Iterator iterator = policyElements.iterator();
iterator.hasNext();) {
+ policyComponent = iterator.next();
+
+ if (policyComponent instanceof Policy) {
+ // policy found for the id
+
+ if (id.equals(((Policy) policyComponent).getId())) {
+ return (Policy) policyComponent;
+ }
+ }
+ }
+
+ AxisDescription child;
+
+ for (Iterator iterator = des.getChildren(); iterator.hasNext();) {
+ child = (AxisDescription) iterator.next();
+ policy = findPolicy(id, child);
+
+ if (policy != null) {
+ return policy;
+ }
+ }
+
+ return null;
+ }
+
+}
Propchange:
webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/ListingAgent.java
------------------------------------------------------------------------------
svn:eol-style = native