code stringlengths 3 1.18M | language stringclasses 1 value |
|---|---|
/*
* 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.xmlrpc.serializer;
import java.util.Iterator;
import java.util.Map;
import org.apache.xmlrpc.common.TypeFactory;
import org.apache.xmlrpc.common.XmlRpcStreamConfig;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
/** A {@link TypeSerializer} for maps.
*/
public class MapSerializer extends TypeSerializerImpl {
/** Tag name of a maps struct tag.
*/
public static final String STRUCT_TAG = "struct";
/** Tag name of a maps member tag.
*/
public static final String MEMBER_TAG = "member";
/** Tag name of a maps members name tag.
*/
public static final String NAME_TAG = "name";
private final XmlRpcStreamConfig config;
private final TypeFactory typeFactory;
/** Creates a new instance.
* @param pTypeFactory The factory being used for creating serializers.
* @param pConfig The configuration being used for creating serializers.
*/
public MapSerializer(TypeFactory pTypeFactory, XmlRpcStreamConfig pConfig) {
typeFactory = pTypeFactory;
config = pConfig;
}
protected void writeEntry(ContentHandler pHandler, Object pKey, Object pValue) throws SAXException {
pHandler.startElement("", MEMBER_TAG, MEMBER_TAG, ZERO_ATTRIBUTES);
pHandler.startElement("", NAME_TAG, NAME_TAG, ZERO_ATTRIBUTES);
if (config.isEnabledForExtensions() && !(pKey instanceof String)) {
writeValue(pHandler, pKey);
} else {
String key = pKey.toString();
pHandler.characters(key.toCharArray(), 0, key.length());
}
pHandler.endElement("", NAME_TAG, NAME_TAG);
writeValue(pHandler, pValue);
pHandler.endElement("", MEMBER_TAG, MEMBER_TAG);
}
private void writeValue(ContentHandler pHandler, Object pValue)
throws SAXException {
TypeSerializer ts = typeFactory.getSerializer(config, pValue);
if (ts == null) {
throw new SAXException("Unsupported Java type: " + pValue.getClass().getName());
}
ts.write(pHandler, pValue);
}
protected void writeData(ContentHandler pHandler, Object pData) throws SAXException {
Map map = (Map) pData;
for (Iterator iter = map.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry entry = (Map.Entry) iter.next();
writeEntry(pHandler, entry.getKey(), entry.getValue());
}
}
public void write(final ContentHandler pHandler, Object pObject) throws SAXException {
pHandler.startElement("", VALUE_TAG, VALUE_TAG, ZERO_ATTRIBUTES);
pHandler.startElement("", STRUCT_TAG, STRUCT_TAG, ZERO_ATTRIBUTES);
writeData(pHandler, pObject);
pHandler.endElement("", STRUCT_TAG, STRUCT_TAG);
pHandler.endElement("", VALUE_TAG, VALUE_TAG);
}
}
| Java |
/*
* 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.xmlrpc.serializer;
import org.apache.xmlrpc.common.TypeFactory;
import org.apache.xmlrpc.common.XmlRpcStreamConfig;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
/** A {@link TypeSerializer} for object arrays.
*/
public class ObjectArraySerializer extends TypeSerializerImpl {
/** Tag name of an array value.
*/
public static final String ARRAY_TAG = "array";
/** Tag name of an arrays data.
*/
public static final String DATA_TAG = "data";
private final XmlRpcStreamConfig config;
private final TypeFactory typeFactory;
/** Creates a new instance.
* @param pTypeFactory The factory being used for creating serializers.
* @param pConfig The configuration being used for creating serializers.
*/
public ObjectArraySerializer(TypeFactory pTypeFactory, XmlRpcStreamConfig pConfig) {
typeFactory = pTypeFactory;
config = pConfig;
}
protected void writeObject(ContentHandler pHandler, Object pObject) throws SAXException {
TypeSerializer ts = typeFactory.getSerializer(config, pObject);
if (ts == null) {
throw new SAXException("Unsupported Java type: " + pObject.getClass().getName());
}
ts.write(pHandler, pObject);
}
protected void writeData(ContentHandler pHandler, Object pObject) throws SAXException {
Object[] data = (Object[]) pObject;
for (int i = 0; i < data.length; i++) {
writeObject(pHandler, data[i]);
}
}
public void write(final ContentHandler pHandler, Object pObject) throws SAXException {
pHandler.startElement("", VALUE_TAG, VALUE_TAG, ZERO_ATTRIBUTES);
pHandler.startElement("", ARRAY_TAG, ARRAY_TAG, ZERO_ATTRIBUTES);
pHandler.startElement("", DATA_TAG, DATA_TAG, ZERO_ATTRIBUTES);
writeData(pHandler, pObject);
pHandler.endElement("", DATA_TAG, DATA_TAG);
pHandler.endElement("", ARRAY_TAG, ARRAY_TAG);
pHandler.endElement("", VALUE_TAG, VALUE_TAG);
}
} | Java |
/*
* 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.xmlrpc.serializer;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
/** A {@link TypeSerializer} for booleans.
*/
public class BooleanSerializer extends TypeSerializerImpl {
/** Tag name of a boolean value.
*/
public static final String BOOLEAN_TAG = "boolean";
private static final char[] TRUE = new char[]{'1'};
private static final char[] FALSE = new char[]{'0'};
public void write(ContentHandler pHandler, Object pObject) throws SAXException {
write(pHandler, BOOLEAN_TAG, ((Boolean) pObject).booleanValue() ? TRUE : FALSE);
}
} | Java |
/*
* 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.xmlrpc.serializer;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
/** Base class for external XML representations, like DOM,
* or JAXB.
*/
public abstract class ExtSerializer implements TypeSerializer {
/** Returns the unqualied tag name.
*/
protected abstract String getTagName();
/** Performs the actual serialization.
*/
protected abstract void serialize(ContentHandler pHandler, Object pObject) throws SAXException;
public void write(ContentHandler pHandler, Object pObject)
throws SAXException {
final String tag = getTagName();
final String exTag = "ex:" + getTagName();
pHandler.startElement("", TypeSerializerImpl.VALUE_TAG, TypeSerializerImpl.VALUE_TAG, TypeSerializerImpl.ZERO_ATTRIBUTES);
pHandler.startElement(XmlRpcWriter.EXTENSIONS_URI, tag, exTag, TypeSerializerImpl.ZERO_ATTRIBUTES);
serialize(pHandler, pObject);
pHandler.endElement(XmlRpcWriter.EXTENSIONS_URI, tag, exTag);
pHandler.endElement("", TypeSerializerImpl.VALUE_TAG, TypeSerializerImpl.VALUE_TAG);
}
}
| Java |
/*
* 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.xmlrpc.serializer;
import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
import java.util.HashMap;
import java.util.Map;
import org.apache.xmlrpc.XmlRpcRequest;
import org.apache.xmlrpc.XmlRpcRequestConfig;
import org.apache.xmlrpc.common.TypeFactory;
import org.apache.xmlrpc.common.XmlRpcStreamConfig;
import org.apache.xmlrpc.common.XmlRpcStreamRequestConfig;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
/** This class is responsible for writing an XmlRpc request or an
* XmlRpc response to an output stream.
*/
public class XmlRpcWriter {
/** The namespace URI for proprietary XML-RPC extensions.
*/
public static final String EXTENSIONS_URI = "http://ws.apache.org/xmlrpc/namespaces/extensions";
private static final Attributes ZERO_ATTRIBUTES = new AttributesImpl();
private final XmlRpcStreamConfig config;
private final TypeFactory typeFactory;
private final ContentHandler handler;
/** Creates a new instance.
* @param pConfig The clients configuration.
* @param pHandler The target SAX handler.
* @param pTypeFactory The type factory being used to create serializers.
*/
public XmlRpcWriter(XmlRpcStreamConfig pConfig, ContentHandler pHandler,
TypeFactory pTypeFactory) {
config = pConfig;
handler = pHandler;
typeFactory = pTypeFactory;
}
/** Writes a clients request to the output stream.
* @param pRequest The request being written.
* @throws SAXException Writing the request failed.
*/
public void write(XmlRpcRequest pRequest) throws SAXException {
handler.startDocument();
boolean extensions = pRequest.getConfig().isEnabledForExtensions();
if (extensions) {
handler.startPrefixMapping("ex", XmlRpcWriter.EXTENSIONS_URI);
}
handler.startElement("", "methodCall", "methodCall", ZERO_ATTRIBUTES);
handler.startElement("", "methodName", "methodName", ZERO_ATTRIBUTES);
String s = pRequest.getMethodName();
handler.characters(s.toCharArray(), 0, s.length());
handler.endElement("", "methodName", "methodName");
handler.startElement("", "params", "params", ZERO_ATTRIBUTES);
int num = pRequest.getParameterCount();
for (int i = 0; i < num; i++) {
handler.startElement("", "param", "param", ZERO_ATTRIBUTES);
writeValue(pRequest.getParameter(i));
handler.endElement("", "param", "param");
}
handler.endElement("", "params", "params");
handler.endElement("", "methodCall", "methodCall");
if (extensions) {
handler.endPrefixMapping("ex");
}
handler.endDocument();
}
/** Writes a servers response to the output stream.
* @param pConfig The request configuration.
* @param pResult The result object.
* @throws SAXException Writing the response failed.
*/
public void write(XmlRpcRequestConfig pConfig, Object pResult) throws SAXException {
handler.startDocument();
boolean extensions = pConfig.isEnabledForExtensions();
if (extensions) {
handler.startPrefixMapping("ex", XmlRpcWriter.EXTENSIONS_URI);
}
handler.startElement("", "methodResponse", "methodResponse", ZERO_ATTRIBUTES);
handler.startElement("", "params", "params", ZERO_ATTRIBUTES);
handler.startElement("", "param", "param", ZERO_ATTRIBUTES);
writeValue(pResult);
handler.endElement("", "param", "param");
handler.endElement("", "params", "params");
handler.endElement("", "methodResponse", "methodResponse");
if (extensions) {
handler.endPrefixMapping("ex");
}
handler.endDocument();
}
/** Writes a servers error message to the output stream.
* @param pConfig The request configuration.
* @param pCode The error code
* @param pMessage The error message
* @throws SAXException Writing the error message failed.
*/
public void write(XmlRpcRequestConfig pConfig, int pCode, String pMessage) throws SAXException {
write(pConfig, pCode, pMessage, null);
}
/** Writes a servers error message to the output stream.
* @param pConfig The request configuration.
* @param pCode The error code
* @param pMessage The error message
* @param pThrowable An exception, which is being sent to the client
* @throws SAXException Writing the error message failed.
*/
public void write(XmlRpcRequestConfig pConfig, int pCode, String pMessage,
Throwable pThrowable) throws SAXException {
handler.startDocument();
boolean extensions = pConfig.isEnabledForExtensions();
if (extensions) {
handler.startPrefixMapping("ex", XmlRpcWriter.EXTENSIONS_URI);
}
handler.startElement("", "methodResponse", "methodResponse", ZERO_ATTRIBUTES);
handler.startElement("", "fault", "fault", ZERO_ATTRIBUTES);
Map map = new HashMap();
map.put("faultCode", new Integer(pCode));
map.put("faultString", pMessage == null ? "" : pMessage);
if (pThrowable != null && extensions && (pConfig instanceof XmlRpcStreamRequestConfig) &&
((XmlRpcStreamRequestConfig) pConfig).isEnabledForExceptions()) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(pThrowable);
oos.close();
baos.close();
map.put("faultCause", baos.toByteArray());
} catch (Throwable t) {
// Ignore me
}
}
writeValue(map);
handler.endElement("", "fault", "fault");
handler.endElement("", "methodResponse", "methodResponse");
if (extensions) {
handler.endPrefixMapping("ex");
}
handler.endDocument();
}
/** Writes the XML representation of a Java object.
* @param pObject The object being written.
* @throws SAXException Writing the object failed.
*/
protected void writeValue(Object pObject) throws SAXException {
TypeSerializer serializer = typeFactory.getSerializer(config, pObject);
if (serializer == null) {
throw new SAXException("Unsupported Java type: " + pObject.getClass().getName());
}
serializer.write(handler, pObject);
}
}
| Java |
/*
* 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.xmlrpc.serializer;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
/** A {@link TypeSerializer} for strings.
*/
public class StringSerializer extends TypeSerializerImpl {
/** (Optional) Tag name of a string value.
*/
public static final String STRING_TAG = "string";
public void write(ContentHandler pHandler, Object pObject) throws SAXException {
write(pHandler, null, pObject.toString());
}
} | Java |
/*
* 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.xmlrpc.serializer;
import java.io.IOException;
import org.apache.ws.commons.util.Base64;
import org.apache.ws.commons.util.Base64.Encoder;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
/** A {@link TypeSerializer} for byte arrays.
*/
public class ByteArraySerializer extends TypeSerializerImpl {
/** Tag name of a base64 value.
*/
public static final String BASE_64_TAG = "base64";
public void write(final ContentHandler pHandler, Object pObject) throws SAXException {
pHandler.startElement("", VALUE_TAG, VALUE_TAG, ZERO_ATTRIBUTES);
pHandler.startElement("", BASE_64_TAG, BASE_64_TAG, ZERO_ATTRIBUTES);
byte[] buffer = (byte[]) pObject;
if (buffer.length > 0) {
char[] charBuffer = new char[buffer.length >= 1024 ? 1024 : ((buffer.length+3)/4)*4];
Encoder encoder = new Base64.SAXEncoder(charBuffer, 0, null, pHandler);
try {
encoder.write(buffer, 0, buffer.length);
encoder.flush();
} catch (Base64.SAXIOException e) {
throw e.getSAXException();
} catch (IOException e) {
throw new SAXException(e);
}
}
pHandler.endElement("", BASE_64_TAG, BASE_64_TAG);
pHandler.endElement("", VALUE_TAG, VALUE_TAG);
}
} | Java |
/*
* 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.xmlrpc.serializer;
import java.text.Format;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
/** A {@link TypeSerializer} for date values.
*/
public class DateSerializer extends TypeSerializerImpl {
/** Tag name of a date value.
*/
public static final String DATE_TAG = "dateTime.iso8601";
private final Format format;
/** Creates a new instance with the given formatter.
*/
public DateSerializer(Format pFormat) {
format = pFormat;
}
public void write(ContentHandler pHandler, Object pObject) throws SAXException {
write(pHandler, DATE_TAG, format.format(pObject));
}
}
| Java |
/*
* 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.xmlrpc.serializer;
import java.io.OutputStream;
import java.io.StringWriter;
import org.apache.ws.commons.serialize.CharSetXMLWriter;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.common.XmlRpcStreamConfig;
import org.xml.sax.ContentHandler;
import org.xml.sax.helpers.AttributesImpl;
/** The default implementation of {@link org.apache.xmlrpc.serializer.XmlWriterFactory}
* tests, whether the {@link org.apache.xmlrpc.serializer.CharSetXmlWriterFactory}
* is usable. This is the case, when running in Java 1.4 or later. If so,
* this factory is used. Otherwise, the
* {@link org.apache.xmlrpc.serializer.BaseXmlWriterFactory} is used as a
* fallback.
*/
public class DefaultXMLWriterFactory implements XmlWriterFactory {
private final XmlWriterFactory factory;
/** Creates a new instance.
*/
public DefaultXMLWriterFactory() {
XmlWriterFactory xwf;
try {
CharSetXMLWriter csw = new CharSetXMLWriter();
StringWriter sw = new StringWriter();
csw.setWriter(sw);
csw.startDocument();
csw.startElement("", "test", "test", new AttributesImpl());
csw.endElement("", "test", "test");
csw.endDocument();
xwf = new CharSetXmlWriterFactory();
} catch (Throwable t) {
xwf = new BaseXmlWriterFactory();
}
factory = xwf;
}
public ContentHandler getXmlWriter(XmlRpcStreamConfig pConfig,
OutputStream pStream) throws XmlRpcException {
return factory.getXmlWriter(pConfig, pStream);
}
}
| Java |
/*
* 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.xmlrpc.serializer;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import org.apache.ws.commons.util.Base64;
import org.apache.ws.commons.util.Base64.Encoder;
import org.apache.ws.commons.util.Base64.EncoderOutputStream;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
/** A {@link org.apache.xmlrpc.serializer.TypeSerializer} for
* instances of {@link java.io.Serializable}.
*/
public class SerializableSerializer extends TypeSerializerImpl {
/** Tag name of a base64 value.
*/
public static final String SERIALIZABLE_TAG = "serializable";
private static final String EX_SERIALIZABLE_TAG = "ex:" + SERIALIZABLE_TAG;
public void write(final ContentHandler pHandler, Object pObject) throws SAXException {
pHandler.startElement("", VALUE_TAG, VALUE_TAG, ZERO_ATTRIBUTES);
pHandler.startElement("", SERIALIZABLE_TAG, EX_SERIALIZABLE_TAG, ZERO_ATTRIBUTES);
char[] buffer = new char[1024];
Encoder encoder = new Base64.SAXEncoder(buffer, 0, null, pHandler);
try {
OutputStream ostream = new EncoderOutputStream(encoder);
ObjectOutputStream oos = new ObjectOutputStream(ostream);
oos.writeObject(pObject);
oos.close();
} catch (Base64.SAXIOException e) {
throw e.getSAXException();
} catch (IOException e) {
throw new SAXException(e);
}
pHandler.endElement("", SERIALIZABLE_TAG, EX_SERIALIZABLE_TAG);
pHandler.endElement("", VALUE_TAG, VALUE_TAG);
}
}
| Java |
/*
* 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.xmlrpc;
/** Interface of a request configuration. Depending on
* the transport, implementations will also implement
* additional interfaces like
* {@link org.apache.xmlrpc.common.XmlRpcStreamRequestConfig}.
*/
public interface XmlRpcRequestConfig extends XmlRpcConfig {
}
| Java |
/*
* 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.xmlrpc;
/** The XML-RPC server uses this interface to call a method of an RPC handler.
*/
public interface XmlRpcHandler {
/** Performs the request and returns the result object.
* @param pRequest The request being performed (method name and
* parameters.)
* @return The result object.
* @throws XmlRpcException Performing the request failed.
*/
public Object execute(XmlRpcRequest pRequest) throws XmlRpcException;
}
| Java |
/*
* 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.xmlrpc;
import java.util.TimeZone;
import org.apache.xmlrpc.common.XmlRpcHttpConfig;
/** Default implementation of {@link org.apache.xmlrpc.XmlRpcConfig}.
*/
public abstract class XmlRpcConfigImpl implements XmlRpcConfig, XmlRpcHttpConfig {
private boolean enabledForExtensions;
private boolean contentLengthOptional;
private String basicEncoding;
private String encoding;
private TimeZone timeZone = TimeZone.getDefault();
public boolean isEnabledForExtensions() { return enabledForExtensions; }
/** Sets, whether extensions are enabled. By default, the
* client or server is strictly compliant to the XML-RPC
* specification and extensions are disabled.
* @param pExtensions True to enable extensions, false otherwise.
*/
public void setEnabledForExtensions(boolean pExtensions) {
enabledForExtensions = pExtensions;
}
/** Sets the encoding for basic authentication.
* @param pEncoding The encoding; may be null, in which case
* UTF-8 is choosen.
*/
public void setBasicEncoding(String pEncoding) {
basicEncoding = pEncoding;
}
public String getBasicEncoding() { return basicEncoding; }
/** Sets the requests encoding.
* @param pEncoding The requests encoding or null (default
* UTF-8).
*/
public void setEncoding(String pEncoding) {
encoding = pEncoding;
}
public String getEncoding() { return encoding; }
public boolean isContentLengthOptional() {
return contentLengthOptional;
}
/** Sets, whether a "Content-Length" header may be
* omitted. The XML-RPC specification demands, that such
* a header be present.
* @param pContentLengthOptional True, if the content length may be omitted.
*/
public void setContentLengthOptional(boolean pContentLengthOptional) {
contentLengthOptional = pContentLengthOptional;
}
public TimeZone getTimeZone() {
return timeZone;
}
/** Returns the timezone, which is used to interpret date/time
* values. Defaults to {@link TimeZone#getDefault()}.
*/
public void setTimeZone(TimeZone pTimeZone) {
timeZone = pTimeZone;
}
}
| Java |
/*
* 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.xmlrpc.jaxb;
import javax.xml.bind.Element;
import javax.xml.bind.JAXBContext;
import org.apache.ws.commons.util.NamespaceContextImpl;
import org.apache.xmlrpc.common.TypeFactoryImpl;
import org.apache.xmlrpc.common.XmlRpcController;
import org.apache.xmlrpc.common.XmlRpcStreamConfig;
import org.apache.xmlrpc.parser.TypeParser;
import org.apache.xmlrpc.serializer.TypeSerializer;
import org.apache.xmlrpc.serializer.XmlRpcWriter;
import org.xml.sax.SAXException;
/** A type factory with support for JAXB objects.
*/
public class JaxbTypeFactory extends TypeFactoryImpl {
private final JAXBContext context;
private final JaxbSerializer serializer;
/** Creates a new instance with the given controller and
* JAXB context.
* @param pController The controller, which will invoke the factory.
* @param pContext The context being used to create marshallers
* and unmarshallers.
*/
public JaxbTypeFactory(XmlRpcController pController, JAXBContext pContext) {
super(pController);
context = pContext;
serializer = new JaxbSerializer(context);
}
public TypeParser getParser(XmlRpcStreamConfig pConfig, NamespaceContextImpl pContext, String pURI, String pLocalName) {
TypeParser tp = super.getParser(pConfig, pContext, pURI, pLocalName);
if (tp == null) {
if (XmlRpcWriter.EXTENSIONS_URI.equals(pURI) && JaxbSerializer.JAXB_TAG.equals(pLocalName)) {
return new JaxbParser(context);
}
}
return tp;
}
public TypeSerializer getSerializer(XmlRpcStreamConfig pConfig, Object pObject) throws SAXException {
TypeSerializer ts = super.getSerializer(pConfig, pObject);
if (ts == null) {
if (pObject instanceof Element) {
return serializer;
}
}
return ts;
}
}
| Java |
/*
* 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.xmlrpc.jaxb;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.UnmarshallerHandler;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.parser.ExtParser;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
/** A parser for JAXB objects.
*/
public class JaxbParser extends ExtParser {
private final JAXBContext context;
private UnmarshallerHandler handler;
/** Creates a new instance with the given context.
* @param pContext The context being used for creating unmarshallers.
*/
public JaxbParser(JAXBContext pContext) {
context = pContext;
}
protected ContentHandler getExtHandler() throws SAXException {
try {
handler = context.createUnmarshaller().getUnmarshallerHandler();
} catch (JAXBException e) {
throw new SAXException(e);
}
return handler;
}
protected String getTagName() { return JaxbSerializer.JAXB_TAG; }
public Object getResult() throws XmlRpcException {
try {
return handler.getResult();
} catch (JAXBException e) {
throw new XmlRpcException("Failed to create result object: " + e.getMessage(), e);
}
}
}
| Java |
/*
* 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.xmlrpc.jaxb;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import org.apache.xmlrpc.serializer.ExtSerializer;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
/** A serializer for JAXB objects.
*/
public class JaxbSerializer extends ExtSerializer {
private final JAXBContext context;
/** The tag name for serializing JAXB objects.
*/
public static final String JAXB_TAG = "jaxb";
/** Creates a new instance with the given context.
* @param pContext The context being used for creating marshallers.
*/
public JaxbSerializer(JAXBContext pContext) {
context = pContext;
}
protected String getTagName() { return JAXB_TAG; }
protected void serialize(final ContentHandler pHandler, Object pObject) throws SAXException {
/* We must ensure, that startDocument() and endDocument() events
* are suppressed. So we replace the content handler with the following:
*/
ContentHandler h = new ContentHandler() {
public void endDocument() throws SAXException {}
public void startDocument() throws SAXException {}
public void characters(char[] pChars, int pOffset, int pLength) throws SAXException {
pHandler.characters(pChars, pOffset, pLength);
}
public void ignorableWhitespace(char[] pChars, int pOffset, int pLength) throws SAXException {
pHandler.ignorableWhitespace(pChars, pOffset, pLength);
}
public void endPrefixMapping(String pPrefix) throws SAXException {
pHandler.endPrefixMapping(pPrefix);
}
public void skippedEntity(String pName) throws SAXException {
pHandler.endPrefixMapping(pName);
}
public void setDocumentLocator(Locator pLocator) {
pHandler.setDocumentLocator(pLocator);
}
public void processingInstruction(String pTarget, String pData) throws SAXException {
pHandler.processingInstruction(pTarget, pData);
}
public void startPrefixMapping(String pPrefix, String pURI) throws SAXException {
pHandler.startPrefixMapping(pPrefix, pURI);
}
public void endElement(String pURI, String pLocalName, String pQName) throws SAXException {
pHandler.endElement(pURI, pLocalName, pQName);
}
public void startElement(String pURI, String pLocalName, String pQName, Attributes pAttrs) throws SAXException {
pHandler.startElement(pURI, pLocalName, pQName, pAttrs);
}
};
try {
context.createMarshaller().marshal(pObject, h);
} catch (JAXBException e) {
Throwable t = e.getLinkedException();
if (t != null && t instanceof SAXException) {
throw (SAXException) t;
} else {
throw new SAXException(e);
}
}
}
}
| Java |
/*
* 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.xmlrpc;
/** Interface to an XML-RPC request made by a client. Replaces the
* class <code>org.apache.xmlrpc.XmlRpcClientRequest</code> from
* Apache XML-RPC 2.0.
* @since 3.0
*/
public interface XmlRpcRequest {
/** Returns the request configuration.
* @return The request configuration.
*/
XmlRpcRequestConfig getConfig();
/** Returns the requests method name.
* @return Name of the method being invoked.
*/
String getMethodName();
/** Returns the number of parameters.
* @return Number of parameters.
*/
int getParameterCount();
/** Returns the parameter with index <code>pIndex</code>.
* @param pIndex Number between 0 and {@link #getParameterCount()}-1.
* @return Parameter being sent to the server.
*/
public Object getParameter(int pIndex);
}
| Java |
/*
* 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.xmlrpc.util;
import java.io.InputStream;
import java.io.IOException;
/** A filtering {@link java.io.InputStream} for proper handling of
* the <code>Content-Length</code> header: It guarantees to return
* at most a given number of bytes.
*/
public class LimitedInputStream extends InputStream {
// bytes remaining to be read from the input stream. This is
// initialized from CONTENT_LENGTH (or getContentLength()).
// This is used in order to correctly return a -1 when all the
// data POSTed was read. If this is left to -1, content length is
// assumed as unknown and the standard InputStream methods will be used
private long available;
private long markedAvailable;
private InputStream in;
/** Creates a new instance, reading from the given input stream
* and returning at most the given number of bytes.
* @param pIn Input stream being read.
* @param pAvailable Number of bytes available in <code>pIn</code>.
*/
public LimitedInputStream(InputStream pIn, int pAvailable) {
in = pIn;
available = pAvailable;
}
public int read() throws IOException {
if (available > 0) {
available--;
return in.read();
}
return -1;
}
public int read(byte b[], int off, int len) throws IOException {
if (available > 0) {
if (len > available) {
// shrink len
len = (int) available;
}
int read = in.read(b, off, len);
if (read == -1) {
available = 0;
} else {
available -= read;
}
return read;
}
return -1;
}
public long skip(long n) throws IOException {
long skip = in.skip(n);
if (available > 0) {
available -= skip;
}
return skip;
}
public void mark(int readlimit) {
in.mark(readlimit);
markedAvailable = available;
}
public void reset() throws IOException {
in.reset();
available = markedAvailable;
}
public boolean markSupported() {
return true;
}
}
| Java |
/*
* 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.xmlrpc.util;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
/** A utility class for using reflection.
*/
public class ReflectionUtil {
/**
* This method attempts to set a property value on a given object by calling a
* matching setter.
* @param pObject The object, on which a property is being set.
* @param pPropertyName The property name.
* @param pPropertyValue The property value.
* @throws IllegalAccessException Setting the property value failed, because invoking
* the setter raised an {@link IllegalAccessException}.
* @throws InvocationTargetException Setting the property value failed, because invoking
* the setter raised another exception.
* @return Whether a matching setter was found. The value false indicates, that no such
* setter exists.
*/
public static boolean setProperty(Object pObject, String pPropertyName, String pPropertyValue)
throws IllegalAccessException, InvocationTargetException {
final String methodName = "set" + pPropertyName.substring(0, 1).toUpperCase() + pPropertyName.substring(1);
// try to find method signature that matches init param
Method[] methods = pObject.getClass().getMethods();
for (int i = 0; i < methods.length; i++) {
final Method method = methods[i];
if (!method.getName().equals(methodName)) {
continue; // Ignore methods, which does have the right name
}
if (!Modifier.isPublic(method.getModifiers())) {
continue; // Ignore methods, which aren't public
}
Class[] parameterTypes = method.getParameterTypes();
if (parameterTypes.length != 1) {
continue; // Ignore methods, which don't not have exactly one parameter
}
Class parameterType = parameterTypes[0];
final Object param;
try {
if (parameterType.equals(boolean.class) || parameterType.equals(Boolean.class)) {
param = Boolean.valueOf(pPropertyValue);
} else if (parameterType.equals(char.class) || parameterType.equals(Character.class)) {
if (pPropertyValue.length() != 1) {
throw new IllegalArgumentException("Invalid value for parameter "
+ pPropertyName + "(length != 1):"
+ pPropertyValue);
}
param = new Character(pPropertyValue.charAt(0));
} else if (parameterType.equals(byte.class) || parameterType.equals(Byte.class)) {
param = Byte.valueOf(pPropertyValue);
} else if (parameterType.equals(short.class) || parameterType.equals(Short.class)) {
param = Short.valueOf(pPropertyValue);
} else if (parameterType.equals(int.class) || parameterType.equals(Integer.class)) {
param = Integer.valueOf(pPropertyValue);
} else if (parameterType.equals(long.class) || parameterType.equals(Long.class)) {
param = Long.valueOf(pPropertyValue);
} else if (parameterType.equals(float.class) || parameterType.equals(Float.class)) {
param = Float.valueOf(pPropertyValue);
} else if (parameterType.equals(double.class) || parameterType.equals(Double.class)) {
param = Double.valueOf(pPropertyValue);
} else if (parameterType.equals(String.class)) {
param = pPropertyValue;
} else {
throw new IllegalStateException("The property " + pPropertyName
+ " has an unsupported type of " + parameterType.getName());
}
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Invalid value for property "
+ pPropertyName + ": " + pPropertyValue);
}
method.invoke(pObject, new Object[]{param});
return true;
}
return false;
}
}
| Java |
/*
* 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.xmlrpc.util;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Enumeration;
import java.util.StringTokenizer;
import org.apache.ws.commons.util.Base64;
import org.apache.xmlrpc.common.XmlRpcHttpRequestConfigImpl;
import org.apache.xmlrpc.common.XmlRpcStreamConfig;
/** Provides utility functions useful in HTTP communications
*/
public class HttpUtil {
/** Creates the Base64 encoded credentials for HTTP Basic Authentication.
* @param pUser User name, or null, if no Basic Authentication is being used.
* @param pPassword Users password, or null, if no Basic Authentication is being used.
* @param pEncoding Encoding being used for conversion of the credential string into a byte array.
* @return Base64 encoded credentials, for use in the HTTP header
* @throws UnsupportedEncodingException The encoding <code>pEncoding</code> is invalid.
*/
public static String encodeBasicAuthentication(String pUser, String pPassword, String pEncoding) throws UnsupportedEncodingException {
if (pUser == null) {
return null;
}
final String s = pUser + ':' + pPassword;
if (pEncoding == null) {
pEncoding = XmlRpcStreamConfig.UTF8_ENCODING;
}
final byte[] bytes = s.getBytes(pEncoding);
return Base64.encode(s.getBytes(pEncoding), 0, bytes.length, 0, null);
}
/** Returns, whether the HTTP header value <code>pHeaderValue</code>
* indicates, that GZIP encoding is used or may be used.
* @param pHeaderValue The HTTP header value being parsed. This is typically
* the value of "Content-Encoding", or "Accept-Encoding".
* @return True, if the header value suggests that GZIP encoding is or may
* be used.
*/
public static boolean isUsingGzipEncoding(String pHeaderValue) {
if (pHeaderValue == null) {
return false;
}
for (StringTokenizer st = new StringTokenizer(pHeaderValue, ","); st.hasMoreTokens(); ) {
String encoding = st.nextToken();
int offset = encoding.indexOf(';');
if (offset >= 0) {
encoding = encoding.substring(0, offset);
}
if ("gzip".equalsIgnoreCase(encoding.trim())) {
return true;
}
}
return false;
}
/**
* Returns, whether the HTTP header value <code>pHeaderValue</code>
* indicates, that another encoding than "identity" is used.
* This is typically the value of "Transfer-Encoding", or "TE".
* @return Null, if the transfer encoding in use is "identity".
* Otherwise, another transfer encoding.
*/
public static String getNonIdentityTransferEncoding(String pHeaderValue) {
if (pHeaderValue == null) {
return null;
}
for (StringTokenizer st = new StringTokenizer(pHeaderValue, ","); st.hasMoreTokens(); ) {
String encoding = st.nextToken();
int offset = encoding.indexOf(';');
if (offset >= 0) {
encoding = encoding.substring(0, offset);
}
if (!"identity".equalsIgnoreCase(encoding.trim())) {
return encoding.trim();
}
}
return null;
}
/** Returns, whether the HTTP header values in <code>pValues</code>
* indicate, that GZIP encoding is used or may be used.
* @param pValues The HTTP header values being parsed. These are typically
* the values of "Content-Encoding", or "Accept-Encoding".
* @return True, if the header values suggests that GZIP encoding is or may
* be used.
*/
public static boolean isUsingGzipEncoding(Enumeration pValues) {
if (pValues != null) {
while (pValues.hasMoreElements()) {
if (isUsingGzipEncoding((String) pValues.nextElement())) {
return true;
}
}
}
return false;
}
/** Reads a header line from the input stream <code>pIn</code>
* and converts it into a string.
* @param pIn The input stream being read.
* @param pBuffer A buffer being used for temporary storage.
* The buffers length is a limit of the header lines length.
* @return Next header line or null, if no more header lines
* are available.
* @throws IOException Reading the header line failed.
*/
public static String readLine(InputStream pIn, byte[] pBuffer) throws IOException {
int next;
int count = 0;
while (true) {
next = pIn.read();
if (next < 0 || next == '\n') {
break;
}
if (next != '\r') {
pBuffer[count++] = (byte) next;
}
if (count >= pBuffer.length) {
throw new IOException ("HTTP Header too long");
}
}
return new String(pBuffer, 0, count, "US-ASCII");
}
/** Parses an "Authorization" header and adds the username and password
* to <code>pConfig</code>.
* @param pConfig The request configuration being created.
* @param pLine The header being parsed, including the "basic" part.
*/
public static void parseAuthorization(XmlRpcHttpRequestConfigImpl pConfig, String pLine) {
if (pLine == null) {
return;
}
pLine = pLine.trim();
StringTokenizer st = new StringTokenizer(pLine);
if (!st.hasMoreTokens()) {
return;
}
String type = st.nextToken();
if (!"basic".equalsIgnoreCase(type)) {
return;
}
if (!st.hasMoreTokens()) {
return;
}
String auth = st.nextToken();
try {
byte[] c = Base64.decode(auth.toCharArray(), 0, auth.length());
String enc = pConfig.getBasicEncoding();
if (enc == null) {
enc = XmlRpcStreamConfig.UTF8_ENCODING;
}
String str = new String(c, enc);
int col = str.indexOf(':');
if (col >= 0) {
pConfig.setBasicUserName(str.substring(0, col));
pConfig.setBasicPassword(str.substring(col+1));
}
} catch (Throwable ignore) {
}
}
}
| Java |
/*
* 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.xmlrpc.util;
import java.text.FieldPosition;
import java.text.Format;
import java.text.ParsePosition;
import java.util.Calendar;
import java.util.TimeZone;
/** <p>An instance of {@link java.text.Format}, which may be used
* to parse and format <code>dateTime</code> values, as specified
* by the XML-RPC specification. The specification doesn't precisely
* describe the format, it only gives an example:</p>
* <pre>
* 19980717T14:08:55
* </pre>
* This class accepts and creates instances of {@link Calendar}.
*/
public abstract class XmlRpcDateTimeFormat extends Format {
private static final long serialVersionUID = -8008230377361175138L;
/** Returns the time zone, which is used to interpret date/time
* values.
*/
protected abstract TimeZone getTimeZone();
private int parseInt(String pString, int pOffset, StringBuffer pDigits, int pMaxDigits) {
int length = pString.length();
pDigits.setLength(0);
while (pMaxDigits-- > 0 && pOffset < length) {
char c = pString.charAt(pOffset);
if (Character.isDigit(c)) {
pDigits.append(c);
++pOffset;
} else {
break;
}
}
return pOffset;
}
public Object parseObject(String pString, ParsePosition pParsePosition) {
if (pString == null) {
throw new NullPointerException("The String argument must not be null.");
}
if (pParsePosition == null) {
throw new NullPointerException("The ParsePosition argument must not be null.");
}
int offset = pParsePosition.getIndex();
int length = pString.length();
StringBuffer digits = new StringBuffer();
int year, month, mday;
offset = parseInt(pString, offset, digits, 4);
if (digits.length() < 4) {
pParsePosition.setErrorIndex(offset);
return null;
}
year = Integer.parseInt(digits.toString());
offset = parseInt(pString, offset, digits, 2);
if (digits.length() != 2) {
pParsePosition.setErrorIndex(offset);
return null;
}
month = Integer.parseInt(digits.toString());
offset = parseInt(pString, offset, digits, 2);
if (digits.length() != 2) {
pParsePosition.setErrorIndex(offset);
return null;
}
mday = Integer.parseInt(digits.toString());
if (offset < length && pString.charAt(offset) == 'T') {
++offset;
} else {
pParsePosition.setErrorIndex(offset);
return null;
}
int hour, minute, second;
offset = parseInt(pString, offset, digits, 2);
if (digits.length() != 2) {
pParsePosition.setErrorIndex(offset);
return null;
}
hour = Integer.parseInt(digits.toString());
if (offset < length && pString.charAt(offset) == ':') {
++offset;
} else {
pParsePosition.setErrorIndex(offset);
return null;
}
offset = parseInt(pString, offset, digits, 2);
if (digits.length() != 2) {
pParsePosition.setErrorIndex(offset);
return null;
}
minute = Integer.parseInt(digits.toString());
if (offset < length && pString.charAt(offset) == ':') {
++offset;
} else {
pParsePosition.setErrorIndex(offset);
return null;
}
offset = parseInt(pString, offset, digits, 2);
if (digits.length() != 2) {
pParsePosition.setErrorIndex(offset);
return null;
}
second = Integer.parseInt(digits.toString());
Calendar cal = Calendar.getInstance(getTimeZone());
cal.set(year, month-1, mday, hour, minute, second);
cal.set(Calendar.MILLISECOND, 0);
pParsePosition.setIndex(offset);
return cal;
}
private void append(StringBuffer pBuffer, int pNum, int pMinLen) {
String s = Integer.toString(pNum);
for (int i = s.length(); i < pMinLen; i++) {
pBuffer.append('0');
}
pBuffer.append(s);
}
public StringBuffer format(Object pCalendar, StringBuffer pBuffer, FieldPosition pPos) {
if (pCalendar == null) {
throw new NullPointerException("The Calendar argument must not be null.");
}
if (pBuffer == null) {
throw new NullPointerException("The StringBuffer argument must not be null.");
}
if (pPos == null) {
throw new NullPointerException("The FieldPosition argument must not be null.");
}
Calendar cal = (Calendar) pCalendar;
int year = cal.get(Calendar.YEAR);
append(pBuffer, year, 4);
append(pBuffer, cal.get(Calendar.MONTH)+1, 2);
append(pBuffer, cal.get(Calendar.DAY_OF_MONTH), 2);
pBuffer.append('T');
append(pBuffer, cal.get(Calendar.HOUR_OF_DAY), 2);
pBuffer.append(':');
append(pBuffer, cal.get(Calendar.MINUTE), 2);
pBuffer.append(':');
append(pBuffer, cal.get(Calendar.SECOND), 2);
return pBuffer;
}
}
| Java |
/*
* 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.xmlrpc.util;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;
import org.apache.xmlrpc.XmlRpcException;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
/** Utility class for working with SAX parsers.
*/
public class SAXParsers {
private static SAXParserFactory spf;
static {
spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
spf.setValidating(false);
}
/** Creates a new instance of {@link XMLReader}.
*/
public static XMLReader newXMLReader() throws XmlRpcException {
try {
return spf.newSAXParser().getXMLReader();
} catch (ParserConfigurationException e) {
throw new XmlRpcException("Unable to create XML parser: " + e.getMessage(), e);
} catch (SAXException e) {
throw new XmlRpcException("Unable to create XML parser: " + e.getMessage(), e);
}
}
/**
* Returns the SAX parser factory, which is used by Apache XML-RPC. You may
* use this to configure the factory.
*/
public static SAXParserFactory getSAXParserFactory() {
return spf;
}
/**
* Sets the SAX parser factory, which is used by Apache XML-RPC. You may use
* this to configure another instance than the default.
*/
public static void setSAXParserFactory(SAXParserFactory pFactory) {
spf = pFactory;
}
}
| Java |
/*
* 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.xmlrpc.util;
import java.util.ArrayList;
import java.util.List;
/** Simple thread pool. A task is executed by obtaining a thread from
* the pool
*/
public class ThreadPool {
/** The thread pool contains instances of {@link ThreadPool.Task}.
*/
public interface Task {
/** Performs the task.
* @throws Throwable The task failed, and the worker thread won't be used again.
*/
void run() throws Throwable;
}
/** A task, which may be interrupted, if the pool is shutting down.
*/
public interface InterruptableTask extends Task {
/** Interrupts the task.
* @throws Throwable Shutting down the task failed.
*/
void shutdown() throws Throwable;
}
private class Poolable {
private volatile boolean shuttingDown;
private Task task;
private Thread thread;
Poolable(ThreadGroup pGroup, int pNum) {
thread = new Thread(pGroup, pGroup.getName() + "-" + pNum){
public void run() {
while (!shuttingDown) {
final Task t = getTask();
if (t == null) {
try {
synchronized (this) {
if (!shuttingDown && getTask() == null) {
wait();
}
}
} catch (InterruptedException e) {
// Do nothing
}
} else {
try {
t.run();
resetTask();
repool(Poolable.this);
} catch (Throwable e) {
remove(Poolable.this);
Poolable.this.shutdown();
resetTask();
}
}
}
}
};
thread.start();
}
synchronized void shutdown() {
shuttingDown = true;
final Task t = getTask();
if (t != null && t instanceof InterruptableTask) {
try {
((InterruptableTask) t).shutdown();
} catch (Throwable th) {
// Ignore me
}
}
task = null;
synchronized (thread) {
thread.notify();
}
}
private Task getTask() {
return task;
}
private void resetTask() {
task = null;
}
void start(Task pTask) {
task = pTask;
synchronized (thread) {
thread.notify();
}
}
}
private final ThreadGroup threadGroup;
private final int maxSize;
private final List waitingThreads = new ArrayList();
private final List runningThreads = new ArrayList();
private final List waitingTasks = new ArrayList();
private int num;
/** Creates a new instance.
* @param pMaxSize Maximum number of concurrent threads.
* @param pName Thread group name.
*/
public ThreadPool(int pMaxSize, String pName) {
maxSize = pMaxSize;
threadGroup = new ThreadGroup(pName);
}
private synchronized void remove(Poolable pPoolable) {
runningThreads.remove(pPoolable);
waitingThreads.remove(pPoolable);
}
void repool(Poolable pPoolable) {
boolean discarding = false;
Task task = null;
Poolable poolable = null;
synchronized (this) {
if (runningThreads.remove(pPoolable)) {
if (maxSize != 0 && runningThreads.size() + waitingThreads.size() >= maxSize) {
discarding = true;
} else {
waitingThreads.add(pPoolable);
if (waitingTasks.size() > 0) {
task = (Task) waitingTasks.remove(waitingTasks.size() - 1);
poolable = getPoolable(task, false);
}
}
} else {
discarding = true;
}
if (discarding) {
remove(pPoolable);
}
}
if (poolable != null) {
poolable.start(task);
}
if (discarding) {
pPoolable.shutdown();
}
}
/** Starts a task immediately.
* @param pTask The task being started.
* @return True, if the task could be started immediately. False, if
* the maxmimum number of concurrent tasks was exceeded. If so, you
* might consider to use the {@link #addTask(ThreadPool.Task)} method instead.
*/
public boolean startTask(Task pTask) {
final Poolable poolable = getPoolable(pTask, false);
if (poolable == null) {
return false;
}
poolable.start(pTask);
return true;
}
private synchronized Poolable getPoolable(Task pTask, boolean pQueue) {
if (maxSize != 0 && runningThreads.size() >= maxSize) {
if (pQueue) {
waitingTasks.add(pTask);
}
return null;
}
Poolable poolable;
if (waitingThreads.size() > 0) {
poolable = (Poolable) waitingThreads.remove(waitingThreads.size()-1);
} else {
poolable = new Poolable(threadGroup, num++);
}
runningThreads.add(poolable);
return poolable;
}
/** Adds a task for immediate or deferred execution.
* @param pTask The task being added.
* @return True, if the task was started immediately. False, if
* the task will be executed later.
* @deprecated No longer in use.
*/
public boolean addTask(Task pTask) {
final Poolable poolable = getPoolable(pTask, true);
if (poolable != null) {
poolable.start(pTask);
return true;
}
return false;
}
/** Closes the pool.
*/
public synchronized void shutdown() {
while (!waitingThreads.isEmpty()) {
Poolable poolable = (Poolable) waitingThreads.remove(waitingThreads.size()-1);
poolable.shutdown();
}
while (!runningThreads.isEmpty()) {
Poolable poolable = (Poolable) runningThreads.remove(runningThreads.size()-1);
poolable.shutdown();
}
}
/** Returns the maximum number of concurrent threads.
* @return Maximum number of threads.
*/
public int getMaxThreads() { return maxSize; }
/** Returns the number of threads, which have actually been created,
* as opposed to the number of currently running threads.
*/
public synchronized int getNumThreads() { return num; }
}
| Java |
/*
* 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.xmlrpc.util;
import java.io.IOException;
/** This is a subclass of {@link IOException}, which
* allows to attach a linked exception. Throwing this
* particular instance of {@link IOException} allows
* to catch it and throw the linked exception instead.
*/
public class XmlRpcIOException extends IOException {
private static final long serialVersionUID = -7704704099502077919L;
private final Throwable linkedException;
/** Creates a new instance of {@link XmlRpcIOException}
* with the given cause.
*/
public XmlRpcIOException(Throwable t) {
super(t.getMessage());
linkedException = t;
}
/** Returns the linked exception, which is the actual
* cause for this exception.
*/
public Throwable getLinkedException() {
return linkedException;
}
}
| Java |
/*
* 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.xmlrpc.util;
import java.text.FieldPosition;
import java.text.ParsePosition;
import java.util.Calendar;
import java.util.Date;
/** An extension of {@link XmlRpcDateTimeFormat}, which accepts
* and/or creates instances of {@link Date}.
*/
public abstract class XmlRpcDateTimeDateFormat extends XmlRpcDateTimeFormat {
private static final long serialVersionUID = -5107387618606150784L;
public StringBuffer format(Object pCalendar, StringBuffer pBuffer, FieldPosition pPos) {
final Object cal;
if (pCalendar != null && pCalendar instanceof Date) {
Calendar calendar = Calendar.getInstance(getTimeZone());
calendar.setTime((Date) pCalendar);
cal = calendar;
} else {
cal = pCalendar;
}
return super.format(cal, pBuffer, pPos);
}
public Object parseObject(String pString, ParsePosition pParsePosition) {
Calendar cal = (Calendar) super.parseObject(pString, pParsePosition);
return cal == null ? null : cal.getTime();
}
}
| Java |
/*
* 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.xmlrpc;
import java.util.TimeZone;
/** A common base interface for
* {@link org.apache.xmlrpc.client.XmlRpcClientConfig}, and
* {@link org.apache.xmlrpc.server.XmlRpcServerConfig}.
*/
public interface XmlRpcConfig {
/** Returns, whether support for extensions are enabled.
* By default, extensions are disabled and your client is
* interoperable with other XML-RPC implementations.
* Interoperable XML-RPC implementations are those, which
* are compliant to the
* <a href="http://www.xmlrpc.org/spec">XML-RPC Specification</a>.
* @return Whether extensions are enabled or not.
*/
boolean isEnabledForExtensions();
/** Returns the timezone, which is used to interpret date/time
* values. Defaults to {@link TimeZone#getDefault()}.
*/
TimeZone getTimeZone();
}
| Java |
/*
* 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.xmlrpc.parser;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
/** Parser for short values.
*/
public class I2Parser extends AtomicParser {
protected void setResult(String pResult) throws SAXException {
try {
super.setResult(new Short(pResult.trim()));
} catch (NumberFormatException e) {
throw new SAXParseException("Failed to parse short value: " + pResult,
getDocumentLocator());
}
}
}
| Java |
/*
* 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.xmlrpc.parser;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
/** Parser for boolean values.
*/
public class BooleanParser extends AtomicParser {
protected void setResult(String pResult) throws SAXException {
String s = pResult.trim();
if ("1".equals(s)) {
super.setResult(Boolean.TRUE);
} else if ("0".equals(s)) {
super.setResult(Boolean.FALSE);
} else {
throw new SAXParseException("Failed to parse boolean value: " + pResult,
getDocumentLocator());
}
}
}
| Java |
/*
* 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.xmlrpc.parser;
import javax.xml.namespace.QName;
import org.apache.ws.commons.util.NamespaceContextImpl;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.common.TypeFactory;
import org.apache.xmlrpc.common.XmlRpcExtensionException;
import org.apache.xmlrpc.common.XmlRpcStreamConfig;
import org.apache.xmlrpc.serializer.XmlRpcWriter;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
/** Abstract base class of a parser, that invokes other type
* parsers recursively.
*/
public abstract class RecursiveTypeParserImpl extends TypeParserImpl {
private final NamespaceContextImpl context;
protected final XmlRpcStreamConfig cfg;
private final TypeFactory factory;
private boolean inValueTag;
private TypeParser typeParser;
private StringBuffer text = new StringBuffer();
/** Creates a new instance.
* @param pContext The namespace context.
* @param pConfig The request or response configuration.
* @param pFactory The type factory.
*/
protected RecursiveTypeParserImpl(XmlRpcStreamConfig pConfig,
NamespaceContextImpl pContext,
TypeFactory pFactory) {
cfg = pConfig;
context = pContext;
factory = pFactory;
}
/**
* Called to start a value tag.
* @throws SAXException
*/
protected void startValueTag() throws SAXException {
inValueTag = true;
text.setLength(0);
typeParser = null;
}
protected abstract void addResult(Object pResult) throws SAXException;
protected void endValueTag() throws SAXException {
if (inValueTag) {
if (typeParser == null) {
addResult(text.toString());
text.setLength(0);
} else {
typeParser.endDocument();
try {
addResult(typeParser.getResult());
} catch (XmlRpcException e) {
throw new SAXException(e);
}
typeParser = null;
}
} else {
throw new SAXParseException("Invalid state: Not inside value tag.",
getDocumentLocator());
}
}
public void startDocument() throws SAXException {
inValueTag = false;
text.setLength(0);
typeParser = null;
}
public void endElement(String pURI, String pLocalName, String pQName)
throws SAXException {
if (inValueTag) {
if (typeParser == null) {
throw new SAXParseException("Invalid state: No type parser configured.",
getDocumentLocator());
} else {
typeParser.endElement(pURI, pLocalName, pQName);
}
} else {
throw new SAXParseException("Invalid state: Not inside value tag.",
getDocumentLocator());
}
}
public void startElement(String pURI, String pLocalName,
String pQName, Attributes pAttrs) throws SAXException {
if (inValueTag) {
if (typeParser == null) {
typeParser = factory.getParser(cfg, context, pURI, pLocalName);
if (typeParser == null) {
if (XmlRpcWriter.EXTENSIONS_URI.equals(pURI) && !cfg.isEnabledForExtensions()) {
String msg = "The tag " + new QName(pURI, pLocalName) + " is invalid, if isEnabledForExtensions() == false.";
throw new SAXParseException(msg, getDocumentLocator(),
new XmlRpcExtensionException(msg));
} else {
throw new SAXParseException("Unknown type: " + new QName(pURI, pLocalName),
getDocumentLocator());
}
}
typeParser.setDocumentLocator(getDocumentLocator());
typeParser.startDocument();
if (text.length() > 0) {
typeParser.characters(text.toString().toCharArray(), 0, text.length());
text.setLength(0);
}
}
typeParser.startElement(pURI, pLocalName, pQName, pAttrs);
} else {
throw new SAXParseException("Invalid state: Not inside value tag.",
getDocumentLocator());
}
}
public void characters(char[] pChars, int pOffset, int pLength) throws SAXException {
if (typeParser == null) {
if (inValueTag) {
text.append(pChars, pOffset, pLength);
} else {
super.characters(pChars, pOffset, pLength);
}
} else {
typeParser.characters(pChars, pOffset, pLength);
}
}
public void ignorableWhitespace(char[] pChars, int pOffset, int pLength) throws SAXException {
if (typeParser == null) {
if (inValueTag) {
text.append(pChars, pOffset, pLength);
} else {
super.ignorableWhitespace(pChars, pOffset, pLength);
}
} else {
typeParser.ignorableWhitespace(pChars, pOffset, pLength);
}
}
public void processingInstruction(String pTarget, String pData) throws SAXException {
if (typeParser == null) {
super.processingInstruction(pTarget, pData);
} else {
typeParser.processingInstruction(pTarget, pData);
}
}
public void skippedEntity(String pEntity) throws SAXException {
if (typeParser == null) {
super.skippedEntity(pEntity);
} else {
typeParser.skippedEntity(pEntity);
}
}
public void startPrefixMapping(String pPrefix, String pURI) throws SAXException {
if (typeParser == null) {
super.startPrefixMapping(pPrefix, pURI);
} else {
context.startPrefixMapping(pPrefix, pURI);
}
}
public void endPrefixMapping(String pPrefix) throws SAXException {
if (typeParser == null) {
super.endPrefixMapping(pPrefix);
} else {
context.endPrefixMapping(pPrefix);
}
}
}
| Java |
/*
* 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.xmlrpc.parser;
import java.util.ArrayList;
import java.util.List;
import javax.xml.namespace.QName;
import org.apache.ws.commons.util.NamespaceContextImpl;
import org.apache.xmlrpc.common.TypeFactory;
import org.apache.xmlrpc.common.XmlRpcStreamConfig;
import org.apache.xmlrpc.serializer.ObjectArraySerializer;
import org.apache.xmlrpc.serializer.TypeSerializerImpl;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
/** Parser for an array of objects, as created by
* {@link org.apache.xmlrpc.serializer.ObjectArraySerializer}.
*/
public class ObjectArrayParser extends RecursiveTypeParserImpl {
private int level = 0;
private List list;
/** Creates a new instance.
* @param pContext The namespace context.
* @param pConfig The request or response configuration.
* @param pFactory The type factory.
*/
public ObjectArrayParser(XmlRpcStreamConfig pConfig,
NamespaceContextImpl pContext,
TypeFactory pFactory) {
super(pConfig, pContext, pFactory);
}
public void startDocument() throws SAXException {
level = 0;
list = new ArrayList();
super.startDocument();
}
protected void addResult(Object pValue) {
list.add(pValue);
}
public void endElement(String pURI, String pLocalName, String pQName) throws SAXException {
switch (--level) {
case 0:
setResult(list.toArray());
break;
case 1:
break;
case 2:
endValueTag();
break;
default:
super.endElement(pURI, pLocalName, pQName);
}
}
public void startElement(String pURI, String pLocalName, String pQName, Attributes pAttrs) throws SAXException {
switch (level++) {
case 0:
if (!"".equals(pURI) || !ObjectArraySerializer.ARRAY_TAG.equals(pLocalName)) {
throw new SAXParseException("Expected array element, got "
+ new QName(pURI, pLocalName),
getDocumentLocator());
}
break;
case 1:
if (!"".equals(pURI) || !ObjectArraySerializer.DATA_TAG.equals(pLocalName)) {
throw new SAXParseException("Expected data element, got "
+ new QName(pURI, pLocalName),
getDocumentLocator());
}
break;
case 2:
if (!"".equals(pURI) || !TypeSerializerImpl.VALUE_TAG.equals(pLocalName)) {
throw new SAXParseException("Expected data element, got "
+ new QName(pURI, pLocalName),
getDocumentLocator());
}
startValueTag();
break;
default:
super.startElement(pURI, pLocalName, pQName, pAttrs);
break;
}
}
}
| Java |
/*
* 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.xmlrpc.parser;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
/** SAX parser for a nil element (null value).
*/
public class NullParser extends AtomicParser {
protected void setResult(String pResult) throws SAXException {
if (pResult == null || "".equals(pResult.trim())) {
super.setResult((Object) null);
} else {
throw new SAXParseException("Unexpected characters in nil element.",
getDocumentLocator());
}
}
}
| Java |
/*
* 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.xmlrpc.parser;
import java.io.ByteArrayInputStream;
import java.io.ObjectInputStream;
import java.util.Map;
import javax.xml.namespace.QName;
import org.apache.ws.commons.util.NamespaceContextImpl;
import org.apache.xmlrpc.common.TypeFactory;
import org.apache.xmlrpc.common.XmlRpcStreamRequestConfig;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
/** A SAX parser for an {@link org.apache.xmlrpc.server.XmlRpcServer}'s
* response.
*/
public class XmlRpcResponseParser extends RecursiveTypeParserImpl {
private int level;
private boolean isSuccess;
private int errorCode;
private String errorMessage;
private Throwable errorCause;
/** Creates a new instance.
* @param pConfig The response configuration.
* @param pTypeFactory The type factory for creating instances of
* {@link TypeParser}.
*/
public XmlRpcResponseParser(XmlRpcStreamRequestConfig pConfig,
TypeFactory pTypeFactory) {
super(pConfig, new NamespaceContextImpl(), pTypeFactory);
}
protected void addResult(Object pResult) throws SAXException {
if (isSuccess) {
super.setResult(pResult);
} else {
Map map = (Map) pResult;
Integer faultCode = (Integer) map.get("faultCode");
if (faultCode == null) {
throw new SAXParseException("Missing faultCode", getDocumentLocator());
}
try {
errorCode = faultCode.intValue();
} catch (NumberFormatException e) {
throw new SAXParseException("Invalid faultCode: " + faultCode,
getDocumentLocator());
}
errorMessage = (String) map.get("faultString");
Object exception = map.get("faultCause");
if (exception != null) {
try {
byte[] bytes = (byte[]) exception;
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bais);
errorCause = (Throwable) ois.readObject();
ois.close();
bais.close();
} catch (Throwable t) {
// Ignore me
}
}
}
}
public void startDocument() throws SAXException {
super.startDocument();
level = 0;
isSuccess = false;
errorCode = 0;
errorMessage = null;
}
public void startElement(String pURI, String pLocalName, String pQName,
Attributes pAttrs) throws SAXException {
switch (level++) {
case 0:
if (!"".equals(pURI) || !"methodResponse".equals(pLocalName)) {
throw new SAXParseException("Expected methodResponse element, got "
+ new QName(pURI, pLocalName),
getDocumentLocator());
}
break;
case 1:
if ("".equals(pURI) && "params".equals(pLocalName)) {
isSuccess = true;
} else if ("".equals(pURI) && "fault".equals(pLocalName)) {
isSuccess = false;
} else {
throw new SAXParseException("Expected params or fault element, got "
+ new QName(pURI, pLocalName),
getDocumentLocator());
}
break;
case 2:
if (isSuccess) {
if (!"".equals(pURI) || !"param".equals(pLocalName)) {
throw new SAXParseException("Expected param element, got "
+ new QName(pURI, pLocalName),
getDocumentLocator());
}
} else {
if ("".equals(pURI) && "value".equals(pLocalName)) {
startValueTag();
} else {
throw new SAXParseException("Expected value element, got "
+ new QName(pURI, pLocalName),
getDocumentLocator());
}
}
break;
case 3:
if (isSuccess) {
if ("".equals(pURI) && "value".equals(pLocalName)) {
startValueTag();
} else {
throw new SAXParseException("Expected value element, got "
+ new QName(pURI, pLocalName),
getDocumentLocator());
}
} else {
super.startElement(pURI, pLocalName, pQName, pAttrs);
}
break;
default:
super.startElement(pURI, pLocalName, pQName, pAttrs);
break;
}
}
public void endElement(String pURI, String pLocalName, String pQName) throws SAXException {
switch (--level) {
case 0:
if (!"".equals(pURI) || !"methodResponse".equals(pLocalName)) {
throw new SAXParseException("Expected /methodResponse element, got "
+ new QName(pURI, pLocalName),
getDocumentLocator());
}
break;
case 1:
{
String tag;
if (isSuccess) {
tag = "params";
} else {
tag = "fault";
}
if (!"".equals(pURI) || !tag.equals(pLocalName)) {
throw new SAXParseException("Expected /" + tag + " element, got "
+ new QName(pURI, pLocalName),
getDocumentLocator());
}
break;
}
case 2:
if (isSuccess) {
if (!"".equals(pURI) || !"param".equals(pLocalName)) {
throw new SAXParseException("Expected /param, got "
+ new QName(pURI, pLocalName),
getDocumentLocator());
}
} else {
if ("".equals(pURI) && "value".equals(pLocalName)) {
endValueTag();
} else {
throw new SAXParseException("Expected /value, got "
+ new QName(pURI, pLocalName),
getDocumentLocator());
}
}
break;
case 3:
if (isSuccess) {
if ("".equals(pURI) && "value".equals(pLocalName)) {
endValueTag();
} else {
throw new SAXParseException("Expected /value, got "
+ new QName(pURI, pLocalName),
getDocumentLocator());
}
} else {
super.endElement(pURI, pLocalName, pQName);
}
break;
default:
super.endElement(pURI, pLocalName, pQName);
break;
}
}
/** Returns whether the response returned success. If so, the
* result object may be fetched using {@link #getResult()}.
* Otherwise, you may use the methods
* {@link #getErrorCode()} and {@link #getErrorMessage()} to
* check for error reasons.
* @return True, if the response indicated success, false otherwise.
*/
public boolean isSuccess() { return isSuccess; }
/** If the response contained a fault, returns the error code.
* @return The numeric error code.
*/
public int getErrorCode() { return errorCode; }
/** If the response contained a fault, returns the error message.
* @return The error message.
*/
public String getErrorMessage() { return errorMessage; }
/** If the response contained a fault, returns the (optional)
* exception.
*/
public Throwable getErrorCause() { return errorCause; }
}
| Java |
/*
* 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.xmlrpc.parser;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.ws.commons.serialize.DOMBuilder;
import org.apache.xmlrpc.serializer.NodeSerializer;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
/** A parser for DOM document.
*/
public class NodeParser extends ExtParser {
private static final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
private final DOMBuilder builder = new DOMBuilder();
protected String getTagName() {
return NodeSerializer.DOM_TAG;
}
protected ContentHandler getExtHandler() throws SAXException {
try {
builder.setTarget(dbf.newDocumentBuilder().newDocument());
} catch (ParserConfigurationException e) {
throw new SAXException(e);
}
return builder;
}
public Object getResult() {
return builder.getTarget();
}
}
| Java |
/*
* 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.xmlrpc.parser;
import javax.xml.namespace.QName;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
/** Abstract base implementation of {@link org.apache.xmlrpc.parser.TypeParser}
* for parsing an atomic value.
*/
public abstract class AtomicParser extends TypeParserImpl {
private int level;
protected StringBuffer sb;
/** Creates a new instance.
*/
protected AtomicParser() {
}
protected abstract void setResult(String pResult) throws SAXException;
public void startDocument() throws SAXException {
level = 0;
}
public void characters(char[] pChars, int pStart, int pLength) throws SAXException {
if (sb == null) {
if (!isEmpty(pChars, pStart, pLength)) {
throw new SAXParseException("Unexpected non-whitespace characters",
getDocumentLocator());
}
} else {
sb.append(pChars, pStart, pLength);
}
}
public void endElement(String pURI, String pLocalName, String pQName) throws SAXException {
if (--level == 0) {
setResult(sb.toString());
} else {
throw new SAXParseException("Unexpected end tag in atomic element: "
+ new QName(pURI, pLocalName),
getDocumentLocator());
}
}
public void startElement(String pURI, String pLocalName, String pQName, Attributes pAttrs) throws SAXException {
if (level++ == 0) {
sb = new StringBuffer();
} else {
throw new SAXParseException("Unexpected start tag in atomic element: "
+ new QName(pURI, pLocalName),
getDocumentLocator());
}
}
}
| Java |
/*
* 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.xmlrpc.parser;
import java.util.ArrayList;
import java.util.List;
import javax.xml.namespace.QName;
import org.apache.xmlrpc.serializer.XmlRpcWriter;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
/** Base class for parsing external XML representations, like DOM,
* or JAXB.
*/
public abstract class ExtParser implements TypeParser {
private Locator locator;
private ContentHandler handler;
private int level = 0;
private final List prefixes = new ArrayList();
/** Returns a content handler for parsing the actual
* contents.
* @return A SAX handler for parsing the XML inside
* the outer ex:foo element.
* @throws SAXException Creating the handler failed.
*/
protected abstract ContentHandler getExtHandler() throws SAXException;
/** Returns the outer node name.
*/
protected abstract String getTagName();
public void endDocument() throws SAXException {
}
public void startDocument() throws SAXException {
}
public void characters(char[] pChars, int pOffset, int pLength)
throws SAXException {
if (handler == null) {
if (!TypeParserImpl.isEmpty(pChars, pOffset, pLength)) {
throw new SAXParseException("Unexpected non-whitespace content: " + new String(pChars, pOffset, pLength),
locator);
}
} else {
handler.characters(pChars, pOffset, pLength);
}
}
public void ignorableWhitespace(char[] pChars, int pOffset, int pLength)
throws SAXException {
if (handler != null) {
ignorableWhitespace(pChars, pOffset, pLength);
}
}
public void endPrefixMapping(String pPrefix) throws SAXException {
if (handler != null) {
handler.endPrefixMapping(pPrefix);
}
}
public void skippedEntity(String pName) throws SAXException {
if (handler == null) {
throw new SAXParseException("Don't know how to handle entity " + pName,
locator);
} else {
handler.skippedEntity(pName);
}
}
public void setDocumentLocator(Locator pLocator) {
locator = pLocator;
if (handler != null) {
handler.setDocumentLocator(pLocator);
}
}
public void processingInstruction(String pTarget, String pData)
throws SAXException {
if (handler != null) {
handler.processingInstruction(pTarget, pData);
}
}
public void startPrefixMapping(String pPrefix, String pURI)
throws SAXException {
if (handler == null) {
prefixes.add(pPrefix);
prefixes.add(pURI);
} else {
handler.startPrefixMapping(pPrefix, pURI);
}
}
public void startElement(String pURI, String pLocalName,
String pQName, Attributes pAttrs) throws SAXException {
switch (level++) {
case 0:
final String tag = getTagName();
if (!XmlRpcWriter.EXTENSIONS_URI.equals(pURI) ||
!tag.equals(pLocalName)) {
throw new SAXParseException("Expected " +
new QName(XmlRpcWriter.EXTENSIONS_URI, tag) +
", got " +
new QName(pURI, pLocalName),
locator);
}
handler = getExtHandler();
handler.startDocument();
for (int i = 0; i < prefixes.size(); i += 2) {
handler.startPrefixMapping((String) prefixes.get(i),
(String) prefixes.get(i+1));
}
break;
default:
handler.startElement(pURI, pLocalName, pQName, pAttrs);
break;
}
}
public void endElement(String pURI, String pLocalName, String pQName)
throws SAXException {
switch (--level) {
case 0:
for (int i = 0; i < prefixes.size(); i += 2) {
handler.endPrefixMapping((String) prefixes.get(i));
}
handler.endDocument();
handler = null;
break;
default:
handler.endElement(pURI, pLocalName, pQName);
break;
}
}
}
| Java |
/*
* 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.xmlrpc.parser;
import org.xml.sax.SAXException;
/** Parser implementation for parsing a string.
*/
public class StringParser extends AtomicParser {
protected void setResult(String pResult) throws SAXException {
super.setResult((Object) pResult);
}
}
| Java |
/*
* 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.xmlrpc.parser;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
/** Parser for double values.
*/
public class DoubleParser extends AtomicParser {
protected void setResult(String pResult) throws SAXException {
try {
super.setResult(new Double(pResult));
} catch (NumberFormatException e) {
throw new SAXParseException("Failed to parse double value: " + pResult,
getDocumentLocator());
}
}
}
| Java |
/*
* 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.xmlrpc.parser;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
/** Parser for byte values.
*/
public class I1Parser extends AtomicParser {
protected void setResult(String pResult) throws SAXException {
try {
super.setResult(new Byte(pResult.trim()));
} catch (NumberFormatException e) {
throw new SAXParseException("Failed to parse byte value: " + pResult,
getDocumentLocator());
}
}
}
| Java |
/*
* 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.xmlrpc.parser;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import org.apache.xmlrpc.XmlRpcException;
/** A parser for serializable objects.
*/
public class SerializableParser extends ByteArrayParser {
public Object getResult() throws XmlRpcException {
try {
byte[] res = (byte[]) super.getResult();
ByteArrayInputStream bais = new ByteArrayInputStream(res);
ObjectInputStream ois = new ObjectInputStream(bais);
return ois.readObject();
} catch (IOException e) {
throw new XmlRpcException("Failed to read result object: " + e.getMessage(), e);
} catch (ClassNotFoundException e) {
throw new XmlRpcException("Failed to load class for result object: " + e.getMessage(), e);
}
}
}
| Java |
/*
* 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.xmlrpc.parser;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
/** Parser for long values.
*/
public class LongParser extends AtomicParser {
protected void setResult(String pResult) throws SAXException {
try {
super.setResult(new Long(pResult.trim()));
} catch (NumberFormatException e) {
throw new SAXParseException("Failed to parse long value: " + pResult,
getDocumentLocator());
}
}
}
| Java |
/*
* 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.xmlrpc.parser;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
/** Parser for integer values.
*/
public class I4Parser extends AtomicParser {
protected void setResult(String pResult) throws SAXException {
try {
super.setResult(new Integer(pResult.trim()));
} catch (NumberFormatException e) {
throw new SAXParseException("Failed to parse integer value: " + pResult,
getDocumentLocator());
}
}
}
| Java |
/*
* 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.xmlrpc.parser;
import java.util.ArrayList;
import java.util.List;
import javax.xml.namespace.QName;
import org.apache.ws.commons.util.NamespaceContextImpl;
import org.apache.xmlrpc.common.TypeFactory;
import org.apache.xmlrpc.common.XmlRpcStreamConfig;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
/** A SAX parser for an {@link org.apache.xmlrpc.client.XmlRpcClient}'s
* request.
*/
public class XmlRpcRequestParser extends RecursiveTypeParserImpl {
private int level;
private boolean inMethodName;
private String methodName;
private List params;
/** Creates a new instance, which parses a clients request.
* @param pConfig The client configuration.
* @param pTypeFactory The type factory.
*/
public XmlRpcRequestParser(XmlRpcStreamConfig pConfig, TypeFactory pTypeFactory) {
super(pConfig, new NamespaceContextImpl(), pTypeFactory);
}
protected void addResult(Object pResult) {
params.add(pResult);
}
public void startDocument() throws SAXException {
super.startDocument();
level = 0;
inMethodName = false;
methodName = null;
params = null;
}
public void characters(char[] pChars, int pOffset, int pLength) throws SAXException {
if (inMethodName) {
String s = new String(pChars, pOffset, pLength);
methodName = methodName == null ? s : methodName + s;
} else {
super.characters(pChars, pOffset, pLength);
}
}
public void startElement(String pURI, String pLocalName, String pQName,
Attributes pAttrs) throws SAXException {
switch (level++) {
case 0:
if (!"".equals(pURI) || !"methodCall".equals(pLocalName)) {
throw new SAXParseException("Expected root element 'methodCall', got "
+ new QName(pURI, pLocalName),
getDocumentLocator());
}
break;
case 1:
if (methodName == null) {
if ("".equals(pURI) && "methodName".equals(pLocalName)) {
inMethodName = true;
} else {
throw new SAXParseException("Expected methodName element, got "
+ new QName(pURI, pLocalName),
getDocumentLocator());
}
} else if (params == null) {
if ("".equals(pURI) && "params".equals(pLocalName)) {
params = new ArrayList();
} else {
throw new SAXParseException("Expected params element, got "
+ new QName(pURI, pLocalName),
getDocumentLocator());
}
} else {
throw new SAXParseException("Expected /methodCall, got "
+ new QName(pURI, pLocalName),
getDocumentLocator());
}
break;
case 2:
if (!"".equals(pURI) || !"param".equals(pLocalName)) {
throw new SAXParseException("Expected param element, got "
+ new QName(pURI, pLocalName),
getDocumentLocator());
}
break;
case 3:
if (!"".equals(pURI) || !"value".equals(pLocalName)) {
throw new SAXParseException("Expected value element, got "
+ new QName(pURI, pLocalName),
getDocumentLocator());
}
startValueTag();
break;
default:
super.startElement(pURI, pLocalName, pQName, pAttrs);
break;
}
}
public void endElement(String pURI, String pLocalName, String pQName) throws SAXException {
switch(--level) {
case 0:
break;
case 1:
if (inMethodName) {
if ("".equals(pURI) && "methodName".equals(pLocalName)) {
if (methodName == null) {
methodName = "";
}
} else {
throw new SAXParseException("Expected /methodName, got "
+ new QName(pURI, pLocalName),
getDocumentLocator());
}
inMethodName = false;
} else if (!"".equals(pURI) || !"params".equals(pLocalName)) {
throw new SAXParseException("Expected /params, got "
+ new QName(pURI, pLocalName),
getDocumentLocator());
}
break;
case 2:
if (!"".equals(pURI) || !"param".equals(pLocalName)) {
throw new SAXParseException("Expected /param, got "
+ new QName(pURI, pLocalName),
getDocumentLocator());
}
break;
case 3:
if (!"".equals(pURI) || !"value".equals(pLocalName)) {
throw new SAXParseException("Expected /value, got "
+ new QName(pURI, pLocalName),
getDocumentLocator());
}
endValueTag();
break;
default:
super.endElement(pURI, pLocalName, pQName);
break;
}
}
/** Returns the method name being invoked.
* @return Requested method name.
*/
public String getMethodName() { return methodName; }
/** Returns the parameter list.
* @return Parameter list.
*/
public List getParams() { return params; }
}
| Java |
/*
* 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.xmlrpc.parser;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
/** Parser for long values.
*/
public class I8Parser extends AtomicParser {
protected void setResult(String pResult) throws SAXException {
try {
super.setResult(new Long(pResult.trim()));
} catch (NumberFormatException e) {
throw new SAXParseException("Failed to parse long value: " + pResult,
getDocumentLocator());
}
}
}
| Java |
/*
* 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.xmlrpc.parser;
import java.math.BigInteger;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
/** Parser for BigInteger values.
*/
public class BigIntegerParser extends AtomicParser {
protected void setResult(String pResult) throws SAXException {
try {
super.setResult(new BigInteger(pResult));
} catch (NumberFormatException e) {
throw new SAXParseException("Failed to parse BigInteger value: " + pResult,
getDocumentLocator());
}
}
}
| Java |
/*
* 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.xmlrpc.parser;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
/** Parser for float values.
*/
public class FloatParser extends AtomicParser {
protected void setResult(String pResult) throws SAXException {
try {
super.setResult(new Float(pResult));
} catch (NumberFormatException e) {
throw new SAXParseException("Failed to parse float value: " + pResult,
getDocumentLocator());
}
}
}
| Java |
/*
* 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.xmlrpc.parser;
import java.util.HashMap;
import java.util.Map;
import javax.xml.namespace.QName;
import org.apache.ws.commons.util.NamespaceContextImpl;
import org.apache.xmlrpc.common.TypeFactory;
import org.apache.xmlrpc.common.XmlRpcStreamConfig;
import org.apache.xmlrpc.serializer.MapSerializer;
import org.apache.xmlrpc.serializer.TypeSerializerImpl;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
/** {@link org.apache.xmlrpc.parser.TypeParser} implementation
* for maps.
*/
public class MapParser extends RecursiveTypeParserImpl {
private int level = 0;
private StringBuffer nameBuffer = new StringBuffer();
private Object nameObject;
private Map map;
private boolean inName, inValue, doneValue;
/** Creates a new instance.
* @param pConfig The request or response configuration.
* @param pContext The namespace context.
* @param pFactory The factory.
*/
public MapParser(XmlRpcStreamConfig pConfig,
NamespaceContextImpl pContext,
TypeFactory pFactory) {
super(pConfig, pContext, pFactory);
}
protected void addResult(Object pResult) throws SAXException {
if (inName) {
nameObject = pResult;
} else {
if (nameObject == null) {
throw new SAXParseException("Invalid state: Expected name",
getDocumentLocator());
} else {
if (map.containsKey(nameObject)) {
throw new SAXParseException("Duplicate name: " + nameObject,
getDocumentLocator());
} else {
map.put(nameObject, pResult);
}
}
}
}
public void startDocument() throws SAXException {
super.startDocument();
level = 0;
map = new HashMap();
inValue = inName = false;
}
public void characters(char[] pChars, int pOffset, int pLength) throws SAXException {
if (inName && !inValue) {
nameBuffer.append(pChars, pOffset, pLength);
} else {
super.characters(pChars, pOffset, pLength);
}
}
public void ignorableWhitespace(char[] pChars, int pOffset, int pLength) throws SAXException {
if (inName) {
characters(pChars, pOffset, pLength);
} else {
super.ignorableWhitespace(pChars, pOffset, pLength);
}
}
public void startElement(String pURI, String pLocalName, String pQName,
Attributes pAttrs) throws SAXException {
switch (level++) {
case 0:
if (!"".equals(pURI) || !MapSerializer.STRUCT_TAG.equals(pLocalName)) {
throw new SAXParseException("Expected " + MapSerializer.STRUCT_TAG + ", got "
+ new QName(pURI, pLocalName),
getDocumentLocator());
}
break;
case 1:
if (!"".equals(pURI) || !MapSerializer.MEMBER_TAG.equals(pLocalName)) {
throw new SAXParseException("Expected " + MapSerializer.MEMBER_TAG + ", got "
+ new QName(pURI, pLocalName),
getDocumentLocator());
}
doneValue = inName = inValue = false;
nameObject = null;
nameBuffer.setLength(0);
break;
case 2:
if (doneValue) {
throw new SAXParseException("Expected /" + MapSerializer.MEMBER_TAG
+ ", got " + new QName(pURI, pLocalName),
getDocumentLocator());
}
if ("".equals(pURI) && MapSerializer.NAME_TAG.equals(pLocalName)) {
if (nameObject == null) {
inName = true;
} else {
throw new SAXParseException("Expected " + TypeSerializerImpl.VALUE_TAG
+ ", got " + new QName(pURI, pLocalName),
getDocumentLocator());
}
} else if ("".equals(pURI) && TypeSerializerImpl.VALUE_TAG.equals(pLocalName)) {
if (nameObject == null) {
throw new SAXParseException("Expected " + MapSerializer.NAME_TAG
+ ", got " + new QName(pURI, pLocalName),
getDocumentLocator());
} else {
inValue = true;
startValueTag();
}
}
break;
case 3:
if (inName && "".equals(pURI) && TypeSerializerImpl.VALUE_TAG.equals(pLocalName)) {
if (cfg.isEnabledForExtensions()) {
inValue = true;
startValueTag();
} else {
throw new SAXParseException("Expected /" + MapSerializer.NAME_TAG
+ ", got " + new QName(pURI, pLocalName),
getDocumentLocator());
}
} else {
super.startElement(pURI, pLocalName, pQName, pAttrs);
}
break;
default:
super.startElement(pURI, pLocalName, pQName, pAttrs);
break;
}
}
public void endElement(String pURI, String pLocalName, String pQName) throws SAXException {
switch (--level) {
case 0:
setResult(map);
break;
case 1:
break;
case 2:
if (inName) {
inName = false;
if (nameObject == null) {
nameObject = nameBuffer.toString();
} else {
for (int i = 0; i < nameBuffer.length(); i++) {
if (!Character.isWhitespace(nameBuffer.charAt(i))) {
throw new SAXParseException("Unexpected non-whitespace character in member name",
getDocumentLocator());
}
}
}
} else if (inValue) {
endValueTag();
doneValue = true;
}
break;
case 3:
if (inName && inValue && "".equals(pURI) && TypeSerializerImpl.VALUE_TAG.equals(pLocalName)) {
endValueTag();
} else {
super.endElement(pURI, pLocalName, pQName);
}
break;
default:
super.endElement(pURI, pLocalName, pQName);
}
}
}
| Java |
/*
* 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.xmlrpc.parser;
import java.text.ParseException;
import org.apache.ws.commons.util.XsDateTimeFormat;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
/** Parser for integer values.
*/
public class CalendarParser extends AtomicParser {
private static final XsDateTimeFormat format = new XsDateTimeFormat();
protected void setResult(String pResult) throws SAXException {
try {
super.setResult(format.parseObject(pResult.trim()));
} catch (ParseException e) {
int offset = e.getErrorOffset();
final String msg;
if (offset == -1) {
msg = "Failed to parse dateTime value: " + pResult;
} else {
msg = "Failed to parse dateTime value " + pResult
+ " at position " + e.getErrorOffset();
}
throw new SAXParseException(msg, getDocumentLocator(), e);
}
}
}
| Java |
/*
* 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.xmlrpc.parser;
import java.text.Format;
import java.text.ParseException;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
/** Parser for integer values.
*/
public class DateParser extends AtomicParser {
private final Format f;
/** Creates a new instance with the given format.
*/
public DateParser(Format pFormat) {
f = pFormat;
}
protected void setResult(String pResult) throws SAXException {
final String s = pResult.trim();
if (s.length() == 0) {
return;
}
try {
super.setResult(f.parseObject(s));
} catch (ParseException e) {
final String msg;
int offset = e.getErrorOffset();
if (e.getErrorOffset() == -1) {
msg = "Failed to parse date value: " + pResult;
} else {
msg = "Failed to parse date value " + pResult
+ " at position " + offset;
}
throw new SAXParseException(msg, getDocumentLocator(), e);
}
}
}
| Java |
/*
* 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.xmlrpc.parser;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.xml.namespace.QName;
import org.apache.ws.commons.util.Base64;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
/** A parser for base64 elements.
*/
public class ByteArrayParser extends TypeParserImpl {
private int level;
private ByteArrayOutputStream baos;
private Base64.Decoder decoder;
public void startDocument() throws SAXException {
level = 0;
}
public void characters(char[] pChars, int pStart, int pLength) throws SAXException {
if (baos == null) {
if (!isEmpty(pChars, pStart, pLength)) {
throw new SAXParseException("Unexpected non-whitespace characters",
getDocumentLocator());
}
} else {
try {
decoder.write(pChars, pStart, pLength);
} catch (IOException e) {
throw new SAXParseException("Failed to decode base64 stream.", getDocumentLocator(), e);
}
}
}
public void endElement(String pURI, String pLocalName, String pQName) throws SAXException {
if (--level == 0) {
try {
decoder.flush();
} catch (IOException e) {
throw new SAXParseException("Failed to decode base64 stream.", getDocumentLocator(), e);
}
setResult(baos.toByteArray());
} else {
throw new SAXParseException("Unexpected end tag in atomic element: "
+ new QName(pURI, pLocalName),
getDocumentLocator());
}
}
public void startElement(String pURI, String pLocalName, String pQName, Attributes pAttrs) throws SAXException {
if (level++ == 0) {
baos = new ByteArrayOutputStream();
decoder = new Base64.Decoder(1024){
protected void writeBuffer(byte[] pBytes, int pOffset, int pLen) throws IOException {
baos.write(pBytes, pOffset, pLen);
}
};
} else {
throw new SAXParseException("Unexpected start tag in atomic element: "
+ new QName(pURI, pLocalName),
getDocumentLocator());
}
}
}
| Java |
/*
* 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.xmlrpc.parser;
import java.math.BigDecimal;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
/** Parser for BigDecimal values.
*/
public class BigDecimalParser extends AtomicParser {
protected void setResult(String pResult) throws SAXException {
try {
super.setResult(new BigDecimal(pResult));
} catch (NumberFormatException e) {
throw new SAXParseException("Failed to parse BigDecimal value: " + pResult,
getDocumentLocator());
}
}
}
| Java |
/*
* 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.xmlrpc.parser;
import org.apache.xmlrpc.XmlRpcException;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
/** Abstract base implementation of a {@link org.apache.xmlrpc.parser.TypeParser},
* for derivation of subclasses.
*/
public abstract class TypeParserImpl implements TypeParser {
private Object result;
private Locator locator;
/** Sets the result object.
* @param pResult The result object.
*/
public void setResult(Object pResult) { result = pResult; }
public Object getResult() throws XmlRpcException { return result; }
/** Returns the document locator.
* @return Locator object describing the current location within the
* document.
*/
public Locator getDocumentLocator() { return locator; }
public void setDocumentLocator(Locator pLocator) { locator = pLocator; }
/** PI's are by default ignored.
*/
public void processingInstruction(String pTarget, String pData) throws SAXException {
}
/** Skipped entities raise an exception by default.
*/
public void skippedEntity(String pName) throws SAXException {
throw new SAXParseException("Don't know how to handle entity " + pName,
getDocumentLocator());
}
public void startPrefixMapping(String pPrefix, String pURI) throws SAXException {
}
public void endPrefixMapping(String pPrefix) throws SAXException {
}
public void endDocument() throws SAXException {
}
public void startDocument() throws SAXException {
}
protected static boolean isEmpty(char[] pChars, int pStart, int pLength) {
for (int i = 0; i < pLength; i++) {
if (!Character.isWhitespace(pChars[pStart+i])) {
return false;
}
}
return true;
}
public void characters(char[] pChars, int pOffset, int pLength) throws SAXException {
if (!isEmpty(pChars, pOffset, pLength)) {
throw new SAXParseException("Unexpected non-whitespace character data",
getDocumentLocator());
}
}
public void ignorableWhitespace(char[] pChars, int pOffset, int pLength) throws SAXException {
}
}
| Java |
/*
* 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.xmlrpc.parser;
import org.apache.xmlrpc.XmlRpcException;
import org.xml.sax.ContentHandler;
/** Interface of a SAX handler parsing a single parameter or
* result object.
*/
public interface TypeParser extends ContentHandler {
/** Returns the parsed object.
* @return The parameter or result object.
* @throws XmlRpcException Creating the result object failed.
* @throws IllegalStateException The method was invoked before
* {@link org.xml.sax.ContentHandler#endDocument}.
*/
public Object getResult() throws XmlRpcException;
}
| Java |
/*
* 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.xmlrpc;
import java.io.PrintStream;
import java.io.PrintWriter;
/** This exception is thrown by the XmlRpcClient, if an invocation of the
* remote method failed. Failure may have two reasons: The invocation
* failed on the remote side (for example, an exception was thrown within
* the server) or the communication with the server failed. The latter
* is indicated by throwing an instance of
* {@link org.apache.xmlrpc.client.XmlRpcClientException}.
*/
public class XmlRpcException extends Exception {
private static final long serialVersionUID = 3258693217049325618L;
/** The fault code of the exception. For servers based on this library, this
* will always be 0. (If there are predefined error codes, they should be in
* the XML-RPC spec.)
*/
public final int code;
/** If the transport was able to catch a remote exception
* (as is the case, if the local transport is used or if extensions
* are enabled and the server returned a serialized exception),
* then this field contains the trapped exception.
*/
public final Throwable linkedException;
/** Creates a new instance with the given error code and error message.
* @param pCode Error code.
* @param pMessage Detail message.
*/
public XmlRpcException(int pCode, String pMessage) {
this(pCode, pMessage, null);
}
/** Creates a new instance with the given error message
* and cause.
* @param pMessage Detail message.
* @param pLinkedException The errors cause.
*/
public XmlRpcException(String pMessage, Throwable pLinkedException) {
this(0, pMessage, pLinkedException);
}
/** Creates a new instance with the given error message
* and error code 0.
* @param pMessage Detail message.
*/
public XmlRpcException(String pMessage) {
this(0, pMessage, null);
}
/** Creates a new instance with the given error code, error message
* and cause.
* @param pCode Error code.
* @param pMessage Detail message.
* @param pLinkedException The errors cause.
*/
public XmlRpcException(int pCode, String pMessage, Throwable pLinkedException) {
super(pMessage);
code = pCode;
linkedException = pLinkedException;
}
public void printStackTrace(PrintStream pStream) {
super.printStackTrace(pStream);
if (linkedException != null) {
pStream.println("Caused by:");
linkedException.printStackTrace(pStream);
}
}
public void printStackTrace(PrintWriter pWriter) {
super.printStackTrace(pWriter);
if (linkedException != null) {
pWriter.println("Caused by:");
linkedException.printStackTrace(pWriter);
}
}
public Throwable getCause() {
return linkedException;
}
}
| Java |
/*
* 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.xmlrpc.common;
/** Interface of a configuration for HTTP requests.
*/
public interface XmlRpcHttpConfig extends XmlRpcStreamConfig {
/** Returns the encoding being used to convert the String "username:password"
* into bytes.
* @return Encoding being used for basic HTTP authentication credentials,
* or null, if the default encoding
* ({@link org.apache.xmlrpc.common.XmlRpcStreamRequestConfig#UTF8_ENCODING})
* is being used.
*/
String getBasicEncoding();
/** Returns, whether a "Content-Length" header may be
* omitted. The XML-RPC specification demands, that such
* a header be present.
* @return True, if the content length may be omitted.
*/
boolean isContentLengthOptional();
}
| Java |
/*
* 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.xmlrpc.common;
import org.apache.xmlrpc.common.XmlRpcHttpConfig;
import org.apache.xmlrpc.common.XmlRpcStreamRequestConfig;
/** Extension of {@link org.apache.xmlrpc.client.XmlRpcClientConfig}
* for HTTP based transport. Provides details like server URL,
* user credentials, and so on.
*/
public interface XmlRpcHttpRequestConfig extends XmlRpcStreamRequestConfig, XmlRpcHttpConfig {
/** Returns the user name being used for basic HTTP authentication.
* @return User name or null, if no basic HTTP authentication is being used.
*/
String getBasicUserName();
/** Returns the password being used for basic HTTP authentication.
* @return Password or null, if no basic HTTP authentication is beind used.
* @throws IllegalStateException A user name is configured, but no password.
*/
String getBasicPassword();
/** Return the connection timeout in milliseconds
* @return connection timeout in milliseconds or 0 if no set
*/
int getConnectionTimeout();
/** Return the reply timeout in milliseconds
* @return reply timeout in milliseconds or 0 if no set
*/
int getReplyTimeout();
}
| Java |
/*
* 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.xmlrpc.common;
import org.apache.xmlrpc.XmlRpcException;
/** This exception is thrown, if the clients or servers maximum
* number of concurrent threads is exceeded.
*/
public class XmlRpcLoadException extends XmlRpcException {
private static final long serialVersionUID = 4050760511635272755L;
/** Creates a new instance.
* @param pMessage Error description.
*/
public XmlRpcLoadException(String pMessage) {
super(0, pMessage, null);
}
}
| Java |
/*
* 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.xmlrpc.common;
import org.apache.xmlrpc.XmlRpcException;
/** This exception must be thrown, if the user isn't authenticated.
*/
public class XmlRpcNotAuthorizedException extends XmlRpcException {
private static final long serialVersionUID = 3258410629709574201L;
/** Creates a new instance with the given error message.
* @param pMessage The error message.
*/
public XmlRpcNotAuthorizedException(String pMessage) {
super(0, pMessage);
}
}
| Java |
/*
* 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.xmlrpc.common;
/** Interface of an object, which may be used
* to create instances of {@link XmlRpcRequestProcessor}.
*/
public interface XmlRpcRequestProcessorFactory {
/** Returns the {@link XmlRpcRequestProcessor} being invoked.
* @return Server object being invoked. This will typically
* be a singleton instance, but could as well create a new
* instance with any call.
*/
XmlRpcRequestProcessor getXmlRpcServer();
}
| Java |
/*
* 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.xmlrpc.common;
import org.apache.xmlrpc.XmlRpcConfigImpl;
/** Default implementation of a request configuration.
*/
public class XmlRpcHttpRequestConfigImpl extends XmlRpcConfigImpl implements
XmlRpcHttpRequestConfig {
private boolean gzipCompressing;
private boolean gzipRequesting;
private String basicUserName;
private String basicPassword;
private int connectionTimeout = 0;
private int replyTimeout = 0;
private boolean enabledForExceptions;
/** Sets, whether gzip compression is being used for
* transmitting the request.
* @param pCompressing True for enabling gzip compression,
* false otherwise.
* @see #setGzipRequesting(boolean)
*/
public void setGzipCompressing(boolean pCompressing) {
gzipCompressing = pCompressing;
}
public boolean isGzipCompressing() {
return gzipCompressing;
}
/** Sets, whether gzip compression is requested for the
* response.
* @param pRequesting True for requesting gzip compression,
* false otherwise.
* @see #setGzipCompressing(boolean)
*/
public void setGzipRequesting(boolean pRequesting) {
gzipRequesting = pRequesting;
}
public boolean isGzipRequesting() {
return gzipRequesting;
}
/** Sets the user name for basic authentication.
* @param pUser The user name.
*/
public void setBasicUserName(String pUser) {
basicUserName = pUser;
}
public String getBasicUserName() { return basicUserName; }
/** Sets the password for basic authentication.
* @param pPassword The password.
*/
public void setBasicPassword(String pPassword) {
basicPassword = pPassword;
}
public String getBasicPassword() { return basicPassword; }
/** Set the connection timeout in milliseconds.
* @param pTimeout connection timeout, 0 to disable it
*/
public void setConnectionTimeout(int pTimeout) {
connectionTimeout = pTimeout;
}
public int getConnectionTimeout() {
return connectionTimeout;
}
/** Set the reply timeout in milliseconds.
* @param pTimeout reply timeout, 0 to disable it
*/
public void setReplyTimeout(int pTimeout) {
replyTimeout = pTimeout;
}
public int getReplyTimeout() {
return replyTimeout;
}
/** Sets, whether the response should contain a "faultCause" element
* in case of errors. The "faultCause" is an exception, which the
* server has trapped and written into a byte stream as a serializable
* object.
*/
public void setEnabledForExceptions(boolean pEnabledForExceptions) {
enabledForExceptions = pEnabledForExceptions;
}
public boolean isEnabledForExceptions() {
return enabledForExceptions;
}
}
| Java |
/*
* 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.xmlrpc.common;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.XmlRpcRequest;
/** An object, which executes requests on the controllers
* behalf. These objects are mainly used for controlling the
* clients or servers load, which is defined in terms of the
* number of currently active workers.
*/
public interface XmlRpcWorker {
/** Returns the workers controller.
* @return The controller, an instance of
* {@link org.apache.xmlrpc.client.XmlRpcClient}, or
* {@link org.apache.xmlrpc.server.XmlRpcServer}.
*/
XmlRpcController getController();
/** Performs a synchronous request. The client worker extends
* this interface with the ability to perform asynchronous
* requests.
* @param pRequest The request being performed.
* @return The requests result.
* @throws XmlRpcException Performing the request failed.
*/
Object execute(XmlRpcRequest pRequest) throws XmlRpcException;
}
| Java |
/*
* 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.xmlrpc.common;
/** A {@link TypeConverterFactory} is called for creating instances
* of {@link TypeConverter}.
*/
public interface TypeConverterFactory {
/** Creates an instance of {@link TypeFactory}, which may be
* used to create instances of the given class.
*/
TypeConverter getTypeConverter(Class pClass);
}
| Java |
/*
* 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.xmlrpc.common;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import org.apache.ws.commons.util.NamespaceContextImpl;
import org.apache.xmlrpc.parser.BigDecimalParser;
import org.apache.xmlrpc.parser.BigIntegerParser;
import org.apache.xmlrpc.parser.BooleanParser;
import org.apache.xmlrpc.parser.ByteArrayParser;
import org.apache.xmlrpc.parser.CalendarParser;
import org.apache.xmlrpc.parser.DateParser;
import org.apache.xmlrpc.parser.DoubleParser;
import org.apache.xmlrpc.parser.FloatParser;
import org.apache.xmlrpc.parser.I1Parser;
import org.apache.xmlrpc.parser.I2Parser;
import org.apache.xmlrpc.parser.I4Parser;
import org.apache.xmlrpc.parser.I8Parser;
import org.apache.xmlrpc.parser.MapParser;
import org.apache.xmlrpc.parser.NodeParser;
import org.apache.xmlrpc.parser.NullParser;
import org.apache.xmlrpc.parser.ObjectArrayParser;
import org.apache.xmlrpc.parser.SerializableParser;
import org.apache.xmlrpc.parser.StringParser;
import org.apache.xmlrpc.parser.TypeParser;
import org.apache.xmlrpc.serializer.BigDecimalSerializer;
import org.apache.xmlrpc.serializer.BigIntegerSerializer;
import org.apache.xmlrpc.serializer.BooleanSerializer;
import org.apache.xmlrpc.serializer.ByteArraySerializer;
import org.apache.xmlrpc.serializer.CalendarSerializer;
import org.apache.xmlrpc.serializer.DateSerializer;
import org.apache.xmlrpc.serializer.DoubleSerializer;
import org.apache.xmlrpc.serializer.FloatSerializer;
import org.apache.xmlrpc.serializer.I1Serializer;
import org.apache.xmlrpc.serializer.I2Serializer;
import org.apache.xmlrpc.serializer.I4Serializer;
import org.apache.xmlrpc.serializer.I8Serializer;
import org.apache.xmlrpc.serializer.ListSerializer;
import org.apache.xmlrpc.serializer.MapSerializer;
import org.apache.xmlrpc.serializer.NodeSerializer;
import org.apache.xmlrpc.serializer.NullSerializer;
import org.apache.xmlrpc.serializer.ObjectArraySerializer;
import org.apache.xmlrpc.serializer.SerializableSerializer;
import org.apache.xmlrpc.serializer.StringSerializer;
import org.apache.xmlrpc.serializer.TypeSerializer;
import org.apache.xmlrpc.serializer.XmlRpcWriter;
import org.apache.xmlrpc.util.XmlRpcDateTimeDateFormat;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
/** Default implementation of a type factory.
*/
public class TypeFactoryImpl implements TypeFactory {
private static final TypeSerializer NULL_SERIALIZER = new NullSerializer();
private static final TypeSerializer STRING_SERIALIZER = new StringSerializer();
private static final TypeSerializer I4_SERIALIZER = new I4Serializer();
private static final TypeSerializer BOOLEAN_SERIALIZER = new BooleanSerializer();
private static final TypeSerializer DOUBLE_SERIALIZER = new DoubleSerializer();
private static final TypeSerializer BYTE_SERIALIZER = new I1Serializer();
private static final TypeSerializer SHORT_SERIALIZER = new I2Serializer();
private static final TypeSerializer LONG_SERIALIZER = new I8Serializer();
private static final TypeSerializer FLOAT_SERIALIZER = new FloatSerializer();
private static final TypeSerializer NODE_SERIALIZER = new NodeSerializer();
private static final TypeSerializer SERIALIZABLE_SERIALIZER = new SerializableSerializer();
private static final TypeSerializer BIGDECIMAL_SERIALIZER = new BigDecimalSerializer();
private static final TypeSerializer BIGINTEGER_SERIALIZER = new BigIntegerSerializer();
private static final TypeSerializer CALENDAR_SERIALIZER = new CalendarSerializer();
private final XmlRpcController controller;
private DateSerializer dateSerializer;
/** Creates a new instance.
* @param pController The controller, which operates the type factory.
*/
public TypeFactoryImpl(XmlRpcController pController) {
controller = pController;
}
/** Returns the controller, which operates the type factory.
* @return The controller, an instance of
* {@link org.apache.xmlrpc.client.XmlRpcClient},
* or {@link org.apache.xmlrpc.server.XmlRpcServer}.
*/
public XmlRpcController getController() {
return controller;
}
public TypeSerializer getSerializer(XmlRpcStreamConfig pConfig, Object pObject) throws SAXException {
if (pObject == null) {
if (pConfig.isEnabledForExtensions()) {
return NULL_SERIALIZER;
} else {
throw new SAXException(new XmlRpcExtensionException("Null values aren't supported, if isEnabledForExtensions() == false"));
}
} else if (pObject instanceof String) {
return STRING_SERIALIZER;
} else if (pObject instanceof Byte) {
if (pConfig.isEnabledForExtensions()) {
return BYTE_SERIALIZER;
} else {
throw new SAXException(new XmlRpcExtensionException("Byte values aren't supported, if isEnabledForExtensions() == false"));
}
} else if (pObject instanceof Short) {
if (pConfig.isEnabledForExtensions()) {
return SHORT_SERIALIZER;
} else {
throw new SAXException(new XmlRpcExtensionException("Short values aren't supported, if isEnabledForExtensions() == false"));
}
} else if (pObject instanceof Integer) {
return I4_SERIALIZER;
} else if (pObject instanceof Long) {
if (pConfig.isEnabledForExtensions()) {
return LONG_SERIALIZER;
} else {
throw new SAXException(new XmlRpcExtensionException("Long values aren't supported, if isEnabledForExtensions() == false"));
}
} else if (pObject instanceof Boolean) {
return BOOLEAN_SERIALIZER;
} else if (pObject instanceof Float) {
if (pConfig.isEnabledForExtensions()) {
return FLOAT_SERIALIZER;
} else {
throw new SAXException(new XmlRpcExtensionException("Float values aren't supported, if isEnabledForExtensions() == false"));
}
} else if (pObject instanceof Double) {
return DOUBLE_SERIALIZER;
} else if (pObject instanceof Calendar) {
if (pConfig.isEnabledForExtensions()) {
return CALENDAR_SERIALIZER;
} else {
throw new SAXException(new XmlRpcExtensionException("Calendar values aren't supported, if isEnabledForExtensions() == false"));
}
} else if (pObject instanceof Date) {
if (dateSerializer == null) {
dateSerializer = new DateSerializer(new XmlRpcDateTimeDateFormat(){
private static final long serialVersionUID = 24345909123324234L;
protected TimeZone getTimeZone() {
return controller.getConfig().getTimeZone();
}
});
}
return dateSerializer;
} else if (pObject instanceof byte[]) {
return new ByteArraySerializer();
} else if (pObject instanceof Object[]) {
return new ObjectArraySerializer(this, pConfig);
} else if (pObject instanceof List) {
return new ListSerializer(this, pConfig);
} else if (pObject instanceof Map) {
return new MapSerializer(this, pConfig);
} else if (pObject instanceof Node) {
if (pConfig.isEnabledForExtensions()) {
return NODE_SERIALIZER;
} else {
throw new SAXException(new XmlRpcExtensionException("DOM nodes aren't supported, if isEnabledForExtensions() == false"));
}
} else if (pObject instanceof BigInteger) {
if (pConfig.isEnabledForExtensions()) {
return BIGINTEGER_SERIALIZER;
} else {
throw new SAXException(new XmlRpcExtensionException("BigInteger values aren't supported, if isEnabledForExtensions() == false"));
}
} else if (pObject instanceof BigDecimal) {
if (pConfig.isEnabledForExtensions()) {
return BIGDECIMAL_SERIALIZER;
} else {
throw new SAXException(new XmlRpcExtensionException("BigDecimal values aren't supported, if isEnabledForExtensions() == false"));
}
} else if (pObject instanceof Serializable) {
if (pConfig.isEnabledForExtensions()) {
return SERIALIZABLE_SERIALIZER;
} else {
throw new SAXException(new XmlRpcExtensionException("Serializable objects aren't supported, if isEnabledForExtensions() == false"));
}
} else {
return null;
}
}
public TypeParser getParser(XmlRpcStreamConfig pConfig, NamespaceContextImpl pContext, String pURI, String pLocalName) {
if (XmlRpcWriter.EXTENSIONS_URI.equals(pURI)) {
if (!pConfig.isEnabledForExtensions()) {
return null;
}
if (NullSerializer.NIL_TAG.equals(pLocalName)) {
return new NullParser();
} else if (I1Serializer.I1_TAG.equals(pLocalName)) {
return new I1Parser();
} else if (I2Serializer.I2_TAG.equals(pLocalName)) {
return new I2Parser();
} else if (I8Serializer.I8_TAG.equals(pLocalName)) {
return new I8Parser();
} else if (FloatSerializer.FLOAT_TAG.equals(pLocalName)) {
return new FloatParser();
} else if (NodeSerializer.DOM_TAG.equals(pLocalName)) {
return new NodeParser();
} else if (BigDecimalSerializer.BIGDECIMAL_TAG.equals(pLocalName)) {
return new BigDecimalParser();
} else if (BigIntegerSerializer.BIGINTEGER_TAG.equals(pLocalName)) {
return new BigIntegerParser();
} else if (SerializableSerializer.SERIALIZABLE_TAG.equals(pLocalName)) {
return new SerializableParser();
} else if (CalendarSerializer.CALENDAR_TAG.equals(pLocalName)) {
return new CalendarParser();
}
} else if ("".equals(pURI)) {
if (I4Serializer.INT_TAG.equals(pLocalName) || I4Serializer.I4_TAG.equals(pLocalName)) {
return new I4Parser();
} else if (BooleanSerializer.BOOLEAN_TAG.equals(pLocalName)) {
return new BooleanParser();
} else if (DoubleSerializer.DOUBLE_TAG.equals(pLocalName)) {
return new DoubleParser();
} else if (DateSerializer.DATE_TAG.equals(pLocalName)) {
return new DateParser(new XmlRpcDateTimeDateFormat(){
private static final long serialVersionUID = 7585237706442299067L;
protected TimeZone getTimeZone() {
return controller.getConfig().getTimeZone();
}
});
} else if (ObjectArraySerializer.ARRAY_TAG.equals(pLocalName)) {
return new ObjectArrayParser(pConfig, pContext, this);
} else if (MapSerializer.STRUCT_TAG.equals(pLocalName)) {
return new MapParser(pConfig, pContext, this);
} else if (ByteArraySerializer.BASE_64_TAG.equals(pLocalName)) {
return new ByteArrayParser();
} else if (StringSerializer.STRING_TAG.equals(pLocalName)) {
return new StringParser();
}
}
return null;
}
}
| Java |
/*
* 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.xmlrpc.common;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.XmlRpcRequest;
/** Interface of an object, which is able to process
* XML-RPC requests.
*/
public interface XmlRpcRequestProcessor {
/** Processes the given request and returns a
* result object.
* @throws XmlRpcException Processing the request failed.
*/
Object execute(XmlRpcRequest pRequest) throws XmlRpcException;
/** Returns the request processors {@link TypeConverterFactory}.
*/
TypeConverterFactory getTypeConverterFactory();
}
| Java |
/*
* 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.xmlrpc.common;
import org.apache.xmlrpc.XmlRpcException;
/**
* This exception is thrown, if the server catches an exception, which
* is thrown by the handler.
*/
public class XmlRpcInvocationException extends XmlRpcException {
private static final long serialVersionUID = 7439737967784966169L;
/**
* Creates a new instance with the given error code, error message
* and cause.
*/
public XmlRpcInvocationException(int pCode, String pMessage, Throwable pLinkedException) {
super(pCode, pMessage, pLinkedException);
}
/**
* Creates a new instance with the given error message and cause.
*/
public XmlRpcInvocationException(String pMessage, Throwable pLinkedException) {
super(pMessage, pLinkedException);
}
}
| Java |
/*
* 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.xmlrpc.common;
import org.apache.xmlrpc.XmlRpcException;
/** This exception is thrown, if an attempt to use extensions
* is made, but extensions aren't explicitly enabled.
*/
public class XmlRpcExtensionException extends XmlRpcException {
private static final long serialVersionUID = 3617014169594311221L;
/** Creates a new instance with the given error message.
* @param pMessage The error message.
*/
public XmlRpcExtensionException(String pMessage) {
super(0, pMessage);
}
}
| Java |
/*
* 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.xmlrpc.common;
import java.util.ArrayList;
import java.util.List;
/** A factory for {@link XmlRpcWorker} instances.
*/
public abstract class XmlRpcWorkerFactory {
private final XmlRpcWorker singleton = newWorker();
private final XmlRpcController controller;
private final List pool = new ArrayList();
private int numThreads;
/** Creates a new instance.
* @param pController The client controlling the factory.
*/
public XmlRpcWorkerFactory(XmlRpcController pController) {
controller = pController;
}
/** Creates a new worker instance.
* @return New instance of {@link XmlRpcWorker}.
*/
protected abstract XmlRpcWorker newWorker();
/** Returns the factory controller.
* @return The controller, an instance of
* {@link org.apache.xmlrpc.client.XmlRpcClient}, or
* {@link org.apache.xmlrpc.server.XmlRpcServer}.
*/
public XmlRpcController getController() {
return controller;
}
/** Returns a worker for synchronous processing.
* @return An instance of {@link XmlRpcWorker}, which is ready
* for use.
* @throws XmlRpcLoadException The clients maximum number of concurrent
* threads is exceeded.
*/
public synchronized XmlRpcWorker getWorker() throws XmlRpcLoadException {
int max = controller.getMaxThreads();
if (max > 0 && numThreads == max) {
throw new XmlRpcLoadException("Maximum number of concurrent requests exceeded: " + max);
}
if (max == 0) {
return singleton;
}
++numThreads;
if (pool.size() == 0) {
return newWorker();
} else {
return (XmlRpcWorker) pool.remove(pool.size() - 1);
}
}
/** Called, when the worker did its job. Frees resources and
* decrements the number of concurrent requests.
* @param pWorker The worker being released.
*/
public synchronized void releaseWorker(XmlRpcWorker pWorker) {
--numThreads;
int max = controller.getMaxThreads();
if (pWorker == singleton) {
// Do nothing, it's the singleton
} else {
if (pool.size() < max) {
pool.add(pWorker);
}
}
}
/** Returns the number of currently running requests.
* @return Current number of concurrent requests.
*/
public synchronized int getCurrentRequests() {
return numThreads;
}
}
| Java |
/*
* 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.xmlrpc.common;
import org.apache.xmlrpc.XmlRpcConfig;
/** Interface of a configuration for a stream based transport.
*/
public interface XmlRpcStreamConfig extends XmlRpcConfig {
/** Default encoding (UTF-8).
*/
public static final String UTF8_ENCODING = "UTF-8";
/** Returns the encoding being used for data encoding, when writing
* to a stream.
* @return Suggested encoding, or null, if the {@link #UTF8_ENCODING}
* is being used.
*/
String getEncoding();
}
| Java |
/*
* 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.xmlrpc.common;
import org.apache.xmlrpc.XmlRpcConfig;
/** A common base class for
* {@link org.apache.xmlrpc.server.XmlRpcServer} and
* {@link org.apache.xmlrpc.client.XmlRpcClient}.
*/
public abstract class XmlRpcController {
private XmlRpcWorkerFactory workerFactory = getDefaultXmlRpcWorkerFactory();
private int maxThreads;
private TypeFactory typeFactory = new TypeFactoryImpl(this);
/** Creates the controllers default worker factory.
* @return The default factory for workers.
*/
protected abstract XmlRpcWorkerFactory getDefaultXmlRpcWorkerFactory();
/** Sets the maximum number of concurrent requests. This includes
* both synchronous and asynchronous requests.
* @param pMaxThreads Maximum number of threads or 0 to disable
* the limit.
*/
public void setMaxThreads(int pMaxThreads) {
maxThreads = pMaxThreads;
}
/** Returns the maximum number of concurrent requests. This includes
* both synchronous and asynchronous requests.
* @return Maximum number of threads or 0 to disable
* the limit.
*/
public int getMaxThreads() {
return maxThreads;
}
/** Sets the clients worker factory.
* @param pFactory The factory being used to create workers.
*/
public void setWorkerFactory(XmlRpcWorkerFactory pFactory) {
workerFactory = pFactory;
}
/** Returns the clients worker factory.
* @return The factory being used to create workers.
*/
public XmlRpcWorkerFactory getWorkerFactory() {
return workerFactory;
}
/** Returns the controllers default configuration.
* @return The default configuration.
*/
public abstract XmlRpcConfig getConfig();
/** Sets the type factory.
* @param pTypeFactory The type factory.
*/
public void setTypeFactory(TypeFactory pTypeFactory) {
typeFactory = pTypeFactory;
}
/** Returns the type factory.
* @return The type factory.
*/
public TypeFactory getTypeFactory() {
return typeFactory;
}
}
| Java |
/*
* 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.xmlrpc.common;
import java.util.List;
import java.util.Vector;
/** A {@link TypeConverter} is used when actually calling the
* handler method or actually returning the result object. It's
* purpose is to convert a single parameter or the return value
* from a generic representation (for example an array of objects)
* to an alternative representation, which is actually used in
* the methods signature (for example {@link List}, or
* {@link Vector}.
*/
public interface TypeConverter {
/** Returns, whether the {@link TypeConverter} is
* ready to handle the given object. If so,
* {@link #convert(Object)} may be called.
*/
boolean isConvertable(Object pObject);
/** Converts the given object into the required
* representation.
*/
Object convert(Object pObject);
/** Converts the given object into its generic
* representation.
*/
Object backConvert(Object result);
}
| Java |
/*
* 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.xmlrpc.common;
import org.apache.xmlrpc.XmlRpcRequestConfig;
/** Interface of a client configuration for a transport, which
* is implemented by writing to a stream.
*/
public interface XmlRpcStreamRequestConfig extends XmlRpcStreamConfig, XmlRpcRequestConfig {
/** Returns, whether the request stream is being compressed. Note,
* that the response stream may still be uncompressed.
* @return Whether to use Gzip compression or not. Defaults to false.
* @see #isGzipRequesting()
*/
boolean isGzipCompressing();
/** Returns, whether compression is requested for the response stream.
* Note, that the request is stull uncompressed, unless
* {@link #isGzipCompressing()} is activated. Also note, that the
* server may still decide to send uncompressed data.
* @return Whether to use Gzip compression or not. Defaults to false.
* @see #isGzipCompressing()
*/
boolean isGzipRequesting();
/** Returns, whether the response should contain a "faultCause" element
* in case of errors. The "faultCause" is an exception, which the
* server has trapped and written into a byte stream as a serializable
* object.
*/
boolean isEnabledForExceptions();
}
| Java |
/*
* 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.xmlrpc.common;
import org.apache.xmlrpc.XmlRpcException;
/** An instance of {@link XmlRpcRequestProcessor},
* which is processing an XML stream.
*/
public interface XmlRpcStreamRequestProcessor extends XmlRpcRequestProcessor {
/** Reads an XML-RPC request from the connection
* object and processes the request, writing the
* result to the same connection object.
* @throws XmlRpcException Processing the request failed.
*/
void execute(XmlRpcStreamRequestConfig pConfig, ServerStreamConnection pConnection) throws XmlRpcException;
}
| Java |
/*
* 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.xmlrpc.common;
import org.apache.ws.commons.util.NamespaceContextImpl;
import org.apache.xmlrpc.parser.TypeParser;
import org.apache.xmlrpc.serializer.TypeSerializer;
import org.xml.sax.SAXException;
/** A type factory creates serializers or handlers, based on the object
* type.
*/
public interface TypeFactory {
/** Creates a serializer for the object <code>pObject</code>.
* @param pConfig The request configuration.
* @param pObject The object being serialized.
* @return A serializer for <code>pObject</code>.
* @throws SAXException Creating the serializer failed.
*/
TypeSerializer getSerializer(XmlRpcStreamConfig pConfig, Object pObject) throws SAXException;
/** Creates a parser for a parameter or result object.
* @param pConfig The request configuration.
* @param pContext A namespace context, for looking up prefix mappings.
* @param pURI The namespace URI of the element containing the parameter or result.
* @param pLocalName The local name of the element containing the parameter or result.
* @return The created parser.
*/
TypeParser getParser(XmlRpcStreamConfig pConfig, NamespaceContextImpl pContext, String pURI, String pLocalName);
}
| Java |
/*
* 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.xmlrpc.common;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
/** Implementation of {@link ServerStreamConnection} for
* use by the
* {@link org.apache.xmlrpc.client.XmlRpcLocalStreamTransport}.
*/
public class LocalStreamConnection {
private class LocalServerStreamConnection implements ServerStreamConnection {
public InputStream newInputStream() throws IOException {
return request;
}
public OutputStream newOutputStream() throws IOException {
return response;
}
public void close() throws IOException {
if (response != null) {
response.close();
}
}
}
private final InputStream request;
private final XmlRpcStreamRequestConfig config;
private final ByteArrayOutputStream response = new ByteArrayOutputStream();
private final ServerStreamConnection serverStreamConnection;
/** Creates a new instance with the given request stream.
*/
public LocalStreamConnection(XmlRpcStreamRequestConfig pConfig,
InputStream pRequest) {
config = pConfig;
request = pRequest;
serverStreamConnection = new LocalServerStreamConnection();
}
/** Returns the request stream.
*/
public InputStream getRequest() {
return request;
}
/** Returns the request configuration.
*/
public XmlRpcStreamRequestConfig getConfig() {
return config;
}
/** Returns an output stream, to which the response
* may be written.
*/
public ByteArrayOutputStream getResponse() {
return response;
}
/** Returns the servers connection.
*/
public ServerStreamConnection getServerStreamConnection() {
return serverStreamConnection;
}
}
| Java |
/*
* 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.xmlrpc.common;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Vector;
import org.w3c.dom.Document;
/** Default implementation of {@link TypeConverterFactory}.
*/
public class TypeConverterFactoryImpl implements TypeConverterFactory {
private static class IdentityTypeConverter implements TypeConverter {
private final Class clazz;
IdentityTypeConverter(Class pClass) {
clazz = pClass;
}
public boolean isConvertable(Object pObject) {
return pObject == null || clazz.isAssignableFrom(pObject.getClass());
}
public Object convert(Object pObject) {
return pObject;
}
public Object backConvert(Object pObject) {
return pObject;
}
}
private static abstract class ListTypeConverter implements TypeConverter {
private final Class clazz;
ListTypeConverter(Class pClass) {
clazz = pClass;
}
protected abstract List newList(int pSize);
public boolean isConvertable(Object pObject) {
return pObject == null || pObject instanceof Object[] || pObject instanceof Collection;
}
public Object convert(Object pObject) {
if (pObject == null) {
return null;
}
if (clazz.isAssignableFrom(pObject.getClass())) {
return pObject;
}
if (pObject instanceof Object[]) {
Object[] objects = (Object[]) pObject;
List result = newList(objects.length);
for (int i = 0; i < objects.length; i++) {
result.add(objects[i]);
}
return result;
}
Collection collection = (Collection) pObject;
List result = newList(collection.size());
result.addAll(collection);
return result;
}
public Object backConvert(Object pObject) {
return ((List) pObject).toArray();
}
}
private static class PrimitiveTypeConverter implements TypeConverter {
private final Class clazz;
PrimitiveTypeConverter(Class pClass) {
clazz = pClass;
}
public boolean isConvertable(Object pObject) {
return pObject != null && pObject.getClass().isAssignableFrom(clazz);
}
public Object convert(Object pObject) {
return pObject;
}
public Object backConvert(Object pObject) {
return pObject;
}
}
private static final TypeConverter voidTypeConverter = new IdentityTypeConverter(void.class);
private static final TypeConverter mapTypeConverter = new IdentityTypeConverter(Map.class);
private static final TypeConverter objectArrayTypeConverter = new IdentityTypeConverter(Object[].class);
private static final TypeConverter byteArrayTypeConverter = new IdentityTypeConverter(byte[].class);
private static final TypeConverter stringTypeConverter = new IdentityTypeConverter(String.class);
private static final TypeConverter booleanTypeConverter = new IdentityTypeConverter(Boolean.class);
private static final TypeConverter characterTypeConverter = new IdentityTypeConverter(Character.class);
private static final TypeConverter byteTypeConverter = new IdentityTypeConverter(Byte.class);
private static final TypeConverter shortTypeConverter = new IdentityTypeConverter(Short.class);
private static final TypeConverter integerTypeConverter = new IdentityTypeConverter(Integer.class);
private static final TypeConverter longTypeConverter = new IdentityTypeConverter(Long.class);
private static final TypeConverter bigDecimalTypeConverter = new IdentityTypeConverter(BigDecimal.class);
private static final TypeConverter bigIntegerTypeConverter = new IdentityTypeConverter(BigInteger.class);
private static final TypeConverter floatTypeConverter = new IdentityTypeConverter(Float.class);
private static final TypeConverter doubleTypeConverter = new IdentityTypeConverter(Double.class);
private static final TypeConverter dateTypeConverter = new IdentityTypeConverter(Date.class);
private static final TypeConverter calendarTypeConverter = new IdentityTypeConverter(Calendar.class);
private static final TypeConverter domTypeConverter = new IdentityTypeConverter(Document.class);
private static final TypeConverter primitiveBooleanTypeConverter = new PrimitiveTypeConverter(Boolean.class);
private static final TypeConverter primitiveCharTypeConverter = new PrimitiveTypeConverter(Character.class);
private static final TypeConverter primitiveByteTypeConverter = new PrimitiveTypeConverter(Byte.class);
private static final TypeConverter primitiveShortTypeConverter = new PrimitiveTypeConverter(Short.class);
private static final TypeConverter primitiveIntTypeConverter = new PrimitiveTypeConverter(Integer.class);
private static final TypeConverter primitiveLongTypeConverter = new PrimitiveTypeConverter(Long.class);
private static final TypeConverter primitiveFloatTypeConverter = new PrimitiveTypeConverter(Float.class);
private static final TypeConverter primitiveDoubleTypeConverter = new PrimitiveTypeConverter(Double.class);
private static final TypeConverter propertiesTypeConverter = new TypeConverter() {
public boolean isConvertable(Object pObject) {
return pObject == null || pObject instanceof Map;
}
public Object convert(Object pObject) {
if (pObject == null) {
return null;
}
Properties props = new Properties();
props.putAll((Map) pObject);
return props;
}
public Object backConvert(Object pObject) {
return pObject;
}
};
private static final TypeConverter hashTableTypeConverter = new TypeConverter() {
public boolean isConvertable(Object pObject) {
return pObject == null || pObject instanceof Map;
}
public Object convert(Object pObject) {
if (pObject == null) {
return null;
}
return new Hashtable((Map) pObject);
}
public Object backConvert(Object pObject) {
return pObject;
}
};
private static final TypeConverter listTypeConverter = new ListTypeConverter(List.class) {
protected List newList(int pSize) {
return new ArrayList(pSize);
}
};
private static final TypeConverter vectorTypeConverter = new ListTypeConverter(Vector.class) {
protected List newList(int pSize) {
return new Vector(pSize);
}
};
private static class CastCheckingTypeConverter implements TypeConverter {
private final Class clazz;
CastCheckingTypeConverter(Class pClass) {
clazz = pClass;
}
public boolean isConvertable(Object pObject) {
return pObject == null || clazz.isAssignableFrom(pObject.getClass());
}
public Object convert(Object pObject) {
return pObject;
}
public Object backConvert(Object pObject) {
return pObject;
}
}
/** Returns a type converter for the given class.
*/
public TypeConverter getTypeConverter(Class pClass) {
if (void.class.equals(pClass)) {
return voidTypeConverter;
}
if (pClass.isAssignableFrom(boolean.class)) {
return primitiveBooleanTypeConverter;
}
if (pClass.isAssignableFrom(char.class)) {
return primitiveCharTypeConverter;
}
if (pClass.isAssignableFrom(byte.class)) {
return primitiveByteTypeConverter;
}
if (pClass.isAssignableFrom(short.class)) {
return primitiveShortTypeConverter;
}
if (pClass.isAssignableFrom(int.class)) {
return primitiveIntTypeConverter;
}
if (pClass.isAssignableFrom(long.class)) {
return primitiveLongTypeConverter;
}
if (pClass.isAssignableFrom(float.class)) {
return primitiveFloatTypeConverter;
}
if (pClass.isAssignableFrom(double.class)) {
return primitiveDoubleTypeConverter;
}
if (pClass.isAssignableFrom(String.class)) {
return stringTypeConverter;
}
if (pClass.isAssignableFrom(Boolean.class)) {
return booleanTypeConverter;
}
if (pClass.isAssignableFrom(Character.class)) {
return characterTypeConverter;
}
if (pClass.isAssignableFrom(Byte.class)) {
return byteTypeConverter;
}
if (pClass.isAssignableFrom(Short.class)) {
return shortTypeConverter;
}
if (pClass.isAssignableFrom(Integer.class)) {
return integerTypeConverter;
}
if (pClass.isAssignableFrom(Long.class)) {
return longTypeConverter;
}
if (pClass.isAssignableFrom(BigDecimal.class)) {
return bigDecimalTypeConverter;
}
if (pClass.isAssignableFrom(BigInteger.class)) {
return bigIntegerTypeConverter;
}
if (pClass.isAssignableFrom(Float.class)) {
return floatTypeConverter;
}
if (pClass.isAssignableFrom(Double.class)) {
return doubleTypeConverter;
}
if (pClass.isAssignableFrom(Date.class)) {
return dateTypeConverter;
}
if (pClass.isAssignableFrom(Calendar.class)) {
return calendarTypeConverter;
}
if (pClass.isAssignableFrom(Object[].class)) {
return objectArrayTypeConverter;
}
if (pClass.isAssignableFrom(List.class)) {
return listTypeConverter;
}
if (pClass.isAssignableFrom(Vector.class)) {
return vectorTypeConverter;
}
if (pClass.isAssignableFrom(Map.class)) {
return mapTypeConverter;
}
if (pClass.isAssignableFrom(Hashtable.class)) {
return hashTableTypeConverter;
}
if (pClass.isAssignableFrom(Properties.class)) {
return propertiesTypeConverter;
}
if (pClass.isAssignableFrom(byte[].class)) {
return byteArrayTypeConverter;
}
if (pClass.isAssignableFrom(Document.class)) {
return domTypeConverter;
}
if (Serializable.class.isAssignableFrom(pClass)) {
return new CastCheckingTypeConverter(pClass);
}
throw new IllegalStateException("Invalid parameter or result type: " + pClass.getName());
}
}
| Java |
/*
* 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.xmlrpc.common;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
/** Interface of an object, which is able to provide
* an XML stream, containing an XML-RPC request.
* Additionally, the object may also be used to
* write the response as an XML stream.
*/
public interface ServerStreamConnection {
/** Returns the connections input stream.
*/
InputStream newInputStream() throws IOException;
/** Returns the connections output stream.
*/
OutputStream newOutputStream() throws IOException;
/** Closes the connection, and frees resources.
*/
void close() throws IOException;
}
| Java |
/*
* 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.xmlrpc.client;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.XmlRpcRequest;
/**
* <p>A callback object that can wait up to a specified amount
* of time for the XML-RPC response. Suggested use is as follows:
* </p>
* <pre>
* // Wait for 10 seconds.
* TimingOutCallback callback = new TimingOutCallback(10 * 1000);
* XmlRpcClient client = new XmlRpcClient(url);
* client.executeAsync(methodName, aVector, callback);
* try {
* return callback.waitForResponse();
* } catch (TimeoutException e) {
* System.out.println("No response from server.");
* } catch (Exception e) {
* System.out.println("Server returned an error message.");
* }
* </pre>
*/
public class TimingOutCallback implements AsyncCallback {
/** This exception is thrown, if the request times out.
*/
public static class TimeoutException extends XmlRpcException {
private static final long serialVersionUID = 4875266372372105081L;
/** Creates a new instance with the given error code and
* error message.
*/
public TimeoutException(int pCode, String message) {
super(pCode, message);
}
}
private final long timeout;
private Object result;
private Throwable error;
private boolean responseSeen;
/** Waits the specified number of milliseconds for a response.
*/
public TimingOutCallback(long pTimeout) {
timeout = pTimeout;
}
/** Called to wait for the response.
* @throws InterruptedException The thread was interrupted.
* @throws TimeoutException No response was received after waiting the specified time.
* @throws Throwable An error was returned by the server.
*/
public synchronized Object waitForResponse() throws Throwable {
if (!responseSeen) {
wait(timeout);
if (!responseSeen) {
throw new TimeoutException(0, "No response after waiting for " + timeout + " milliseconds.");
}
}
if (error != null) {
throw error;
}
return result;
}
public synchronized void handleError(XmlRpcRequest pRequest, Throwable pError) {
responseSeen = true;
error = pError;
notify();
}
public synchronized void handleResult(XmlRpcRequest pRequest, Object pResult) {
responseSeen = true;
result = pResult;
notify();
}
}
| Java |
/*
* 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.xmlrpc.client;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
import javax.net.ssl.SSLSocketFactory;
/**
* A "light" HTTP transport implementation for Java 1.4.
*/
public class XmlRpcLite14HttpTransport extends XmlRpcLiteHttpTransport {
private SSLSocketFactory sslSocketFactory;
/**
* Creates a new instance.
* @param pClient The client controlling this instance.
*/
public XmlRpcLite14HttpTransport(XmlRpcClient pClient) {
super(pClient);
}
/**
* Sets the SSL Socket Factory to use for https connections.
*/
public SSLSocketFactory getSSLSocketFactory() {
return sslSocketFactory;
}
/**
* Returns the SSL Socket Factory to use for https connections.
*/
public void setSSLSocketFactory(SSLSocketFactory pSSLSocketFactory) {
sslSocketFactory = pSSLSocketFactory;
}
protected Socket newSocket(boolean pSSL, String pHostName, int pPort) throws UnknownHostException, IOException {
if (pSSL) {
SSLSocketFactory sslSockFactory = getSSLSocketFactory();
if (sslSockFactory == null) {
sslSockFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
}
return sslSockFactory.createSocket(pHostName, pPort);
} else {
return super.newSocket(pSSL, pHostName, pPort);
}
}
}
| Java |
/*
* 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.xmlrpc.client;
import javax.net.ssl.SSLSocketFactory;
/**
* Default implementation of an HTTP transport factory in Java 1.4, based
* on the {@link java.net.HttpURLConnection} class.
*/
public class XmlRpcSun14HttpTransportFactory extends XmlRpcTransportFactoryImpl {
private SSLSocketFactory sslSocketFactory;
/**
* Creates a new factory, which creates transports for the given client.
* @param pClient The client, which is operating the factory.
*/
public XmlRpcSun14HttpTransportFactory(XmlRpcClient pClient) {
super(pClient);
}
/**
* Sets the SSLSocketFactory to be used by transports.
* @param pSocketFactory The SSLSocketFactory to use.
*/
public void setSSLSocketFactory(SSLSocketFactory pSocketFactory) {
sslSocketFactory = pSocketFactory;
}
/**
* Returns the SSLSocketFactory to be used by transports.
*/
public SSLSocketFactory getSSLSocketFactory() {
return sslSocketFactory;
}
public XmlRpcTransport getTransport() {
XmlRpcSun14HttpTransport transport = new XmlRpcSun14HttpTransport(getClient());
transport.setSSLSocketFactory(sslSocketFactory);
return transport;
}
}
| Java |
/*
* 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.xmlrpc.client;
/** Default implementation of a HTTP transport factory, based on the
* {@link java.net.HttpURLConnection} class.
*/
public class XmlRpcSunHttpTransportFactory extends XmlRpcTransportFactoryImpl {
/** Creates a new factory, which creates transports for the given client.
* @param pClient The client, which is operating the factory.
*/
public XmlRpcSunHttpTransportFactory(XmlRpcClient pClient) {
super(pClient);
}
public XmlRpcTransport getTransport() {
return new XmlRpcSunHttpTransport(getClient());
}
}
| Java |
/*
* 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.xmlrpc.client;
import org.apache.xmlrpc.XmlRpcRequest;
/** A callback interface for an asynchronous XML-RPC call.
* @since 3.0
*/
public interface AsyncCallback {
/** Call went ok, handle result.
* @param pRequest The request being performed.
* @param pResult The result object, which was returned by the server.
*/
public void handleResult(XmlRpcRequest pRequest, Object pResult);
/** Something went wrong, handle error.
* @param pRequest The request being performed.
* @param pError The error being thrown.
*/
public void handleError(XmlRpcRequest pRequest, Throwable pError);
}
| Java |
/*
* 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.xmlrpc.client;
import org.apache.xmlrpc.common.XmlRpcRequestProcessorFactory;
/** Interface of a client configuration for local rpc calls. Local
* rpc calls are mainly useful for testing, because you don't need
* a running server.
*/
public interface XmlRpcLocalClientConfig extends XmlRpcClientConfig,
XmlRpcRequestProcessorFactory {
}
| Java |
/*
* 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.xmlrpc.client;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import org.apache.xmlrpc.XmlRpcConfig;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.XmlRpcRequest;
import org.apache.xmlrpc.common.TypeConverter;
import org.apache.xmlrpc.common.TypeConverterFactory;
import org.apache.xmlrpc.common.XmlRpcExtensionException;
import org.apache.xmlrpc.common.XmlRpcRequestProcessor;
/** The default implementation of a local transport.
*/
public class XmlRpcLocalTransport extends XmlRpcTransportImpl {
/** Creates a new instance.
* @param pClient The client, which creates the transport.
*/
public XmlRpcLocalTransport(XmlRpcClient pClient) {
super(pClient);
}
private boolean isExtensionType(Object pObject) {
if (pObject == null) {
return true;
} else if (pObject instanceof Object[]) {
Object[] objects = (Object[]) pObject;
for (int i = 0; i < objects.length; i++) {
if (isExtensionType(objects[i])) {
return true;
}
}
return false;
} else if (pObject instanceof Collection) {
for (Iterator iter = ((Collection) pObject).iterator(); iter.hasNext(); ) {
if (isExtensionType(iter.next())) {
return true;
}
}
return false;
} else if (pObject instanceof Map) {
Map map = (Map) pObject;
for (Iterator iter = map.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry entry = (Map.Entry) iter.next();
if (isExtensionType(entry.getKey()) || isExtensionType(entry.getValue())) {
return true;
}
}
return false;
} else {
return !(pObject instanceof Integer
|| pObject instanceof Date
|| pObject instanceof String
|| pObject instanceof byte[]
|| pObject instanceof Double);
}
}
public Object sendRequest(XmlRpcRequest pRequest) throws XmlRpcException {
XmlRpcConfig config = pRequest.getConfig();
if (!config.isEnabledForExtensions()) {
for (int i = 0; i < pRequest.getParameterCount(); i++) {
if (isExtensionType(pRequest.getParameter(i))) {
throw new XmlRpcExtensionException("Parameter " + i + " has invalid type, if isEnabledForExtensions() == false");
}
}
}
final XmlRpcRequestProcessor server = ((XmlRpcLocalClientConfig) config).getXmlRpcServer();
Object result;
try {
result = server.execute(pRequest);
} catch (XmlRpcException t) {
throw t;
} catch (Throwable t) {
throw new XmlRpcClientException("Failed to invoke method " + pRequest.getMethodName()
+ ": " + t.getMessage(), t);
}
if (!config.isEnabledForExtensions()) {
if (isExtensionType(result)) {
throw new XmlRpcExtensionException("Result has invalid type, if isEnabledForExtensions() == false");
}
}
if (result == null) {
return null;
}
final TypeConverterFactory typeConverterFactory = server.getTypeConverterFactory();
final TypeConverter typeConverter = typeConverterFactory.getTypeConverter(result.getClass());
return typeConverter.backConvert(result);
}
} | Java |
/*
* 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.xmlrpc.client;
import java.net.InetSocketAddress;
import java.net.Proxy;
/**
* Default implementation of an HTTP transport in Java 1.5, based on the
* {@link java.net.HttpURLConnection} class.
*/
public class XmlRpcSun15HttpTransportFactory extends XmlRpcSun14HttpTransportFactory {
private Proxy proxy;
/**
* Creates a new factory, which creates transports for the given client.
* @param pClient The client, which is operating the factory.
*/
public XmlRpcSun15HttpTransportFactory(XmlRpcClient pClient) {
super(pClient);
}
/**
* Sets the proxy to use.
* @param proxyHost The proxy hostname.
* @param proxyPort The proxy port number.
* @throws IllegalArgumentException if the proxyHost parameter is null or if
* the proxyPort parameter is outside the range of valid port values.
*/
public void setProxy(String proxyHost, int proxyPort) {
setProxy(new Proxy(Proxy.Type.HTTP,new InetSocketAddress(proxyHost,proxyPort)));
}
/**
* Sets the proxy to use.
* @param pProxy The proxy settings.
*/
public void setProxy(Proxy pProxy) {
proxy = pProxy;
}
public XmlRpcTransport getTransport() {
XmlRpcSun15HttpTransport transport = new XmlRpcSun15HttpTransport(getClient());
transport.setSSLSocketFactory(getSSLSocketFactory());
transport.setProxy(proxy);
return transport;
}
}
| Java |
/*
* 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.xmlrpc.client;
/** Interface of an object creating instances of
* {@link org.apache.xmlrpc.client.XmlRpcTransport}. The implementation
* is typically based on singletons.
*/
public interface XmlRpcTransportFactory {
/** Returns an instance of {@link XmlRpcTransport}. This may
* be a singleton, but the caller should not depend on that:
* A new instance may as well be created for any request.
* @return The configured transport.
*/
public XmlRpcTransport getTransport();
}
| Java |
/*
* 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.xmlrpc.client;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.XmlRpcRequest;
/** <p>Interface from XML-RPC to an underlying transport, most likely based on HTTP.</p>
* Replaces the interface <code>org.apache.xmlrpc.client</code> from Apache XML-RPC
* 2.0, which has actually been a stream based transport.
* @since 3.0
*/
public interface XmlRpcTransport {
/** Send an XML-RPC message. This method is called to send a message to the
* other party.
* @param pRequest The request being performed.
* @return Result object, if invoking the remote method was successfull.
* @throws XmlRpcException Performing the request failed.
*/
public Object sendRequest(XmlRpcRequest pRequest) throws XmlRpcException;
}
| Java |
/*
* 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.xmlrpc.client;
import org.apache.xmlrpc.XmlRpcRequestConfig;
/** This interface is being implemented by an Apache XML-RPC clients
* configuration object. Depending on the transport factory, a
* configuration object must implement additional methods. For
* example, an HTTP transport requires an instance of
* {@link org.apache.xmlrpc.client.XmlRpcHttpClientConfig}. A
* local transport requires an instance of
* {@link org.apache.xmlrpc.client.XmlRpcLocalClientConfig}.
*/
public interface XmlRpcClientConfig extends XmlRpcRequestConfig {
}
| Java |
/*
* 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.xmlrpc.client;
import java.io.IOException;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSocketFactory;
import org.apache.xmlrpc.XmlRpcRequest;
/**
* Default implementation of an HTTP transport in Java 1.4, based on the
* {@link java.net.HttpURLConnection} class. Adds support for the
* {@link Proxy} class.
*/
public class XmlRpcSun15HttpTransport extends XmlRpcSun14HttpTransport {
/**
* Creates a new instance.
* @param pClient The client controlling this instance.
*/
public XmlRpcSun15HttpTransport(XmlRpcClient pClient) {
super(pClient);
}
private Proxy proxy;
/**
* Sets the proxy to use.
*/
public void setProxy(Proxy pProxy) {
proxy = pProxy;
}
/**
* Returns the proxy to use.
*/
public Proxy getProxy() {
return proxy;
}
protected void initHttpHeaders(XmlRpcRequest pRequest)
throws XmlRpcClientException {
final XmlRpcHttpClientConfig config = (XmlRpcHttpClientConfig) pRequest.getConfig();
int connectionTimeout = config.getConnectionTimeout();
if (connectionTimeout > 0) {
getURLConnection().setConnectTimeout(connectionTimeout);
}
int replyTimeout = config.getReplyTimeout();
if (replyTimeout > 0) {
getURLConnection().setReadTimeout(replyTimeout);
}
super.initHttpHeaders(pRequest);
}
protected URLConnection newURLConnection(URL pURL) throws IOException {
final Proxy prox = getProxy();
final URLConnection conn = prox == null ? pURL.openConnection() : pURL.openConnection(prox);
final SSLSocketFactory sslSockFactory = getSSLSocketFactory();
if (sslSockFactory != null && conn instanceof HttpsURLConnection) {
((HttpsURLConnection)conn).setSSLSocketFactory(sslSockFactory);
}
return conn;
}
}
| Java |
/*
* 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.xmlrpc.client.util;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.lang.reflect.UndeclaredThrowableException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.common.TypeConverter;
import org.apache.xmlrpc.common.TypeConverterFactory;
import org.apache.xmlrpc.common.TypeConverterFactoryImpl;
import org.apache.xmlrpc.common.XmlRpcInvocationException;
/**
* <p>The {@link ClientFactory} is a useful tool for simplifying the
* use of Apache XML-RPC. The rough idea is as follows: All XML-RPC
* handlers are implemented as interfaces. The server uses the actual
* implementation. The client uses the {@link ClientFactory} to
* obtain an implementation, which is based on running XML-RPC calls.</p>
*/
public class ClientFactory {
private final XmlRpcClient client;
private final TypeConverterFactory typeConverterFactory;
private boolean objectMethodLocal;
/** Creates a new instance.
* @param pClient A fully configured XML-RPC client, which is
* used internally to perform XML-RPC calls.
* @param pTypeConverterFactory Creates instances of {@link TypeConverterFactory},
* which are used to transform the result object in its target representation.
*/
public ClientFactory(XmlRpcClient pClient, TypeConverterFactory pTypeConverterFactory) {
typeConverterFactory = pTypeConverterFactory;
client = pClient;
}
/** Creates a new instance. Shortcut for
* <pre>
* new ClientFactory(pClient, new TypeConverterFactoryImpl());
* </pre>
* @param pClient A fully configured XML-RPC client, which is
* used internally to perform XML-RPC calls.
* @see TypeConverterFactoryImpl
*/
public ClientFactory(XmlRpcClient pClient) {
this(pClient, new TypeConverterFactoryImpl());
}
/** Returns the factories client.
*/
public XmlRpcClient getClient() {
return client;
}
/** Returns, whether a method declared by the {@link Object
* Object class} is performed by the local object, rather than
* by the server. Defaults to true.
*/
public boolean isObjectMethodLocal() {
return objectMethodLocal;
}
/** Sets, whether a method declared by the {@link Object
* Object class} is performed by the local object, rather than
* by the server. Defaults to true.
*/
public void setObjectMethodLocal(boolean pObjectMethodLocal) {
objectMethodLocal = pObjectMethodLocal;
}
/**
* Creates an object, which is implementing the given interface.
* The objects methods are internally calling an XML-RPC server
* by using the factories client; shortcut for
* <pre>
* newInstance(Thread.currentThread().getContextClassLoader(),
* pClass)
* </pre>
*/
public Object newInstance(Class pClass) {
return newInstance(Thread.currentThread().getContextClassLoader(), pClass);
}
/** Creates an object, which is implementing the given interface.
* The objects methods are internally calling an XML-RPC server
* by using the factories client; shortcut for
* <pre>
* newInstance(pClassLoader, pClass, pClass.getName())
* </pre>
*/
public Object newInstance(ClassLoader pClassLoader, Class pClass) {
return newInstance(pClassLoader, pClass, pClass.getName());
}
/** Creates an object, which is implementing the given interface.
* The objects methods are internally calling an XML-RPC server
* by using the factories client.
* @param pClassLoader The class loader, which is being used for
* loading classes, if required.
* @param pClass Interface, which is being implemented.
* @param pRemoteName Handler name, which is being used when
* calling the server. This is used for composing the
* method name. For example, if <code>pRemoteName</code>
* is "Foo" and you want to invoke the method "bar" in
* the handler, then the full method name would be "Foo.bar".
*/
public Object newInstance(ClassLoader pClassLoader, final Class pClass, final String pRemoteName) {
return Proxy.newProxyInstance(pClassLoader, new Class[]{pClass}, new InvocationHandler(){
public Object invoke(Object pProxy, Method pMethod, Object[] pArgs) throws Throwable {
if (isObjectMethodLocal() && pMethod.getDeclaringClass().equals(Object.class)) {
return pMethod.invoke(pProxy, pArgs);
}
final String methodName;
if (pRemoteName == null || pRemoteName.length() == 0) {
methodName = pMethod.getName();
} else {
methodName = pRemoteName + "." + pMethod.getName();
}
Object result;
try {
result = client.execute(methodName, pArgs);
} catch (XmlRpcInvocationException e) {
Throwable t = e.linkedException;
if (t instanceof RuntimeException) {
throw t;
}
Class[] exceptionTypes = pMethod.getExceptionTypes();
for (int i = 0; i < exceptionTypes.length; i++) {
Class c = exceptionTypes[i];
if (c.isAssignableFrom(t.getClass())) {
throw t;
}
}
throw new UndeclaredThrowableException(t);
}
TypeConverter typeConverter = typeConverterFactory.getTypeConverter(pMethod.getReturnType());
return typeConverter.convert(result);
}
});
}
}
| Java |
/*
* 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.xmlrpc.client;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.XmlRpcRequest;
import org.apache.xmlrpc.common.XmlRpcStreamConfig;
import org.apache.xmlrpc.common.XmlRpcStreamRequestConfig;
import org.apache.xmlrpc.parser.XmlRpcResponseParser;
import org.apache.xmlrpc.serializer.XmlRpcWriter;
import org.apache.xmlrpc.util.SAXParsers;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
/** Implementation of a transport class, which is based on an output
* stream for sending the request and an input stream for receiving
* the response,
*/
public abstract class XmlRpcStreamTransport extends XmlRpcTransportImpl {
protected interface ReqWriter {
/**
* Writes the requests data to the given output stream.
* The method ensures, that the target is being closed.
*/
void write(OutputStream pStream) throws XmlRpcException, IOException, SAXException;
}
protected class ReqWriterImpl implements ReqWriter {
private final XmlRpcRequest request;
protected ReqWriterImpl(XmlRpcRequest pRequest) {
request = pRequest;
}
/** Writes the requests uncompressed XML data to the given
* output stream. Ensures, that the output stream is being
* closed.
*/
public void write(OutputStream pStream)
throws XmlRpcException, IOException, SAXException {
final XmlRpcStreamConfig config = (XmlRpcStreamConfig) request.getConfig();
try {
ContentHandler h = getClient().getXmlWriterFactory().getXmlWriter(config, pStream);
XmlRpcWriter xw = new XmlRpcWriter(config, h, getClient().getTypeFactory());
xw.write(request);
pStream.close();
pStream = null;
} finally {
if (pStream != null) { try { pStream.close(); } catch (Throwable ignore) {} }
}
}
}
protected class GzipReqWriter implements ReqWriter {
private final ReqWriter reqWriter;
protected GzipReqWriter(ReqWriter pReqWriter) {
reqWriter = pReqWriter;
}
public void write(OutputStream pStream) throws XmlRpcException, IOException, SAXException {
try {
GZIPOutputStream gStream = new GZIPOutputStream(pStream);
reqWriter.write(gStream);
pStream.close();
pStream = null;
} catch (IOException e) {
throw new XmlRpcException("Failed to write request: " + e.getMessage(), e);
} finally {
if (pStream != null) { try { pStream.close(); } catch (Throwable ignore) {} }
}
}
}
/** Creates a new instance on behalf of the given client.
*/
protected XmlRpcStreamTransport(XmlRpcClient pClient) {
super(pClient);
}
/** Closes the connection and ensures, that all resources are being
* released.
*/
protected abstract void close() throws XmlRpcClientException;
/** Returns, whether the response is gzip compressed.
* @param pConfig The clients configuration.
* @return Whether the response stream is gzip compressed.
*/
protected abstract boolean isResponseGzipCompressed(XmlRpcStreamRequestConfig pConfig);
/** Returns the input stream, from which the response is
* being read.
*/
protected abstract InputStream getInputStream() throws XmlRpcException;
protected boolean isCompressingRequest(XmlRpcStreamRequestConfig pConfig) {
return pConfig.isEnabledForExtensions()
&& pConfig.isGzipCompressing();
}
/**
* Creates a new instance of {@link ReqWriter}.
* @throws XmlRpcException Creating the instance failed.
* @throws IOException Creating the instance failed, because
* an {@link IOException} occurs.
* @throws SAXException Creating the instance failed, because
* the request could not be parsed.
*/
protected ReqWriter newReqWriter(XmlRpcRequest pRequest)
throws XmlRpcException, IOException, SAXException {
ReqWriter reqWriter = new ReqWriterImpl(pRequest);
if (isCompressingRequest((XmlRpcStreamRequestConfig) pRequest.getConfig())) {
reqWriter = new GzipReqWriter(reqWriter);
}
return reqWriter;
}
protected abstract void writeRequest(ReqWriter pWriter)
throws XmlRpcException, IOException, SAXException;
public Object sendRequest(XmlRpcRequest pRequest) throws XmlRpcException {
XmlRpcStreamRequestConfig config = (XmlRpcStreamRequestConfig) pRequest.getConfig();
boolean closed = false;
try {
ReqWriter reqWriter = newReqWriter(pRequest);
writeRequest(reqWriter);
InputStream istream = getInputStream();
if (isResponseGzipCompressed(config)) {
istream = new GZIPInputStream(istream);
}
Object result = readResponse(config, istream);
closed = true;
close();
return result;
} catch (IOException e) {
throw new XmlRpcException("Failed to read server's response: "
+ e.getMessage(), e);
} catch (SAXException e) {
Exception ex = e.getException();
if (ex != null && ex instanceof XmlRpcException) {
throw (XmlRpcException) ex;
}
throw new XmlRpcException("Failed to generate request: "
+ e.getMessage(), e);
} finally {
if (!closed) { try { close(); } catch (Throwable ignore) {} }
}
}
protected XMLReader newXMLReader() throws XmlRpcException {
return SAXParsers.newXMLReader();
}
protected Object readResponse(XmlRpcStreamRequestConfig pConfig, InputStream pStream) throws XmlRpcException {
InputSource isource = new InputSource(pStream);
XMLReader xr = newXMLReader();
XmlRpcResponseParser xp;
try {
xp = new XmlRpcResponseParser(pConfig, getClient().getTypeFactory());
xr.setContentHandler(xp);
xr.parse(isource);
} catch (SAXException e) {
throw new XmlRpcClientException("Failed to parse server's response: " + e.getMessage(), e);
} catch (IOException e) {
throw new XmlRpcClientException("Failed to read server's response: " + e.getMessage(), e);
}
if (xp.isSuccess()) {
return xp.getResult();
}
Throwable t = xp.getErrorCause();
if (t == null) {
throw new XmlRpcException(xp.getErrorCode(), xp.getErrorMessage());
}
if (t instanceof XmlRpcException) {
throw (XmlRpcException) t;
}
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
}
throw new XmlRpcException(xp.getErrorCode(), xp.getErrorMessage(), t);
}
}
| Java |
/*
* 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.xmlrpc.client;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.UndeclaredThrowableException;
import java.net.URL;
import java.util.Properties;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.XmlRpcRequest;
import org.apache.xmlrpc.util.HttpUtil;
import org.xml.sax.SAXException;
/** Abstract base implementation of an HTTP transport. Base class for the
* concrete implementations, like {@link org.apache.xmlrpc.client.XmlRpcSunHttpTransport},
* or {@link org.apache.xmlrpc.client.XmlRpcCommonsTransport}.
*/
public abstract class XmlRpcHttpTransport extends XmlRpcStreamTransport {
protected class ByteArrayReqWriter implements ReqWriter {
private final ByteArrayOutputStream baos = new ByteArrayOutputStream();
ByteArrayReqWriter(XmlRpcRequest pRequest)
throws XmlRpcException, IOException, SAXException {
new ReqWriterImpl(pRequest).write(baos);
}
protected int getContentLength() {
return baos.size();
}
public void write(OutputStream pStream) throws IOException {
try {
baos.writeTo(pStream);
pStream.close();
pStream = null;
} finally {
if (pStream != null) { try { pStream.close(); } catch (Throwable ignore) {} }
}
}
}
/** The user agent string.
*/
public static final String USER_AGENT;
static {
final String p = "XmlRpcClient.properties";
final URL url = XmlRpcHttpTransport.class.getResource(p);
if (url == null) {
throw new IllegalStateException("Failed to locate resource: " + p);
}
InputStream stream = null;
try {
stream = url.openStream();
final Properties props = new Properties();
props.load(stream);
USER_AGENT = props.getProperty("user.agent");
if (USER_AGENT == null || USER_AGENT.trim().length() == 0) {
throw new IllegalStateException("The property user.agent is not set.");
}
stream.close();
stream = null;
} catch (IOException e) {
throw new UndeclaredThrowableException(e, "Failed to load resource " + url + ": " + e.getMessage());
} finally {
if (stream != null) { try { stream.close(); } catch (Throwable t) { /* Ignore me */ } }
}
}
private String userAgent;
protected XmlRpcHttpTransport(XmlRpcClient pClient, String pUserAgent) {
super(pClient);
userAgent = pUserAgent;
}
protected String getUserAgent() { return userAgent; }
protected abstract void setRequestHeader(String pHeader, String pValue);
protected void setCredentials(XmlRpcHttpClientConfig pConfig)
throws XmlRpcClientException {
String auth;
try {
auth = HttpUtil.encodeBasicAuthentication(pConfig.getBasicUserName(),
pConfig.getBasicPassword(),
pConfig.getBasicEncoding());
} catch (UnsupportedEncodingException e) {
throw new XmlRpcClientException("Unsupported encoding: " + pConfig.getBasicEncoding(), e);
}
if (auth != null) {
setRequestHeader("Authorization", "Basic " + auth);
}
}
protected void setContentLength(int pLength) {
setRequestHeader("Content-Length", Integer.toString(pLength));
}
protected void setCompressionHeaders(XmlRpcHttpClientConfig pConfig) {
if (pConfig.isGzipCompressing()) {
setRequestHeader("Content-Encoding", "gzip");
}
if (pConfig.isGzipRequesting()) {
setRequestHeader("Accept-Encoding", "gzip");
}
}
protected void initHttpHeaders(XmlRpcRequest pRequest) throws XmlRpcClientException {
XmlRpcHttpClientConfig config = (XmlRpcHttpClientConfig) pRequest.getConfig();
setRequestHeader("Content-Type", "text/xml");
if(config.getUserAgent() != null)
setRequestHeader("User-Agent", config.getUserAgent());
else
setRequestHeader("User-Agent", getUserAgent());
setCredentials(config);
setCompressionHeaders(config);
}
public Object sendRequest(XmlRpcRequest pRequest) throws XmlRpcException {
initHttpHeaders(pRequest);
return super.sendRequest(pRequest);
}
protected boolean isUsingByteArrayOutput(XmlRpcHttpClientConfig pConfig) {
return !pConfig.isEnabledForExtensions()
|| !pConfig.isContentLengthOptional();
}
protected ReqWriter newReqWriter(XmlRpcRequest pRequest)
throws XmlRpcException, IOException, SAXException {
final XmlRpcHttpClientConfig config = (XmlRpcHttpClientConfig) pRequest.getConfig();
if (isUsingByteArrayOutput(config)) {
ByteArrayReqWriter reqWriter = new ByteArrayReqWriter(pRequest);
setContentLength(reqWriter.getContentLength());
if (isCompressingRequest(config)) {
return new GzipReqWriter(reqWriter);
}
return reqWriter;
} else {
return super.newReqWriter(pRequest);
}
}
}
| Java |
/*
* 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.xmlrpc.client;
import org.apache.xmlrpc.serializer.DefaultXMLWriterFactory;
import org.apache.xmlrpc.serializer.XmlWriterFactory;
/**
* This class is responsible to provide default settings.
*/
public class XmlRpcClientDefaults {
private static final XmlWriterFactory xmlWriterFactory = new DefaultXMLWriterFactory();
/**
* Creates a new transport factory for the given client.
*/
public static XmlRpcTransportFactory newTransportFactory(XmlRpcClient pClient) {
try {
return new XmlRpcSun15HttpTransportFactory(pClient);
} catch (Throwable t1) {
try {
return new XmlRpcSun14HttpTransportFactory(pClient);
} catch (Throwable t2) {
return new XmlRpcSunHttpTransportFactory(pClient);
}
}
}
/**
* Creates a new instance of {@link XmlRpcClientConfig}.
*/
public static XmlRpcClientConfig newXmlRpcClientConfig() {
return new XmlRpcClientConfigImpl();
}
/**
* Creates a new {@link XmlWriterFactory}.
*/
public static XmlWriterFactory newXmlWriterFactory() {
return xmlWriterFactory;
}
}
| Java |
/*
* 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.xmlrpc.client;
/** Abstract base implementation of a factory for stream transports.
*/
public abstract class XmlRpcStreamTransportFactory extends XmlRpcTransportFactoryImpl {
protected XmlRpcStreamTransportFactory(XmlRpcClient pClient) {
super(pClient);
}
}
| Java |
/*
* 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.xmlrpc.client;
import java.net.URL;
import org.apache.xmlrpc.common.XmlRpcHttpRequestConfig;
/** Extension of {@link org.apache.xmlrpc.client.XmlRpcClientConfig}
* for HTTP based transport. Provides details like server URL,
* user credentials, and so on.
*/
public interface XmlRpcHttpClientConfig extends XmlRpcHttpRequestConfig {
/** Returns the HTTP servers URL.
* @return XML-RPC servers URL; for example, this may be the URL of a
* servlet
*/
URL getServerURL();
/**
* Returns the user agent header to use
* @return the http user agent header to set when doing xmlrpc requests
*/
String getUserAgent();
}
| Java |
/*
* 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.xmlrpc.client;
import java.io.BufferedOutputStream;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.HttpVersion;
import org.apache.commons.httpclient.URI;
import org.apache.commons.httpclient.URIException;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.XmlRpcRequest;
import org.apache.xmlrpc.common.XmlRpcStreamConfig;
import org.apache.xmlrpc.common.XmlRpcStreamRequestConfig;
import org.apache.xmlrpc.util.HttpUtil;
import org.apache.xmlrpc.util.XmlRpcIOException;
import org.xml.sax.SAXException;
/** An HTTP transport factory, which is based on the Jakarta Commons
* HTTP Client.
*/
public class XmlRpcCommonsTransport extends XmlRpcHttpTransport {
/**
* Maximum number of allowed redirects.
*/
private static final int MAX_REDIRECT_ATTEMPTS = 100;
protected final HttpClient client;
private static final String userAgent = USER_AGENT + " (Jakarta Commons httpclient Transport)";
protected PostMethod method;
private int contentLength = -1;
private XmlRpcHttpClientConfig config;
/** Creates a new instance.
* @param pFactory The factory, which created this transport.
*/
public XmlRpcCommonsTransport(XmlRpcCommonsTransportFactory pFactory) {
super(pFactory.getClient(), userAgent);
HttpClient httpClient = pFactory.getHttpClient();
if (httpClient == null) {
httpClient = newHttpClient();
}
client = httpClient;
}
protected void setContentLength(int pLength) {
contentLength = pLength;
}
protected HttpClient newHttpClient() {
return new HttpClient();
}
protected void initHttpHeaders(XmlRpcRequest pRequest) throws XmlRpcClientException {
config = (XmlRpcHttpClientConfig) pRequest.getConfig();
method = newPostMethod(config);
super.initHttpHeaders(pRequest);
if (config.getConnectionTimeout() != 0)
client.getHttpConnectionManager().getParams().setConnectionTimeout(config.getConnectionTimeout());
if (config.getReplyTimeout() != 0)
client.getHttpConnectionManager().getParams().setSoTimeout(config.getReplyTimeout());
method.getParams().setVersion(HttpVersion.HTTP_1_1);
}
protected PostMethod newPostMethod(XmlRpcHttpClientConfig pConfig) {
return new PostMethod(pConfig.getServerURL().toString());
}
protected void setRequestHeader(String pHeader, String pValue) {
method.setRequestHeader(new Header(pHeader, pValue));
}
protected boolean isResponseGzipCompressed() {
Header h = method.getResponseHeader( "Content-Encoding" );
if (h == null) {
return false;
} else {
return HttpUtil.isUsingGzipEncoding(h.getValue());
}
}
protected InputStream getInputStream() throws XmlRpcException {
try {
checkStatus(method);
return method.getResponseBodyAsStream();
} catch (HttpException e) {
throw new XmlRpcClientException("Error in HTTP transport: " + e.getMessage(), e);
} catch (IOException e) {
throw new XmlRpcClientException("I/O error in server communication: " + e.getMessage(), e);
}
}
protected void setCredentials(XmlRpcHttpClientConfig pConfig) throws XmlRpcClientException {
String userName = pConfig.getBasicUserName();
if (userName != null) {
String enc = pConfig.getBasicEncoding();
if (enc == null) {
enc = XmlRpcStreamConfig.UTF8_ENCODING;
}
client.getParams().setParameter(HttpMethodParams.CREDENTIAL_CHARSET, enc);
Credentials creds = new UsernamePasswordCredentials(userName, pConfig.getBasicPassword());
AuthScope scope = new AuthScope(null, AuthScope.ANY_PORT, null, AuthScope.ANY_SCHEME);
client.getState().setCredentials(scope, creds);
client.getParams().setAuthenticationPreemptive(true);
}
}
protected void close() throws XmlRpcClientException {
method.releaseConnection();
}
protected boolean isResponseGzipCompressed(XmlRpcStreamRequestConfig pConfig) {
Header h = method.getResponseHeader( "Content-Encoding" );
if (h == null) {
return false;
} else {
return HttpUtil.isUsingGzipEncoding(h.getValue());
}
}
protected boolean isRedirectRequired() {
switch (method.getStatusCode()) {
case HttpStatus.SC_MOVED_TEMPORARILY:
case HttpStatus.SC_MOVED_PERMANENTLY:
case HttpStatus.SC_SEE_OTHER:
case HttpStatus.SC_TEMPORARY_REDIRECT:
return true;
default:
return false;
}
}
protected void resetClientForRedirect()
throws XmlRpcException {
//get the location header to find out where to redirect to
Header locationHeader = method.getResponseHeader("location");
if (locationHeader == null) {
throw new XmlRpcException("Invalid redirect: Missing location header");
}
String location = locationHeader.getValue();
URI redirectUri = null;
URI currentUri = null;
try {
currentUri = method.getURI();
String charset = currentUri.getProtocolCharset();
redirectUri = new URI(location, true, charset);
method.setURI(redirectUri);
} catch (URIException ex) {
throw new XmlRpcException(ex.getMessage(), ex);
}
//And finally invalidate the actual authentication scheme
method.getHostAuthState().invalidate();
}
protected void writeRequest(final ReqWriter pWriter) throws XmlRpcException {
method.setRequestEntity(new RequestEntity(){
public boolean isRepeatable() { return true; }
public void writeRequest(OutputStream pOut) throws IOException {
try {
/* Make sure, that the socket is not closed by replacing it with our
* own BufferedOutputStream.
*/
OutputStream ostream;
if (isUsingByteArrayOutput(config)) {
// No need to buffer the output.
ostream = new FilterOutputStream(pOut){
public void close() throws IOException {
flush();
}
};
} else {
ostream = new BufferedOutputStream(pOut){
public void close() throws IOException {
flush();
}
};
}
pWriter.write(ostream);
} catch (XmlRpcException e) {
throw new XmlRpcIOException(e);
} catch (SAXException e) {
throw new XmlRpcIOException(e);
}
}
public long getContentLength() { return contentLength; }
public String getContentType() { return "text/xml"; }
});
try {
int redirectAttempts = 0;
for (;;) {
client.executeMethod(method);
if (!isRedirectRequired()) {
break;
}
if (redirectAttempts++ > MAX_REDIRECT_ATTEMPTS) {
throw new XmlRpcException("Too many redirects.");
}
resetClientForRedirect();
}
} catch (XmlRpcIOException e) {
Throwable t = e.getLinkedException();
if (t instanceof XmlRpcException) {
throw (XmlRpcException) t;
} else {
throw new XmlRpcException("Unexpected exception: " + t.getMessage(), t);
}
} catch (IOException e) {
throw new XmlRpcException("I/O error while communicating with HTTP server: " + e.getMessage(), e);
}
}
/**
* Check the status of the HTTP request and throw an XmlRpcHttpTransportException if it
* indicates that there is an error.
* @param pMethod the method that has been executed
* @throws XmlRpcHttpTransportException if the status of the method indicates that there is an error.
*/
private void checkStatus(HttpMethod pMethod) throws XmlRpcHttpTransportException {
final int status = pMethod.getStatusCode();
// All status codes except SC_OK are handled as errors. Perhaps some should require special handling (e.g., SC_UNAUTHORIZED)
if (status < 200 || status > 299) {
throw new XmlRpcHttpTransportException(status, pMethod.getStatusText());
}
}
}
| Java |
/*
* 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.xmlrpc.client;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.XmlRpcRequest;
import org.apache.xmlrpc.common.XmlRpcStreamRequestConfig;
import org.apache.xmlrpc.util.HttpUtil;
import org.xml.sax.SAXException;
/** Default implementation of an HTTP transport, based on the
* {@link java.net.HttpURLConnection} class.
*/
public class XmlRpcSunHttpTransport extends XmlRpcHttpTransport {
private static final String userAgent = USER_AGENT + " (Sun HTTP Transport)";
private URLConnection conn;
/** Creates a new instance.
* @param pClient The client controlling this instance.
*/
public XmlRpcSunHttpTransport(XmlRpcClient pClient) {
super(pClient, userAgent);
}
protected URLConnection newURLConnection(URL pURL) throws IOException {
return pURL.openConnection();
}
/**
* For use by subclasses.
*/
protected URLConnection getURLConnection() {
return conn;
}
public Object sendRequest(XmlRpcRequest pRequest) throws XmlRpcException {
XmlRpcHttpClientConfig config = (XmlRpcHttpClientConfig) pRequest.getConfig();
try {
final URLConnection c = conn = newURLConnection(config.getServerURL());
c.setUseCaches(false);
c.setDoInput(true);
c.setDoOutput(true);
} catch (IOException e) {
throw new XmlRpcException("Failed to create URLConnection: " + e.getMessage(), e);
}
return super.sendRequest(pRequest);
}
protected void setRequestHeader(String pHeader, String pValue) {
getURLConnection().setRequestProperty(pHeader, pValue);
}
protected void close() throws XmlRpcClientException {
final URLConnection c = getURLConnection();
if (c instanceof HttpURLConnection) {
((HttpURLConnection) c).disconnect();
}
}
protected boolean isResponseGzipCompressed(XmlRpcStreamRequestConfig pConfig) {
return HttpUtil.isUsingGzipEncoding(getURLConnection().getHeaderField("Content-Encoding"));
}
protected InputStream getInputStream() throws XmlRpcException {
try {
URLConnection connection = getURLConnection();
if ( connection instanceof HttpURLConnection ) {
HttpURLConnection httpConnection = (HttpURLConnection) connection;
int responseCode = httpConnection.getResponseCode();
if (responseCode < 200 || responseCode > 299) {
throw new XmlRpcHttpTransportException(responseCode, httpConnection.getResponseMessage());
}
}
return connection.getInputStream();
} catch (IOException e) {
throw new XmlRpcException("Failed to create input stream: " + e.getMessage(), e);
}
}
protected void writeRequest(ReqWriter pWriter) throws IOException, XmlRpcException, SAXException {
pWriter.write(getURLConnection().getOutputStream());
}
} | Java |
/*
* 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.xmlrpc.client;
import javax.net.ssl.SSLSocketFactory;
/**
* Java 1.4 specific factory for the lite HTTP transport,
* {@link org.apache.xmlrpc.client.XmlRpcLiteHttpTransport}.
*/
public class XmlRpcLite14HttpTransportFactory extends XmlRpcLiteHttpTransportFactory {
private SSLSocketFactory sslSocketFactory;
/**
* Creates a new instance.
* @param pClient The client, which will invoke the factory.
*/
public XmlRpcLite14HttpTransportFactory(XmlRpcClient pClient) {
super(pClient);
}
/**
* Sets the SSL Socket Factory to use for https connections.
*/
public SSLSocketFactory getSSLSocketFactory() {
return sslSocketFactory;
}
/**
* Returns the SSL Socket Factory to use for https connections.
*/
public void setSSLSocketFactory(SSLSocketFactory pSSLSocketFactory) {
sslSocketFactory = pSSLSocketFactory;
}
public XmlRpcTransport getTransport() {
XmlRpcLite14HttpTransport transport = new XmlRpcLite14HttpTransport(getClient());
transport.setSSLSocketFactory(sslSocketFactory);
return transport;
}
}
| Java |
/*
* 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.xmlrpc.client;
import org.apache.xmlrpc.XmlRpcException;
/** <p>This is thrown by many of the client classes if an error occured processing
* and XML-RPC request or response due to client side processing. This exception
* will wrap a cause exception in the JDK 1.4 style.</p>
* <p>This class replaces the class <code>org.apache.xmlrpc.XmlRpcClientException</code>
* from Apache XML-RPC 2.0</p>
* @since 3.0
*/
public class XmlRpcClientException extends XmlRpcException {
private static final long serialVersionUID = 3545798797134608691L;
/**
* Create an XmlRpcClientException with the given message and
* underlying cause exception.
*
* @param pMessage the message for this exception.
* @param pCause the cause of the exception.
*/
public XmlRpcClientException(String pMessage, Throwable pCause) {
super(0, pMessage, pCause);
}
}
| Java |
/*
* 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.xmlrpc.client;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSocketFactory;
/**
* Default implementation of an HTTP transport in Java 1.4, based on the
* {@link java.net.HttpURLConnection} class. Adds support for the
* {@link SSLSocketFactory}.
*/
public class XmlRpcSun14HttpTransport extends XmlRpcSunHttpTransport {
private SSLSocketFactory sslSocketFactory;
/**
* Creates a new instance.
* @param pClient The client controlling this instance.
*/
public XmlRpcSun14HttpTransport(XmlRpcClient pClient) {
super(pClient);
}
/**
* Sets the SSLSocketFactory used to create secure sockets.
* @param pSocketFactory The SSLSocketFactory to use.
*/
public void setSSLSocketFactory(SSLSocketFactory pSocketFactory) {
sslSocketFactory = pSocketFactory;
}
/**
* Returns the SSLSocketFactory used to create secure sockets.
*/
public SSLSocketFactory getSSLSocketFactory() {
return sslSocketFactory;
}
protected URLConnection newURLConnection(URL pURL) throws IOException {
final URLConnection conn = super.newURLConnection(pURL);
final SSLSocketFactory sslSockFactory = getSSLSocketFactory();
if ((sslSockFactory != null) && (conn instanceof HttpsURLConnection))
((HttpsURLConnection)conn).setSSLSocketFactory(sslSockFactory);
return conn;
}
}
| Java |
/*
* 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.xmlrpc.client;
import java.util.List;
import org.apache.xmlrpc.XmlRpcRequest;
import org.apache.xmlrpc.XmlRpcRequestConfig;
/** Default implementation of
* {@link org.apache.xmlrpc.XmlRpcRequest}.
*/
public class XmlRpcClientRequestImpl implements XmlRpcRequest {
private static final Object[] ZERO_PARAMS = new Object[0];
private final XmlRpcRequestConfig config;
private final String methodName;
private final Object[] params;
/** Creates a new instance.
* @param pConfig The request configuration.
* @param pMethodName The method name being performed.
* @param pParams The parameters.
* @throws NullPointerException One of the parameters is null.
*/
public XmlRpcClientRequestImpl(XmlRpcRequestConfig pConfig,
String pMethodName, Object[] pParams) {
config = pConfig;
if (config == null) {
throw new NullPointerException("The request configuration must not be null.");
}
methodName = pMethodName;
if (methodName == null) {
throw new NullPointerException("The method name must not be null.");
}
params = pParams == null ? ZERO_PARAMS : pParams;
}
/** Creates a new instance.
* @param pConfig The request configuration.
* @param pMethodName The method name being performed.
* @param pParams The parameters.
* @throws NullPointerException The method name or the parameters are null.
*/
public XmlRpcClientRequestImpl(XmlRpcRequestConfig pConfig,
String pMethodName, List pParams) {
this(pConfig, pMethodName, pParams == null ? null : pParams.toArray());
}
public String getMethodName() { return methodName; }
public int getParameterCount() { return params.length; }
public Object getParameter(int pIndex) { return params[pIndex]; }
public XmlRpcRequestConfig getConfig() { return config; }
}
| Java |
/*
* 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.xmlrpc.client;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.XmlRpcRequest;
import org.apache.xmlrpc.common.LocalStreamConnection;
import org.apache.xmlrpc.common.XmlRpcStreamRequestConfig;
import org.apache.xmlrpc.common.XmlRpcStreamRequestProcessor;
import org.xml.sax.SAXException;
/** Another local transport for debugging and testing. This one is
* similar to the {@link org.apache.xmlrpc.client.XmlRpcLocalTransport},
* except that it adds request serialization. In other words, it is
* particularly well suited for development and testing of XML serialization
* and parsing.
*/
public class XmlRpcLocalStreamTransport extends XmlRpcStreamTransport {
private final XmlRpcStreamRequestProcessor localServer;
private LocalStreamConnection conn;
private XmlRpcRequest request;
/** Creates a new instance.
* @param pClient The client, which is controlling the transport.
* @param pServer An instance of {@link XmlRpcStreamRequestProcessor}.
*/
public XmlRpcLocalStreamTransport(XmlRpcClient pClient,
XmlRpcStreamRequestProcessor pServer) {
super(pClient);
localServer = pServer;
}
protected boolean isResponseGzipCompressed(XmlRpcStreamRequestConfig pConfig) {
return pConfig.isGzipRequesting();
}
protected void close() throws XmlRpcClientException {
}
protected InputStream getInputStream() throws XmlRpcException {
localServer.execute(conn.getConfig(), conn.getServerStreamConnection());
return new ByteArrayInputStream(conn.getResponse().toByteArray());
}
protected ReqWriter newReqWriter(XmlRpcRequest pRequest)
throws XmlRpcException, IOException, SAXException {
request = pRequest;
return super.newReqWriter(pRequest);
}
protected void writeRequest(ReqWriter pWriter)
throws XmlRpcException, IOException, SAXException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
pWriter.write(baos);
XmlRpcStreamRequestConfig config = (XmlRpcStreamRequestConfig) request.getConfig();
conn = new LocalStreamConnection(config, new ByteArrayInputStream(baos.toByteArray()));
}
}
| Java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.