|
Axis 2 example source code file (PolicyUtil.java)
The Axis 2 PolicyUtil.java source code
/*
* 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.util;
import org.apache.axiom.om.OMElement;
import org.apache.axis2.description.AxisDescription;
import org.apache.axis2.description.AxisMessage;
import org.apache.axis2.description.AxisOperation;
import org.apache.axis2.description.AxisService;
import org.apache.axis2.description.PolicyInclude;
import org.apache.neethi.Constants;
import org.apache.neethi.Policy;
import org.apache.neethi.PolicyComponent;
import org.apache.neethi.PolicyEngine;
import org.apache.neethi.PolicyReference;
import javax.xml.stream.FactoryConfigurationError;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.Iterator;
import java.util.List;
import com.ibm.wsdl.util.xml.DOM2Writer;
public class PolicyUtil {
public static String getSafeString(String unsafeString) {
StringBuffer sbuf = new StringBuffer();
char[] chars = unsafeString.toCharArray();
for (int i = 0; i < chars.length; i++) {
char c = chars[i];
switch (c) {
case'\\':
sbuf.append('\\');
sbuf.append('\\');
break;
case'"':
sbuf.append('\\');
sbuf.append('"');
break;
case'\n':
sbuf.append('\\');
sbuf.append('n');
break;
case'\r':
sbuf.append('\\');
sbuf.append('r');
break;
default:
sbuf.append(c);
}
}
return sbuf.toString();
}
public static OMElement getPolicyComponentAsOMElement(
PolicyComponent policyComponent,
ExternalPolicySerializer externalPolicySerializer)
throws XMLStreamException, FactoryConfigurationError {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
if (policyComponent instanceof Policy) {
externalPolicySerializer.serialize((Policy) policyComponent, baos);
} else {
XMLStreamWriter writer = XMLOutputFactory.newInstance()
.createXMLStreamWriter(baos);
policyComponent.serialize(writer);
writer.flush();
}
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
return (OMElement) XMLUtils.toOM(bais);
}
public static OMElement getPolicyComponentAsOMElement(
PolicyComponent component) throws XMLStreamException,
FactoryConfigurationError {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLStreamWriter writer = XMLOutputFactory.newInstance()
.createXMLStreamWriter(baos);
component.serialize(writer);
writer.flush();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
return (OMElement) XMLUtils.toOM(bais);
}
public static PolicyComponent getPolicyComponentFromOMElement(
OMElement policyComponent) throws IllegalArgumentException {
if (policyComponent instanceof Policy) {
return PolicyEngine.getPolicy(policyComponent);
} else if (policyComponent instanceof PolicyReference) {
return PolicyEngine.getPolicyReference(policyComponent);
} else {
throw new IllegalArgumentException(
"Agrument is neither a <wsp:Policy> nor a
Other Axis 2 examples (source code examples)Here is a short list of links related to this Axis 2 PolicyUtil.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.