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