Merge branch 'master' of https://bitbucket.org/openesb/openesb-components
commit
cadb31ba03
|
@ -1,8 +1,9 @@
|
|||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
package com.sun.jbi.httpsoapbc;
|
||||
|
||||
import com.ibm.wsdl.Constants;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.net.InetAddress;
|
||||
|
@ -51,430 +52,496 @@ import com.sun.jbi.internationalization.Messages;
|
|||
|
||||
/**
|
||||
* @author Sujit Biswas
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class WsdlQueryHelper {
|
||||
|
||||
private String lbHost;
|
||||
private String lbPort;
|
||||
private Definition definition;
|
||||
// private Definition definition;
|
||||
private boolean isWsdl;
|
||||
private String localhostFQDN;
|
||||
|
||||
private Document doc;
|
||||
|
||||
private ByteBuffer byteBuffer;
|
||||
|
||||
/**
|
||||
* this is the port on which http-bc is running
|
||||
*/
|
||||
String httpbcPort;
|
||||
|
||||
private CoyoteRequest request;
|
||||
|
||||
private static Messages mMessages = Messages.getMessages(WsdlQueryHelper.class);
|
||||
private static Logger mLog = Messages.getLogger(WsdlQueryHelper.class);
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public WsdlQueryHelper(CoyoteRequest request, int rPort, ByteBuffer def, boolean wsdl) {
|
||||
|
||||
this.isWsdl = wsdl;
|
||||
this.isWsdl = wsdl;
|
||||
|
||||
this.request = request;
|
||||
this.request = request;
|
||||
|
||||
this.byteBuffer = def;
|
||||
this.byteBuffer = def;
|
||||
|
||||
lbHost = request.getServerName();
|
||||
lbPort = Integer.toString(request.getServerPort());
|
||||
lbHost = request.getServerName();
|
||||
lbPort = Integer.toString(request.getServerPort());
|
||||
|
||||
httpbcPort = Integer.toString(rPort);
|
||||
httpbcPort = Integer.toString(rPort);
|
||||
|
||||
try {
|
||||
try {
|
||||
|
||||
localhostFQDN = InetAddress.getLocalHost().getCanonicalHostName().toString();
|
||||
localhostFQDN = InetAddress.getLocalHost().getCanonicalHostName().toString();
|
||||
|
||||
if (isWsdl) {
|
||||
WSDLFactoryImpl wsdlFactory = new WSDLFactoryImpl();
|
||||
WSDLReader reader = (WSDLReader) wsdlFactory.newWSDLReader();
|
||||
reader.setFeature(com.ibm.wsdl.Constants.FEATURE_VERBOSE, false);
|
||||
/*
|
||||
if (isWsdl) {
|
||||
WSDLFactoryImpl wsdlFactory = new WSDLFactoryImpl();
|
||||
WSDLReader reader = (WSDLReader) wsdlFactory.newWSDLReader();
|
||||
reader.setFeature(com.ibm.wsdl.Constants.FEATURE_VERBOSE, false);
|
||||
|
||||
InputSource source = new InputSource(new ByteArrayInputStream(def.array()));
|
||||
InputSource source = new InputSource(new ByteArrayInputStream(def.array()));
|
||||
|
||||
this.definition = reader.readWSDL("", source);
|
||||
} else {
|
||||
DocumentBuilderFactory builderF = DocumentBuilderFactory.newInstance();
|
||||
this.definition = reader.readWSDL("", source);
|
||||
} else {
|
||||
* */
|
||||
DocumentBuilderFactory builderF = DocumentBuilderFactory.newInstance();
|
||||
|
||||
builderF.setNamespaceAware(true);
|
||||
DocumentBuilder builder = builderF.newDocumentBuilder();
|
||||
builderF.setNamespaceAware(true);
|
||||
DocumentBuilder builder = builderF.newDocumentBuilder();
|
||||
|
||||
doc = builder.parse(new ByteArrayInputStream(def.array()));
|
||||
doc = builder.parse(new ByteArrayInputStream(def.array()));
|
||||
|
||||
}
|
||||
//}
|
||||
|
||||
} catch (Exception e) {
|
||||
if (mLog.isLoggable(Level.FINE)) {
|
||||
mLog.log(Level.FINE, "init query helper failed.", e);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (mLog.isLoggable(Level.FINE)) {
|
||||
mLog.log(Level.FINE, "init query helper failed.", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public WsdlQueryHelper(CoyoteRequest request, int rPort, ByteArrayOutputStream baos, boolean wsdl) {
|
||||
|
||||
public WsdlQueryHelper(CoyoteRequest request, int rPort, Definition def, boolean wsdl) {
|
||||
this.isWsdl = wsdl;
|
||||
|
||||
this.isWsdl = wsdl;
|
||||
this.request = request;
|
||||
|
||||
this.request = request;
|
||||
// this.definition = def;
|
||||
|
||||
this.definition = def;
|
||||
lbHost = request.getServerName();
|
||||
lbPort = Integer.toString(request.getServerPort());
|
||||
|
||||
lbHost = request.getServerName();
|
||||
lbPort = Integer.toString(request.getServerPort());
|
||||
httpbcPort = Integer.toString(rPort);
|
||||
|
||||
httpbcPort = Integer.toString(rPort);
|
||||
try {
|
||||
localhostFQDN = InetAddress.getLocalHost().getCanonicalHostName().toString();
|
||||
|
||||
DocumentBuilderFactory builderF = DocumentBuilderFactory.newInstance();
|
||||
|
||||
try {
|
||||
localhostFQDN = InetAddress.getLocalHost().getCanonicalHostName().toString();
|
||||
} catch (UnknownHostException e) {
|
||||
if (mLog.isLoggable(Level.FINE)) {
|
||||
mLog.log(Level.FINE, "the proxy host may be unknown.", e);
|
||||
}
|
||||
}
|
||||
builderF.setNamespaceAware(true);
|
||||
DocumentBuilder builder = builderF.newDocumentBuilder();
|
||||
|
||||
doc = builder.parse(new ByteArrayInputStream(baos.toByteArray()));
|
||||
} catch (Exception e) {
|
||||
if (mLog.isLoggable(Level.FINE)) {
|
||||
mLog.log(Level.FINE, "the proxy host may be unknown.", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
public Definition getServiceDescriptor() {
|
||||
|
||||
try {
|
||||
modifyWSDL(definition);
|
||||
try {
|
||||
modifyWSDL(definition);
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO need to update some of the exception to warning where
|
||||
// suitable
|
||||
if (mLog.isLoggable(Level.FINE)) {
|
||||
mLog.log(Level.FINE, "modify wsdl failed, this will return the original wsdl.", e);
|
||||
}
|
||||
}
|
||||
return definition;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// TODO need to update some of the exception to warning where
|
||||
// suitable
|
||||
if (mLog.isLoggable(Level.FINE)) {
|
||||
mLog.log(Level.FINE, "modify wsdl failed, this will return the original wsdl.", e);
|
||||
}
|
||||
}
|
||||
return definition;
|
||||
}*/
|
||||
|
||||
public ByteBuffer getServiceDescriptorAsByteBuffer() {
|
||||
|
||||
/**
|
||||
* check if the request is a direct request, return the byte-buffer if
|
||||
* true
|
||||
*/
|
||||
/**
|
||||
* check if the request is a direct request, return the byte-buffer if
|
||||
* true
|
||||
*/
|
||||
if (isDirectRequest()) {
|
||||
return byteBuffer;
|
||||
}
|
||||
|
||||
if (isDirectRequest()) {
|
||||
return byteBuffer;
|
||||
}
|
||||
if (isWsdl) {
|
||||
try {
|
||||
updateImportDom(doc.getDocumentElement());
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
System.out.println("Exception : " + ex);
|
||||
if (mLog.isLoggable(Level.FINE)) {
|
||||
mLog.log(Level.FINE, "unable to modify the wsdl.", ex);
|
||||
}
|
||||
}
|
||||
} else {// this is xsd
|
||||
try {
|
||||
updateSchemaDom(doc.getDocumentElement());
|
||||
} catch (Exception e) {
|
||||
if (mLog.isLoggable(Level.FINE)) {
|
||||
mLog.log(Level.FINE, "unable to modify the xsd.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isWsdl) {
|
||||
try {
|
||||
WSDLFactory wsdlFactory = (WSDLFactory) WSDLFactory.newInstance();
|
||||
WSDLWriter writer = (WSDLWriter) wsdlFactory.newWSDLWriter();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
writer.writeWSDL(getServiceDescriptor(), baos);
|
||||
return ByteBuffer.wrap(baos.toByteArray());
|
||||
} catch (Exception ex) {
|
||||
if (mLog.isLoggable(Level.FINE)) {
|
||||
mLog.log(Level.FINE, "unable to write the wsdl.", ex);
|
||||
}
|
||||
}
|
||||
} else {// this is xsd
|
||||
try {
|
||||
updateSchemaDom(doc.getDocumentElement());
|
||||
try {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
String encoding = doc.getXmlEncoding();
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
String encoding = doc.getXmlEncoding();
|
||||
Transformer trans = TransformerFactory.newInstance().newTransformer();
|
||||
//trans.setOutputProperty(OutputKeys.ENCODING, encoding);
|
||||
if (encoding == null) {
|
||||
trans.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
|
||||
} else {
|
||||
trans.setOutputProperty(OutputKeys.ENCODING, encoding);
|
||||
}
|
||||
//changes ends here
|
||||
trans.setOutputProperty(OutputKeys.INDENT, "yes");
|
||||
trans.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
|
||||
trans.setOutputProperty(OutputKeys.METHOD, "xml");
|
||||
trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, false ? "yes" : "no");
|
||||
trans.transform(new DOMSource(doc), new StreamResult(baos));
|
||||
|
||||
Transformer trans = TransformerFactory.newInstance().newTransformer();
|
||||
//trans.setOutputProperty(OutputKeys.ENCODING, encoding);
|
||||
if(encoding == null){
|
||||
trans.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
|
||||
}else{
|
||||
trans.setOutputProperty(OutputKeys.ENCODING, encoding);
|
||||
}
|
||||
//changes ends here
|
||||
trans.setOutputProperty(OutputKeys.INDENT, "yes");
|
||||
trans.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
|
||||
trans.setOutputProperty(OutputKeys.METHOD, "xml");
|
||||
trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, false ? "yes" : "no");
|
||||
trans.transform(new DOMSource(doc), new StreamResult(baos));
|
||||
return ByteBuffer.wrap(baos.toByteArray());
|
||||
} catch (Exception e) {
|
||||
if (mLog.isLoggable(Level.FINE)) {
|
||||
mLog.log(Level.FINE, "not able to transform.", e);
|
||||
}
|
||||
}
|
||||
|
||||
return ByteBuffer.wrap(baos.toByteArray());
|
||||
/*
|
||||
if (isWsdl) {
|
||||
try {
|
||||
WSDLFactory wsdlFactory = (WSDLFactory) WSDLFactory.newInstance();
|
||||
WSDLWriter writer = (WSDLWriter) wsdlFactory.newWSDLWriter();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
writer.writeWSDL(getServiceDescriptor(), baos);
|
||||
return ByteBuffer.wrap(baos.toByteArray());
|
||||
} catch (Exception ex) {
|
||||
if (mLog.isLoggable(Level.FINE)) {
|
||||
mLog.log(Level.FINE, "unable to write the wsdl.", ex);
|
||||
}
|
||||
}
|
||||
} else {// this is xsd
|
||||
try {
|
||||
updateSchemaDom(doc.getDocumentElement());
|
||||
|
||||
} catch (Exception e) {
|
||||
if (mLog.isLoggable(Level.FINE)) {
|
||||
mLog.log(Level.FINE, "not able to transform.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
String encoding = doc.getXmlEncoding();
|
||||
|
||||
Transformer trans = TransformerFactory.newInstance().newTransformer();
|
||||
//trans.setOutputProperty(OutputKeys.ENCODING, encoding);
|
||||
if(encoding == null){
|
||||
trans.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
|
||||
}else{
|
||||
trans.setOutputProperty(OutputKeys.ENCODING, encoding);
|
||||
}
|
||||
//changes ends here
|
||||
trans.setOutputProperty(OutputKeys.INDENT, "yes");
|
||||
trans.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
|
||||
trans.setOutputProperty(OutputKeys.METHOD, "xml");
|
||||
trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, false ? "yes" : "no");
|
||||
trans.transform(new DOMSource(doc), new StreamResult(baos));
|
||||
|
||||
return ByteBuffer.wrap(baos.toByteArray());
|
||||
|
||||
} catch (Exception e) {
|
||||
if (mLog.isLoggable(Level.FINE)) {
|
||||
mLog.log(Level.FINE, "not able to transform.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean isDirectRequest() {
|
||||
|
||||
if (isLocalHost()) {
|
||||
if (lbPort.equalsIgnoreCase(httpbcPort)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (isLocalHost()) {
|
||||
if (lbPort.equalsIgnoreCase(httpbcPort)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isLocalHost() {
|
||||
boolean b = "localhost".equalsIgnoreCase(lbHost) || localhostFQDN.equalsIgnoreCase(lbHost);
|
||||
boolean b = "localhost".equalsIgnoreCase(lbHost) || localhostFQDN.equalsIgnoreCase(lbHost);
|
||||
|
||||
if (!b) {
|
||||
try {
|
||||
String s = InetAddress.getByName(lbHost).getCanonicalHostName();
|
||||
if (s.equalsIgnoreCase(localhostFQDN)) {
|
||||
return true;
|
||||
}
|
||||
} catch (UnknownHostException e) {
|
||||
if (mLog.isLoggable(Level.FINE)) {
|
||||
mLog.log(Level.FINE, "unknown host.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return b;
|
||||
if (!b) {
|
||||
try {
|
||||
String s = InetAddress.getByName(lbHost).getCanonicalHostName();
|
||||
if (s.equalsIgnoreCase(localhostFQDN)) {
|
||||
return true;
|
||||
}
|
||||
} catch (UnknownHostException e) {
|
||||
if (mLog.isLoggable(Level.FINE)) {
|
||||
mLog.log(Level.FINE, "unknown host.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return b;
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void modifyWSDL(Definition def) throws Exception {
|
||||
private void modifyWSDL(Definition def) throws Exception {
|
||||
|
||||
// Search all wsdl imports for the resourceName
|
||||
Iterator importLists = def.getImports().values().iterator();
|
||||
while (importLists.hasNext()) {
|
||||
Iterator imports = ((List) importLists.next()).iterator();
|
||||
while (imports.hasNext()) {
|
||||
Import anImport = (Import) imports.next();
|
||||
// Search all wsdl imports for the resourceName
|
||||
Iterator importLists = def.getImports().values().iterator();
|
||||
while (importLists.hasNext()) {
|
||||
Iterator imports = ((List) importLists.next()).iterator();
|
||||
while (imports.hasNext()) {
|
||||
Import anImport = (Import) imports.next();
|
||||
|
||||
String location = anImport.getLocationURI();
|
||||
String result = getResultUrl(location);
|
||||
anImport.setLocationURI(result);
|
||||
String location = anImport.getLocationURI();
|
||||
String result = getResultUrl(location);
|
||||
anImport.setLocationURI(result);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Search all XSD imports and includes for the resourceName
|
||||
Types types = def.getTypes();
|
||||
if (types != null) {
|
||||
Iterator schemas = types.getExtensibilityElements().iterator();
|
||||
while (schemas.hasNext()) {
|
||||
ExtensibilityElement element = (ExtensibilityElement) schemas.next();
|
||||
if (element instanceof Schema) {
|
||||
Schema schema = (Schema) element;
|
||||
// Search all XSD imports and includes for the resourceName
|
||||
Types types = def.getTypes();
|
||||
if (types != null) {
|
||||
Iterator schemas = types.getExtensibilityElements().iterator();
|
||||
while (schemas.hasNext()) {
|
||||
ExtensibilityElement element = (ExtensibilityElement) schemas.next();
|
||||
if (element instanceof Schema) {
|
||||
Schema schema = (Schema) element;
|
||||
|
||||
handleSchema(schema);
|
||||
handleSchema(schema);
|
||||
|
||||
updateSchemaDom(schema.getElement());
|
||||
updateSchemaDom(schema.getElement());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Map services = def.getAllServices();
|
||||
Iterator iter = services.keySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Service s = (Service) services.get(iter.next());
|
||||
Map services = def.getAllServices();
|
||||
Iterator iter = services.keySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Service s = (Service) services.get(iter.next());
|
||||
|
||||
Map ports = s.getPorts();
|
||||
Iterator iter1 = ports.keySet().iterator();
|
||||
Map ports = s.getPorts();
|
||||
Iterator iter1 = ports.keySet().iterator();
|
||||
|
||||
while (iter1.hasNext()) {
|
||||
Port port = (Port) ports.get(iter1.next());
|
||||
while (iter1.hasNext()) {
|
||||
Port port = (Port) ports.get(iter1.next());
|
||||
|
||||
List address = port.getExtensibilityElements();
|
||||
for (Iterator iterator = address.iterator(); iterator.hasNext();) {
|
||||
Object object = (Object) iterator.next();
|
||||
List address = port.getExtensibilityElements();
|
||||
for (Iterator iterator = address.iterator(); iterator.hasNext();) {
|
||||
Object object = (Object) iterator.next();
|
||||
|
||||
if (object instanceof SOAPAddress) {
|
||||
if (object instanceof SOAPAddress) {
|
||||
|
||||
SOAPAddress sa = (SOAPAddress) object;
|
||||
String result = getResultUrl(sa.getLocationURI());
|
||||
sa.setLocationURI(result);
|
||||
SOAPAddress sa = (SOAPAddress) object;
|
||||
String result = getResultUrl(sa.getLocationURI());
|
||||
sa.setLocationURI(result);
|
||||
|
||||
} else if (object instanceof SOAP12Address) {
|
||||
SOAP12Address sa = (SOAP12Address) object;
|
||||
String result = getResultUrl(sa.getLocationURI());
|
||||
sa.setLocationURI(result);
|
||||
}
|
||||
} else if (object instanceof SOAP12Address) {
|
||||
SOAP12Address sa = (SOAP12Address) object;
|
||||
String result = getResultUrl(sa.getLocationURI());
|
||||
sa.setLocationURI(result);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void handleSchema(Schema schema) {
|
||||
Map imports = schema.getImports();
|
||||
Map imports = schema.getImports();
|
||||
|
||||
Iterator iter = imports.keySet().iterator();
|
||||
Iterator iter = imports.keySet().iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
Collection refs = (Collection) imports.get(iter.next());
|
||||
while (iter.hasNext()) {
|
||||
Collection refs = (Collection) imports.get(iter.next());
|
||||
|
||||
Iterator iterator = refs.iterator();
|
||||
Iterator iterator = refs.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
SchemaReference si = (SchemaReference) iterator.next();
|
||||
while (iterator.hasNext()) {
|
||||
SchemaReference si = (SchemaReference) iterator.next();
|
||||
|
||||
si.getSchemaLocationURI();
|
||||
String location = si.getSchemaLocationURI();
|
||||
String result = getResultUrl(location);
|
||||
si.setSchemaLocationURI(result);
|
||||
}
|
||||
si.getSchemaLocationURI();
|
||||
String location = si.getSchemaLocationURI();
|
||||
String result = getResultUrl(location);
|
||||
si.setSchemaLocationURI(result);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
List includes = schema.getIncludes();
|
||||
List includes = schema.getIncludes();
|
||||
|
||||
Iterator iter1 = includes.iterator();
|
||||
Iterator iter1 = includes.iterator();
|
||||
|
||||
while (iter1.hasNext()) {
|
||||
SchemaReference sr = (SchemaReference) iter1.next();
|
||||
sr.getSchemaLocationURI();
|
||||
String location = sr.getSchemaLocationURI();
|
||||
String result = getResultUrl(location);
|
||||
sr.setSchemaLocationURI(result);
|
||||
while (iter1.hasNext()) {
|
||||
SchemaReference sr = (SchemaReference) iter1.next();
|
||||
sr.getSchemaLocationURI();
|
||||
String location = sr.getSchemaLocationURI();
|
||||
String result = getResultUrl(location);
|
||||
sr.setSchemaLocationURI(result);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
List redefines = schema.getRedefines();
|
||||
List redefines = schema.getRedefines();
|
||||
|
||||
Iterator iter2 = redefines.iterator();
|
||||
Iterator iter2 = redefines.iterator();
|
||||
|
||||
while (iter2.hasNext()) {
|
||||
SchemaReference sr = (SchemaReference) iter2.next();
|
||||
sr.getSchemaLocationURI();
|
||||
String location = sr.getSchemaLocationURI();
|
||||
String result = getResultUrl(location);
|
||||
sr.setSchemaLocationURI(result);
|
||||
while (iter2.hasNext()) {
|
||||
SchemaReference sr = (SchemaReference) iter2.next();
|
||||
sr.getSchemaLocationURI();
|
||||
String location = sr.getSchemaLocationURI();
|
||||
String result = getResultUrl(location);
|
||||
sr.setSchemaLocationURI(result);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private String getResultUrl(String location) {
|
||||
String result = "", hostPort = "", host = "", port = "", rest = "";
|
||||
String result = "", hostPort = "", host = "", port = "", rest = "";
|
||||
|
||||
boolean isSecure = request.isSecure();
|
||||
boolean isSecure = request.isSecure();
|
||||
|
||||
if (location.startsWith("http://") && !isSecure) {
|
||||
String s = location.substring("http://".length());
|
||||
int i = s.indexOf("/");
|
||||
if (location.startsWith("http://") && !isSecure) {
|
||||
String s = location.substring("http://".length());
|
||||
int i = s.indexOf("/");
|
||||
|
||||
rest = s.substring(i);
|
||||
rest = s.substring(i);
|
||||
|
||||
hostPort = s.substring(0, i);
|
||||
hostPort = hostPort.trim();
|
||||
int index = hostPort.indexOf(':');
|
||||
hostPort = s.substring(0, i);
|
||||
hostPort = hostPort.trim();
|
||||
int index = hostPort.indexOf(':');
|
||||
|
||||
if (index == -1) {
|
||||
return location;
|
||||
}
|
||||
if (index == -1) {
|
||||
return location;
|
||||
}
|
||||
|
||||
host = hostPort.substring(0, index);
|
||||
port = hostPort.substring(index + 1);
|
||||
host = hostPort.substring(0, index);
|
||||
port = hostPort.substring(index + 1);
|
||||
|
||||
if (host.equalsIgnoreCase(getlocalhostFQDN())) {
|
||||
host = lbHost;
|
||||
if (port.equalsIgnoreCase(httpbcPort)) {
|
||||
port = lbPort;
|
||||
}
|
||||
if (host.equalsIgnoreCase(getlocalhostFQDN())) {
|
||||
host = lbHost;
|
||||
if (port.equalsIgnoreCase(httpbcPort)) {
|
||||
port = lbPort;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
result = "http://" + host + ":" + port + rest;
|
||||
result = "http://" + host + ":" + port + rest;
|
||||
|
||||
} else if (location.startsWith("https://") && isSecure) {
|
||||
} else if (location.startsWith("https://") && isSecure) {
|
||||
|
||||
String s = location.substring("https://".length());
|
||||
int i = s.indexOf("/");
|
||||
String s = location.substring("https://".length());
|
||||
int i = s.indexOf("/");
|
||||
|
||||
rest = s.substring(i);
|
||||
rest = s.substring(i);
|
||||
|
||||
hostPort = s.substring(0, i);
|
||||
hostPort = hostPort.trim();
|
||||
int index = hostPort.indexOf(':');
|
||||
hostPort = s.substring(0, i);
|
||||
hostPort = hostPort.trim();
|
||||
int index = hostPort.indexOf(':');
|
||||
|
||||
if (index == -1) {
|
||||
return location;
|
||||
}
|
||||
if (index == -1) {
|
||||
return location;
|
||||
}
|
||||
|
||||
host = hostPort.substring(0, index);
|
||||
port = hostPort.substring(index + 1);
|
||||
host = hostPort.substring(0, index);
|
||||
port = hostPort.substring(index + 1);
|
||||
|
||||
if (host.equalsIgnoreCase(getlocalhostFQDN())) {
|
||||
host = lbHost;
|
||||
if (port.equalsIgnoreCase(httpbcPort)) {
|
||||
port = lbPort;
|
||||
}
|
||||
if (host.equalsIgnoreCase(getlocalhostFQDN())) {
|
||||
host = lbHost;
|
||||
if (port.equalsIgnoreCase(httpbcPort)) {
|
||||
port = lbPort;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
result = "https://" + host + ":" + port + rest;
|
||||
//Fix for [ bug #102 ] schemaLocation in xsd is empty
|
||||
}else {
|
||||
// Don't change location for relative paths
|
||||
result = location;
|
||||
}
|
||||
return result;
|
||||
result = "https://" + host + ":" + port + rest;
|
||||
//Fix for [ bug #102 ] schemaLocation in xsd is empty
|
||||
} else {
|
||||
// Don't change location for relative paths
|
||||
result = location;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void updateImportDom(Element el) throws Exception {
|
||||
Element tempEl = DOMUtils.getFirstChildElement(el);
|
||||
|
||||
for (; tempEl != null; tempEl = DOMUtils.getNextSiblingElement(tempEl)) {
|
||||
QName tempElType = QNameUtils.newQName(tempEl);
|
||||
|
||||
if (Constants.Q_ELEM_IMPORT.equals(tempElType)) {
|
||||
updateImportDomReference(tempEl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSchemaDom(Element el) throws Exception {
|
||||
Element tempEl = DOMUtils.getFirstChildElement(el);
|
||||
Element tempEl = DOMUtils.getFirstChildElement(el);
|
||||
|
||||
for (; tempEl != null; tempEl = DOMUtils.getNextSiblingElement(tempEl)) {
|
||||
QName tempElType = QNameUtils.newQName(tempEl);
|
||||
for (; tempEl != null; tempEl = DOMUtils.getNextSiblingElement(tempEl)) {
|
||||
QName tempElType = QNameUtils.newQName(tempEl);
|
||||
|
||||
if (SchemaConstants.XSD_IMPORT_QNAME_LIST.contains(tempElType) || SchemaConstants.XSD_INCLUDE_QNAME_LIST.contains(tempElType)
|
||||
|| SchemaConstants.XSD_REDEFINE_QNAME_LIST.contains(tempElType)) {
|
||||
updateSchemaDomReference(tempEl);
|
||||
}
|
||||
}
|
||||
if (SchemaConstants.XSD_IMPORT_QNAME_LIST.contains(tempElType) || SchemaConstants.XSD_INCLUDE_QNAME_LIST.contains(tempElType)
|
||||
|| SchemaConstants.XSD_REDEFINE_QNAME_LIST.contains(tempElType)) {
|
||||
updateSchemaDomReference(tempEl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateImportDomReference(Element tempEl) throws Exception {
|
||||
String locationURI = DOMUtils.getAttribute(tempEl, Constants.ATTR_LOCATION);
|
||||
if (locationURI != null) {
|
||||
if (mLog.isLoggable(Level.FINE)) {
|
||||
mLog.log(Level.FINE, "nlocationURI = " + locationURI);
|
||||
}
|
||||
String result = getResultUrl(locationURI);
|
||||
|
||||
setAttribute(tempEl, Constants.ATTR_LOCATION, result);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSchemaDomReference(Element tempEl) throws Exception {
|
||||
String locationURI = DOMUtils.getAttribute(tempEl, SchemaConstants.ATTR_SCHEMA_LOCATION);
|
||||
if (locationURI != null) {
|
||||
if (mLog.isLoggable(Level.FINE)) {
|
||||
mLog.log(Level.FINE, "nlocationURI = " + locationURI);
|
||||
}
|
||||
String result = getResultUrl(locationURI);
|
||||
String locationURI = DOMUtils.getAttribute(tempEl, SchemaConstants.ATTR_SCHEMA_LOCATION);
|
||||
if (locationURI != null) {
|
||||
if (mLog.isLoggable(Level.FINE)) {
|
||||
mLog.log(Level.FINE, "nlocationURI = " + locationURI);
|
||||
}
|
||||
String result = getResultUrl(locationURI);
|
||||
|
||||
setAttribute(tempEl, SchemaConstants.ATTR_SCHEMA_LOCATION, result);
|
||||
setAttribute(tempEl, SchemaConstants.ATTR_SCHEMA_LOCATION, result);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setAttribute(Element el, String attrName, String attrValue) {
|
||||
Attr attr = el.getAttributeNode(attrName);
|
||||
Attr attr = el.getAttributeNode(attrName);
|
||||
|
||||
if (attr != null) {
|
||||
attr.setValue(attrValue);
|
||||
}
|
||||
if (attr != null) {
|
||||
attr.setValue(attrValue);
|
||||
}
|
||||
}
|
||||
|
||||
private String getlocalhostFQDN() {
|
||||
return localhostFQDN;
|
||||
return localhostFQDN;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ import com.ibm.wsdl.extensions.schema.SchemaImpl;
|
|||
*/
|
||||
public class WsdlQueryHelperTest extends TestCase {
|
||||
|
||||
private CoyoteRequest req = new DummyCoyoteRequest();
|
||||
private CoyoteRequest req = new WsdlQueryHelperTest.DummyCoyoteRequest();
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -50,7 +50,7 @@ public class WsdlQueryHelperTest extends TestCase {
|
|||
|
||||
System.out.println(new String(baos.toByteArray()));
|
||||
|
||||
WsdlQueryHelper helper = new WsdlQueryHelper(req, 9080, def, true);
|
||||
WsdlQueryHelper helper = new WsdlQueryHelper(req, 9080, baos, true);
|
||||
ByteBuffer buffer = helper.getServiceDescriptorAsByteBuffer();
|
||||
|
||||
System.out.println(new String(buffer.array()));
|
||||
|
|
Loading…
Reference in New Issue